Make Code Readability your Priority – Get Out of the Perl Mentality

by Carey on November 14, 2010

Post image for Make Code Readability your Priority – Get Out of the Perl Mentality

One thing that has always been important to me, no matter what coding language I am using, is maintaining readability of my code.

We are always under pressure to get our developing done, although a bit of foresight can help with maintainability in the future.

The Perl mentality is the idea of solving a problem in a script of as few bytes possible. Back in the early days of coding, memory and processor cycles where precious. A saving of either of these helped your program run quicker and in some cases actually work.

This led to shortcuts, such as using 2 digits for the year (e.g. 89) instead of four (e.g. 1989) – and we all know what lead to.

Getting back on track, the perl mentality would give us something like this in a php for loop:

{code type=php}
if ($condition == true) echo ‘TRUE!’;

By squeezing onto one line and skipping off the curly braces, we have saved a few lines and bytes in our scripts. But at what true cost? Shortcuts like this are harder to read and a page crammed with code doesn’t go easy on the eyes.

Another piece of advice I sometimes hear; “Use tabs instead of spaces, as a tab is 1 byte and a space is 1 byte each”. It is a fair point, but consider that editors will display tabs at different widths causing your script to look completely misaligned on other editors.

Stop hording the bytes and processor cycles, and you will give yourself a greater asset; time.

{ 1 comment… read it below or add one }

Konservir February 7, 2007 at 4:52 am

Nu zdarova !

I just wanted to pass on a note to let you know what a great job you have done with this site. Thanks!


Cancel reply

Leave a Comment

Previous post:

Next post: