creative-scala icon indicating copy to clipboard operation
creative-scala copied to clipboard

question: should infix notation be used for non-symbolic method names?

Open SethTisue opened this issue 6 years ago • 3 comments

I have mixed feelings (leaning towards negative) about the extensive use of infix notation in the book for code like:

circle(10) beside square(20) beside square(30)

my impression is that the Scala community experimented with this style pretty heavily for a long time, but in recent years almost everyone has retreated from it and it's not really a mainstream style anymore for ordinary, alphanumerically-named methods like beside

but my concern isn't only about what the dominant style is in the community, it's also about what an appropriate style for getting started with the language is. for years now, I've seen (on Gitter and IRC, primarily) beginners tripping themselves up with what this syntax means and how it is parsed. beginners end up using a mishmash of spaces and dots and parens and not really knowing what's going on and where infix is permitted and when it isn't and when you need parens to make it work and when you don't. it seems like a distraction to me. by sticking with a.b(c) style you bypass all these issues, freeing up mental energy to focus on more important things

would a PR changing the code to consistently use this style instead:

circle(10).beside(square(20)).beside(square(30))

be welcome...?

SethTisue avatar Jun 18 '18 19:06 SethTisue

(we're at ScalaBridge Montreal right now, @ironfish had the same reaction, that this syntax shouldn't be used to start with, or if it is used, should at least be explained as being equivalent to normal method call syntax)

SethTisue avatar Oct 22 '18 13:10 SethTisue

Yeah, I agree. I realised last time I was teaching @ ScalaBridge that it doesn't bring any benefit to introduce this syntax early.

noelwelsh avatar Oct 22 '18 15:10 noelwelsh

Scala 3 discourages the infix style, so this change would pave the way towards eventually moving to Scala 3.

SethTisue avatar Jan 13 '21 23:01 SethTisue