3 ms·
OP also glossed over the important distinction between opt-in static types (TS, Python etc) and opt-in lack of them ("dynamic" in C#). When talking about what's
by int_19h 4y ago
OP also glossed over the important distinction between opt-in static types (TS, Python etc) and opt-in lack of them ("dynamic" in C#). When talking about what's permitted, these are functionally the same, but the difference has an immense effect on the actual idiomatic use.
I would argue that something like "dynamic" is preferable in a sense that it gives you an escape hatch with minimal syntactic overhead for those cases where dynamicity is really that beneficial, yet defaults to a safer option that's usually the best choice.
- kaba0 4y agoIsn’t dynamic’s primary purpose is multiple dispatch methods? In an OOP language (not caring about primitives and non-objects), you can go “dynamic” typed by using Object, and casts.
- int_19h 4y ago"dynamic" literally behaves as if the variable declared such had the actual type of the object at runtime every time that it's referenced, and under the hood it is all implemented using casts and reflection (and a lot of caching to make it fast enough - that's the DLR bit). So method calls are still single-receiver, it just makes them behave as if all methods were virtual. I guess the part where it will also pick the correct overload at runtime depending on the actual type of the arguments is a bit like multiple dispatch, especially if the argument itself is "dynamic". I'd say that the difference is that the list of possible candidates is closed once the class is defined, so even if you declare a new type, you can't customize the behavior when passing it to an object of an existing class.