CodeSOD: Prepend Everlasting

by admin

Octavia inherited a decade outdated pile of C#, and the code high quality was just about what one would anticipate from a decade outdated pile that hadn't seen any actual refactoring: nothing however spaghetti. Worse, it additionally had an "interior platform" downside, as every thing they put of their API might conceivably be referred to as by their prospects' personal "customizations".

One small block caught her eye, as suspicious:

.remark { border: none }

public void SomeFunctionality { // Different performance right here int x = SomeIntMethod(); String y = PrependZeros(x.ToString()); // Do different issues with y right here }

That decision to PrependZeros regarded… suspicious. For starters, how many zeroes? It clearly was meant to padd to a sure size, however what?

public String PrependZeros(string n) { if (n.Size == 1) { return "00" + n; } else if (n.Size == 2) { return "0" + n; } else { return n; } }

We've reimplemented one of many built-in formatting strategies, badly, which isn't notably uncommon to see. This technique clearly doesn't care if it will get a quantity that's higher than three digits, which perhaps that's the right habits? Contained in the codebase, this could be trivial for Octavia to take away, as its solely invoked that one time.

Besides she will't do this. As a result of the unique developer positioned the code within the namespace accessible to buyer customizations. Which suggests some unknown variety of prospects may need baked this technique into their very own code. Octavia can't rename it, can't take away it, and there's no actual level in re-implementing it. Perhaps sometime, they'll ship a brand new model and launch some breaking adjustments, however for now, PrependZeros should reside on, simply in case a buyer is utilizing it.

Each change breaks anyone's workflow.


ProGet’s acquired you coated with safety and entry controls in your NuGet feeds. Learn more.

Related Posts

Leave a Comment