Scala 3: No parentheses in control structures alvin September 28, 2019 - 7:55am

When I originally saw the first image, I thought it was a “This would be nice in Scala 3 (Dotty)” idea. But then I found the “No parentheses in control structures” pull request shown in the second image. Here’s a link to that pull request.

Scala style: Side-effect methods with no parameters should be declared with parentheses alvin August 2, 2019 - 12:13pm

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 println() (or 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!”

Eliminating parentheses in Haskell with ‘$’

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.”

How to force calling methods to leave parentheses off accessor (getter) methods

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:

Parentheses in Haskell make it look like Lisp (a little)

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 compare(2, 3).

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.)