Breaking Promises in the Name of Comfort

A programming language has a well-defined syntax. There’s often an organization behind establishing standards for that syntax, e.g. C++ Standards Committee. It holds meetings, and I imagine offers lots of free coffee.

This morning, in writing a quick Perl script, I used Perl’s here-doc functionality to print multiple lines verbatim to a file. In the default Emacs Perl mode, here-doc syntax is not highlighted properly, which is why I immediately started feeling uneasy. The syntax for here-doc in perl is that it starts with print  LAZY<< and ends with LAZY, where you can use whatever you want instead of LAZY. The extra requirement is that the closing LAZY has to get its own line. However, what I didn’t know, and what I figured out after about 10 minutes (time well wasted) is that it cannot have any spaces before AND after it.

This got me thinking about the powerful features provided by languages such as Perl that break the spirit of the intuitive robust syntax of the rest of the language. Another example of this is Qt’s extension of C++ through the Meta Object Compiler (moc). I’m a big-time fan of Qt’s signal-slot model which is made possible with moc. However, it does require that you add keywords in class definitions which do not follow natural C++ syntax.

I imagine this is the trade-off that language designers are constantly coming up against. Power and comfort sometimes comes at the cost of robustness and consistency. Perl hackers obviously prefer the former over the latter, but a language should work for a beginner as well as the expert, and for a beginner the language should be robust.

Leave a Reply

Your email address will not be published. Required fields are marked *