by jenscow · 6y ago · 0 comments
But I agree, it's a waste to type it all out. So I use an intelligent IDE that reduces the repetitive typing:
So typing `Person.var` gives me `Person person = new Person();` or typing `Person person = ` will suggest `new Person()`
Sure, it doesn't look as appealing when creating an new object, however I get a better information when you've written something like:
Person me = something.GetOwner();
rather than: let me = something.GetOwner();Alan Kay made essentially this suggestion when the requirements for the language that became Ada were being debated, but it was not taken up at that time.
The original C++ 'throw' declaration is an example of an ill-conceived attempt to provide and use more context, and an example where tools provide a better solution than piling on the syntax.
let me: Person = something.getOwner();
so you still have the freedom to write the type explicitly.The white text on a gray background is provided by my IDE.
Honestly though, this is a tooling problem. There's no reason at all that developers should need to spend time encoding information into the source code that's already known to the compiler, but devs also need to use tools that can feed the compiler's knowledge back to them. Jetbrains Rider (and their Resharper extension for Visual Studio) have a set of options called inlay hints [1] that do this exact thing. Personally I tend to keep most of the type hints turned off because they do add a lot of clutter, but the feature is absolutely invaluable for parameter name hints.
[1]: https://www.jetbrains.com/help/rider/Inline_Parameter_Name_H...
The newest C# has the reversed inference for ctors too, so you can actually do this and not have to repeat it and still get it first.
Person p = new();