Stay true to a language?

Posted by Jim Jagielski on Friday, September 22. 2006 in Programming

One thing which I find somewhat troubling, switching from language to language, is that one tends to use idioms and techniques in one language, that are really better suited for another. This is more often problematic when porting and application between languages, but can really happen at any time. It's ever more an issue when the languages share a lot of similarities. For example, consider this Perl code snippet:
($id,$name)=($1,$2) if $line =~ /|name="(\w+)" (.*?)|/;
Now with some very minor changes, this is also valid Ruby:
nid,name = $1,$2 if line =~ /|name="(\w+)" (.*?)|/
But even so, it is a very Perlish-way of writing Ruby. Instead, you could do something like:
if (m = /|name="(\w+)" (.*?)|/.match(line))      nid = m[1]      name = m[2] end
Which is certainly uses more Ruby-like concepts, but is more verbose and not that nice anyway (yes, you could make it less verbose, but stay with me here). I like the Perlish-way better. It's certainly cleaner. So do you write clean, concise code, even if it's not "true" to a language, or do you stay close to the ideals of a particular language, even if it means the code isn't as clean or clear as you'd like...? Me, I'm lazy, so I'll do whatever is easier without being so terse as to be painful. If a language gives me shortcuts, I'll use them, even if it means some language snobs may look down their noses. As far as the above, heck, I'm going to start calling that idiom a "Ruby-ish way" of doing it. Certainly if one started with Ruby and then learned Perl, that's what they would think.

Page 1 of 1, totaling 1 entries


Search for an entry in IMO:

Did not find what you were looking for? Post a comment for an entry or contact us via email!