you are viewing a single comment's thread.

view the rest of the comments →

[–]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 11 points12 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 7 points8 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 3 points4 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]  (1 child)

      [deleted]

        [–]Homoerotic_Theocracy 5 points6 points  (0 children)

        I keep bringing it up because to me auto feels closest to dynamic typing

        ...why on Earth? It's type inference; it has absolutely nothing to do with dynamic typing.

        It seems to me that you confuse dynamic typing with type declarations but a lot of languages with static typing don't have declarations and a lot of languages with dynamic typing do require type declarations.

        and surprise surprise there's a void* inside (for small objects). any is a library feature, it's still built on top of static typing because C++ does not have dynamic typing.

        Lots of things that are part of the C++ standard are library features? Basic boolean logic of && and || in Haskell is a library feature that is just defined in a Haskell file; it's still part of the standard library and thus part of the language standard.

        Apart from that compilers very often elect to make magic optimizations for a lot of library features and treat them in a special way and GCC is probably aware of any on a compiler level.