3 ms·
I don't really know how much type systems help here. I'm not really aware of a type system that enforces code actually be called. I know lots of linters do che
by horsawlarway 6y ago
I don't really know how much type systems help here.
I'm not really aware of a type system that enforces code actually be called. I know lots of linters do check for unused code, but generally only at the local level (ex - you imported/included X but never called it)
I agree 100% that it saves time during refactoring, but it's not going to catch that your NicheHelper class that was only called in one place is not called anymore. Nor is it going to find and highlight css that can be ditched as well.
- thrower123 6y agoAll of the JetBrains tools will do complete project analysis and find unused code, and Visual Studio is approaching this level of functionality out of the box - with extensions and Roslyn plugins it is possible to do some very powerful checks. Dynamic language tooling is really like banging goddamn rocks together, and people take pride in that...
- PaulKeeble 6y agoPMD for Java does as well with the right settings.
- Scarbutt 6y agoI will take a dynamic language over bad statically-typed languages any day, no matter how good the IDE is.
- thrower123 6y agoWhy? I cannot comprehend this mindset.
- sullyj3 6y agoThe difference is that you can delete code with confidence that the compiler will tell you if you did something wrong, rather than things failing at runtime at some indeterminate point in the future.
- steveklabnik 6y agoIt depends on exactly what you mean by "called." Rust will warn you if your function is: * Not marked public * Not called from somewhere in the call graph of a function that's marked public, or your main function. This isn't just simply public though, to be clear. It's "externally callable," that is, it can see transitively if something is just locally public or not. You also can't dynamically generate functions at runtime, or do things like method_missing, so this ends up being much more complete than a similar analysis in a language with those sorts of features.
- cgenschwap 6y agoYou're right the type system isn't really the solution for catching dead code. But compilers can easily check for this, if the language is restricted enough. The issue with a lot of dynamic languages is things like monkey patching and reflection, which means that functions can be called at runtime but otherwise there is no way of checking beforehand. Some people swear by this dynamic flexibility and the benefits it brings, but there are some serious downsides in terms of refactoring.
- marcosdumay 6y ago> but it's not going to catch that your NicheHelper class that was only called in one place is not called anymore Your NiceHelper function gets one type as argument and returns the same type? Is it `void NiceHelper(...)`? Severely restricting the number of `void X(...)` functions on your code helps a lot. Also `a someF(a)` is a type that is useful once in a while, but if it's useful all the time something may be broken.