4 ms·
> because you spend all this time telling the compiler what it already knows But a program should be optimized not for reading by a compiler but for reading by
by IlliOnato 3y ago
> because you spend all this time telling the compiler what it already knows
But a program should be optimized not for reading by a compiler but for reading by a human. This is essential for maintainability.
The question is not how hard it is for a compiler to deduce types, but how hard it is for a human (and a human that hasn't necessary written this ode, and hasn't necessary read and remembered the whole codebase) to figure it out.
It is not a simple question in general. Too much "infrastructure" clutter can hide the logic and intent of the code too. So to get the right balance in a language or in the code is non-trivial.
- bmitc 3y ago> But a program should be optimized not for reading by a compiler but for reading by a human. I absolutely agree, more than you could imagine, but I think this is not a case where that's the issue. Type annotating everything will quickly make the code harder to read. There's a reason why people like Python. But the problem with Python is that you don't have a way to figure out the types. With F#, just hover over anything and get the type. > This is essential for maintainability. Even more to the point, over type annotating will make maintenance harder, not easier. This is because you are fixing the types statically. When you then go to update code in the future, you have thrown out the benefits of type inference and now have to go around manually updating all of these type annotations. So you took the quote a bit out of context. If you're type annotating code, you're telling the compiler something it already knows, you're telling the human reader what it can already find out immediately for any value, you're increasing the surface area of needed updates, and making the code harder to read.