7 ms·
Scala Actors are Just Code - No Magic
- catch23 15y agoI think languages that allow the use of non-alphanumeric characters as method definitions make the language appear more magical simply because it looks like built-in language syntax. I remember when I first looked at sbt, they were creating directory paths with the '/' as an operator to concatenate strings. (ie "home" / "user") I'm guessing that might also be the reason Ruby is cited as magical all the time.
- apl 15y agoProbably true, yes. For instance, the apply-transformation x.apply(y) == x(y) and the way operators are handled 1 + 2 == 1.+(2) are fairly powerful syntactical tools which allow seemingly magic DSL stuff. Many enter programming via Java and C; languages that are far less malleable and open to seemingly built-in modification than, say, Lisp, Scala or Ruby. However, flip side of syntactical magic? Stuff like '·' (which I recently encountered in some Scala library). Or Databinder Dispatch: Http(:/("google.com") / "bla" / "bar" << "why=so&x=y" ># foo) Nice library, but, you know, conciseness isn't everything. (By the way, this places a POST request to http://google.com/bla/bar http://google.com/bla/bar with request body "why=so&x=y" and delivers the response as a parsed JSON tree to foo.)
- cmelbye 15y agoI really can't stand this trend. When I took a look at Lift, it was riddled with these "magical" method definitions that look nice but mean absolutely nothing to someone who's new to the framework. I'll gladly take a self-explanatory alphanumeric method name over a "/", a "+", etc.
- barkmadley 15y agoWhy not have both? Also do you happen to use any regular expressions ever? Can you imagine specifying a regular expression using self-explanatory alphanumeric method names?
- kenbot 15y agoRegarding the for loop, it's not magic either. "For comprehensions" in Scala are a wonderful syntax sugar that can look like familiar "for loops" for Java folk, or familiar "do loops" for Haskell folk depending on how you use them. But they always desugar to flatMap/map/withFilter method calls that you could have written yourself -- there is nothing "special" about them in that regard.
- barkmadley 15y agoThe desugaring process is what makes the for loop magic. I cannot write a different control structure that looks like the that for loop in scala without touching the compiler. A counter example that shows how to avoid the sugar would be "if expressions" in smalltalk (simplified, may differ to reality). In smalltalk, the abstract boolean class has a method 'if'. And the "true" subclass of the boolean class implements the 'if' method to execute its first parameter, while the "false" subclass implements the 'if' method to execute its second parameter.