3 ms·
Type inference (or type deduction, as it's called in C++) is the number one reason for the resurgence of static typing these days. I for one would find C# and
by SloopJon 8y ago
Type inference (or type deduction, as it's called in C++) is the number one reason for the resurgence of static typing these days. I for one would find C# and C++ much less pleasant both to write and read without it; so much so that I would probably use a dynamically typed language instead.
Your perspective is that type annotations are there for the reader. I agree with tzahola that type safety itself is valuable in its own right without forcing the user to type little reminders to himself everywhere. Thanks to language servers, I can hover an expression in a text editor and remove all doubt.
I also agree with the other responses that if any language benefits from type deduction, it's C++. No way would the code be more readable if you were forced to be explicit about some of the dependent types in the STL.
That said, you are obviously not alone in your perspective. I've heard the exact same arguments from experienced C# programmers.
- mlthoughts2018 8y agoIt’s funny because for me, I spent well over a decade as a Python engineer. And the thing I find most valuable about statically typed languages is the act of writing type annotations, creating typedefs, etc., as part of the overall design of a program. Type safety and compilation have never really mattered to me — it was always extremely easy to write safe programs in Python, without crazy indecipherable language grammars or long compile times. I would say having written and maintained large programs in C++ and Haskell, it is no easier to write safe programs in those languages than in Python. The compiler doesn’t save you time by catching bugs, that stuff is all just myth. But what it does offer you is a way to communicate the design of your program through efficient type annotation, and give a lot of clarity into how things are intended to flow, and exactly at what points certain types of extensibility can be implemented. I’m sure this can vary by project and personnel, but it has been really true for me. It is so, so easy to write safe, huge programs in Python, and the fear of hitting an uncaught runtime problem after lots of wasted time is misguided. Meanwhile, the benefit of static typing in Haskell, for example, is that I can create stub functions for everything while working on the right type-level flow of operations. Then I have a nice end to end skeleton code with expressive application-specific type descriptions as I start to fill in the implementation for the stubs. And at the end, people can understand the code from reading the flow of type annotations.