Python Forum
Python 2 vs Python 3, developers should be more coherent!!!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python 2 vs Python 3, developers should be more coherent!!!
#1
As an experienced developer in Python 2 & 3, I would like to give Python developer team some significant comments.
It is understood that we all want to make Python better, more efficient and more robust to handle the ever growing algorithmic complexities in real life. Thus, for every change you are going to make to the language, I hope you could think over it very carefully. I also understand that different people have different ideas and opinions, sometimes they don't agree with each other, but then you should try to think of how to make a compromise w.r.t the majority, instead of just changing it at your own will.

Regarding the differences between Python 2 & 3, Sebastian Raschka (sebastianraschka.com/Articles/2014_python_2_3_key_diff.html) has given a very comprehensive and in-depth comparison. And I will base my comments on that list of differences:
  1. The print function. The print statement in Python 2, even though it is not as powerful as the print function in Python3 (Python3 can specify the ending character), it is much more convenient in most cases: programmers do not need to type the (), which involves holding the shift key; for IO direction, ">>fp" is much simpler than typing "file=fp,"; for space ending, "," is much simpler than "end=' ',". Changing the print statement into a function will break compatibility on old codes. So how to incorporate your new idea in print function while preserving the old print statement? Very simple, you keep the print statement and add a printf function which does what Python3 print function do.
  2. Integer division. I do understand that in Python2 it is very annoying to type "float(a)/b" when you want to get floating-point value out of integer variables a and b. But if you do change that, you should realize that it actually breaks the systematicity of the programming language, i.e., addition, subtraction and multiplication between two integers all give rise to an integer value, so why division is an exception? Also, sometimes when you do need integer division, then you need to type int(a/b) instead. As a compromise, I suggest to use ./ to perform floating point division, it won't cause problems with 5./6 because both (5.)/6 and 5(./)6 will give floating-point values. Furthermore, the // operator in Python2 is redundant with math.floor(). So perhaps you can put all the 3 functions: ceil(), floor(), and round() into global namespace.
  3. Unicode. I have no objection of changing the default plain string to utf-8, but perhaps you can keep both u'' and b'' for backward compatibility.
  4. xrange. Beginners tend to use range only in a for loops, e.g., "for i in range(10)". But have you ever considered passing a range list into a function, i.e., I want to get a list [1,2,3,4,5]. Then, compare the two: {Python2 using range(5) and xrange(5)} vs {Python3 using list(range(5)) and range(5)}, which is simpler? I think if you want to highlight the iterator version of range, zip, etc., you may want to consider irange, izip, etc.
    (Implementing the __contains__ method for range or xrange is quite straight forward, and thus should not cause any compatibility problem)
  5. Raising exceptions. Python2 is more robust that it supports both syntax "raise IOError, 'file error'" and "raise IOError('file error')", so why do you change it away? I hardly consider this as an improvement.
  6. The next() function and .next() method. I do understand that you want to make all builtin class member functions to look consistent, i.e., __func__, so you replaced the A.next() by A.__next__(). This is perfectly okay. But for compatibility, maybe you can create a default .next() method for every class and initialize it to point to .__next__() method. So next(A) or A.next() or A.__next__(), either way works. Btw, A.next() is more readable than A.__next__(), isn't it?
  7. For-loop variables and the global namespace leak. This is good for some programmers. But in terms of functionality, if I want the last covered item of [func(i) for i in arbituary_iterable], where the last valid element of the arbituary_iterable might not be that easy to get, e.g. arbituary_iterable is an iterator, or func(i) throws exception for some intermediate value i, and I want to know which i causes the exception, then Python2 is still easier.
  8. Comparing unorderable types. This change is elegant. It can review a lot of potential and silent bugs. And I don't think this will cause a lot of incompatibilities when porting from Python2 to Python3.
  9. Parsing user inputs via input(). You kind of eliminated the use of automatic type detection in Python2. But in terms of compatibility, I hardly consider this as an improvement. However, you do have a point because an input of '20' can be interpreted as either an integer 20, a floating point value 20.0, or a string u'20'. So as a compromise, I suggest to add an optional option in the input function, e.g., input('enter a number: ', type=int/float/str/auto), similar to the case of of add_argument function in argparse.
  10. Returning iterable objects instead of lists. As I mentioned previously, sometimes we do need to get the list object instead of the iterator object. Thus, the best solution is to keep both versions instead of performing an explicit list(...) function call. Thus, I would suggest creating both the list version (lrange, lzip, lmap, lfilter) and iterator version (irange, izip, imap, ifilter) and map the default (range, zip, map, filter) to one of these two, typically the list version for compatibility.
  11. Banker’s Rounding. This change is for convenience only. It is okay. But for compatibility, I would suggest to add a round2int function to explicitly round a value to integer.

In general, if you had been cautious enough in making compromises and considerations, I do not think that migrating from Python2 to Python3 should incur that many incompatibilities as what is happening now. To make a programming language better, you developers should be more cohesive and considerate in solving key issues (such as execution speed, multi-core multi-threading (GIL)) rather than enforcing your own preferential style and introduce numerous incompatibilities, and then old codes cannot run, and then efforts are needed to convert old codes into the new format. I do appreciate your efforts in adding new operators such as matrix multiplication '@', but those can be easily added on top of Python2 as well.

At last, I hope the developers can be more coherent in improving Python, only so can we together make Python better! Cool
Reply
#2
python2.x is soon to be dead. They already extended support from 2015 to 2020. But i doubt they are going to do it again. There are no more features since 2015, just bug fixes. Almost all main 3rd party libraries support 3.x. The fact that 2020 is the aimed year of death for python2.x you should switch to 3.x now, not wait until 2020. The time has passed to move to 3.x.
https://pythonclock.org/

Quote:such as execution speed
I never really have a problem with speed in python. All the times i have seen others have issues, it is in their coding, in which would occur in any language, including C/C++ if they coded it that way. And then they blame the bottleneck issue on python.
Recommended Tutorials:
Reply
#3
I'm confused, what point are you trying to get across? 

Python3 wasn't just a few personal preferences, and it wasn't hastily done.  It was under development for years, until it represented the language GvR wanted.
And if your goal is for developers of the language itself (instead of consumers of that language) to consider undoing the changes from python3, that ...
a) isn't going to happen (it was released 9 years ago, after all), and
b) they don't even view this forum, so they won't see it anyway.
Reply
#4
These are the same old tired complaints we've been hearing for years. Python 3.x is here, deal with it. It's not a big or even medium problem unless you have a huge code base in 2.x. And if you do have a huge code base in 2.x, you've had nine years to upgrade it.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#5
Many of the decisions in Python 3 improved the language much and remove old wrong decisions. For example the use of iterators and the change of the range function was a good step. You should read the Zen of Python. Explicit is better than implicit. It fits perfectly together with generators. A pure function should never define which data type it returns. You define outside of the function which datatype you need. When I need an set for an operation, why should I return in the first place a list when I need a set.

Also the Unicode support is good, when you understand the difference between bytes and strings. In Python 2 Unicode was a huge mess. There happened also much implicit encoding and decoding. You can't do this mistake in Python 3.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  certifications for Python developers isarkhan95 3 65,928 Apr-07-2020, 07:57 PM
Last Post: micseydel
  How do you find freelance Python Developers? officeace 3 2,667 Dec-23-2019, 05:29 PM
Last Post: DimaBereza
  Official PSF Python Developers Survey 2018 buran 1 2,552 Feb-06-2019, 08:48 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020