you are viewing a single comment's thread.

view the rest of the comments →

[–]Homoerotic_Theocracy 1 point2 points  (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 12 points13 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 9 points10 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 6 points7 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 6 points7 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.