Thursday, October 8, 2020

Perl is Write Only?!

There are way too many Python users who bad mouth Perl scripting language, including Mark Lutz, the author of Learning Python. In fact, he took every opportunity in that book to disparage Perl so much that it left a bad taste. If he spend so much effort discrediting Perl language, then it must be because it's so good, that in order to make Python a better language than it is, Perl needs to be taken down. Which is not only stupid, but incredibly harmful, that I wonder why O'Reilly, the publisher of Learning Perl would put up with it.

I certainly wouldn't put up with such destructive comment, even if they're true. They aren't true. Half of the criticism levied to Perl isn't true, and the other half ... also applies to Python! How's that for self-destructive behavior?

I'm going to focus the on one criticism that has been applied to Perl in this post, that is the claim that you cannot read the code after 6 months has passed. There are several considerations:

1. It's a complicated algorithm. No matter how clean the language is, if your program is full of regex manipulations, people who aren't comfortable handling them will have trouble.

2. Advance features. Perl has several variables worked on behind the scene. That is, you don't necessarily see the variables being set. One regex operation sets up so many different variables all at once, and unless your Perl skill is top notch, then you're going to be confused.

3. You have spaghetti code. Perl is linguistic, and so, extremely natural to write. However, it does mean that it allows you to express your ideas anyway you choose. If your linguistic skill is subpar, then yes, you will have trouble reading the code afterwards.

4. Shorthand coding. Interestingly, Perl also allows you to code very densely. This is similar to C programming language, where although you can write in clear formatting style, the high density style marks you as expert programmer and should be sought.


So, now that you know the reasons why Perl code can be hard to read, what can you do about it? 

1. Well, you can pick up Python, or BASIC. Yes, BASIC. No, I'm not kidding. There's no reason why BASIC needs to be slow anymore, and besides, Python isn't known for speed either.

2. You can write in clear style formatting. Perl and C lets you write in however coding style you choose. Simply write in clear, well documented manner, and you should be fine. More importantly, those maintenance programmers who will come after you, who has never seen your code, will be able to read and understand your program quickly, easily, and effortlessly.

3. Write a Design Document! This is one of the biggest fail of computer programmers. In professional programming environment, I always write the Design Document. That's because it's essential to have it. Just because the source code is readable, doesn't mean that you can skip writing the Design Document. So, you write the Design Document that tells the reader what your program is doing, in plain English. There wouldn't be any confusion at all. Then you figure out what the Perl code would look like, which will be instantenous if you know what you're doing. If not, then your Design Document is faulty, and needs a rewrite. How do you know your Design Document is good? Once you figure out how to code it in Perl, simply look at the source code and you should see the exact code already there. Hence, no confusion.


Most people would choose option 1. I chose option 2 and 3, and I can tell you from experience that I never had any trouble reading my source code many months or years later, simply because I have no problem reading the Design Document. You don't need to be a coding hero if you have good Design skills.

Why is learning Python a bad thing? Learning Python is not a bad thing if that's what you want. If you need structured coding to be imposed upon you, then by all means, use Python. But that doesn't mean that you can put down other languages that are very expressive and fluid in their coding, just because those languages do not impose structure upon you. Some of us are highly disciplined coders, you know? The more you complain that Perl is Write-Only, the more you tell me that you do not have good design skill and coding discipline necessary to write high level or high standard computer programming.

I will also mention that a lot of Python coders aren't really coders when all they do is glue library functions, but that's topic for another day.


No comments: