Site hosted by Angelfire.com: Build your free website today!

Moving from Python 2.7 to 3- Some pros & cons


It has been quite some time that Python 3 has been introduced in the software community, but due to some technical glitches, it was not widely accepted. Earlier, it did not have the basic Python libraries like SciPy and NumPy but now they have been imported. In fact, it is an incremental release and that is why the casual programmers may not have many new features to use. But it has now ironed out the glitches as well as quirks which were there in the earlier versions, making the syntax consistent. So before moving to version 3, here are some pros and cons to know about.

Pros

python developmentUsing compatible syntax- There are many common features between versions 2.7 and 3 due to backporting which essentially allows you to use them in the old scripts, subsequently making the transition very easy. Like % operator that works in version 3; only the format method is different, and that gives increased flexibility.

Unicode support- The version’s text model has been revised which makes the primary string type totally Unicode-capable. Thus the models used in Unicode-capable Windows APIs, JVM, .NET CLR, etc. and Python 3 are brought closer. Its interpreter core is more tolerant to paths containing Unicode characters, which leads to less chances of problems when running scripts on Windows from home directory if, for example, the user name has non-ASCII characters. In fact, the support is more deeply embedded in the language itself. Since a huge variety of Unicode characters are now allowed, developers can use other languages, apart from English when naming; they do not have to use names which suit the fixed character set.

Set literals- Sets in the version have new literal syntax. {1, 2, 3} can be written instead of the set([1, 2, 3)]; the former is quite clean. In fact, both work perfectly, but using the new one gives less problems.

Abstract base classes- Support to make abstract base classes is contained by abc module; in it a property or method may be marked as “abstract” on base classes and implemented in subclasses. This is for definition of interfaces with the creation of classes which has no concrete method(s). One example of the concept is the mathematical class hierarchy.

Cons

Using ported libraries- The pure libraries may be converted semi-automatically to Python 3 but those depending on C extensions are really hard to port. Many libraries have been already ported, but there are some which have not been ported yet. However, this may not be of much problem if the project is small.However, in case of large scale projects this might pose a problem.

Differences in builtin functions- All functions of the previous version are not compatible or rather related to the Python 3 counterparts. Like when you use filter function, an iterator is returned in version 3 but the previous versions return a list. The same is applicable for .keys method.

Filesystem access- It is assumed by the software that all the filesystems have encoding, but then as a matter of fact, there is no encoding in many Linux systems as well as OS X. In fact, different rules for Unicode normalization are applied for filesystem on OS X than for applications. So the filename has to be normalized manually to separate encoding when filenames have to be compared in file system.

Beginners in the world of programming can benefit if they learn Python 3, especially if they do not know C. All in all, there is no huge difference between the implementation of Python 2.7 and 3. In fact, the usage of version 3 seems to be a complicated procedure for many, especially if the project is a big one and there is less time for unit testing. When unit testing is conducted the ultimate code turns out to be well tested as well as reproducable. Porting to Python 3 will yield in plenty of minor and innocent changes, but this will make it more dangerous, making it necessary to test particular and individual functions in the scripts. This will ultimately lead to profit in the long run, but you will have to waste some of your precious time which could have been devoted in bettering the application and other such things.

You can hire programmers from top custom python development company who can help you build products within allocated budgets and time schedules.

We provide python development services. If you would like to hire python developers from our team, please get in touch with us at Mindfire Solutions.