2 ms·
Programming in Scala has a very straightforward explanation of for comprehensions. Mysteriously, almost every other explanation I read left me more confused th
by dkarl 15y ago
Programming in Scala has a very straightforward explanation of for comprehensions. Mysteriously, almost every other explanation I read left me more confused than before. I don't know why there are so many poor and/or partial explanations out there. Read Programming in Scala instead and you'll be fine.
As for type inference, another week of programming and you'll fall into a groove where you're anticipating when you need to declare types and when you don't. I had the same pain, and after a week, it had dropped down to a very occasional annoyance. It might just be my programming style, though -- I declare the return types on all functions that are meant to be called from another class or object, so there's a lot of information for the compiler to work with.
I agree about the underscore thing. It's pretty useless, and Clojure's version looks superior to me. As best as I can tell, the underscore doesn't work inside an extra layer of parens or curly braces. But it's just syntactic sugar, after all. Using a named variable isn't the end of the world. It's just three extra non-whitespace characters, "n =>".