The big problem with this take is that they seem to assume it is an all or nothing feature.
Personally I love how rust does it, types are inferred inside a body of a function where they matter less and are generally unambiguous (you need to specify them if they are ambiguous) as you often don't care as much about the exact type you have. But on function parameters are return types they are never inferred as these form the contract to the rest of your program and a unexpected change to one of these can result in your code breaking somewhere else entirely.
Personally I never really use the automatic type annotations in IDEs, they just add noise I rarely care about.
The solution to this problem (and many others) is to use an IDE / editor which supports refactoring like that. Which is pretty much every IDE / editor unless you're using some very obscure language I think.
If it returned a "Foo", whose structure changes in such a way as to requires changes in all places it was used...
That, sounds to me like a disaster you avoided by being helped (which is the polite way to describe developers not getting away with ignoring lazy and dangerous type conversion bugs) to fix each and every usage of it.
I can't speak for OCaml, but type inference provides a lot of benefit in Rust. I already have too many keystrokes as it is, and forcing me to be explicit about everything would just add to the stress of using a keyboard.
I agree that types should be explicit at API boundaries. That's precisely where you want to catch misuse.
As for the point about inference making code harder to read: I suppose that's true if you spend a lot of time reading code outside of your editor where you also must know what the types are. But that just sounds like a bad workflow in general. Why are you avoiding using a better tool for the job? Modern code review tools like Github even support LSP-like features to solve this problem; and if your language isn't supported... just pull the feature branch to review it.
He explicitly states that its not that bad in Rust because all functions must have type annotations. Its only a problem if your functions are huge (they shouldn't). I think thats the correct way to go. Local variables can be inferred but anything else should be annotated.
Modern code review tools like Github even support LSP-like features to solve this problem; and if your language isn’t supported… just pull the feature branch to review it.
But now your requiring more tools and effort on the reviewer over, just reading the code.
It’s really weird to me to base any decisions around how much typing you have to do.
Typing is such a small part of programming I really don’t get it.
Typing is a huge part of programming. Have you heard of RSI? People invest hundreds (sometimes thousands) of dollars in ergonomic keyboards just to overcome RSI pain. If you're younger than 30 you might not be impacted by this, but many people who have been typing every day for over a decade are realizing it's not sustainable without proper ergonomics.
Readability and maintainability are core imo.
I don't think you sacrifice these by having local type inference. It's never been an obstacle for me.
Type inference is wonderful for prototyping and writing short lived tools - it is an unnecessary expense for mature projects with a large number of developers on it.
At my shop we have a concept of "one off" routes that are written to accomplish a specific task and intended to be run once. A few of these are run repeatedly but with the understanding that these routes are unmaintained and exempt from automated testing requirements (we've got a separate bucket for routes that are only rarely invoked but are complex enough and frequently enough used to get test coverage). For stuff like those one off scripts I'll never block a PR for omitting typing - while I absolutely will in our regular codebase.
I prefer type inference. It's extra clutter that can often be abstracted away with good variable and method names. If it quacks the way I need it then that's one less thing I need to hold context of in my head.
You should read the article, because it's pretty much a direct rebuttal with justifications to this exact argument. You've really just re-stated what the article disputes.
Which isn't to say you're wrong, I'd just be interested in your response to the arguments.
The article doesn't make a persuasive case at all. It immediately backs off by acknowledging that 99% of type inference is fine, because it's really only complaining about function signature inference, which is an extreme case that only a few obscure ML variants like Ocaml and F# support.
It's like saying all american movies are terrible, and then clarifying that you've only seen White Chicks
My response to the article is that you're sacrificing gains in language because some people use outdated tools. Code has more context than what is just written. Many times you can't see things in the code unless you dig in, for example responses from a database or key value store, or literally any external api. Type inference in languages that have bad IDE support leads to a bad experience, hence the author's views on ocaml. But in a language like Kotlin it's absolutely wonderful. If needed you can provide context, but otherwise the types are always there, you can view them easily if you're using a decent IDE, and type inference makes the code much more readable in the long run. I would say that a majority of the time, you do not care about the types in any application. You care about the data flow, so having a type system that protects you from mismatched types is much more important that requiring types to be specified.
That’s false for closures (or unnamed/inline) functions with context because their type is unique and so you just can’t write their type and that’s not a lang’s fault - that’s logically correct side-effect by-design.
To me this is an argument for why Go should not add type inference to function/method declarations. Go is like Rust (I guess, I haven't used Rust) - type inference works for declaring a variable (or const) and generic type parameters but not for type declarations, methods, functions, etc. I was in the "more inference is always better" camp but now I'm thinking Go has the perfect level of inference. Except for function literals/lambdas. I really want go to infer the argument and return types when I'm passing a function literal/lambda to a function.
The thing about Rust's type inference that seems wild to anyone who hasn't seen Hindley-Milner/ML style type systems before is that it's "bidirectional" (in quotes because that's not a proper type theory term as far as I know). The type of the left-side of an assignment can determine the type (and behavior!) of the right side. For instance, this is ambiguous:
let foo = [("a", 1), ("b", 2)].into_iter().collect();
The expression creates an iterator over the (letter, number) pairs, and collect() stores the elements in a newly created container. But which container type? Here are two valid variants:
let foo: Vec<_> = [("a", 1), ("b", 2)].into_iter().collect();
This creates a vector with items ("a", 1) and ("b", 2).
let foo: HashMap<_, _> = [("a", 1), ("b", 2)].into_iter().collect();
This creates a mapping where "a" and "b" are keys, and 1 and 2 are the corresponding values.