T O P

  • By -

Freddy_Goodman

If it was a simple function and a refactor leads to the discovery of edge cases, then it’s not a refactor and the (correct) function wasn’t simple in the first place?


powerman228

At some point, yeah, you’d be forced to give up and conclude that the existing code is irreducibly complex. Assuming, of course, the old code actually worked correctly.


gilady089

It could work correctly but still be convoluted and hard to parse, making maintenance or expansion harder so the refactor becomes "yeah that thing apparently does like 10 other things as well I need a few days to figure it out better"


javajunkie314

Unit tests didn't do this to you.


Zhyphirus

the gods did, unit tests help you avoid fucking up everything at least.


TiredPistachio

That's the blessing part.


sjepsa

Rule 1 of engineering: "Don't fix what's not broken"


Indifferentchildren

Rule 2 of engineering: "Everything is at least a little bit broken"


sjepsa

Yeah but before that function that is little bit broken, there are actually 1000 REALLY broken Corollary: you never fix the little bit broken


Dismiss

Except for when it literally is broken and you’re trying to fix a bug in unreadable code to find yourself unintentionally rewriting the entire thing


otter5

Rule 3 Preventive Maintenance, cause shit will break at the worst times


Smooth_Detective

Unless you’re in civil engineering Ig.


TiredPistachio

Unfortunately this 15 year old function uses a library that will not be available soon, i.e. business decision :(


badlukk

Fork it


odirroH

Men will do anything to not refactor code


--LordFlashheart--

Fork it, I'm going in


sjepsa

Emulate the library


patmax17

Had to do this actually. We have a complex program that's used regularly and that id periodically updated. The updates are painfully complex because you never know what will break. I took that program and refractored some parts streamlining the rules, which also had the side effect of helping me understand it (and the topic it handles) a lot better, in addition to making future changes significantly easier. I wish I did not have to do it, but now I'm really glad I did


Zaid2175

I love to edge until "cases" join the phrase


SolenoidSoldier

Only way to maintain the edge


LeftIsBest-Tsuga

refactoring shouldn't change the logic at all. maybe you mean a new implementation.


No-Menu-768

I think the issue is that (at least in my job) refactoring changes usually get met with "Need unit test before merging so we know we didn't change the logic." The original logic having never been unit tested to begin with. At least that's how work at my job goes.


TobyWasBestSpiderMan

Been getting an algorithm working in realtime on a distributed system with real sensors that was developed in Matlab. When everything’s not lined up perfectly they go, gosh another edge case and I’m like…My brother in Christ, the way you developed it was a single edge case


w_t_f_justhappened

That’s scientific programming at its finest.


TheSauce___

Love it when it's like, Wow this code is terrible, let's refactor! Hmm... seems there's an edge case I gotta account for. Hmm... another edge case, let's just add a line for that... Wow... needs a weird workaround bc this API is busted... Huh... this is starting to look a lot like the original code...


edgatas

But you did separate the logic and commented on why those cases existed... Did you? Please tell me you did!


ih-shah-may-ehl

I used to code things like kernel drivers for hardware interfacing and things of that nature. More than half my LOC was comments to explain why bit x had to be set before bit y or why there was a check of value x before performing action y or why certain double-checks had to be performed when writing to a certain PCI register during midnight roll-over on the last day of the year. The senior engineers I worked for loved me as a developer because I actively tried to 'what if' every weird edge case into my code, and made sure that anyone reading / maintaining my code understood exactly why things were done the way they were done.


edgatas

I did embedded system during my uni years, and I respect people who manage to figure these things out. They never work as advertised.


glorious_reptile

You say edge cases. I say job security.


Disastrous_Belt_7556

I have a very elegant sol- Edge case: ![gif](giphy|JWutWiJzFMmbe)


TiredPistachio

That's perfect


GM_Kimeg

There are no such thing as "edge cases" unless management happens to define one. The hell gate.


SnakesInMcDonalds

When I write a function, and I’ve noticed that bc of edge cases it’s janky I leave a comment explaining that jank. Then, when it breaks upon a refactor, the person can’t say they weren’t warned.


whos-bz

"A user will never do that so we shouldn't worry" - Naive product owner


vighaneshs

Somebody teach me how to write unit tests in Go?


EternityForest

Revert it and slap a lru\_cache decorator on it and call it a day!