4 ms·
> Ok, so you have ParentClass and ChildClassA and ChildClassB that inherit from it. Why do you even assume classes are involved? > And, bam, now your “statica
by masklinn 4y ago
> Ok, so you have ParentClass and ChildClassA and ChildClassB that inherit from it.
Why do you even assume classes are involved?
> And, bam, now your “statically typed” language actually has dynamic type checking.
Not in any way, shape, or form?
You have a ParentClass, it lets you perform ParentClass operations. If you want to do a ChildClassA operation if that's that, you check whether that's what you have, then do the operation. Both are enforced by the compiler (though how safe the check is varies).
If you have a dynamically typed language, you might think you have a ParentClass but you actually have a completely unrelated ToyotaSupra.
> And if you use a “statically typed” language, but have an algebraic type that holds int or string or ClassA or Array, how useful is that static typing?
Extremely. Because you know what the potential is, and you have to check for it exhaustively.
> That’s why I prefer calling the code either weekly typed or strongly typed.
So complete nonsense to make you feel good?
- pwdisswordfish9 4y ago>> And, bam, now your “statically typed” language actually has dynamic type checking. > Not in any way, shape, or form? https://en.cppreference.com/w/cpp/language/type#Dynamic_type https://en.cppreference.com/w/cpp/language/type#Dynamic_type https://en.cppreference.com/w/cpp/language/dynamic_cast https://en.cppreference.com/w/cpp/language/dynamic_cast https://en.cppreference.com/w/cpp/language/typeid https://en.cppreference.com/w/cpp/language/typeid It’s there in the name.
- masklinn 4y ago> It’s there in the name. In the same way that the Democratic Republic of North Korea is democratic. Right there in the name. Also that Dynamic Programming involves not knowing anything. Right there in the name. A Dynamic Microphone? Not actually a microphone at all.
- sparkie 4y ago`dynamic_cast` does a dynamic type cast (a downcast). It does what it says on the tin. It's purpose is to cast a value whose precise type may not be known until runtime.
- LudwigNagasena 4y ago> Why do you even assume classes are involved? Because classes are almost ubiquitous in modern commercial programming? > If you want to do a ChildClassA operation if that's that, you check whether that's what you have, then do the operation. Both are enforced by the compiler (though how safe the check is varies). Go to GitHub and search for "GetType language:csharp" or "getClass language:java" and see millions of hits for runtime checking in “statically typed languages". And who knows how many ad hoc runtime checks there are in C++ and other languages without a default reflection framework. > If you have a dynamically typed language, you might think you have a ParentClass but you actually have a completely unrelated ToyotaSupra. So is a dynamic language that supports type annotations in comments (eg JavaScript + JSDoc) actually a statically typed language? > Extremely. Because you know what the potential is, and you have to check for it exhaustively. It’s still going to be a mess that should be refactored. > So complete nonsense to make you feel good? You can do runtime type checks in “statically typed” languages. You can use type inference in “dynamic” languages. That is just facts.