« Facebook Dumping + Flickr Hacking = Worry | Main | Large Update to Identity Research Repository »

December 8, 2007

 Language Wars (part eleventeen)  

I'm a man of many languages. Not necessarily human languages ( though I can speak/write French & Swahili ), but computer languages. I've always advocated using the right tool for the right job - and have found myself jumping between Perl and Python nonstop, with occasional work in PHP and recently Erlang.

People always ask why, my answer is simple: some languages are faster to develop or execute on than others. Perl kicks ass at string manipulation; Python is amazing at manipulating numbers and matrices; with PHP you can have simple webpage operational in minutes. Because each one has different frameworks and modules generally available, you can't honestly evaluate them across the board.

Anyways... xkcd has a new comic about leaving Perl for Python. I've come close to doing that myself so many times - but I honestly still love using both.

Or at least I was... I'm starting to hate on Perl's comparison operators lately.

PHP and Python both do automagic comparisons, so you only have "==" as an operator. Perl requires a specific choice in operators - either "==" for numeric or "eq" for string. The canonical rationale is that 1 and 1.00000 are both numerically equivalent, but are different strings.

I'm fine with the concept of multiple comparison operators, I just *hate* how they're implemented. I've been doing a lot of Python lately on the FindMeOn spiders and proxy servers, and prototyped a Facebook App via PHP -- I got too used to using "==" for everything. Transitioning back to Perl for work on the core FindMeOn and RoadSound platforms, I've been experiencing a ton of bugs that have taken forever to fix-- and all of which have been attributable to me using "==" instead of "eq".

The confusing part illustrated:

All:
True: 1 == 1

Python
False: 1 == "1" ( not the same type )
True: "a" == "a"

PHP
True: 1 == "1"
False: 1 === "1" ( same value, not the same type )
True: "a" == "a"

Perl:
True: 1 == "1"
False: "a" == "a"
True : "a" eq "a"

Note how they're all logical - just not consistent.

Personally, I wish Perl would have used == as a comparison that supports autotyping, and corollary functions handled int/string comparison. Maybe that would mean a numeric version of eq, or that eq were replaced with a same type & value operator. Perl is generally called the 'messier' or 'sloppier' language - after spending more and more time in stricter languages like Python, I'm kind of amazed how simple comparisons in Perl are such a PITA.

Posted by Jonathan at December 8, 2007 9:45 PM

Comments

Post a comment

Thanks for signing in, . Now you can comment. (sign out)

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)


Remember me?