News for hackers. Stuff that matters.
Re:Strong typing, a hill I'm willing to die on by JonChesterfield on Wednesday October 04, 2023 @11:13AM (#37766353)
It really matters which static type system is in question.

SML or Haskell? Yep, like those ones. The languages would not be so useful without their compile time type checking.

C? Not worth the trouble. C++? Not worth the tarpit or the trouble.

Python? Definitely not keen, that language was much better without the annotations.

Typescript people really like but I haven't played with. I'm pleasantly surprised that unsound static + sound dynamic works well.

Type annotations are not inherently good. Some type systems add a lot of value, some really don't.

Re:Strong typing, a hill I'm willing to die on by xigoi on Wednesday October 04, 2023 @11:44AM (#37766855)
> C? Not worth the trouble. C++? Not worth the tarpit or the trouble.

The OP said strong static type system, so C and C++ are out of the question.

Re:Strong typing, a hill I'm willing to die on by chongli on Wednesday October 04, 2023 @11:52AM (#37766986)
This is not about type annotations, it’s about type systems. You can write Haskell programs without any type annotations. Your program will type check and compile just fine. The value comes from the checks (as well as the inference, documentation, optimization, and everything else a modern type system gives you), which you don’t have to write yourself, you get them for free.

People who say they prefer dynamic languages are really just saying ‘no’ to all these free benefits.

Re:Strong typing, a hill I'm willing to die on by JonChesterfield on Wednesday October 04, 2023 @12:12PM (#37767285)
If your language is wholly type inferred, and the type system is expressive enough to deal with whatever one wishes to write, it is indeed "free". If you ignore compile time performance, run time performance, and that you're writing in something between Idris and vapourware.

Otherwise the cost is merely being unable to write anything that the type checker does not understand, and however long your compiler takes to do the checks on what it does understand.

Also a fair chance the whole program must type check before you can see the results of changing a subset. In the worst case you get to hunt down all the unused variables before it'll run the test suite.

I prefer dynamic languages. That makes me a heathen on these boards, to be ignored or chastised for my stupidity. Regardless, those benefits do not come for free.

Re:Strong typing, a hill I'm willing to die on by WJW on Wednesday October 04, 2023 @12:16PM (#37767348)
Even though I usually fall more on the "types good" side of the discussion, the advantages you listed are not free at all. They come at the cost of at least:

- having a compile step in between writing and running your code. This drastically slows down the feedback loop of development. The more your compiler has to check for you, the slower it gets.

- being able to run your program in a half-broken state. This may not seem like much of an advantage, but sometimes it is good to just be able to run a broken piece of code to see how it crashes. This is especially important when learning to program, but is still very beneficial when learning a new language or framework, or sometimes for debugging.

- As someone who has contributed to the main Haskell compiler, I can definitely confirm that a more complicated type system can slow down development of the language itself too. It takes significantly more effort to grok all the possible interactions as the codebase of the compiler grows.

Don't get me wrong, I think encoding and enforcing program properties with types is a great idea that will grow further in the future. But the dynamic languages gained popularity for good reasons, and some of those reasons are still valid today.

Re:Strong typing, a hill I'm willing to die on by ActorNightly on Wednesday October 04, 2023 @01:14PM (#37768368)
>SML or Haskell? Yep, like those ones

Not strong enough.

If you are proponent of strong typing, you need something that is effectively a theorem prover. I.e when you define a type, you define the scope of the data it can hold, operations on that data, and the resultant types of those operations. That way, when you code compiles, it is by definition "correct".

When you accept anything less then that, you are basically making a statement that you are willing to forgo some of that correctness for convenience, which is fine, but that means that no language out there is really good or bad.

Re:Strong typing, a hill I'm willing to die on by DonaldPShimoda on Wednesday October 04, 2023 @01:27PM (#37768597)
Theorem provers' type systems are not necessarily stronger than SML's or Haskell's; they are more expressive, which is a separate thing entirely.

That said, your position is also just weird to me. Yes, theorem provers have nice type systems that are wonderfully expressive. The trade-off is that some common programming patterns become difficult to use or are even impossible.

