by yxhuvud · 7y ago · 0 comments
Not really, in my opinion. Type inference especially has come a long way. If I offer you a choice between language A and language B and claim that their syntax is nearly identical and you'll use essentially the same number of keystrokes to accomplish the same task in both, but language B can inform you about mistakes you've made at compile-time instead of waiting until run-time... which one are you going to choose?
While dynamic languages afford some degree of freedom, that freedom comes at a cost. The tradeoff used to be that safety required lots of extra writing (e.g., Java). Now that this isn't the case... the freedom of dynamic typing can be more harmful than helpful.
(I still use Python all the time, so don't mistake me for a static-only zealot of some sort. But I think the landscape of type systems has changed a lot since Kay made these claims.)
Types can be thought of as a way to defensively program - encode what you can to avoid runtime errors. At minimum this means you have to think about your constraints - we may both agree that that's a fine tradeoff, but it's a tradeoff nonetheless.
Erlang, an actor based system, does not do this. Instead, it assumes that even if you added types youd run into failures and any reliable system should spend its efforts not trying to avoid that but to deal with it.
Erlang allows you to instead encode failure modes in an extremely resilient way (supervisory trees) and to trivially move code across networks to avoid hardware failures.
Languages like Python, in my opinion, are the worst of both worlds. Python encourages lots of shared mutable state but, until recently, offered very little static analysis. Time was instead spent on testing code - something that I do not believe it does any better than Erlang or a statically typed language.
To me, the answer is sort of... why not both? We can use actors and supervisory trees and static types. As an example, I write Rust services that execute on AWS lambda in response to queue events. I get state isolation and all of the good bits of the actor model, and static types.
Pony is a more fine grained solution, offering static types and in-process actors.
The time you save from writing a dynamic program is time not spent on defining that contract. You will eventually be paying for that when the first major refactor comes - if it comes, that is. You will pay for it with extra test coverage, if that's in the budget. Or you will pay for it by re-writing everything.
Those may all be worthwhile tradeoffs, but in the long run, I think static types win out.
Cos in this paper they suggest actor coordination is a problem for AWS and that using queues for message passing is slow.
https://www2.eecs.berkeley.edu/Pubs/TechRpts/2019/EECS-2019-...
Very interested in your experience cos I’m interested in trying this pattern.
Static types assume a "static" phase: an edit-compile-run cycle, with bright lines between each stage.
But as a Smalltalk programmer, you inhabit the system and build it inside-out, while it is running. For example, during development it is routine to query live objects. The lines between the edit-compile-run phases disappear.
Static types don't make sense in the Smalltalk model because there's no static phase.
Which is why I feel that a dynamic language that doesn't focus on the interactivity, like having a great REPL based development cycle, hot swapping capabilities and strong code as data utilities kinda misses the point in the trade-off between static and dynamic, sacrificing safety for too little. Jupyter notebooks seem to have recently brought a little of the first to the mainstream at least.
This is still a way to use Ocaml today, and Poly/ML, which is the standard ML used for the Isabelle theorem prover, makes heavy use of an image based model.
Realistically you don't have the choice between hypothetical buffet languages A and B, you have a choice between Java or C# and Python or Javascript and maybe a handful others. Those are the type systems you will have to deal with, most likely.
I'm sure the type inference in Haskell (or similar) is fantastic but virtually nobody uses those languages so those benefits are purely theoretical for most programmers.
By the way, static type inference in Javascript also has gotten pretty good and in many cases it can catch all of the bugs that an ordinary type checker would catch.
> I'm sure the type inference in Haskell (or similar) is fantastic but virtually nobody uses those languages so those benefits are purely theoretical for most programmers.
I think this argument would hold more water if the dynamic language under discussion wasn't Smalltalk...
Does dynamic typing also make writing tests easier?
For example when writing tests in Python it's relatively trivial to mock out specific methods or functions. However, when I was writing tests in Go, I realized to test things which required mocks I would have to change all the type signatures to use interfaces instead of structs, and that required writing a new interface as well.
I admit I am not entirely sure whether this difficulty stems from static vs dynamic typing or something else.
You get a huge amount of power in your type system (Python is actively working on dependent types and supports variance first class), but for code where that's a burden (test cases), you can drop it.
Maybe powerful macros that let you copy an interface (Python's mock.patch with autospec=true, but better) would solve the same problems, but you don't generally have that option.
Maybe it's dynamic typing what makes writing (so many) tests necessary to begin with.
Maybe you know this, but type inference goes back to the 1970s. It's taken this long to start seeing it in mainstream languages.
Similarly, pure functional strongly statically typed languages with type inference, pattern matching, algebraic data types and non-null types have been around for literally decades yet we're still stuck debating about the so-called benefits of dynamically typed languages.
It's a risk and reward. You're giving away seconds or so on every line, for what might take a little debugging if one is encountered.
I'd rather get the code written and the problem solved than make converting a string into a date the problem to be solved. There are plenty of problems figuring out if something is a date or not, but it's worth it.
9 out of the 10 most common JavaScript errors are around types, hence why such a large push to type JavaScript (TS, Flow, Elm, ReasonML)
Smalltalk has been pretty fast for ages (without inference, and may or may not be as easy as Python to you).
JavaScript JITs can use a form of type inference, so you get the benefits of speed with no change to syntax. Again, it’s pretty fast, and “easy” is in the eye of the beholder.
This is the part I always fail to grok in discussions about type systems. For me it is just the opposite: I typically don't find dynamic typing to be worth the trouble, so I fail to understand this sentiment when going the other direction.
Maybe it's because my degree is in mathematics (lots of proofs written out long-hand), and my first language was Java? I have since all but abandoned many of the ideas that Java so rigidly enforces, OOP among them, but static typing just has so many advantages for me that I have no desire to get rid of it.
One thing I've noticed in some recent work is that the static language I'm using (Go) allows me to both be lazier and get more done than comparable work being done in dynamic languages. I'm not reading or writing tons of documentation (I'm reading other people's code directly, or just looking at the types involved and moving on). I'm not constantly handling byzantine runtime errors or having to memorize the arbitrary intricacies of any over-bearing frameworks in order to be productive. I don't need to be on guard quite so much, I lean on static analysis. In general I just don't need to hold so much extraneous crap in my head, it's all spelled out right there in the code and I'm free to think about larger concerns, like the best way to solve the problem at hand. And when I circle back around to some 10-20k line library I wrote 3-6 months ago, I can read, understand and refactor parts of it quickly.
People often talk about developer comfort and speed being improved by dynamic languages, and maybe that's true if Rails solves all your business needs, but for many of the tasks I've work on, that just hasn't borne out over the past 10 years. I have no doubt that dynamic languages seemed a breath of fresh air after fighting with C/C++/Java, but to my eyes Ruby/Python/Javascript etc were always a bridge too far for a lot of tasks.
I think the problem is that mainstream statically typed programming languages come with terrible or non-existing metaprogramming facilities to make up for type constraints.
Rust supposedly has good metaprogramming but then it also has a type system that is so obnoxious it's not "worth the trouble in many situations".
Care to elaborate?
From the programmer's point of view default arguments are a cheap way to achieve some benefits of "type declarations". And they are especially cheap when you consider that in return you get - default arguments. They are a win-win.
This means that anything that gets modified inside an object is done by methods of that object. That means that it is easy for you to add dynamic type-checks whenever you are writing an instance-variable. That goes a long away towards alleviating type-problems.
Whereas in a language where objects' properties can be modified from the outside there is no way to intercept such modifications and type-check them. EXCEPT in recent developments such as ES6 you can define SETTERS which get automatically called when you or anybody tries to set a value of a property. That means you can then put the type-checks there.This just as an example of improvements in dynamic type-checking.
Now ES6 is great, but it does not force you to create such setters. Whereas Smalltalk does force you to create methods if you want to modify property-values.
This great feature is somewhat diminished in value by the fact that (in Smalltalk) many methods can write the same instance-variable so it sometimes becomes tedious to figure out which method including inherited ones wrote a delinquent value to the instance variable. But then Smalltalk IDEs allow you to browse all methods which read or write a given instance variable, which helps in such a situation. Then you can think about refactoring it so that really there is only one setter for a given instance variable.
smalltalk goes by by having a sensible topology of classes that can encode a lot of natural information about processes (errors, restarts etc)