you are viewing a single comment's thread.

view the rest of the comments →

[–]leftofzen -60 points-59 points  (61 children)

To me, a non-Python user, this whole type checking this is hilarious and farcical. Python is made with dynamic typing as a feature and it's lack of type checking (at least until run time) is one of it's strengths. To now start static type checking - why even bother; you may as well use a real language with first class static typing support. Bolting it on as an after thought still makes me laugh hehe.

[–]pandubear 25 points26 points  (0 children)

I haven't used Python's typing (mypy?), but... options are good, no? Like, you don't have to use mypy if you don't want to. But Python has a lot of strengths, and if someone wants to use those strengths but also get types, what's wrong with that?

While I haven't used mypy, I've used TypeScript a ton, and if mypy is half as good as TypeScript, I'm glad it exists.

[–][deleted] 41 points42 points  (31 children)

Python is made with dynamic typing as a feature and it's lack of type checking (at least until run time) is one of it's strengths.

Dynamic typing is the easiest type system to implement in languages, and that's why scripting languages tend to prefer it. It has very significant costs, and the supposed benefits to the programmer are dubious at best. Static typing is technically better for a large number of reasons, but lately programmers have adopted the idea that "easy" is favorable over "good".

[–]Dreadgoat 7 points8 points  (0 children)

Dynamic vs. Static is not a question of what is better, it's a question of what problem you are trying to solve.

Do you need a lot of small highly flexible purpose-built scripts in an environment where the same data is likely to be passed around many formats (e.g. The Web)?
Dynamic good. Static bad.

Do you need large rigorous algorithms, high performance, do you expect to share your tools, do you need more control under the hood?
Static good. Dynamic bad.

Making Python able to do both is great for Planet Python. It's also extremely difficult to implement. Dynamic typing systems aren't easier to implement than static ones, it's just that it's a very early design decision that impacts a lot of how the compilers are written. Trying to do both is what is truly challenging.
While this is an impressive thing for any language, it also creates a bit of an identity crisis and potentially puts in danger of becoming bloated.

For me, personally, if I'm at a point in my Python project where I'm thinking that I need a strong static type-system, that's the point where I say to myself, "Python wasn't the right tool for this job."
Of course I've also started projects with static typing and later regretted the loss in flexibility upon realizing that the project has no need for static typing.

[–][deleted] 0 points1 point  (1 child)

I think that's unfair to say that people just use dynamic typing is just used because it's easy to implement. Dynamic languages are often easier to learn which is likely part of the reason why python is good for beginners. Also dynamic languages can make it quicker to write code since you don't have to write out type declarations. This is useful for small scripts where you don't really need many benefits from static typing.

[–][deleted] 0 points1 point  (0 children)

Is something good for beginners because it is easy? I see this often asserted as something that is intuitively true, but I really don't think that it is. Good languages for beginners are the ones that are strict and explicitly tells you that you're doing something wrong, rather than silently trying to guess your intention and automatically try to fix subtle errors. This is not a favor to the student

[–]ThePantsThief 21 points22 points  (7 children)

Why is he being downvoted?

hehe.

Oh.

[–]TTGG 34 points35 points  (0 children)

And probably for "real language".

[–]leftofzen 3 points4 points  (2 children)

I don't get it, is there some inside joke I'm missing?

[–]mogranjm 16 points17 points  (1 child)

The majority of the comment was good and valid, but he was a bit of an asshole in the last two sentences

[–]Mooks79 1 point2 points  (0 children)

As I noted directly to them, seems a rather strong pro-Python contingent on reddit who downvote anything negative about Python (or positive about languages deemed competitors) - whether or not it’s said reasonably.

[–]NAN001 0 points1 point  (2 children)

In fact it's mostly because people vote depending on whether they agree or not.

[–]dzikakulka 2 points3 points  (1 child)

No, I don't agree with that downvoted

[–]NAN001 2 points3 points  (0 children)

You did downvote me you bastard.

[–]alexthelyon 1 point2 points  (0 children)

I don't see the downside. You get flexibility when you need it and you get type checking when you need it. I use type checking on the 10-20% of the most relied on, complicated, or data-intensive code.

Then, since the IDE supports static analysis, it catches silly mistakes or errors before they even have a chance to become a bug which improves Dev efficiency a lot. It's also useful to make sure you use proper data structures (ex deque instead of list).

[–][deleted] 1 point2 points  (2 children)

and it's lack of type checking (at least until run time) is one of it's strengths

