A fun thing about looking at different programming languages is that you get to see the unique features of each language. For instance, some people don’t like Lisp because of all of the parentheses, and then Haskell seems to counter that by saying, “Hey, here are a couple of ways to get rid of parentheses.”
As a note about Scala style, this Scala page strongly encourages that side-effect methods that takes no parameters should be declared with parentheses:
“However, this syntax (leaving off parentheses) should only be used when the method in question has no side-effects (purely-functional). In other words, it would be acceptable to omit parentheses when calling
queue.size, but not when calling
openGarageDoor()). This convention mirrors the method declaration convention given above.”
“Religiously observing this convention will dramatically improve code readability and will make it much easier to understand at a glance the most basic operation of any given method. Resist the urge to omit parentheses simply to save two characters!”
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 5.6, “How to force calling methods to leave parentheses off accessor (getter) methods.”
You want to enforce a coding style where getter/accessor methods can’t have parentheses when they are invoked.
Define your getter/accessor method without parentheses after the method name:
As I keep trying to learn more about functional programming (FP), I keep going back to old Haskell books, like Real World Haskell, where this image comes from. Every time I try to learn more about Haskell my brain gets stuck not on FP, but on a couple of pieces of Haskell’s syntax. For instance, I don’t like the way function parameters are passed to functions, as shown in the top of this image. I much prefer the Java/Scala approach of
Last night I saw on the bottom of this image that this situation gets a little better (for me) when you nest several function calls together. The syntax at the bottom of the page looks more like Lisp, which is more readable for my brain.
(FWIW, I don’t call this a “rant” or “flame” about another language. I don’t like a few parts of Haskell’s syntax in the same way that I don’t like putting
$ characters in front of variable names in other languages. It’s just an observation of what I don’t like about a language.)