Live data from Hacker News

Diminishing returns of static typing

blog.merovius.de

61–70 of 632 posts

Re: Diminishing returns of static typing

#61
post #3

The benefit of static typing isn't just reliability. Tooling is another major argument. Won't appeal to certain hardcore programmers who think that even notepad has too many features. But it is great for refactoring, finding all references to a function or a property or navigating through the code at design time. Basically all the features visual studio excels at for .net languages. And I disagree with the barrier to…

>Tooling is another major argument. vscode seems to figure out the types in javascript without any static typing. >But it is great for refactoring Searching for strings isn't that much worse. Also, when it comes to web development, you cross into the client-side and suddenly you can't refactor. So you can only refactor the server-side and end up with a mismatch. >finding all references to a function or a property or…

>vscode seems to figure out the types in javascript without any static typing.

There are limits to type inference. And if you're going to rely on type inference to prevent runtime bugs you might as well double-down on static typing since you're giving up on some of the 'features' (insanity) of dynamic languages anyway.

Dart 2.0 now mandates strict typing but will allow you syntactic shortcuts as long as the compiler can infer the type (if it can't, you get a compile-time error) - that's a great compromise. I wish more people would love Dart. It's such a great, well-designed, language.

>Searching for strings isn't that much worse.

There are very real limits with what you can do with 'strings'. And yes, it is that much worse.

>When I was working in c# on the server and javascript on the client, I really hated having to go back into c#.

I do not understand that view. You are an alien to me. C# is a beautiful language that fixes a lot of syntactic problems in Java. It is much more pleasurable to write C# code than JS code (outside of dinky 50 line programs).

>I think static typing is necessary when you need performance because all of the fast languages are statically typed.

That's not the only reason but it is one of them. JIT and AOT compilers can do more with strongly typed code.

>There are a ridiculous amount of tech companies that have used dynamic languages to go from nothing to the biggest companies in the world and only switched to static languages well and truly after that occurred.

Sure. PHP (pre-5) and JavaScript made a ton of money for a ton of people. Both languages were integral in the Web revolution. Doesn't change the fact that PHP was a terrible language and JavaScript is still a terrible language.

Re: Diminishing returns of static typing

#62
post #32

Earlier quoted context omitted.

Does anyone believe in using the wrong tool for the job?

Yes! Many engineers use tools they like for reasons unrelated to the job they're doing or the product they're building.

It might still, at least arguably, be "the right tool for the job." If you have a huge team of expert C# developers C# might be "the right tool for the job" even if it would be a little easier to do in a different language, given the same pool of experts in that language.

Re: Diminishing returns of static typing

#63
post #45

The effort to fix a defect is proportional to the time between introduction of a defect and it's discovery. This is a basic intuition behind all good practices, including CI, QA, etc. Types allow one to discover program defects (even generalized ones, when using some of the programming languages) in (almost) shortest possible amount of time. Types also allows one to constrain effects of various kind (again, use good…

Also, retaining dynamic types at runtime enables you to find type errors that the static type system could not discover, or that were worked around. Language implementations that discard dynamic types make it harder to find defects.

Re: Diminishing returns of static typing

#64

Earlier quoted context omitted.

Does anyone believe in using the wrong tool for the job?

At a place I worked at once, it was "use Microsoft for everything". So yeah.

Yeah but that's more a matter of the criteria to decide on the right tool. Nobody would say "I intend to use the wrong tool for the job."

Re: Diminishing returns of static typing

#65
post #38
post #9

Earlier quoted context omitted.

Dynamic languages support this kind of tooling too - you can even have seamless data completion (eg. map/dictionary keys). The original Refactoring Browser was written for Smalltalk. Etc. Of course there are cases where dynamic languages do worse, but it balances out I think.

But how can you offer any refactoring or auto-complete inside a function if you don't know what type to expect as an argument?

You can, but you may start to run into some limitations. Many languages have some version of type inference, which allows them to figure out the type of a thing, even though the programmer didn’t specify it.

C# has a very weak version of this with the auto keyword. Languages like Crystal take it much further by tracing the flow of data through the entire program. It generally works quite well, though there are a few edgecases that require explicit type annotations.

As for auto-completion, some languages feature designs that make it easy to offer auto completion even without type information. For instance, Elixir doesn’t have methods. You only have functions defined on modules, and it’s trivially easy to know what functions are defined on a module.

So it’s possible, but there are some limitations.

Re: Diminishing returns of static typing

#66

Just a technical point that hints at a significant philosophical idea: The asymptote cannot reach 100% of program behavior in any finitary way. That would solve the halting problem. The x-axis should go off to infinity. Also, it's not a smooth progression. There are huge jumps in expressivity involved here. Going from Java-style types to Hindley-Milner to full System F are all massive jumps in expressivity. There are…

> The asymptote cannot reach 100% of program behavior in any finitary way. That would solve the halting problem.

There are languages that enforce termination. They only accept programs that can be shown to terminate through syntactic reasoning (e.g., when processing lists, you only recurse on the tail), or where you can prove termination by other means.

Coq is like this, as is Isabelle, as is F* , as are others. They also provide different kinds of escape hatches if you really want non-terminating things, like processing infinite streams.

This "we can never be sure of anything, because the halting problem" meme is getting boring. Yes, you cannot write the Collatz function in Coq. No, that is not a limitation in the real world.

Re: Diminishing returns of static typing

#67
post #3

The benefit of static typing isn't just reliability. Tooling is another major argument. Won't appeal to certain hardcore programmers who think that even notepad has too many features. But it is great for refactoring, finding all references to a function or a property or navigating through the code at design time. Basically all the features visual studio excels at for .net languages. And I disagree with the barrier to…

I can do all of those things in Smalltalk, which is dynamically typed; these things are not byproducts of static typing, they're simply byproducts of mature tools. So no, these are not arguments in favor of static types.

>> finding all references to a function Yes, you can find all references to a method in Smalltalk -- but those references are not separated-out from all the references to other methods that happen to have the same method name but are defined on a different class.

With type information for the receiver and method arguments, we can find just the references we're looking for.

Re: Diminishing returns of static typing

#68
post #54

Having programmed in languages ranging from Ruby to Coq, for web apps and games, I feel the sweet spot is somewhere in the neighborhood of Java/C#, i.e. include generics but maybe leave out stuff like higher kinds and super-advanced type inference (and null!). The main use case of generics, making collections and datastructures convenient and readable, is more than enough to justify the feature in my view, since virt…

> An awful lot of energy was wasted memorizing various tricks and conventions to make do with loops, slices and maps where in other languages you'd just call a generic method.

I feel the same way going from languages with HKTs back to Java/C#...

Not sure why you think they're not as useful, it sounds like you're making the same argument as OP but just moving the bar one notch over...

Re: Diminishing returns of static typing

#69
Like other commenters, I disagree there are diminishing returns to static typing itself, but rather diminishing returns to proper engineering in certain cases (i.e. do something as perfectly as possible).

By adding types (and in the extreme, dependent types), you're allowing compiler to prove more things about the code (to check correctness or generate more optimal code). If you actually need to prove more things, then it's better to leave that for a compiler rather than human.

Of course, if you're writing e.g. web scraping script, you don't need these guarantees and then you don't have to care about types. But the better engineering you want, the more static typing will help and there is no diminishing returns.

Re: Diminishing returns of static typing

#70

Earlier quoted context omitted.

>Not just, "who the hell uses this", but "where the hell is this defined" as well. On Common Lisp, a dynamic language, I can also get this answered instantly. I just press a key combination on a method call and i jump to the definition. So this isn't exclusive to statically typed languages.

Lets be real, when we say dynamic languages, we aren't talking about niche languages like Lisp. We are talking about JS and Python almost exclusively.

Python has jump to definition too.
Post reply on HN