Static typing is indeed very useful for refactoring. This is why all the (successful) dynamic languages are adding ways to add static typing optionally
Compile By Fire is one of my favourite tricks as well. Some years ago, I was working on a codebase that transmitted certain variables over the air in a particular byte order that was not the same as the host byte order, and that meant that any maths operations on it needed to flip the bytes properly before and after doing the operations. There was a missing byteswap somewhere in the system. By changing the name of the variable, the compiler told me all usages of that variable everywhere in any context and let me audit each instance, silence the good ones by fixing the name locally, and eventually find the missing byteswap.
Wow, using the compiler as an extra-safe alternative for find and replace is so meta, I love that tip
3:50 "Every place we use C is gonna be a disaster, right?" Ah... I love that this could be taken out of context. lol
Really good montage, thanks for sharing.
When I do refactoring I like to make big jumps and not fearing to destroy my system, I avoid trying to keep feeling safe. I use to refactor a lot and include that in my daily routine, I'm always refactoring as soon as I feel the code is ugly. I feel I make much more progress since I started taking this habit. First because you stress the system you designed so you become more familiar with it, and second because it's by taking risks that you become stronger. It's a good way to develop your abstraction skills. You solve problems easier in general.
The power of lexical scopes and strong types :) Great refactoring tool, I gotta use that.
that little define trick was gold!!!
there are similar methods in all languages to encapsulate and alter code in isolation. It does take time to get good at it. There is no better method than just keep programming. I would also say that there is no bound to getting good at the process.
The Math example was amazing. Perfectly shows the "I know my end-goal" mindset to have.
The compiler IS the debugger lol
amazing thats taught me a real meaning of refactoring .
3:40 is absolutely genius. I am certainly using this trick next time I refactor.
Love the "Ancient Aliens"-like thumbnail.
The problem with python is polymorphic functions. In strongly typed languages like Java you are returning a type or subtype or strongly typed implementation, so their are pretty good guard rails. In python, people can write functions that can return a variety of completely incompatible types, and this is common. Python's type hinting system allows this to be accounted for to some degree.
You can do this in Typescript too! If I ever had to write plain JS again, without the ability to track down compiler errors with all the Typescript goodness, I would be bald.
I am surprised more people weren’t aware of this. It became completely apparent that this was powerful when I first started using statically typed languages.
Try this in Basic: "oH HeY, LoOkS LiKe yOu mIsTyPeD A VaRiAbLe nAmE. LeT Me aUtO-dEcLaRe tHaT As a nEw vArIaBlE FoR YoU!"
you definitely need more tests (or use an optional type checker) for languages like python if you want to be able to do refactoring . It's not as convenient and fast turn around as using a statically typed language compiler to do it. It's a trade off between the flexibility of more dynamic expressions and the fact that you have to write tests for stuff that a compiler otherwise would have given you for free. As a contractor I get a lot of jobs where I make a custom web site for a customer in a few weeks where dynamically typed languages and no tests at all helps me do very fast but if the projects are at least 6-12 months in length I might start looking at languages that offers more safety and help long term maintainability.
@keithpatrick156