Live data from Hacker News

PEP 0484 – Type Hints is accepted

python.org

51–60 of 75 posts

Re: PEP 0484 – Type Hints is accepted

#52
post #9

So now two popular dynamic languages have type hinting of a kind: Python (unenforced annotations) and PHP (declarations). Great!

I encourage all use of the type system to ensure program correctness, but once you've had Hindley-Milner inference, it's hard to muddle along with something like this.

You can use both, actually. Type systems here days are more about type feedback (code completion, yeh!) than correctness (important, just not the central focus).

Re: PEP 0484 – Type Hints is accepted

#53
post #37

Earlier quoted context omitted.

It really is. Since using Haskell, the type systems in the mainstream languages I've used have seemed sorely lacking.

Though make the type system sufficiently more expressive than Haskell's and you have to give up on type inference again... Though maybe you could restrict how expressive the type system is on something like a module (Haskell module) level, so that you can have type inference if you give up on some power? I don't know.

Type inference doesn't somehow fail if we go beyond Haskell's type system. The inferable subset of the language remains inferable. Haskell already has inferable (Hindley-Milner) and uninferable (higher-rank polymorphism, GADTs) parts. If we go beyond Haskell's type system, it actually becomes crucial for productivity to have powerful type (and term) inference. Agda and Coq both have much more powerful inference than Haskell; it's just that don't bother with using it to realize Hindley-Milner-style annotation-free bindings, because there's little use for it in proof assistants.

Re: PEP 0484 – Type Hints is accepted

#54
post #47

Earlier quoted context omitted.

Though I agree with your sentiment, I must mention that there is nothing "weak" about Python's type system. You likely meant "dynamic", not "weak". See here: wiki.python.org/moin/Why%20is%20Python%20a%20dynamic%20language%20and%20also%20a%20strongly%20typed%20language

Yep, thanks.

[deleted]

Re: PEP 0484 – Type Hints is accepted

#55

Earlier quoted context omitted.

Though I agree with your sentiment, I must mention that there is nothing "weak" about Python's type system. You likely meant "dynamic", not "weak". See here: wiki.python.org/moin/Why%20is%20Python%20a%20dynamic%20language%20and%20also%20a%20strongly%20typed%20language

Python's type system is weak whether they self-identify that way or not. Types are implicitly converted in a variety of cases, notably True-ness. Meanwhile, runtime type identity is kind of meaningless; classes and individual objects can have their behavior meaningfully changed at runtime. The most you can say about any variable in Python is that it is a descendant of 'object' or else some primitive type.

I think you should brush up a little on your python-bashing methodology. It might work on individuals that don't know enough about Python, but not for the rest of us.

Re: PEP 0484 – Type Hints is accepted

#57
post #14
post #12

Earlier quoted context omitted.

Yeah, isn't that amazing? I really think this "type" idea is a good one. I wonder if other languages have thought about following Python's lead and adding a type system.

Would you like to reconsider your tone?

Wow, he used sarcasm to make a point that was both humorous and relevant, and you're reacting like an imam hearing a joke about muhammad.

Maybe you should reconsider yours?

Re: PEP 0484 – Type Hints is accepted

#58
post #38

Earlier quoted context omitted.

Python's type system is weak whether they self-identify that way or not. Types are implicitly converted in a variety of cases, notably True-ness. Meanwhile, runtime type identity is kind of meaningless; classes and individual objects can have their behavior meaningfully changed at runtime. The most you can say about any variable in Python is that it is a descendant of 'object' or else some primitive type.

If Python's `if` is weakly typed, then Rust's `for` and `.` are weakly typed. Few would say that, though.

One place where Python is pretty weakly typed is going the other way, where it accepts things like: true + true * 2 - false / true, even outside of if statements.

I've definitely been bitten by this before, accidentally passing in a book parameter instead of an int, and having some math work initially and then blow up months later.

Knuth argues against this kind of implicit bool to integer conversion in Concrete Mathematics.

Re: PEP 0484 – Type Hints is accepted

#59
I mostly like Python for its clean syntax but the examples contained in this PEP turn unreadable really fast. I don't look forward to this and I don't really see the point of it. I can see how it can be useful in theory but, in practice, I just see a symptom of language bloat.

The way I see it, if you find yourself in the situation where explicit type checking is important, there's probably something wrong with your process or team. Either your are not testing properly, or your team's mindset is more adjusted to another language.

The danger I see with this becoming widespread is Python becoming somewhat like C++ where it's very easy to come across code one can't easily read because it uses a different subset of features than you're used to. This sort of "language accents" so common in human languages is something that should be avoided in computer languages, IMHO.

Re: PEP 0484 – Type Hints is accepted

#60
post #58
post #38

Earlier quoted context omitted.

If Python's `if` is weakly typed, then Rust's `for` and `.` are weakly typed. Few would say that, though.

One place where Python is pretty weakly typed is going the other way, where it accepts things like: true + true * 2 - false / true, even outside of if statements. I've definitely been bitten by this before, accidentally passing in a book parameter instead of an int, and having some math work initially and then blow up months later. Knuth argues against this kind of implicit bool to integer conversion in Concrete Math…

Nitpick: this isn't an implicit conversion.

There's a lot of history of languages without a real boolean type using integer 0 and 1 as the sentinel values indicating false-ness and true-ness.

And Python, in a nod to that, implements bool as a subclass of int, of which only two instances can ever exist (with False having a value of 0 and True having a value of 1).

So this isn't weak typing -- isinstance(True, int) is True in Python, and operations like the ones you're mentioning work because of that, for the same reason any other subclass of int would work.

Post reply on HN