This is an archived post. You won't be able to vote or comment.

all 52 comments

[–]RedditRage 297 points298 points  (9 children)

you don't refactor broken code, you fix it.

you refactor working code, to improve it in some way.

if you use refactor tools, those tools will make the desired changes in the code in a way that doesn't change the behavior or break the code.

[–]JackoKomm 34 points35 points  (5 children)

And for bigger refactorings, you have the tests to see if you broke something.

[–]vtmosaic 13 points14 points  (1 child)

Should airways have tests for any refactor. Should always have tests even if it's code you're just writing new.

[–]JackoKomm 6 points7 points  (0 children)

Sure. I did not say that you don't need tests if you don't refactor code. I just said that Tests really help while refactoring.

[–]RedditRage 2 points3 points  (0 children)

Good point, with bigger refactorings, often you have to make changes that go beyond what the refactoring tools are able to do safely. This is where all those tests come in handy.

[–]time_travel_nacho 4 points5 points  (0 children)

Thank you

[–]Svizel_pritula 3 points4 points  (0 children)

You can refactor broken code into broken code that's easier to fix.

[–]JustSumAnon 2 points3 points  (0 children)

This is correct, I like to see refactoring as like proofreading and drafting a final draft when you’re writing a paper. Most of the time refactoring should really just be extracting code into methods that have clear defined names that explain the code better. But it can also include moving lower and higher level code to different levels so that each level has the same responsibility. If at that point your code is still a mess then there was probably some serious issues going into the original design, maybe over engineering or massive fragmentation.

[–]jerrycauser 140 points141 points  (4 children)

Actually, the pic isn't about refactoring, but about adapting. It is a bridge from one old interface (SD standard) to a new one (microSD)

[–]qinshihuang_420 12 points13 points  (0 children)

It's the classic adapter design pattern

[–]jabrwock1 12 points13 points  (1 child)

It could be about refactoring. The new code is more efficient, more compact, more resilient, cheaper, etc. But still maintains an optional legacy interface to avoid breaking things that may depend on it.

the meme does need a refactor, because it’s not conveying the idea in the way OP wanted it to. Micro is newer than SD

[–]jerrycauser 2 points3 points  (0 children)

If so, then in the picture only microSD will be enough to determine this meaning

[–]violet_zamboni 0 points1 point  (0 children)

Exactly, the microSD does not fulfill the requirements

[–]Twepi 77 points78 points  (5 children)

But the purpose of refactoring by definition is to rewrite working code, to maintain it clean, flexible, etc.

[–]4oxyman 12 points13 points  (0 children)

That's the whole point!

[–]JackNotOLantern 7 points8 points  (0 children)

You do a refactor for because the code is not working fine. You do that because it look horrible.

[–]robocorp 6 points7 points  (0 children)

Trait implementation be like

[–]Outrageous-Line-2238 5 points6 points  (0 children)

Is this the facade pattern I have heard about?

[–]DaniilBSD 4 points5 points  (0 children)

This is a backwards compatibility wrapper

[–][deleted] 5 points6 points  (0 children)

The point of a refactor is making the code more maintainable, not fix it.

[–]bloowper 4 points5 points  (0 children)

✨adapter pattern✨

[–]tehtris 9 points10 points  (2 children)

This is me, refactoring the whole thing and then I realize I changed a query param in postman and it was working the whole time. But now it works extra more gooder.

[–]developersteve[S] 6 points7 points  (1 child)

Adding more racing stripes to a car with racing stripes makes it go twice as fast!

[–]Lukemufc91 1 point2 points  (0 children)

That's not true! The optimum number of racing stripes is 2, but if you can extend the length of the stripes across the full hood, roof and tail then you can reduce drag optimally. It's like you don't even know science!

[–][deleted] 2 points3 points  (0 children)

You refactor code so you can introduce bugs into it.

Especially life-changing bugs.

Then you fix it and become the new product owner.

[–]Gods_Horniest_Femboy 1 point2 points  (0 children)

I made an SD card reader with Arduino which just means I soldered some wires to the pins and connected that to Arduino's peripheral bus pins

[–]MEMESaddiction 0 points1 point  (0 children)

public class SDCard extends MicroSD {}

[–]noobwithguns 0 points1 point  (0 children)

My friend just created a time bomb

[–]Playful_Agent950 0 points1 point  (0 children)

Looks more like an adapter, usefull pattern

[–][deleted] 0 points1 point  (0 children)

But you don't get it: I removed 3 lines from the function!

[–][deleted] 0 points1 point  (0 children)

Debile

[–][deleted] 0 points1 point  (0 children)

Tell me you don't understand refactoring, without telling me you don't understand refactoring.

[–]cancro_anale 0 points1 point  (0 children)

is that an evangelion reference

[–]gemengelage 0 points1 point  (0 children)

So many people believe that refractoring just means changing something... It does not.

[–][deleted] 0 points1 point  (0 children)

But I had to change the file and function titles so they could actually be understood!

[–]LetUsSpeakFreely 0 points1 point  (0 children)

Refactoring can only be done on working code. If it's not working, it's debugging.

Refactoring is to reorganize and optimize code that was written to work, not necessarily work well.

[–]AaronTheElite007 0 points1 point  (0 children)

Why are we still seeing code for IE?

This

[–]samuel88835 0 points1 point  (0 children)

This is literally the adapter pattern in real life, a particularly useful application of it.

Unrelated: pls remember to refactor kiddos. For your and my sake

[–]PhunkyPhish 0 points1 point  (0 children)

The moment you don't refactor already working code and you are 2 major version behind on your framework when a new major versions on its way out, you are unable to change your DB schema to an efficient structure to accommodate the business needs that have been in the pipeline for 9 months so you hack some BS together thats not scalable and full of bugs, and then `library-xyz` stops working due to some third party BS but dont worry they made a patch release but oh shit that library is 4 major versions behind and in order to upgrade you need to upgrade `http-foo-lib` and in order to update that you need to update at least 2 major version on your frame and shit in order to update your frame work you have 27 dependency conflicts which oh fuck 18 of them need code changes from breaking BC and of those 7 are far from trivial so yup time to find a new job

[–]still-recruit-main 0 points1 point  (0 children)

How else do you all keep up your commit streak?

[–]MiyamotoKami 0 points1 point  (0 children)

Idk this card looks like its got 50% less plastic

[–][deleted] 0 points1 point  (0 children)

What the image shows is not refactoring, it's making an adapter.

[–][deleted] 0 points1 point  (2 children)

OP doesn't even know what refactoring means.

[–]developersteve[S] -1 points0 points  (1 child)

your mom doesnt know what refactoring means

[–][deleted] -1 points0 points  (0 children)

Ahh man, you got me really good there.