4 ms·
How do people handle this in dynamic languages like JavaScript? I have done a lot of incremental refactoring in C++ and C# and there the compiler usually helped
by maxxxxx 9y ago
How do people handle this in dynamic languages like JavaScript? I have done a lot of incremental refactoring in C++ and C# and there the compiler usually helped to find problems.
I am now working on a node.js app and I find it really hard to make any changes. Even typos when renaming a variable often go undetected unless you have perfect test coverage.
This is not even a large code base and I find it already hard to manage. Maybe i have been using typed languages for a long time so my instincts don't apply to dynamic languages but I seriously wonder how one could maintain a large JavaScript codebase.
- Thasc 9y agoIt's not exactly a general solution fit for all situations and persons and purposes, but there's always TypeScript.
- WorldMaker 9y agoTypescript's increasing ability to type check JS code without modification (especially if it already has JSDoc comments or is already using npm-installed libraries with type information) is moving it to be a better fit as a solution for more situations.
- rocky1138 9y agoI've found integration testing to be very useful when dealing with JavaScript web stuff. If the desired output looks correct, you can usually work with the understanding that the JavaScript did its job. See Selenium. http://docs.seleniumhq.org/ http://docs.seleniumhq.org/
- nulagrithom 9y agoTry TypeScript. Though I wouldn't think that test coverage needs "perfect" to catch a bad variable name, but maybe that's why there's so much obsessive tooling when it comes to coverage in the JavaScript world.
- Roboprog 9y agoDon't forget that JS is often in a UI, doing asynchronous event/IO handling, so testing timing is important, not just spelling. (great, that's exactly the property names that object would have had, if it existed yet) That, and it's often reading in data (JSON or XML) from another system, and it is what it is, so see if it quacks or not. From the people that brought you SOAP, it's (drum roll) TYPE SCRIPT! It's not really solving my problems, just making more work.
- nulagrithom 9y agoSo because Microsoft made SOAP and also made TypeScript then TypeScript must be bad? That's nonsense. Also, I'm not a frontend guy, and the comment I was replying to was talking about node.js, but having to put a setTimeout or something in your tests just seems wrong.
- Roboprog 9y agoOn the one hand, argumentum ad hominem is a logical fallacy. On the other hand, expecting not to be bit after the last dozen times seems kinda stupid. I'm not a fan of MS.
- Roboprog 9y agore: timeout. Yeah, waiting for one (or many!) other async operation(s) to complete in response to an event is a nuisance, but that's how it works, in particular if you don't want a UI to freeze up. Full stack is hard, at least if somebody wants you to swap in and out of levels several times a week. But that's another rant about ruining projects...
- butabah 9y agoYou'll find these issues with pretty much any dynamic or scripting language once the codebase becomes large enough. For JavaScript, your best bet would be to integrate external tooling (such as JSHint) into your gulpfile or grunt.
- stickfigure 9y agoI think you just captured the essence of why microservices are so popular. Dynamic languages just don't scale to large codebases, so there's enormous pressure to decompose software into chunks that can be digested more easily. Some amount of this is good, but it often forces the chunk boundaries to be smaller than the "natural" clumping of data and behavior in a distributed system. IMHO this is a much worse problem than a messy monolith; you can refactor a monolithic codebase to be more modular, but refactoring hundreds of microservices is a herculean endeavor. My problem with microservices is the word micro.
- maxxxxx 9y ago"hundreds of microservices" I can't imagine a scenario where you need hundreds although I don't doubt that people will create such a system.
- jacquesm 9y agoDo not underestimate architecture astronauts, ever.
- Roboprog 9y ago:-) Or non-generalized, custom hard-coded static typed end-points for every single reference/option list and workflow state transition. Welcome to our little "full 'big bang' rewrite" Frankenstein 4.0 :-( Not my idea...
- gedrap 9y agoI was reading "Building Microservices" by Sam Newman, he mentioned that some of his clients moved from monolith to 300+ microservices without going into details, so yeah, that made me wonder about it as well. (it was a decent book otherwise).
- gnaritas 9y ago> Dynamic languages just don't scale to large codebases You mean "popular" dynamic languages due to their lack of tooling. Dynamic languages like Smalltalk scale up just fine, but Smalltalk has automated refactoring tools. In other words it's a tool support problem, not a dynamic language problem.
- Roboprog 9y agoContributing factor: thinking in terms of Simula67 / C++ / Java / C#. (stop doing so) Since property names are dynamic, avoid making data global (singletons, et al) at all costs, to limit the amount of string searching and informed "inferences" you have to make. Using a more functional programming style that tracks data flow of short lived data works better than trying the "COBOL with namespaces" approach of mutable data everywhere that gets whacked on at will. Sorta ironic: monstrous, so called, "self documenting" identifier names are not a good idea in a dynamic language. A short (NOT single letter, long enough to be a memorable mnemonic) identifiable name is more likely to be typed and eye-ball checked correctly. There is no "self documenting" code - literate programming is your friend, or at least JSDoc is. It's not practical to put "why" something is into its name. Of course, if you inherited some hot mess written by a hard-core Java / C# programmer, yeah, life is gonna suck :-( Disclaimer: I've been doing a lot of Angular the last couple of years, which is over reliant on long lived, widely visible, mutable data. I would rather go the route of something like Redux than Type Script, though. (I suppose you could do both, but I want to NOT do Type Script if I can help it) I've also worked with a number of languages that had runtime types and/or that allowed some kind of "string interpolation" for identifiers here and there since the 80s. No biggie. Buh, buh, buh, TYPESSSS!!! Yeah, so. Let's talk about excessive temporal coupling, (mutable) OOP (only) folks... <RANT ENDS> (for now)
- Roboprog 9y agoLet me try again. Don't rename properties that "escape" from a given context. Sorry, but it's not going to be a good use of your time. Do document (JSDoc or similar) what the property is used for and why (as far as you can tell) It's OK to rename local variables and parameters (the "root" local identifier, not the properties), though. It might not be Smalltalk (I wouldn't know), but the JetBrains IDE support for JS is pretty good in terms of type inference, "where defined" lookups, "show documentation" support, duplicate / undefined symbol detection and other stuff I'm probably forgetting at the moment. Seriously, though, avoid the traditional class/constructor/prototype setup (rather than short lived object literals as parameter objects and return values). It makes things too widely visible, and harder to safely change later. And it's more work, anyway. Learn how to refactor a nested function which uses closure values into a reusable function with a longer argument list on which you can use partial function application as a form of dependency injection - or the other way around, for something used only one place. An important lesson in managing code in a dynamic language is to limit the scope of everything as much as possible. Software designed as a cluster of many mutable singletons is going to hurt. OOP was the hotness in the 80s. It's time to learn other paradigms, too (move from the '60s to the '70s), even if IDE designers have to update how "intellisense" (aka auto-complete) works :-)