UFCS idea

bearophile bearophileHUGS at lycos.com
Wed Jun 8 16:52:10 PDT 2011


Andrej Mitrovic:

> Keep the language simple, why the verbosity with special symbols?
> Leave that to Perl 7 fans.

My post was referring about two or three symbols. Regarding two of them, the $ and . operators used in Haskell, they may look a bit weird for the first hour your use Haskell, but after that you learn to appreciate them, and use them all the time, because they allow you to write very clean code. Haskell code is not easy to write for newbies, but it's easy enough to read. "Advanced" Haskell code uses several funny operators (like &&&, etc), but the basic ones like ++ and $ have a very simple semantics and you use them very often. So while Haskell is not an "easy" language, its code is more readable and quite more clean than Perl code. In Perl you use all kind of side effects, invisible variables, global variables, this doesn't happen in Haskell. So you can't compare the two languages.

In the end an operator like $ is just syntax sugar, so it's not so important.

The third symbol I was talking about was the @ used to denote reference/pointer types that can't be null (and ? used for the normal nullable ones). This is not just syntax sugar, this needs a change to the type system too. And I think it's a change important enough to deserve a special symbol in the language. Recently Andrei has said something is moving about this whole topic, so we'll see.

So I agree it's generally better to avoid special symbols, but there are situations where they are acceptable, if their semantics is "natural" (like coming from mathematics), or if their usage is very common (like the $ . ++ in Haskell), or if they are important enough (like a symbol used to denote nullable/nonnullable reference type).

Bye,
bearophile


More information about the Digitalmars-d mailing list