News for hackers. Stuff that matters.
Re:Python’s “type hints” are a bit of a disappointment to me by tootie on Thursday April 21, 2022 @10:36PM (#31117611)
I'm baffled by people loving type hints in python when strongly typed languages have been widely available for so long. This is why people liked java and c#.
Re:Python’s “type hints” are a bit of a disappointment to me by coder543 on Thursday April 21, 2022 @10:53PM (#31117701)
There are way more differences between Python and Java than just "having explicit types". If that was the only difference, your comment would make more sense.

I would even go so far as to say that Java's type system is the very one that left such a bad taste in people's mouth that many people swore off explicitly typed languages for a decade or two. It really was that bad, especially before the last few years. It added a lot of extra boilerplate for minimal practical benefit. People used Java because it was fast, cross-platform, and less likely to go horribly wrong than unmanaged languages like C and C++. I doubt very many people used it because they just loved typing tons of boilerplate or because they thought the type system was good enough to catch tons of errors.

The type systems in Rust, TypeScript, and other more recent languages are far more expressive (and capable of catching real-world bugs) than what Java offered. If you think Java has a good type system... things have come a long way since then. Java gets updated continually, and some people will surely jump at my comment and claim things are great these days, but, no. Java is not up to par, even today. C# has done a better job of keeping up, in my opinion, but even it still lacks extremely useful features like proper Sum Types.

I don't have much experience with Python's type hinting, so I can't comment as directly there.

Re:Python’s “type hints” are a bit of a disappointment to me by cocoa19 on Friday April 22, 2022 @12:31AM (#31118233)
And many of us prefer simplicity in languages.

When a language like typescript supports too many obscure features, or multiple ways to do the same thing, the curve becomes too steep to be proficient.

Re:Python’s “type hints” are a bit of a disappointment to me by jve on Friday April 22, 2022 @08:54AM (#31121013)
> C# has done a better job of keeping up, in my opinion, but even it still lacks extremely useful features like proper Sum Types

Does type pattern matching comes close? https://dotnetfiddle.net/Oz2Qyd

Yeah, it doesn't prevent passing unexpected type as object to Print func and getting runtime exceptions. And returning "object" type isn't helpful if we want to prevent runtime errors. But then again, it can be written to spit out compile time errors: https://dotnetfiddle.net/XfKVaa

Re:Python’s “type hints” are a bit of a disappointment to me by mbrodersen on Sunday April 24, 2022 @08:21PM (#31149548)
F# is a great example of a strongly typed language where you almost never have to write type’s explicitly. The best of both worlds IMHO.
Re:Python’s “type hints” are a bit of a disappointment to me by smohare on Friday April 22, 2022 @12:38AM (#31118270)
You misunderstand the ecosystem. Many folk program in Python because it’s largely forced upon them. It’s often the easiest language to work with for data science, ML Eng, or data engineering, despite many frameworks actually running in the JVM. It’s simply more accessible. The appeal of Python has not been its provenance or design for over 15 years, but rather the ecosystem.
Re:Python’s “type hints” are a bit of a disappointment to me by whiplash451 on Friday April 22, 2022 @08:44AM (#31120927)
Most engineers I work with are very happy to work with python. They would not say it is forced upon them. You are free to provide a much better alternative (that does not exist as far as I know).
Re:Python’s “type hints” are a bit of a disappointment to me by minism on Thursday April 21, 2022 @10:38PM (#31117620)
Same thing happened to the JS world with typescript (though typescript seems more powerful than python type annotations).

Its fine though - I'm glad the culture is trending towards understanding that strong typing saves you time rather than causes you extra time. This is true even for very small and simple programs, and even if you're the only developer.

Re:Python’s “type hints” are a bit of a disappointment to me by goatlover on Thursday April 21, 2022 @10:48PM (#31117672)
The typing debate has been ongoing for decades, and it's switched back and forth a few times. JS, Python and Ruby all came out in the 90s, after there were plenty of statically typed languages being used at the time. Alan Kay has argued that types are too restrictive and usually don't describe the kind of data the program is really about. Maybe that's not as true for an advanced typing language like Haskell. And maybe Kay had C and Pascal in mind, when he thought of objects as being the basis for a proper dynamic type system.
Re:Python’s “type hints” are a bit of a disappointment to me by bayesian_horse on Friday April 22, 2022 @12:17AM (#31118153)
C,Pascal, even C# and C++ need type annotations mostly to actually make the program work. The type systems in Typescript and F# are more about helping the developer than helping the compiler.

Python type hints are slightly different because there are type hints as a syntax feature and then there is type checking, which can be static like mypy or during runtime like Beartype. Every type checker comes with its own type system, though they are hopefully somewhat similar...

Re:Python’s “type hints” are a bit of a disappointment to me by andrewingram on Friday April 22, 2022 @07:50AM (#31120472)
TypeScript has a more powerful type system, but arguably it's less powerful because the hints are invisible to runtime code. Python doesn't do any runtime type checking by default, but the hints are accessible in code, which unlocks a fair amount of power. For example, Strawberry is a GraphQL server library that allows you to define your GraphQL schema using the same syntax as dataclasses.
Re:Python’s “type hints” are a bit of a disappointment to me by aix1 on Thursday April 21, 2022 @11:43PM (#31117945)
Python is, and has always been, a strongly typed language.

Do you mean "statically typed"?

Re:Python’s “type hints” are a bit of a disappointment to me by jsmeaton on Thursday April 21, 2022 @11:48PM (#31117975)
I really like C# and have done a bunch of work with it in the past! But I also love Python for reasons other than just static vs dynamic typing.

To be honest, I think a lot of Python [or arbitrary dynamic language] developers can be quite sloppy, throwing dictionaries around everywhere because it's easy and leading to some really hard to read code. Type hints guide people away from that sloppiness while still allowing access to most of the features that make dynamic languages so useful and expressive.

It's a best-of-both-worlds situation and I'm here for it.

Re:Python’s “type hints” are a bit of a disappointment to me by grumpyprole on Friday April 22, 2022 @01:30AM (#31118507)
Many languages also demonstrated Python-like succinctness with strong static types and type inference. E.g. OCaml dates back to the 90's and ML dates back to the 70's.
Re:Python’s “type hints” are a bit of a disappointment to me by cttet on Friday April 22, 2022 @07:11AM (#31120241)
If the type system is not powerful enough it will be extra works just to get around the inadequacy.. If c# have some support of sum type and structural subtyping like Python I will be using that... I mean even Haskell does not have proper records.. Python is not definitely the best, but quite nice among the current options.
Re:Python’s “type hints” are a bit of a disappointment to me by vegai_ on Friday April 22, 2022 @12:15AM (#31118138)
There's a difference between putting on your own seatbelt and the car forcefully tying you into the chair every time you sit.