Coding in C++, wishing it were Lisp (or Perl)

May 9th, 2003 at 3:45 pm

C++ is a good language for its purpose. It is very powerful, allows to write fast code and has great libraries. But any time I write a program that must have strong customization capabilities, C++ is a b*tch.

Inevitably a new text format is invented, that is parsed and fills some internal structures.

Lisp could do it so much better !

Another thing: STL is great, no really it’s wonderful. It gives C++ great abilities to handle and manipulate complex but efficient data structures. But some things, though looking very cool for people who’ve only written imperative code (C, C++, Java, Pascal, etc…), look extremely clumsy to people who wrote functional code.

For instance, I use the sort algorithm to sort a vector of strings. The sorting is not alphabetic, so the built in ‘less’ operator for STL strings is no good. So, I must define my own predicate:


bool mult_lines_predicate(string s1, string s2)
{ ... blah blah ...
}

And then call:


sort(mult_lines.begin(), mult_lines.end(), mult_lines_predicate);

Again, this looks extremely cool to C++ gurus who didn’t hear of Lisp & Co. But in Lisp it would be much more elegant ! Why define a special function that’s called only once, just pass a lambda. In Perl, btw it’s also possible and looks more elegant than in C++.

Oh, and by the way, STL’s foreach is, again, nice for C++, but sucks comparing to Perl’s.

Related posts:

  1. perl bit-crunching
  2. too much Perl…
  3. coding a simplified cpp
  4. problems with recent changes of use.perl !
  5. Equality in Lisp

Leave a Reply

To post code with preserved formatting, enclose it in `backticks` (even multiple lines)