4 ms·
Maybe it would be better to say, "I'm a pretty good programmer. However, I'm not perfect, and I make mistakes. Static typing helps minimize the mistakes." The
by Aqueous 13y ago
Maybe it would be better to say, "I'm a pretty good programmer. However, I'm not perfect, and I make mistakes. Static typing helps minimize the mistakes."
The one thing I don't like about Scala is type inference. We spend all that time specifying the exact type of parameters and return values, but then we can just lazily declare an immutable value val, set it equal to a return value of a function, whose signature is in different file, and from a quick glance at the code we can not tell what 'val' is. it might be convenient in the short run, and splits the difference between convenience of dynamic typing and the precision of static typing, but it does so at the cost of readability.
- gohrt 13y agoThe type of that value is the type returned by that function. If you want to see what that type is, look at the function. That's not as weird as it sounds. Consider: int x = foo(2); What is x? OK, you know it is an "int", due to the redsundant declaration. But that's not useful to you the programmer. int foo(int n) { return n+1 } Ok, foo is successor. But you have to look at the definition to remind yourself that. Why not put that in the declaration of x as well?
- benmccann 13y agoThere are numerous places I find Scala has preferred brevity over readability and it does not take long for that choice to take it's toll when you have many people working on a project. Yours is a perfect example. Another is allowing multiple ways of importing such as allowing relative imports. When I've tried to use Scala it's much more of a pain to figure out where some classes are coming from whereas in Java it's immediately obvious from the import at the top of the file.
- RivieraKid 13y agoThat's exactly one of my many complains about Scala (and about type inference in general). Type annotations are not there just for the compiler, they also help readability / documentation.
- lmm 13y agoIf you feel a particular value needs an explicit type you can always include the type in the declaration. Or your development environment should be able to tell you what type it is. I do think scala needs an IDE to be used effectively, at least if you're making heavy use of implicits and inferred types (and, as a sibling mentions, indirect imports). But I think that's ultimately a good thing: it uses the power available to us nowadays to allow a more compact representation of code than would be acceptable in a plain text file (which is good for readability - AIUI evidence is that code readability takes a big hit as soon as a function spans more than one screen). Rather than throwing away the convenience of text like the '80s "visual programming" efforts, it's more of a "progressive enhancement".