Thanks for visiting my blog - I have now moved to a new location at Nature Networks. Url: http://blogs.nature.com/fejes - Please come visit my blog there.

Thursday, August 7, 2008

programming with a loaded gun.

I had an anonymous comment the other day that started off like this:

Don't blame sloppy code practices on Perl; it would be just as easy to obfuscate the line you mention in another language.


That got me thinking about it, and I rapidly came to the conclusion that I don't think you can obfuscate code as much in another language as you can in perl. Perl is like a loaded gun. Used wisely, you could win a biathlon, catch crooks or... um... defend your country. (I'm not actually a big fan of guns, so this metaphor is stretching things a bit for me.) Used irresponsibly, you could shoot yourself in the foot, rob a bank or invade Kuwait. The gun-lovers tell you it's not the gun that's responsible for the bad things that are done with it. The famous quote is that "Guns don't kill people, people kill people." Well, I don't want to get into a debate on the merits of guns, but as a tool, they need to be used wisely. I don't think anyone would debate that.

I argue, so does perl.

Giving a novice programmer perl is like giving a teenager a loaded shotgun without a safety. The consequences are less dramatic, but equally irresponsible. You need training to use both. Without training, you write code that can never be understood, can't be trusted, and is unmaintainable. How do you correct a bug in code you can't wrap your head around?

Anyhow, yes, other languages can be used to obfuscate code, but perl, in my humble opinion, is designed to give you a flexibility that just isn't found in other languages. How many other modern languages can be used to read in a variable then use the content of the variable as the name of another variable? Certainly not C, Java or VB. And that's just my favorite example at the moment, I'm sure there are others.

Where this is leading me, is that all languages have problems, and all languages can be abused. A good program in a given languages has certain traits, just as the bad do. I'm working on my next blog post, which I figure I should try to answer the question, what does good code look like in a given language, and - more entertaining for me - what does bad code look like? I've seen a lot of examples of each, lately, so I may as well share what I know.

Labels: ,