6 ms·
Unless you wrote the code yourself you pretty much have to run the program first and then REPL to see what the type actually is and the properties it exposes Sl
by stcredzero 10y ago
Unless you wrote the code yourself you pretty much have to run the program first and then REPL to see what the type actually is and the properties it exposes Slow, arduous, unnecessary.
If the code is well written, then no, to seeing what the type actually is. In a good environment like you have in many Smalltalks, you should be able to compose some implementors searches, then quickly know what you're dealing with. Then you quickly and easily debug the system just to be rigorous. In environments set up by smart people, these actions can be surprisingly quick and easy. (In the same way that git allows for using certain information much more quickly, quantity can become a different quality.)
Do people who prefer dynamic languages actually use the benefits of dynamic typing in the first place? Changing variables from one type to another mid-stream. Dynamically adding properties to objects, using == instead of === etc.. Those things are a recipe for bugs, inconsistency, and unmaintainability right from the get go.
None of those things are the benefits of a dynamic language, except maybe as super debugging tricks. No one who really knows how to write in a dynamic language puts stuff like that in typical code! That you say this makes me think you don't know what you're talking about, or your main exposure to dynamic langs has been through the code of yahoos.
- FrancoDiaz 10y agoIf the code is well written... In a good environment like you have in many Smalltalks... No one who really knows how to write in a dynamic language puts stuff like that in typical code That's the problem. You're talking about some hypothetical, Smalltalk environment, where some expert dynamic language programmers always do "the right thing".
- qwertyuiop924 10y agoOkay then, but if you're not documenting your functions, which is the most important thing, you shouldn't be working on a large project with other people in any case.
- mercurial 10y agoDocumentation will not save you the day you decide to rename a function or change its signature. Static typing will.
- qwertyuiop924 10y ago...No, it won't. It might make the refactoring a little easier, but with various tools, you can check all the call sites and see if you fixed it. Sure, your compiler won't tell you what's wrong, but your REPL and your tests will.
- FrancoDiaz 10y agoYes, given enough time for enough manual work, and enough tests, and enough code review.... The whole point is not to have to do this stuff manually, which is very error prone. Ad-hoc REPL work, and tests are very likely to have missed something.
- mercurial 10y agoPrecisely.
- mercurial 10y agoIt will absolutely save you, because it will complain loudly about every broken call site and prevent the broken code from making it to production (assuming you didn't use any tricks with any). Tests may or may not help (I have yet to see a codebase with perfect test coverage).
- stcredzero 10y agoSure, your compiler won't tell you what's wrong, but your REPL and your tests will. If a REPL and tests make you powerful, then a type system that doesn't drag you down and good tooling around that will only make you more powerful.
- Roboprog 10y ago
- stcredzero 10y agoThat's the problem. You're talking about some hypothetical, Smalltalk environment, where some expert dynamic language programmers always do "the right thing". No, I'm talking about a place I've worked, certain subsets of code in other places I've worked, code at customer's shops, and most of the standard library of Smalltalk. True, I've also seen what can go wrong in Smalltalk. But in my experience, this isn't worse than what can go wrong in other languages, dynamic and static.
- anko 10y agoI think the argument is not "You can't write something maintainable in a dynamic language" - it's more like "Given the majority of projects, static typing would have helped readability". Since in SDLC maintenance is like 80%, and most of the time code isn't written amazingly, it seems pragmatic to have static typing. I love Dynamic languages as much as the next guy (Ruby and clojure are pretty great in my book) but in my career, I get my guys to write in statically typed languages.
- stcredzero 10y agoit's more like "Given the majority of projects, static typing would have helped readability". Not so much readability. That comes mostly from good naming in Smalltalk, and thinking about, "What if I had to understand this through senders/implementors searches?" However, in my experience, it helps maintainability. In general, I didn't need type annotations to help me understand the system. Good Smalltalk is about message passing, so you understood the system through who sends what to whom. What I did experience a lack of, were 100% ironclad guarantees in a couple of instances where we needed to be 100% sure about something. And yes, it is pragmatic to have static typing for the long term!
- qwertyuiop924 10y agoSome of those aren't even dynamic language things. And most of them are bad form. But yeah, shoving a flag onto an object where there was no such flag can come in handy at times, if you're treating your objects as dicts or whatever (in JS). If you're doing Real OO, you'd want to put the flag into the class/prototype declaration, so that it's documented, but if you're not, or just need to attach some extra data to, say, a function, it's handy. Also, in a well documented system, functions should note what types they except, even if it is just "any types that respond to these messages" in smalltalk, or your local equivalent.
- mercurial 10y ago> But yeah, shoving a flag onto an object where there was no such flag can come in handy at times, if you're treating your objects as dicts or whatever (in JS). Ugh, no. I really don't want to be looking at code where properties appear after initialization and you have reason about when the damn thing is actually available, thank you. > Also, in a well documented system, functions should note what types they except, even if it is just "any types that respond to these messages" in smalltalk, or your local equivalent So, like specifying type signatures in Typescript, except probably out of sync because it's not automatically enforced?
- qwertyuiop924 10y agoWell, sometimes, which is why optional type signatures, like those in TS, can be useful. But even if you're not telling all the typing details, at least tell the world that your function works with strings, or whatever. And if you're using the properties everywhere, yeah, define them, but if you need to extend an object, and the extension will only be used locally, than it's useful.
- douche 10y agoWhat infitessimally small numbers of us actually get to use a dynamic language that is on the Smalltalk end of the scale, vs the overgrown scripting languages like python, lua, ruby or javascript?
- qwertyuiop924 10y agoMany of those "overgrown scripting languages" owe a pretty big debt to Smalltalk. Ruby and JS, particularly, borrow heavily from Smalltalk and Self. Lua is very Schemey, and while many talk about JS's Scheme influences, Lua really does feel like Scheme sometimes, and reflects Scheme's values far more than JS (small number of primitives, TCO, emphasis on minimalism and flexability, etc.). Yes, they don't have the refactoring toolkit Smalltalk does, and they can be slow, but don't discount them off the bat. The two ends of the scale are closer together than you think.
- douche 10y agoSure, but to be kind, the tooling mostly sucks bogwater. Trying to detect usages of symbols or perform simple refactorings is considerably harder than even in languages with less than stellar static typing, like the C++/Java/C# enterprise workhorses, much less anything more powerful. Maybe I'm spoiled, but using find&replace and runtime errors feels as primitive as banging two rocks together.
- qwertyuiop924 10y agoWell, maybe I'm spoiled, but waiting forever for your code to recompile, just to discover that you misplaced a semicolon, as opposed to running it through a REPL as you develop feels a primitive as banging rocks together. It's a tradeoff, and I didn't choose the refactoring side. Although refactoring did originate in Smalltalk...
- Roboprog 10y agoIt's funny that the guy that wrote the definitive catalog of refactoring techniques prefers to work in a dynamic language. http://www.martinfowler.com/articles/rubyAtThoughtWorks.html http://www.martinfowler.com/articles/rubyAtThoughtWorks.html