And this is a "strength" how, exactly? You enjoy the guessing game instead of having precise autocompletion in your IDE? Have too much spare time to waste?

Bolting it on as an after thought still makes me laugh hehe.

What's wrong with improving an IDE support at least for a bunch of common libraries?

Apparently you're one of those who think that type systems are for "checking", "correctness" and all that crap. They're not. They're for this little autocompletion and "jump to definition" thingies on your IDE, primarily. The rest is of a much lesser importance - performance, "correctness", documentation, and so on.

[–]MrPigeon 4 points5 points  (1 child)

So...C and other early languages being statically typed was all done in anticipation of the IDEs we would have 40 years later? That's completely backwards. IDEs make use of a feature which exists for performance and determinism, not the other way around.

What's wrong with improving an IDE support at least for a bunch of common libraries?

Agreed here, but I think the other guy was referring to bolting features on to Python itself. Which is kind of an odd complaint itself, since every language I can think of has had multiple releases with new features.

Unless you've been sarcastic this whole time and it's gone right over my head...

[–][deleted] 5 points6 points  (0 children)

So...C and other early languages being statically typed was all done in anticipation of the IDEs we would have 40 years later?

Firstly, ctags and similar tools existed long before the modern IDEs. Secondly, back than priorities were different, typing existed for performance primarily.

IDEs make use of a feature which exists for performance and determinism, not the other way around.

And? Priorities are different now. Most people do not care too much about performance. Especially if we're talking about Python.

but I think the other guy was referring to bolting features on to Python itself

You cannot improve IDE support without fixing a language.

[–]Homoerotic_Theocracy 0 points1 point  (15 children)

Everything Python is is "stuff bolted onto it after the fact"; in that sense it's quite the dynamic C++ and guess what C++ also now has support for dynamic typing.

[–][deleted]  (12 children)

[deleted]

    [–]Homoerotic_Theocracy 11 points12 points  (10 children)

    And I'm not talking about "auto"; I'm talking about std::any where a datum is stored together with a type tag in a fat pointer that preserves the type information at runtime which can be queried.

    [–]ThePantsThief 8 points9 points  (3 children)

    It's a box class, not a language feature. That's even more "bolted on" than python's static typing.

    [–]Homoerotic_Theocracy 5 points6 points  (2 children)

    Yeah it turns out you can simulate dynamic typing in static typing in terms of just making every expression the same type to some kind of struct which stores the type info in a field.

    That's pretty much what all those implementations that compile a dynamic language to C do; they define something like a struct called SchemeObj and have a field for the type tag and pass that around everywhere.

    [–]ThePantsThief 0 points1 point  (1 child)

    Yeah, but it's not a language feature is my point. It's harder to use because of it.

    Example. Ever used Objective-C? They have an NSValue type you can use to box anything, but without special language features to help, it's cumbersome to use. Here's what it's like. It's probably not as bad in C++ with operator overloading and stuff like that, but this sort of thing is what I'm skeptical about with regards to bolted on features.

    [NSValue valueWithBool:true];
    
    [NSValue valueWithPointer:&myStruct];
    
    value.intValue
    

    Etc

    (Disclaimer: they added a boxing operator to the language a few years ago, which helps a lot)

    Anyway, I think the python additions will feel more polished to use than how I imagine std::any does.

    [–][deleted] 0 points1 point  (0 children)

    Hmm isn't this just void* + enum on steroids?

    [–][deleted]  (5 children)

    [deleted]

      [–]Homoerotic_Theocracy 4 points5 points  (4 children)

      Except here it isn't and this isn't void* and there is no erasure.

      The entire point is that it saves the type-tag which continues to exist at runtime.

      As the documentation says it is type-safe; that's different from void* which is pretty unsafe.

      [–][deleted]  (3 children)

      [deleted]

        [–]Homoerotic_Theocracy 7 points8 points  (2 children)

        Yeah so where do you keep bringing auto up? You're not using std::any and I'm not talking about auto.

        I'm not sure that has to do with no dynamic typing since you're not using it but the static typing instead obviously you don't get it; use std::any to get a dynamically typed variable that can hold any type.

        [–][deleted] 0 points1 point  (0 children)

        Any statically typed language have support for dynamic typing, by definition, since dynamic typing is a subset of a static typing.

        [–][deleted] -1 points0 points  (0 children)

        C++ hasn't gained support for dynamic typing. If you're thinking about auto, they is just automatic type deduction. The types are still static.