Scala isn’t complicated; it’s clever

I’ve been away from Scala for a long while now — a little more than three years.  v2.7.1 was the last rev I used significantly, if memory serves.  I enjoyed my time with it, but it just wasn’t the best fit for me.

Anyway, I’ve learned that sometime in that era, Scala added support for the use of Unicode arrows as optional alternatives to the usual ASCII approximations it’s always had.  For example, this:

for (x <- 1 to 10) { ... }

is equivalent to this:

for (x ← 1 to 10) { ... }

The second example uses a Unicode instead of the ASCII <-; other arrows (corresponding to -> and =>) also have Unicode equivalents in Scala.  There are various other Unicode characters that have been proposed to serve similar roles, generally with positive discussion around them, including , , , , , , and .  This syntactic flexibility isn’t defined in a library, or in private code, but in the language itself.

I’m aghast.  This blog now sports a “WTF” category.

An early Scala-specific keyboard design.
An early Scala-specific keyboard design.

In the ticket that suggested the addition of one of these equivalencies, various potential problems are pointed out, and presumably ignored.  Perhaps people yearn for APL; unfortunately, suitable keyboards are not widely available.

I’ve no issue with Unicode identifiers: I work with a language that imposes no restrictions at all on the characters used, so programmers that want to use Japanese, Cherokee, Sanskrit or Greek characters in their identifiers can have at it.  Being able to opt in to such things is unequivocally good.  However, that language wisely tries to avoid doing clever things, like aliasing the core anonymous function operator to the λ character for everyone1.

There’s been various discussions, controversy, and gnashing of teeth about whether Scala is a complicated programming language.  I won’t get into that; that’s an argument over semantics that I don’t think is framed properly to begin with.

Maybe, though, most of us can agree that, if Scala isn’t complicated, it is at least clever, and things like this are just the most facile examples of that nature.  We are left to our personal biases as to whether or not that is commendable, desirable, or good.

1Discussions like this must mention Fortess, and its duality of language representation: one writes Fortress in ASCII, but the language defines a sort of markup within that character set so as to produce quite elegant renderings of code suitable for publishing.  See an example here.

