Hacker News new | ask | show | jobs
by santiagobasulto 18 days ago
Python is not statically typed, so I’ll leave it out of the conversation cause it doesn’t even qualify.

As for Typescript, everything is wrong. Interfaces can’t describe static methods, can’t declare what exceptions a method throws, etc. not even gonna mention type variance because it’d be a waste of time.

I used to study a lot type systems in my youth. Correct statically typed languages are not practical (think Scala). Practical languages can’t be correctly typed (think Go or even Java). There’s always a compromise. That’s why project like this one makes me chuckle, the idea of using statically typed languages is to introduce “some” safety and correctness, so trying to go the other extreme makes no sense.

2 comments

It's very hard to argue against something so hand-wavy where you won't even bother with certain arguments "because it'd be a waste of time". I also doubt that you yourself have a proper definition in your head for what "statically typed" really means, nor do you really answer why these languages "do typing very wrong", whatever that is supposed to mean.

"Python is not statically typed" doesn't really make sense, because if it is possible to build a static type-checker for python, then you can in fact write statically typed programs in Python, whether or not it is dynamic underneath. The same applies to TypeScript. If I have checked all the types in my program statically, I have written a statically typed program, regardless of whether javascript is dynamically typed underneath.

As for this project: I don't think it's useful because the type-checkers that exist for python have type inference. There is no particularly good reason to give every single thing a type annotation because it provides very little value.

In the end, the only question that is relevant for these sort of type-checkers that are built after the fact is really "Do they provide extra safety and value?" and the answer is very clearly a resounding "yes". Your theoretical gripes don't really have any bearing on that.

I'm sorry if it sounded that way, I'm just bored of this topic. I spent most of my 20s researching and debating on it. I have a much more pragmatic approach now.

Regarding Python, I didn't even want to mention it because it'd not be fair. I could point out the shortcoming on Python type annotations: - Completely unsound (you can use `Any` everywhere) - lack of type-level evaluations: a `match` can't be type-annotated - Lack of variance expressiveness: can't declare variance on methods for example - etc...

But the answer regarding Python's type annotations shortcomings is basically "all of them", because it was not designed to be a statically typed language.

And regarding your question: "Do they provide extra safety and value?"

Sadly, it's not a yes/no answer. The answer is "it depends". For example, a method defined as `sum(l: List[Int])` cannot express if it works with an empty list, and depends on the value passed at runtime.

But in Lean you can define:

    def sum (xs : Array Int) (_ : xs.size > 0) : Int :=
So the following expression doesn't even compile:

    #eval sum #[]
And funny enough, the research behind this is called "Dependent type research" [0].

But again, my approach now is a lot more pragmatic. Similar to your question, mine is: can I break down this piece of software in very clearly defined contracts and layers and make it blow up at compile time if anybody violates these constraints or encapsulation? If the answer is "Yes", that's good with me. Python qualifies, Typescript qualifies (although I hate its type system more than python's, etc).

[0] https://en.wikipedia.org/wiki/Dependent_type

Is Rust correctly typed? Is there anything wrong with it
I'm not familiar enough with Rust to say. Especially given it's a system language, and type systems get a lot more complicated the moment you have a pointer :) You have to keep track of memory ownership, aliases, and mutations over time.