I had a senior early on in my career who took pride in producing the smallest diff possible to solve any given ticket and I thought it was so strange -- I'm already in the file, why not clean up a bit? In hindsight, they were entirely right, and I always regret doing just a little cleanup without it being strictly necessary.
post
Better to break things in staging than prod.
Yes, guilty. But also no longer regretting it a year later now that there's a clear naming scheme and structure and I can easily find what I'm looking for.
When refactoring, it always gets worse before it gets better. So, make sure to finish it so you get to the "better" state and don't leave it at "worse"
I feel like it depends on the project.
Typically in the ones I work on, whenever I spot an inconsistency I fix it no matter how much of a mess that causes. Yes it hurts at first, but it may hurt more down the line when the weirdnesses accumulate to the point where it impacts operations and it'll be a much bigger problem to fix.
However, I can totally see a more chill strategy work better for a project that is mostly just relatively simple code, like perhaps some website deployments. In my opinion it depends a lot on whether the code is generally already complicated, which is when you'll typically want to refactor earlier than later.
The problem with renaming environment variables is that you don't always control the environment.
If you are doing a rename you should have it look for the new environment variable and then fall back to the old one if it's not set. Log an error when that occurs, and then slowly go through and remove the old environment variables in your deploy code, then remove the compatibility code
This is one of those things that break two golden rules. Minimal change, or consistency? The only further variable a most senior person considers is the brittleness of the environment and deployment process.
- $variable1
- $othervariable
- $july2014fixvariable
- $notneeded
...and finally...
*$otherothervariable
These shall be the variable names until the heat death of the universe! Blessed be! So say we all!
It doesn't mean you made the wrong decision. Changing the names has a potential cost - you break something (this is especially risky for environment variables which have insanely global scope, no static type checking, etc.).
Not changing the names has a potential cost too - causing confusion in future, wasted time, or even bugs due to the increased chance of mistakes.
I'm currently leaving a company where they almost never clean up their messes. Tons of old unused code is just left in the repo. Causes huge wastes of time.
Don't underestimate the potential cost of not keeping things orderly. There was a famous case (Knight Capital) caused by not cleaning up an old unused CLI flag and it cost them $440m and destroyed the company.
"If it aint broke don't fix it"
I've not done this specifically, but I know the pain of wanting to make things neat and it breaking things. Then having to live with the unsatisfying setup instead of making everything symmetrical and scratching my brain itch.
At a place years ago, I misspelled a word (stupid English) which made its way into the APIs our FE consumed. FE guy decided to do a quick find/replace and broke prod. He missed some files.
(One of oldest database tables also had a spelling error from the site's first dev because English sucks)
Edit: WTAF, autocorrect?
Good names matter.
If you don't refactor codebases continuously and consistently(!), the'll become a total mess over time. I've worked recently with code bases that still use DOS character encodings common before 2000 or so.
If something is purely local, in a single process, it is easy to change. But the more stuff it touches, the more difficult and laborious it gets. On the extreme end, there are things like network protocols like IPv4 which are almost impossible to get rid of.
I once worked on a project where a third party-parser had a bug that effectively made it sensitive to the order it loaded files.
This wasn't a syntactic or a semantic problem. There was a stack processing issue that could be avoided by simply loading the files in a different order. This might have changed the final semantics if one file contradicted another, but that generally didn't happen. Each file had a specific purpose and it would still break without any contradictions.
The default load order was whatever order the file system had the files stored, but knowing that wouldn't necessarily help because changing the size or contents of a file in such a way that it retained the same position might trigger the same issue. Therefore you could force by-Unicode load ordering and still have it choke.
It was very hard to track down and I very much did not like editing those files for fear of triggering the parser bug. When I had to would be where the regret kicks in.
The other regret, and maybe a little more relevant, was renaming all the files to a different filename format that didn't make any difference in the end, but it was uglier than the original and it stuck.
I believe a later version of that parser fixed the bug(s), but I moved on.
all 29 comments