Hit counter:

Sunday, October 23, 2011

Programming Newsflash: Hacking Python






Recently i've been subjected to more than a bit of hype about the Python language. With all embedded scripting being done in either Python or Ruby (anyone remember Perl? RIP), it seems as the way to code, and with Google supporting it - even listing it as one of their three 'supported' languages- seems like it'll stay that way. Well, I've decided to confront the snake and got myself the Python 3.x installation on Windows x64, ripped open the manual and got to some random hacking.  Basically, this blog post will serve as the chronicles of the Python language and my adventures with it, as well as direct comparisons to its native implementation language, C.


P y t h o n :  T h e  F i r s t   E n c o u n t e r


Python's a high-level language, and that's definitely something i'm not accustomed to. Being able to use variables without explicitly declaring them seemed a bit awkward at first, and only got worse for me. It might not be an issue for most, but people coming from a low-level C or similar background will at least have some weird feelings at first. Also, the implicit types got me more than a bit scared- i was writing up typecheck commands after each 15 lines of code or so. Call me a bitch, but i don't believe an interpreter should - or can, for matter- do my programming for me. Major point loss there, though some might like it.

Syntactically, Python's been implemented in C, and it shows in the design. That means that, while you don't have to type in billions of braces and semicolons, the code structure is fairly similar. Sure, indentation can get a bit weird, but that's only if you've got like 5 levels of it, and that probably means you've messed something up anyway. So +1 on the purity of the design, which is rather easy to love.

There is, however, one thing that i do not love about the design: the way for loops work. Sure, i'm a bitch, but i want my iterations flexible. I want to loop over arrays based on indexing. I want to iterate over files based on byte-size. It's how C works. It's how my mind works. It's how every language does it. But Python's for is content-based, and doesn't actually play nicely with it's C counterpart. -1.

Speaking of C counterparts, Python actually doesn't have that many. If you're an array junkie like me, get yourself a different language. Python doesn't have them- apparently, they're considered too 'low level' or something. Instead, it offers dictionaries, tuples and lists - which are fun, but not too flexible. Of course, the list can be considered as an array of sorts, but you have to admit it gets a bit weird after a couple of dozen elements. Not sure whether +1 or -1 here, though, as Python's meant for quick-and-dirty hacks instead of uber programs. But what does annoy me is the inability to pass by reference. Namely, there aren't any pointers. Sure, most people will 'yay' here, as pointers aren't exactly supported in most 'modern' languages like Java and C#, but they'll start yelling as soon as they try to write a swap function. -1 on this one. Make that -2, actually.

Everything else seems to be taken directly from C- the math libraries, file I/O etc. are basically wrappers around the standard GNU libraries. Never the less, i admit to loving the 'batteries included' philosophy of the language, like the huge library with everything from sorting algorithm implementations and archive support to POSIX threads. Major kudos.


T h e  v e r d i c t

Well, i don't exactly hate this language, the way i hate, let's say, Java. It's pretty cool, actually, though i don't plan on replacing gcc with IDLE yet. However it's a nice language to know when you're up for some random hacking with a couple of guys and only have a limited amount of time- you won't believe what semicolons take to write in total.

No comments:

Post a Comment