14 thoughts on “Scala isn’t complicated; it’s clever

  1. For certain characters I project something different to those that I typed and which are interpreted by the underlying language. This is somewhat analogous to the Fortress duality, except it is live in my coding session. The means my reading of code is somewhat prettified, but the writing, storing and sharing of code is unchanged. This only requires cleverness in the editor (Emacs in this case) and is clearly something that isn’t forced on anyone. I personally really love it though.

    I actually use this technique for the example you gave. I type:

    (fn [a b] (+ a b))

    and Emacs displays

    (λ [a b] (+ a b))


    1. Yeah, stuff like that is unabashedly good; local, opt-in, entirely lacking effects on your collaborators, nevermind the language.

      FWIW, this was mentioned as an available option in one of the discussions I liked to. A general-purpose link for emacs appears to be this:

      This page is about displaying sequences of characters as fancy characters or symbols – for example, showing -> as →.

      1. I’m fine with the language allowing unicode chars as aliases to things that are multi-char ASCII representations, as long as they leave in the ability for me to type the two ASCII chars for the same meaning.

        As unicode support becomes more common this could be a boon to programmers. Right now keyboards support is clumsy for unicode, but I can see programmers eventually remapping keys they don’t use often to type the unicode chars they use often (say the Numpad keys, or get a specialty keypad for input like gamers use)

  2. You don’t need a fancy keyboard, just a “modern” OS
    Here’s how Plan9 enables UTF-8 input.
    The second column is the keyboard sequence, one presses the ALT modifier with the first keystroke, or cut & paste (which is easier on Plan 9 as it uses mouse chording (1&2 cut, 2&3 paste).

    Plan9 also allows any UTF-8 character in the source code for the C compiler.

    See Rob Pike and Ken Thompson’s paper on the subject

    1. Alt-codes are not really practical for programming. I can type -> faster than I can type the “alt code”, even if I have it memorized.

  3. Since Scala is less flexible than the language you’re using (there, I said it), it cannot redefine some of the basic syntactic constructs in libraries. It already does for some of them like !, :: and ->. There are a couple of points which I think you’re missing:

    First of all, Scala does not banish the ASCII operators like APL does.

    Second, a language is as much about syntax as it is about community and common patterns. If you take some time to explore some of the Scala applications and libraries, you’ll notice that almost none are using the Unicode syntax, with very few notable exceptions like Scalaz. Even with Scalaz, I’d argue that the authors are not trying to be clever at all. The symbols Scalaz uses are not arbitrary, but are taken from certain Mathematics domains. As such some of these symbols are indeed older than even the Lisp s-expression syntax. Indeed, the arrow notation predates the creation of ASCII (

    Not to belittle the importance of choosing the right syntax, but I find your long list of links about Scala’s semantic complexity to be more important. I also find it revealing that most people I’ve heard complain about Scala’s complexity actually mean functional programming concepts, which are even more widely used by your language of choice. You might find this strange, but I do think that an increase in adoption for Scala would lead to more adoption for Clojure and vice versa.

    To summarize, Scala is about choice, and like you said, it is up to “our personal biases as to whether or not that is commendable, desirable, or good”.

    1. Thanks, Vassil.

      My snark related to APL was very much tongue-in-cheek. I’d have included a ;-), but I figured that calling the APL keyboard an “early Scala keyboard design” was enough. :-)

      I don’t know anything about Scalaz; I’ll presume that its use of Unicode identifiers is compelling. However, as I mentioned in the corresponding Hacker News thread, Akka is using Unicode arrows. Again, I’ve no problem with library authors using Unicode identifiers if the benefits of doing so outweigh the costs; in Akka’s case anyway, the flexibility in language syntax is there for aesthetics only.

      That old saw of “Scala is complex” really is a knot that I’m in no position to unravel. I don’t think anyone can, given shaky foundations of the discourse. In any case, the frustrations I’ve seen people have with Scala have been related more to its type system and syntax than its functional programming aspects (which, in the abstract, are a simplifying force IMO). And yes, in general, gains made by either Scala or Clojure absolutely benefit the other. :-)

      1. >> in Akka’s case anyway, the flexibility in language syntax is there for aesthetics only.

        I find it good practice that all methods represented by characters in Akka (not only Unicode ones) have alphabetic equivalents for the benefit of e.g. Java programmers. I think this sets a good example.

        >> functional programming aspects … are a simplifying force IMO

        >> the frustrations I’ve seen people have with Scala have been related more to its type system

        It’s hard to overstate the importance of typed functional languages in the evolution of functional programming. Scala’s author decided fairly early on not to break with object-oriented concepts though. This might have been a controversial decision for some and has added some complexity, but it has enabled Scala’s superb interoperability with Java. I, for one, am happy that we have a statically typed language on the JVM with strong support for functional concepts.

        >> and syntax

        There are always people who are going to complain about a particular syntax, but I don’t think this is so much about complexity as familiarity. There were people who were decrying even Rich Hickey’s choice to include special syntax for maps, arrays and sets. In the end, I think this pragmatic decision was quite beneficial overall.

        >> gains made by either Scala or Clojure absolutely benefit the other

        Definitely. A little known fact is that the idea for Clojure’s persistent collections were borrowed from a paper from Phil Bagwell from EPFL, and I think some of the ideas found its way back into Scala.

        Fogus is a good example of someone who likes both Clojure and (at least some) parts of Scala, and I’d say both communities have benefited :)

  4. I agree with Vassil’s point that Scala is about choice. I have my opinions about that particular philosophy, but it’s irrelevant to the topic at hand. Providing unicode aliases completely fits with the philosophy of not dictating style, paradigm, mutation, etc. While this might not be good news for someone writing “Effective Scala”, it’s definitely good news for people hoping to express code in a way that makes sense subjectively.


    1. I linked to a number of articles throughout the phrase “whether Scala is a complicated programming language”. All of them either discuss exactly that topic, or are a follow-on to such discussions. I assume you’re referring to your post as being unrelated; I included it because it is a response to Martin Odersky’s “levels” post, which would appear to be at least in part a response to the “Scala is complex” meme.

      That Stack Overflow question (“Is Java *really* less complex than Scala?”) is fairly absurd, so I suppose it deserved an absurd answer.

      1. Yes I am referring to my post, which has nothing do with the proposition, “Scala is complex”, but rather the incredibly low standards being set by Martin.

        I don’t think the question is absurd. It seems quite reasonable. Many of the answers appear absurd to me though. Lots of handwaving and bibble-babbling about nothing important.

  5. In any reasonable modern operating system, you can define “compose” sequences to get any Unicode character you want in an intuitive way. On my laptop, I set the Caps Lock key as the compose key–it’s large, and I don’t use it for anything else. Caps Lock ” a gives ä. That’s already built-in. Caps Lock g l gives a Greek l, i.e. a λ. I had to add that. Caps Lock m E gives a Math E, i.e. an ∃. I had to add that too.

  6. If you’ve got both a typeable version and a pretty version (like with vs ⇒ ), you can arrange for a tool to do the substitution for you (which is what Akka does). It’s neither clever nor complicated — it just makes the source ever so slightly more pleasant to read, no big deal.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s