44 ms·
The benefit of static typing isn't just reliability. Tooling is another major argument. Won't appeal to certain hardcore programmers who think that even notepad
by cm2187 9y ago
The benefit of static typing isn't just reliability. Tooling is another major argument. Won't appeal to certain hardcore programmers who think that even notepad has too many features. But it is great for refactoring, finding all references to a function or a property or navigating through the code at design time. Basically all the features visual studio excels at for .net languages.
And I disagree with the barrier to entry argument. Static typing, by enabling rich tooling, helps a beginner (like it helped me) a lot more by giving live feedback on your code, telling you immediately where you have a problem and why, telling you through a drop down what other options are available from there, etc. Basically makes the language way more self-discoverable than having to RTFM to figure out what you can do on a class.
- taeric 9y agoLive coding environments are amazing at this, as well. Often without the need for as extensive static typing, since it can just use reflection. This isn't to say that static typing isn't good at this. Just, even with that, there is a lot of effort that goes into making the rich tooling. A lot of very smart and capable folks work hard to make Visual Studio.
- fulafel 9y agoDynamic languages support this kind of tooling too - you can even have seamless data completion (eg. map/dictionary keys). The original Refactoring Browser was written for Smalltalk. Etc. Of course there are cases where dynamic languages do worse, but it balances out I think.
- cm2187 9y agoBut how can you offer any refactoring or auto-complete inside a function if you don't know what type to expect as an argument?
- fulafel 9y agoIn dynamic languages functions aren't typically overloaded by argument type. For OO languages and methods it does get a little guesswork-y, and tools often offer a wider range of guesses than is correct for completion. But you can show the class along with the offered completion, so it's not too bad.
- actsasbuffoon 9y agoYou can, but you may start to run into some limitations. Many languages have some version of type inference, which allows them to figure out the type of a thing, even though the programmer didn’t specify it. C# has a very weak version of this with the auto keyword. Languages like Crystal take it much further by tracing the flow of data through the entire program. It generally works quite well, though there are a few edgecases that require explicit type annotations. As for auto-completion, some languages feature designs that make it easy to offer auto completion even without type information. For instance, Elixir doesn’t have methods. You only have functions defined on modules, and it’s trivially easy to know what functions are defined on a module. So it’s possible, but there are some limitations.
- TheDong 9y agoType inference goes hand-in-hand with static typing. Those are not opposite things. > C# .... Crystal Both are fully statically typed languages with type inference. Those are unrelated to the argument the parent comment is making.
- jaggederest 9y agoThey still both allow generic arguments, in reduction, this means that they still have uncertainty. I can and have built a totally untyped language within a fully statically typed language - nostrademons' Scheme-in-haskell exercise is a lot of fun. You just have to define a Universal type and then back out of all that nasty compile-time nonsense. Everything is Univ and Univ is everything.
- andybak 9y ago> Type inference goes hand-in-hand with static typing. That would imply there's no type inference possible with dynamic languages - either at "compile" time or run time. (Wouldn't it also imply that static typing and strong typing are synonymous?)
- bjz_ 9y agoYes! If your language allows you to put constraints on those types you can specify what specific types have access to. For example in Rust: fn foo<T: Positioned>(x: &T) -> Point { x.position() } Note that this doesn't work in languages that use templates for generics, like C++, where templates work more like compile-time duck typing.
- igouy 9y ago> The original Refactoring Browser was written for Smalltalk. Unless you think original means Bill Opdyke's thesis work, where the tooling was written for C++ and written in CLOS. http://www.laputan.org/pub/papers/opdyke-thesis.pdf http://www.laputan.org/pub/papers/opdyke-thesis.pdf
- cle 9y agoIMO the autocomplete argument is rather unconvincing. Every dynamic language I've worked deeply with has powerful and simple introspection capabilities, and they generally come with much more interactive development environments (shell/REPL), so I've never found API discoverability to be any worse than statically typed languages, just different. In general though, the more you can formally reason about the program, the more you can automate program transformations (refactoring). Programmers in dynamic languages will argue that the amount of code is far less than the equivalent code in a mainstream statically-typed language, so while the cost of refactoring may be higher per unit, the number of units is less, so the overall cost is the same (or less). I believe in using the best tool for the job...some use cases would benefit more from static typing, while others would benefit more from using a dynamic language. One of the most important factors is the team and its engineers' backgrounds, preferences, styles, etc.
- wootness 9y agoI found Ruby (even in something like RubyMine) to be a far cry from even the basic stuff you get from Java. Suggestions for vars and funcs that don't actually exist really slowed down things.
- emodendroket 9y agoDoes anyone believe in using the wrong tool for the job?
- disconnected 9y ago> Does anyone believe in using the wrong tool for the job? Yes. PHP developers. :)
- cle 9y agoYes! Many engineers use tools they like for reasons unrelated to the job they're doing or the product they're building.
- emodendroket 9y ago
- ruskimalooski 9y agoAgreed. Although other comments claim that their dynamically typed languages have this same property, inherently in dynamic languages the auto complete will fail out unless you effective write code as if you were using static types.
- christopheml 9y agoMy main progamming language at the time is Java, and the amount of assistance my IDE provides is astonishing (to the surprise of no one, it's IntelliJ). The confidence strong automatic refactors provide is of great help when managing large codebases.
- amirouche 9y agoI agree that static typing helps reading comprehension and that IDEs like pycharm help getting into big code bases, that said, at the end of the day, when you know the code both the IDE and static typing are getting in the way. Actually, I never saw anybody as quick as people using simple editors like emacs and vim. GUI is getting in the way of the programmers intent. Static typing is a hindrance in front of refactoring. Unit tests is the only truth that matters, static typing or not.
- always_good 9y agoYou're kinda damning it with faint praise when you say that you can use dynamically typed languages on small projects that fit in your head (and are also probably written by a single developer). You can pretty much use any language in that scenario. But the chickens come to roost around day 30+ or so.
- icebraining 9y agoA large project is a poorly decoupled set of small projects.
- orthecreedence 9y agoTrue, once my libraries get bigger than five or six assembly instructions, I tend to break them down to a more manageable size.
- always_good 9y agoMay be. Meanwhile real-world non-trivial projects tend to be large projects. Nice to be prepared for that instead of gambling on "surely we'll extract out smaller projects that fall on the right abstraction boundaries in the face of unknown future requirements."
- drblast 9y agoDefinitely. Static typing lets you turn the compiler into a hard-working friend that helps you refactor large projects without going insane. There are no diminishing returns. Defining types is easy and enhances code readability.
- cle 9y agoBelieving that any technology has no cost is poor engineering IMO. There are costs to that rigidity, and they're rather self-evident.
- cobbzilla 9y agoNo one is saying there is no cost. The cost of using static types is (1) you have to think about type info when writing the code and (2) you have to fix compile-time type errors while you are developing. The poster is claiming that, over time, as code bases tend to grow large, this small investment yields increasing (not diminishing) returns; a claim I would agree with.
- ridiculous_fish 9y agoIf you believe there are no diminishing returns, I'm interested to hear your reply to the author's question about why we don't all use Agda or Idris.
- Arcsech 9y agoWell, the easy answer is that dependently-typed languages like Agda and Idris aren't very mature yet. They're still missing many commonly-needed libraries, compile times are slow, the tooling isn't great, etc etc. Getting a language to the point where it's workable for serious projects is a lot of work. Rust is getting there with the backing of Mozilla, Haskell has made some decent strides too (but still has a way to go, and I think has some pretty fundamental flaws entirely apart from the type system). It'll be probably another decade at least before we see any dependently-typed languages getting a serious foothold, but I do think they're going to become a lot more common eventually.
- gnaritas 9y agoI can do all of those things in Smalltalk, which is dynamically typed; these things are not byproducts of static typing, they're simply byproducts of mature tools. So no, these are not arguments in favor of static types.
- igouy 9y ago>> finding all references to a function << Yes, you can find all references to a method in Smalltalk -- but those references are not separated-out from all the references to other methods that happen to have the same method name but are defined on a different class. With type information for the receiver and method arguments, we can find just the references we're looking for.
- lispm 9y agoI can ask my Lisp IDE to find callers for methods based on the sub/class of arguments.
- igouy 9y agoDoes it work better if you use type-specifiers in your code :-)
- KingMob 9y agoI can't speak to Smalltalk, but any namespaced Lisp system can figure out what references what. The key is that the searches happen through the REPL, not grep/ag. So if I tell CIDER to find all instances of a Clojure symbol, it can use the namespace to avoid false positives.
- igouy 9y agoAre you saying that reduces the number of false positives or are you saying that eliminates false positives?
- 9y ago
- Eridrus 9y agoI think dynamic typing proponents get hung up on the auto-complete aspect. The real benefit is when you find someone writing a property with a common-ish name to a data structure and you want to know "who the hell uses this", you can answer that question pretty easy in statically typed languages. In dynamically typed languages you kind of just grep and hope the name is not too common.
- Eire_Banshee 9y agoThis. Not just, "who the hell uses this", but "where the hell is this defined" as well.
- flavio81 9y ago>Not just, "who the hell uses this", but "where the hell is this defined" as well. On Common Lisp, a dynamic language, I can also get this answered instantly. I just press a key combination on a method call and i jump to the definition. So this isn't exclusive to statically typed languages.
- Eire_Banshee 9y agoLets be real, when we say dynamic languages, we aren't talking about niche languages like Lisp. We are talking about JS and Python almost exclusively.
- amirouche 9y agoPython has jump to definition too.
- adamnemecek 9y agoYou mean there’s an ide with that feature? It’s never as good as with any statically type language.
- 9y ago
- 19873287234 9y ago>Tooling is another major argument. vscode seems to figure out the types in javascript without any static typing. >But it is great for refactoring Searching for strings isn't that much worse. Also, when it comes to web development, you cross into the client-side and suddenly you can't refactor. So you can only refactor the server-side and end up with a mismatch. >finding all references to a function or a property or navigating through the code at design time You can do that without static typing in many cases as well. >Basically all the features visual studio excels at for .net languages. When I was working in c# on the server and javascript on the client, I really hated having to go back into c#. >telling you through a drop down what other options are available from there vscode seems to be able to figure this out most of the time as well. I think static typing is necessary when you need performance because all of the fast languages are statically typed. I think a lot of these things are about organisational complexity and making sure new and average programmers don't screw up the software. It is about large companies trying to manage their organisation, it isn't about the complexity of the code itself. There are a ridiculous amount of tech companies that have used dynamic languages to go from nothing to the biggest companies in the world and only switched to static languages well and truly after that occurred.
- cwyers 9y ago> vscode seems to figure out the types in javascript without any static typing. Doesn't it do this by treating Javascript as a statically-typed language (Typescript) and using type inference?
- 19873287234 9y agoNo it works without using typescript. I just figures it out through... I have never thought about it. I mean, var p = new Cat();. I am sure it can find the cat definition easy and read the properties and so on. It probably can't prove things 100% but it can guess very well at what things are.
- FLUX-YOU 9y ago>I just figures it out through... I have never thought about it. Are there not definitions written by someone or a tool that vscode looks at? That is what I saw using some npm packages with typescript: http://definitelytyped.org/ http://definitelytyped.org/
- DavidWoof 9y agoIf Visual Studio is your example, then you're making the same argument as the author: there's a sweet spot. From the python world, c# may look statically typed, but from the Haskell/Idris point of view, the java/c# type systems look really sloppy and ambiguous.
- macspoofing 9y agoI'm so happy to see the pendulum swing the other way, because when JavaScript was becoming popular, and Ruby and Python had a popularity renaissance (around mid to late 2000s), I had a lot of online arguments about the value of static typing. People were complaining about static typing for the dumbest reasons (it's too 'wordy'). It started as a backlash against old-school enterprise Java development (which was fair, EJB2 world sucked) but then it went completely off-the-rails. Typing in Java could be better, sure, but even with its quirks it's way better than the nothing you get with dynamic languages. There are a class of bugs you just never need to worry about when the compiler does some compile-time checks for you ... like worrying that you passed the wrong type into a function, or the wrong number of arguments. Thank God people are coming to their senses.
- wiremine 9y ago> EJB2.0 world sucked This is the #1 reason I leaned away from static typing. Typescript and Swift have changed my mind. I now see typing as a helpful tool that can solve a lot of problems.
- enraged_camel 9y ago>>There are a class of bugs you just never need to worry about when the compiler does some compile-time checks for you ... like worrying that you passed the wrong type into a function, or the wrong number of arguments. People always say this and it baffles me. Bugs like that should be caught immediately by your test cases. You shouldn't rely on the compiler to catch them for you.
- 201709User 9y agoYes, why do something automatically when you can do manual work!
- icebraining 9y agoI think the idea is that you have to write tests anyway.
- sacado2 9y agoThere's not only tooling and reliability. Don't forget performance, too. Knowing at runtime that a memory word represents, for instance, an integer rather than a reference to a struct that contains both a type tag and a reference to the actual value, makes a huge difference. And I'm not even mentioning the inlining possibilities.
- walshemj 9y agoAlso the article does not take into account the much higher cost fixing a bug in live compared to development
- Merovius 9y agoIt does (though admittedly not very explicitly), it just rolls it into the "benefit" (i.e. not shipping broken code is a benefit) and the "weight given to stability". If a bug discovered in prod (or even qa/canary) has a significantly higher cost than a bug discovered early, that will influence the weight you are putting on stability. In that way, this factor is subsumed in one of the other graphs. As you might've noticed, I have been intentionally light on the details and only talked pretty abstractly about the specific scales and factors involved.
- walshemj 9y agoTy I take the point and it depends on the sort of project your working on a celphone app is different to say a major telcos billing system.
- gwbas1c 9y agoIsn't static typing a requirement when writing an algorithm and data structures for "every bit and clock cycle counts" situations? How can a 0-compute overhead for dynamic typing exist in a dynamic typed environment? I always thought dynamic typing is a feature for situations where the code needs an extreme amount of flexibility to adapt to a wide variety of data; even at the expense of performance.
- bjz_ 9y agoA good static type system will give you the ability to be able to control the level of dynamism in various parts of you code. For example you could create tagged unions to create mini dynamic type systems within parts of your codebase.
- tonyg 9y agoNot unless you think assembly language or machine code are statically typed.
- naasking 9y agoAssembly is typed. The types are machine words and usually floating point types are also available. Basically, the machine types are the types of data that the register files can hold.
- tonyg 9y agoYep. You can, of course, make a similar argument for Scheme. But you don't get a very interesting type system out of it. Perhaps I should have written "... nontrivially statically typed."
- naasking 9y agoSure, but to bring it back to the original question, the fact that you can trivially distinguish floating point from word types already means statically typed languages are easier to optimize than dynamically typed languages for numerical programs. And there are all sorts of optimizations like this that simply aren't available to dynamically typed languages. Tracing JIT can only take you so far.
- deleted 9y ago[deleted]
- petters 9y agoThis is really true. I was a complete Java newbie and knew some Python when I joined Google. Yet I found working in an unfamiliar Java code base much, much easier here. Large Python code bases are really hard to understand and work in (here).
- yogthos 9y agoA lot of the same refactoring is possible in dynamic languages as in static ones. I recommend reading up on Term to see what's possible to do with JavaScript http://marijnhaverbeke.nl/blog/tern.html http://marijnhaverbeke.nl/blog/tern.html I use Cursive https://cursive-ide.com/ https://cursive-ide.com/ for working with Clojure, and it can do safe refactoring for symbols by doing static analysis of the source. It can show all usages of a symbol, rename it, do automatic imports, and so on. Another piece of tooling that's not available in any statically typed languages at the moment is REPL integration with the editor seen here http://vvvvalvalval.github.io/posts/what-makes-a-good-repl.html http://vvvvalvalval.github.io/posts/what-makes-a-good-repl.h... I find that the REPL driven workflow found in Lisps is simply unmatched. When you have tight integration between the editor and the application runtime, you can run any code you write within the context of the application immediately. This means that you never have to keep a lot of context in your head when you're working with the application. You always know what the code is doing because you can always run and inspect it. Having the runtime available during development gives you feedback much faster than the compile/run cycle. I write a function, and I can run it immediately within the context of my application. I can see exactly what it's doing and why. The main cost of static typing is that it restricts the ways you can express yourself. You're limited to the set of statements that can be verified by the type checker. This is necessarily a subset of all valid statements you could make in a dynamic language. Finally, dynamic languages use different approaches to provide specification that have different trade offs from static typing. For example, Clojure has Spec that's used to provide runtime contracts. Just like static typing, Spec provides a specification for what the function should be doing, and it can be used to help guide the solution as seen here https://www.anthony-galea.com/blog/post/hello-parking-garage-meet-clojure.spec/ https://www.anthony-galea.com/blog/post/hello-parking-garage... Spec also allows trivially specifying properties that are either difficult or impossible to encode using most type systems. Consider the sort function as an example. The constraints I care about are the following: I want to know that the elements are in their sorted order, and that the same elements that were passed in as arguments are returned as the result. Typing it to demonstrate semantic correctness is impossible using most type systems. However, I can trivially do a runtime verification for it using Spec: (s/def ::sortable (s/coll-of number?)) (s/def ::sorted #(or (empty? %) (apply <= %))) (s/fdef mysort :args (s/cat :s ::sortable) :ret ::sorted :fn (fn [{:keys [args ret]}] (and (= (count ret) (-> args :s count)) (empty? (difference (-> args :s set) (set ret)))))) The above code ensures that the function is doing exactly what was intended and provides me with a useful specification. Just like types I can use Spec to derive the solution, but unlike types I don't have to fight with it when I'm still not sure what the shape of the solution is going to be.
- kuon 9y agoI have been doing some elm, and refactoring is a MAJOR bonus. You can refactor your entire project, and when it compiles it usually works. It's funny how dynamic languages are seen as beginner friendly, while in reality they are not (ruby, js, python...).