Perl considered harmful

From VyOS Wiki
Revision as of 21:05, 2 July 2019 by (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

A good programming language is one that helps programmers write good programs. No programming language will prevent its users from writing bad programs.

— Bertrand Meyer

Some reasons we should not use Perl for long running, unattended programs whose result is not immediately obvious and visible.

Weak typing

Guess what these programs print and if any of them fail.

perl -e 'use strict; print "a" + 1'

perl -e 'use strict; print [1, 2] + 1'

perl -e 'use strict; print (1, 2) + 1'

perl -e 'use strict; print "a" / 1'

perl -e 'use strict; print (1,2) * 3'

perl -e 'use strict; print 3 * chr []'

perl -e 'use strict; print length [1,2,3]'

Show Spoiler

Moreover, there is no sensible way to find out what exactly your function is presented with. Perl is essentially untyped, everything that is not an array, hash, or code is of a single type "scalar".

Note: warnings module can detect some of these and you can make them errors, but it still doesn't give you a chance to prevent or recover from these situations in a sane way.

User-defined types

In OO languages such as Python or Ruby, classes are cheap. In Ada or static functional languages, types are cheap. Cheap in terms of effort, you can easily make them any time you want a new one.

Perl objects are too much effort to create, and it inhibits using them to describe the structure of your data and relationships between them.

Error handling

Boils down to eval and die. You can implement exception handling on top of it, and multiple implementations exist. But then again, you can implement dynamic typing in C by using structs made of a type tag and a value pointer for variables. Should you do instead of using a language that already implements it?