[Melbourne-pm] Arcane operators

Daniel Pittman daniel at rimspace.net
Sun May 9 19:52:26 PDT 2010

Toby Wintermute <tjc at wintrmute.net> writes:

> (Background:
> I've been playing with Scala every now and then, as I've mentioned before.
> It has some nice advantages, like a great concurrency system, a good
> OO implementation, and it's quite fast once the jvm gets warmed up.)
> I've noticed a worrying trend in Scala libraries though.
> In Scala you can invent your own operators - they're just functions on
> the objects with those names. And it seems that Unicode is valid too.

Yay!  APL and A+!  How can you go past a language that supports things like:


...and the kids today complain that Perl and Emacs commands looks like line
noise.  They don't know how good they have it.


> but for the most part, it feels like it's going a bit crazy.

It probably is: the issue you mention is actually both less and more bad than
the equivalent problem back in C++ when I worked there: back then you had a
much more limited set of operators to overload, but the same enthusiasm for
overloading them.

The broader character set means that '*' is less likely to do something
completely unexpected like "map", but you are more likely to see someone write
APL style code.

> In Perl it seems like the received wisdom is to back away from writing
> code that looks like random line noise.

APL is pretty much the extreme end of the Domain Specific Language spectrum,
which is what operator overloading is a small step along the path to.

Done right, this still is gold: you can't beat it.  It is still the killer
advantage of Lisp, that it is so trivial to define a useful DSL, so you tend
to do it all along the way.

OTOH, done poorly DSL code is terrible.  Probably worse than, say, some of the
"I don't understand OO and find Perl5 scary" Perl that I get to support.

> If you could make up any operators you like, would you?

Yes, absolutely.  I also 'use overload' in Perl.

> Do you think it improves code readability or makes it worse?

There isn't a single answer.  Naturally, when *I* do it I think it makes code
readability better, but opinions vary about how that actually looks. :)


✣ Daniel Pittman            ✉ daniel at rimspace.net            ☎ +61 401 155 707
               ♽ made with 100 percent post-consumer electrons

More information about the Melbourne-pm mailing list