Is Python worth all the hype?
Short answer: It is not amazing imho but it is popular enough that it is probably worth learning.
I thought as a die-in-the-wool C# developer, I would see what all the fuss was about with Python. Like many languages, it espouses such adjectives as "cool", "fun" and the ubiquitous "removes all mess and only leaves what is important" making it "much closer to natural language".
The reality that I expected, and then found, was that like most languages, it simply removes some syntactic sugar and replaces it with others. It is quite a neat language and has the advantage of being built from the ground up so should have really capitalised on that, but also like most languages, it suffers from version changes which have polluted the idealistic first release of the language.
There are some inconsistencies and strange choices, which I describe below.
I thought as a die-in-the-wool C# developer, I would see what all the fuss was about with Python. Like many languages, it espouses such adjectives as "cool", "fun" and the ubiquitous "removes all mess and only leaves what is important" making it "much closer to natural language".
The reality that I expected, and then found, was that like most languages, it simply removes some syntactic sugar and replaces it with others. It is quite a neat language and has the advantage of being built from the ground up so should have really capitalised on that, but also like most languages, it suffers from version changes which have polluted the idealistic first release of the language.
There are some inconsistencies and strange choices, which I describe below.
- Python makes a big deal about removing curly brackets found in the C family of languages, which are used to delimit blocks. Apparently these are just cruft that makes code harder to read. One man's cruft, however, is another's delimiter. Python still requires blocks, of course and these are instead created with a combination of a colon and indentation. It's symbolically identical to using a single opening brace, it just happens to be a colon. I'm not sure why the colon is necessary since indentation is blocking the code but hey , I'm a newb.
- A second thing about indentation is that using non-visible characters for syntax correctness is fraught with problems, especially for newbs. I once copied and pasted some hello world code into a local file and tried to build it and got some error. Why? One was tabs and one was spaces. You can use either but they need to be consistent, it would have been much more helpful to decree one or the other but I suspect that the war between tabs and spaces was best avoided. I find calling a language "easy" a bit rich if the first thing a newb has to do is set their editor to replace all tabs with spaces just to compile a 1 line program.
- Python is not statically typed, it is inferred, which is fine. But then enter the list and the dictionary and they need separate syntax to create. A list with square brackets and a dictionary with curly ones. PHP manages with the same brackets but for some reason Python doesn't. There is nothing obvious about this, it is something you simply have to learn. In most other languages if I told you that a list is var myList = new List() and then asked you how you thought a Dictionary would be created, you would be correct!
- Python has a strange mix of built-in functions and object functions. For example, len() is a built-in function you would call length = len(mystring) whereas if you wanted to convert a string to lower, you would call mystring.tolower() not really consistent!
- How about removing an item from a list? list.remove('item') and on a dictionary? del dictionary['item'] - Hmm!
- A nice generic for loop? Nope, for is actually "foreach" and in most cases works as expected, for item in items: but what happens when you do it on a dictionary? You get the keys back, which is a design decision but is not completely obvious. In C#, you can foreach dictionary.Keys or dictionary.Values, which is much clearer imho
- slice(first,last) includes the first index but excludes the last. It appears that this is for some kind of neatness that slice(1,3) + slice(3,10) would return the whole string but that is subtle, I don't think I have ever needed that fact in other programs I have written and, again, it would seem illogical to a newb who would expect that slice(1,2) would return 2 characters and not 1!
- There is a big inconsistency over the language about what it means to be loosely typed and what it means to be strongly typed and safe. In most loosely typed languages, one of the benefits is that you do not have to work hard to assign or compare values. A numeric 1 would be equal to a string "1" because is most cases, that's what you would expect. In strongly typed languages, they would not be equal and would either fail at compile time (most of the time) or if using some kind of loose type at runtime with an exception. That is what strongly typed languages are for! If you are comparing a string with a number, convert one first! But in Python, you get a weird balance. It pretends to be friendly by being loosely typed but then throws exceptions for normal things like comparing numbers and different types of strings.
- No ++ operator :-(