News for hackers. Stuff that matters.
Re:Systematically removing code by horsawlarway on Wednesday November 11, 2020 @10:38AM (#25059206)
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.

Re:Systematically removing code by steveklabnik on Wednesday November 11, 2020 @10:47AM (#25059294)
It 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.

Re:Systematically removing code by cgenschwap on Wednesday November 11, 2020 @10:51AM (#25059330)
You'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.

Re:Systematically removing code by thrower123 on Wednesday November 11, 2020 @10:46AM (#25059279)
All 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...

Re:Systematically removing code by PaulKeeble on Wednesday November 11, 2020 @01:05PM (#25060922)
PMD for Java does as well with the right settings.
Re:Systematically removing code by Scarbutt on Wednesday November 11, 2020 @02:47PM (#25062135)
I will take a dynamic language over bad statically-typed languages any day, no matter how good the IDE is.
Re:Systematically removing code by thrower123 on Thursday November 12, 2020 @10:26AM (#25070846)
Why? I cannot comprehend this mindset.
Re:Systematically removing code by sullyj3 on Wednesday November 11, 2020 @10:47AM (#25059291)
The 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.
Re:Systematically removing code by marcosdumay on Wednesday November 11, 2020 @01:40PM (#25061346)
> 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.