> Making a large refactor without types is the wild west. Types help provide structure/understanding about the data flowing through your system.
If you’re working on a large, unstructured project that you’re trying to refactor, you’re problem probably isn’t with the types. It’s that the people working on it used types as a crutch so that they thought it was okay to write classes that were thousands of lines long with giant methods that are impossible to make sense of.
The interview question I’ve been asking lately is about object design. I tell them not to put things into one big method—that it needs to be readable for junior devs. They always ignore me. The ones who struggle the most are the ones who try to do it in a staticly types language (which I’m sure you agree is crazy to use in an interview for a tiny problem). Their mental model forces them to think about types first, and they then can’t think about anything other than that and just making the thing work.
If you aim to keep your objects and you methods small enough that anyone can read them and make sense of them, then you don’t need static types and refactoring becomes easy. There are plenty of developers of mediocre talent who never use types and are able to build huge features and projects quickly and with high maintainability and flexibility because they write code that sticks to good object oriented design principles.
A class I work on regularly has become so big that everyone, especially the more senior, more talented engineers at my company are too afraid to touch, let alone try to refactor. It’s stayically typed.
Your one big method interview example - so you think had they not been able to reply on static typing for refactoring in their previous work they would have gravitated toward cleaner code? That just seems wildly speculative as a counter to me. A fair amount of projects don't get the refactoring they need in the first place, so developers working on those don't get the experience to begin with. Developers who write large functions often have reasons like "if you use multiple functions you have to jump around to see whats going on." If i'm attacking a straw man, its unintentional.
Anyway having unit tests in a projects would encourage smaller units more, you can have tests easily in static languages - so you get the best of both worlds - smaller units and the ease static typing brings to refactoring.
The go-to sources on writing good code in c#/java land are proponents of keeping methods and classes small as well - that's where i learnt from. (Not to start any wars on over use of design patterns)
Your comment assuming we'd all agree choosing a static language is a bad choice for a small example is also very strange to me. When i'm under pressure id go with what i'm most familiar with, likely C#. Though, with JS and PHP being my dynamic alternatives, i may just be sounding like a very bad programmer to you ;)
I've seen plenty of very long functions in javascript (and c#), and dont think it has anything to do with static typing.
Sounds like you're permanently stuck living in amateur hour... I have never seen anyone past high school level CS try to pull the shit you describe. Those aren't problems of static typing, they're problems of poor dev talent.
At question is whether the benefits of static typing outweigh their costs. From my experience (purely anecdotal) static typing provides a false sense of security that encourages bad practices, thus turning the benefits of types into costs themselves.
To me, that sense of security is not false (even 90% reliable is better than 0%). And to suggest that type systems are a contributory factor to developers writing functions/classes that are too large is completely unsubstantiated.
If you’re working on a large, unstructured project that you’re trying to refactor, you’re problem probably isn’t with the types. It’s that the people working on it used types as a crutch so that they thought it was okay to write classes that were thousands of lines long with giant methods that are impossible to make sense of.
The interview question I’ve been asking lately is about object design. I tell them not to put things into one big method—that it needs to be readable for junior devs. They always ignore me. The ones who struggle the most are the ones who try to do it in a staticly types language (which I’m sure you agree is crazy to use in an interview for a tiny problem). Their mental model forces them to think about types first, and they then can’t think about anything other than that and just making the thing work.
If you aim to keep your objects and you methods small enough that anyone can read them and make sense of them, then you don’t need static types and refactoring becomes easy. There are plenty of developers of mediocre talent who never use types and are able to build huge features and projects quickly and with high maintainability and flexibility because they write code that sticks to good object oriented design principles.
A class I work on regularly has become so big that everyone, especially the more senior, more talented engineers at my company are too afraid to touch, let alone try to refactor. It’s stayically typed.