5 ms·
The main advantage of static typing to me is that it enables automatic refactorings. Without types, it's impossible for tools to refactor your code safely with
by incepted 11y ago
The main advantage of static typing to me is that it enables automatic refactorings.
Without types, it's impossible for tools to refactor your code safely without the supervision of a human. This leads to developers being afraid of refactoring and, ultimately, code bases rot and become huge piles of spaghetti that nobody wants to touch.
With a statically typed language, I'm never afraid to refactor whenever I see an opportunity to do so.
- japhyr 11y agoI haven't done large-scale refactoring work before. How does typing help with refactoring? Is it because you know exactly what's being passed into a function?
- JustSomeNobody 11y agoOr that they're just used to their IDE doing all of it for them.
- incepted 11y agoYou missed "automated" in "automated refactorings". This is what I'm talking about. Without types, IDE's can't perform automated refactorings: you need to supervise them and make sure the IDE didn't break code. This can't happen with static types.
- montibbalt 11y agoIt makes manual refactoring easier too in the sense that you now have a tool that can tell you what you broke and how to fix it.
- ubernostrum 11y agoWithout types, IDE's can't perform automated refactorings This is your obligatory reminder that the entire concept of automated refactoring was first developed in a dynamically-typed language.
- luos 11y agoIt really helps when renaming methods for example. I am not sure how much it helps with extract method.
- DougBTX 11y agoTyping makes it easier to write a "find all references" function. Types distinguish whether a call to foo.bar() is calling the same bar as baz.bar(), which makes it easier to rename Foo's bar wherever it is used, but leave Baz's bar alone.
- orblivion 11y agoOften enough, in Haskell, you can boldly make the primary change you want to make, fix all of the ensuing type errors in the rest of the code, and your refactored code will run as expected. The compiler will more or less tell you what you missed.
- nickpsecurity 11y agoRefactoring changes how various chunks of code interact with each other. Types usually provide security against a limited set of bad interactions. Abstract or compound types can provide security against even more bad interactions, among other things. So, having simple, compiler-checked mechanisms for enforcing good interactions helps when you make changes that can cause bad interactions between chunks of code.
- ptype 11y agoI hear this argument a lot, and I'm sure static typing is helpful when refactoring, but I have found that nothing is as important as tests when refactoring. I'd rather refactor dynamically typed code with good test coverage than statically typed code without good tests.
- zeckalpha 11y agoIt is better with certain languages, and it is better when you encode business logic into your type system.
- grdvnl 11y agoI work on Python and the Pandas data frame is one of the core data structure that is used in the implementation. I have been thinking of how I can translate this code in a more robust type checking language such as Haskell, without loosing some of the conveniences Pandas provides. Do you have any suggestions or pointers to this? I would love to encode the business logic into types. But, I am always afraid I might end up in type hell!
- zeckalpha 11y agoSadly, that's a misconception about types that languages with poor type systems have caused many to have. There's nothing about pandas that shouldn't work in Haskell. Edit: In fact, there's this library! https://github.com/acowley/Frames https://github.com/acowley/Frames
- incepted 11y ago> but I have found that nothing is as important as tests when refactoring You don't need those with static types. You only need to write tests for your actual code, not things that the compiler can check for you. Manually writing code to check things the computer can test for you is a waste of developers time.
- yrro 11y ago