2012/08/13

Python Learning of the Day : Dive into Python 3

As a big fan of Python 3 (Unicode out of the box, more logical behavior of almost everything in general, etc) I can't wait to be using print() instead of print more often.  So I'm reading Dive into Python 3, besides the fact I forget how to write most of a language whenever I go a few weeks out of practice, and the fact my Python education was probably the least comprehensive of my college languages I experienced (CS120 never even got to classes with Python) I still love the language, even if I hate dynamic languages for the obfuscated bug testing required in them.

The syntax is so clean, and I do my interview street challenges in python every time (even if they still use 2.7) and it is astounding how much brevity and clarity can be stuffed into a small package.  For the Evernote Codesprint, as an example, I had a problem that would finish in Python in 16.15 seconds and the time limit was 16.  I tried some rough optimizations, but the way I wrote it used a dictionary and any attempts to translate the inputs into something else after reading them would have cost more than the inefficient dictionary lookups and deletes that were costing me the time limit.  So I just translated the thing into Java, which took approximately 3 - 4 times the lines of code to do the exact same thing in the exact same way, with the same level of clarity (if I want to get a job anywhere, my code should at least look reasonable).  The Java version ran well under the time limit of 5 seconds (it ran in around 3.1 - 3.2 on the longest run problem of the set) so it doesn't make me feel any better about how painfully inefficient python and dynamic languages in general are.

So I'm reading Dive into Python 3 now, since I don't know crap yet about pretty much any language let alone my least well versed one, so I finally got the concepts behind the different containers down I hope.  Lists are mutable and formed with [], tuples are immutable lists formed with (), sets are unordered collections formed with {} and single elements per comma, and dictionaries are unordered collections formed with {} that are colon separated key:values.  I guess that is enough learning for today!  Time for more yogscast.

If anyone is reading this (you silly goose) the book is nice so far.  A little bit more newbie than what I would hope for (there is a tremendous dearth of books for people that know language concepts but are completely lost with larger scale endeavors like using external libraries / APIs / polyglot applications)  but it seems slightly above the average book level and at least doesn't start with hello world and how to declare a variable.  The first chapter being about how to install Python was a little unsettling though... come on, you should know how to install an interpreter if you want to use a scripting language.

No comments:

Post a Comment