When it comes to everyday programming, I don't think theorem provers are at a point where they are particularly useful. Not everything needs to be proved formally, and I don't think this position is at odds with the belief that static type systems are generally "better" than dynamic ones.

Re:Strong typing, a hill I'm willing to die on by ActorNightly on Wednesday October 04, 2023 @02:49PM (#37769809)
> The trade-off is that some common programming patterns become difficult to use or are even impossible.

Not really. Strong and expressive typing at its core is simply creating data packaging containers that have defined operations on them. It says nothing about logic. You may be referring to the functional programming aspect that comes with strong typed languages, which is related but not the same as strong typing.

The point is that typing is just a tool that a programer can use, whether its built into the language or ran statically like MyPy. You can take a piece of code in C, and write a test suite on input and output of that piece of code, and accomplish much of the same thing that typing accomplishes. However, in the case of strict+explicit typing, the idea is that you wouldn't need tests in the first place, because your code would be correct by nature of compilation.

Re:Strong typing, a hill I'm willing to die on by DonaldPShimoda on Wednesday October 04, 2023 @03:36PM (#37770455)
No, you are wrong.

Some theorem provers, such as Coq, are not Turing-complete. This means you cannot write some programs, and in particular you cannot write infinite loops in Coq. Infinite loops are a common pattern (e.g., a REPL or a GUI display waiting for input).

This is a trade-off, as I said. You gain the expressive type system, but lose the ability to implement certain programming patterns. It has nothing to do with the strength of the type system.

---

> whether its built into the language or ran statically like MyPy.

All (true) type-checking is static, so MyPy "running statically" is not a noteworthy feature to distinguish it from other type checkers. I guess this point may seem trivial to some, but the broader context of this conversation involves conflation of the terms "static type system" and "strong type system", so your misuse of the word "statically" here seems worth pointing out.

That said, whether you use an external tool to check your types or the type-checker is built into the compiler is irrelevant, and I'm not sure why you brought it up at all.

---

> You can take a piece of code in C, and write a test suite on input and output of that piece of code, and accomplish much of the same thing that typing accomplishes.

Depending on the perspective, this is factually incorrect.

Type-checking is an ahead-of-time operation that guarantees the absence of certain classes of errors at run-time. Writing tests to check for the absence of such errors is not equivalent, because you have not proved anything; you merely gain confidence. They are semantically distinct, even if you write many tests to gain a lot of confidence.

Re:Strong typing, a hill I'm willing to die on by ActorNightly on Wednesday October 04, 2023 @04:14PM (#37771032)
>Some theorem provers, such as Coq, are not Turing-complete. This means you cannot write some programs, and in particular you cannot write infinite loops in Coq.

You are talking about languages, Im talking about the concept. The modern theorem provers aren't up to the task. Due to Rices theorem, you cannot "fully prove" a program, so a language that does this couldn't even exist. The strict typing however can be applied to subsets of the programming space, namely the data processing pipeline, whereas higher level stuff like the actual server code that does have an infinite loop to listen to requests can be written in whatever.

The point is that no language recommended for strong type safety today is anywhere fully complete to include the rigor of something like a theorem prover, and anything less then that is basically your own opinion on what is "good enough".

>Type-checking is an ahead-of-time operation that guarantees the absence of certain classes of errors at run-time.

Run time errors are no different than compile time errors as far as testing is concerned. Its not like the computer blows up when you have a seg fault. And you absolutely can prove what you need for operation.

Say your input to your code is an HTTP request of length x. And output is some data processing on that request. You can write a test suite that is basically like this

1. Ensure that code returns a well defined error for x values outside of given range.

2. For all valid ranges in x, test all possible values of every byte in that range, and ensure correct behaviour.

While overkill, this will absolutely exercise every single piece of your code and prove correctness. You can also couple this with checking things like memory access

Re:Strong typing, a hill I'm willing to die on by JonChesterfield on Wednesday October 04, 2023 @05:26PM (#37772022)
SML is good enough for theorem proving. That's what it was written for. Though you probably want convenience libraries on top, maybe the one called HOL.
Re:Strong typing, a hill I'm willing to die on by yxhuvud on Wednesday October 04, 2023 @02:38PM (#37769652)
100% this. Developer experience in a language is a so much bigger question than if it has static types or not.