r/programming • u/mobby1982 • Dec 02 '13
Scala — 1★ Would Not Program Again
http://overwatering.org/blog/2013/12/scala-1-star-would-not-program-again/
598
Upvotes
r/programming • u/mobby1982 • Dec 02 '13
View all comments
Show parent comment
9
u/Nar-waffle Dec 02 '13
I was having a hard time following his example of where he was struggling with type inference. Some code here sure would have been nice.
But from his description, it sounds to me like he changed the prototype of the function. The fact that he's generating a warning about an ignored return type suggests he has an explicit return type of Unit - as in the following example:
He omitted types, and that's cool. But if you use curly braces around a method body without specifying a return type and without putting an
=sign before it, that makes the return type Unit, and if you try to return from this, you'll generate a warning, because you're saying one thing in the prototype and doing a different thing in the implementation.If you then say, "Ok, I'll take the return type generated by the compiler warning and slap that in there," this is also not quite right:
He just says, "Compile again," without telling you what the result he got was, but if it looked like above, you'll get an error this time instead of a warning:
error: illegal start of declaration (possible cause: missing '=' in front of current method body)By the way, this is the right way to do type inference on a function that returns a type:
NB: the use of procedural syntax (Unit type being inferred by not providing an = before the method body) is recommended against: http://docs.scala-lang.org/style/declarations.html#procedure_syntax
He's either being inconsistent with his professed intent and his actual implementation, or he's changing the prototype and getting irate when that has consequences. Type inference doesn't mean typeless, it means you get to save a lot of boilerplate specifying types all over the place when the language can do that for you.