4 ms·
Strange piece. Nobody claimed that dynamic type systems are simpler, they're just... well, dynamic. Type system complexity and dynamism are orthogonal. What the
by Barrin92 6y ago
Strange piece. Nobody claimed that dynamic type systems are simpler, they're just... well, dynamic. Type system complexity and dynamism are orthogonal. What the dynamic and static distinction is about is when the program decides to look at what your types actually are. At runtime or compile time, nothing more.
This has some implications for simplicity but not in the sense that the article tries to argue about. The real benefit from dynamic languages is not that you don't have types, it's that your program becomes more flexible at runtime. This is riskier by definition, but it also has the advantage of not eliminating countless of valid programs that a static language eliminates, or only makes possible through fairly complicated constructs.
>"[...]One day you open that module which you haven’t touched in six months, and you see a function call where the third argument is null. You need to remember what kinds of variables you can pass to that third argument[...]"
You don't need to remember that at all. The issue here is that the author applies the static mindset to the dynamic paradigm. The correct behaviour here is to not 'expect' or take for granted any particular input, but for the object/function in question to on its own deal with whatever input it gets. In Smalltalk style OO you would say it's the object that is solely responsible for the message it receives. That's not surprising but the very essence of late-binding.
- Scarbutt 6y agoDo you have an example of a static language eliminating a valid program?
- rowanG077 6y agoDepending on the power of the type system: Heterogeneous lists. They are hard in statically typed language if possible at all but trivial in dynamically typed languages.
- t-writescode 6y agoYou can definitely have heterogeneous lists in typed languages. They're almost always an anti-pattern, but you can do it in a few ways. In Java, you could have a LinkedList<Object>. You'll need to cast to do any operations on the objects; but, it's a heterogeneous list anyway, so why would you? There could be a reason, though. Let's say they all have the same function, then, but they're different objects. Well, for that, you could write a wrapper object that all inherit from the same class, say: interface Clicker { public void click(); } public class ClickerWidget implements Clicker { Widget w; public void click() { w.click(with_parameters); } } Alternatively, Go supports "use the same function" in a different way by having an interface just define a set of functions, no matter their parent class, and as long as the type has that function, it works.
- rowanG077 6y agoPlease read my comment again. I didn't say no statically typed languages support them. But your Java example isn't a true heterogeneous lists, very close but not really. You cannot put instances of value types into it. Even if it were a true heterogeneous list. You have given up on static typing with such a list and defer it to runtime. Which is exactly the dynamic typing approach.
- t-writescode 6y agoList<Object> absolutely is. If you want to do tricky pointer stuff, the Java hack around that is an array that holds the pointer to the value instead; and, autoboxing allows ints into it. It’s a heterogeneous list.
- rowanG077 6y agoThe List<Object> cannot hold int, double etc. It can only hold the boxed variants. Auto boxing takes some of the pain away but it's still not a heterogeneous list which has the requirement that it can hold values of any type. I'd wager that the up and coming inline classes in java also can't be put into a List<Object> but maybe I'm wrong.
- t-writescode 6y ago> The List<Object> cannot hold int, double etc. It can only hold the boxed variants At this point, don't you think you're being more than a little pedantic to the point of having a heterogeneous list?
- rowanG077 6y agoNo I don't think so. The main requirement of a heterogeneous list is that it can hold any type. In addition in a statically typed language I'd say to truly qualify as a heterogeneous list it should actually be typesafe. Java fullfills neither requirement.