creative-scala
creative-scala copied to clipboard
question: should infix notation be used for non-symbolic method names?
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...?
(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)
Yeah, I agree. I realised last time I was teaching @ ScalaBridge that it doesn't bring any benefit to introduce this syntax early.
Scala 3 discourages the infix style, so this change would pave the way towards eventually moving to Scala 3.