Are You Refactoring Code For The Right Reasons?

  Рет қаралды 25,576

Healthy Software Developer

Healthy Software Developer

Күн бұрын

It's tempting to jump into refactoring code that's hard for you to understand.
But before you take that leap, you should probably consider that there can be some dangers.
Whether you're coding in Java, Javascript, C#, Python, or any other language - there are non-technical implications of code refactoring that you should be aware of.
In this video, I share 6 considerations to take into account that will help you avoid getting into a stressful situation when you choose to refactor code.
Subscribe for more videos about Healthy Software Development: kzbin.info...
Related Videos:
"Are You A Perfectionist Programmer?"
• Are You A Perfectionis...
"Software Developer vs Consultant - What's Better For YOU?"
• Software Developer vs ...
"An Agile Budget Keeps You From Being A Code Monkey"
• An Agile Budget Keeps ...
"Technology Addiction: Materialism in Software Development"
• “New Framework Disease...
"Democratic Software Architecture: Sharing Technology Decisions"
• Democratic Software Ar...
#programming #refactoring #code

Пікірлер: 35
@CharlesBallowe
@CharlesBallowe 6 ай бұрын
Just tripped over this older video, but it's something relevant constantly. One thing might be "do I need to understand the code" - rewriting it can help me check that my understanding is correct. Another is how much churn does the code have - if it's being constantly touched, i'd ask if those changes are particularly hard and if restructuring the code would make that easier. If it's not being touched, I'd ask if anybody understands it and if they're avoiding touching it in ways that create more work. Sometimes it's ok to have a box of black magic in the corner that does what it's supposed to do and nobody has to change it.
@IAmAI101
@IAmAI101 11 ай бұрын
There's no harm in refactoring code if you helps you understand it. For me I find this more effective than reading the code with touching it. Nothing says you have to commit or push the code to the master branch. Some call this 'scratch refactoring'.
@frankjonestba
@frankjonestba 6 ай бұрын
Haha. Funny comment. Sorry of an oxymoron haha. You make a good point though 😊.
@ShotgunAFlyboy
@ShotgunAFlyboy 5 ай бұрын
Sometimes the code *is* just wrong though. Like, I've had to rewrite code occasionally written by people that did not really understand the language they were assigned to work in (and had no interest in learning). This is on a product I'm the final butt on the line for though. My goal is never to make it so I can understand it, it's to make it so my juniors can understand it. Gotta make sure the code is well tested beforehand though, so you don't miss those edges.
@HealthyDev
@HealthyDev 6 жыл бұрын
Have you had to decide whether to refactor code you don't understand? How did you deal with it? Skip to points: 02:12 How Valuable Is The Change? 03:19 How Much Time Is Needed To Refactor? 05:29 Will Refactoring Handle The Hardest Case? 08:30 Are You Willing To Get Permission? 10:42 Are You Willing To Teach Everybody? 11:59 Are You Willing To Work Overtime?
@pavelperina7629
@pavelperina7629 3 жыл бұрын
Without watching more than one minute: * If code works and seems maintainable, don't touch it * If code somewhat works and seems hard to maintain, it may have some many dependencies across the project that you can't refactor it and you are doomed to stick with it * If person who wrote this code is still in the company, try to understand his motivation for writing it "wrong" and try to explain your points how to write it "better" and educate him, maybe the biggest piece of code he wrote was his diploma thesis with 2000 lines and he will respect you. * it's much more important to have clear and easy to understand interfaces than clean code. If this is messed up, it's failure or lack of experience of the whole team
@ianedmonds9191
@ianedmonds9191 3 жыл бұрын
Most of my software projects has been teams of 1-4 programmers with a varying amount of designers, PM or POs . Some have felt like a team (pivotal engagement) Others have felt like a bunch of competing groups covering their arse. The teams work better. I'm not sure what the take away is for management but it has something to do with Creative people (devs) don't work well in a culture of pressure, monitoring and blame. To be actually creativity writing code we need to feel free and creative. That only happens when we don't feel threatened. Luv and Peace
@brendanalberto8196
@brendanalberto8196 3 жыл бұрын
@Benedict Ali definitely, I've been using flixzone for months myself :D
@paulcullen5712
@paulcullen5712 3 жыл бұрын
@Benedict Ali yea, I have been watching on flixzone for since november myself =)
@ianedmonds9191
@ianedmonds9191 3 жыл бұрын
I got handed an access database which had no constraints or keys and a bunch of remote tables in an SQL database that also had no restraints or keys. I'd been a .net and SQL programmer for ten years. It had been made by some nut job outside of IT and when he left it was passed to IT to support. It was responsible for bidding for work based on part cost plus a multiplier. Really shonky stuff that was flawed in every way. I looked at the access database and it was truly horrible. The amount of duplicate records was crazy and the disconnect between tables was off the scale. There were orphaned records everywhere and even the records that were connected via crappy natural keys were suspect. Loads of duplicates and no sense of normalisation. Some of the queries were so badly written they were counting some of the costs multiple times. I have no idea how we stayed afloat with such a dysfunctional tender system for so many years. I told my boss it was a dead duck and that we should not maintain it. She insisted we need to fix but asked me to do a report on how broken it was. I did the report with a scenario where we over bid at 4 pieces for every one in the spec. It could have gone to more if more tables were involved. The database was a complete shitshow. They retired the app shortly after. Absolute nightmare of a project. Luv and Peace.
@akivaliaho5166
@akivaliaho5166 3 жыл бұрын
Ahh, I've seen this same crap many times. 10k row long sql queries with hundreds of tables being joined. No normalization, high amounts of duplication. Most of the tables didn't even have primary Keys. This was the most vital database system in the whole company. Everything depended on it to be correct. Management was hovering behind our backs asking for statuses every 15 minutes.
@akivaliaho5166
@akivaliaho5166 3 жыл бұрын
The funny thing is: when you're building new stuff the shittiness of this situation reeks through the ancient integration points and spoils your new code too.
@SlimAgnus
@SlimAgnus 6 жыл бұрын
In 02:12 you ask how valuable the change is, if it's in a piece of code that doesn't have much impact. If the code is too complex or too messy for you to understand what it does, without refactoring it, how will you determine if it's worth refactoring?
@HealthyDev
@HealthyDev 6 жыл бұрын
Great point. You really can’t in this case. I guess my point was even if you can only go by guy feel, to tread lightly on a low value product. As always, just my opinion.
@jtmuzix
@jtmuzix 6 ай бұрын
Hello good sir. Are you familar with C++ and if so, how comfortable are you with utilizing the languages pros such as inheritence, encapsulation, and polymorphism?
@HealthyDev
@HealthyDev 6 ай бұрын
Hey Jason. I haven’t done much C++ since the early 2000s. I’m very familiar with those basic OO patterns but primarily used them with Java and C#.
@leapingblackcat
@leapingblackcat 3 жыл бұрын
You change it. You own it.
@bradenbigham2769
@bradenbigham2769 2 жыл бұрын
yandare dev needs refactoring.
@TomasHayes
@TomasHayes 5 ай бұрын
To refactor code you have to understand it first anyway 😅
@JohnMelaries
@JohnMelaries 3 ай бұрын
If you don't understand the code, read it first and play around with it to understand it.
@kdietz65
@kdietz65 3 жыл бұрын
Oh this sounds like a super fun game. Let's play "would you refactor this code?"
@kdietz65
@kdietz65 3 жыл бұрын
Ah, dangit, KZbin doesn't allow image attachments in comments. That will make it harder for me to attach sample code.
@kdietz65
@kdietz65 3 жыл бұрын
Does it do any code formatting? ``` Line 1 Line 2 Line 3 ```
@kdietz65
@kdietz65 3 жыл бұрын
Well here is just one very short example: string strCssClass = (Height == 230 ? "HBCirChartLayout" : "HBCirTopChartLayout"); I gotta find some way to share this. It's just too good.
@kdietz65
@kdietz65 3 жыл бұрын
For starters, color me this here Batman - Shouldn't the CSS class applied to an element control the height of the element? No sir. Here, they look for the height of the element, and based on the height, they apply one CSS class or another. They check if the height is 230, and if it is, well that's obviously one of the charts that goes in the bottom row, so it gets HBCirChartLayout styles. But if the height isn't 230 (which is to say the height is 178, because that's the only other height a chart could be -- oh, there were checks for that around the code too) then it must be in the top row, and if its in the top row, then it should get the HBCirTopChartLayout styles. Makes perfect sense, right? This is just the beginning of tens of thousands of lines of some of the weirdest, most fragile, most backwardly organized code that I've ever seen. It had not just dynamically generated HTML, but dynamically generated JAVASCRIPT! Code generated from the server, with logic that could vary based on server-side parameters, that was then sent to the browser and executed. Have fun debugging that.
@kdietz65
@kdietz65 3 жыл бұрын
Oh, I just remember this too, this is good. How do you suppose the code ever figured out whether the Height should be 230 or 178? That got set in the chart's constructor. Now the way that worked was based on the rendering sequence of the 4 charts, which were rendered in a 2x2 matrix. The rendering order was 1) Top Left, 2) Bottom Left, 3) Top Right, 4) Bottom Right. So there was an integer session variable that got modified in the charts constructor. They'd flip the sign of it back and forth from negative to positive. If it was positive, they knew it was the top row, and if it was negative, they knew it was the bottom row. Therefore, the constructor code looked something like: Height = (Session["flag"] == 1) ? 178 : 230; . . More stuff . Session["flag"] = -Session["flag"];
@JM-jc8ew
@JM-jc8ew 6 жыл бұрын
Great Video Jayme, Good to have you back, was worried, you were releasing videos less often. I got in trouble in the past when refactoring, if I do not think the same way, as the programmer who did it. I got issues with female programmers ha ha ha! Before refactoring codes, I hit the "blame/show annotation" feature, and if the committer is a female then "Abandon ship!! I repeat, Fall back! fall back! retreat! retreat!". (Believe me, I've seen twisted things out there, this will save you, a lot of time and trouble, specially on a legacy codebase with poor implementation of encapsulation/basic OOP concepts).
@HealthyDev
@HealthyDev 6 жыл бұрын
Thanks for the feedback. I’m not sure why you’d have any more issues with programmers who are women than men.
@HealthyDev
@HealthyDev 6 жыл бұрын
Oh by the way I’m moving to a Tuesday and Thursday publishing schedule starting next week (if I do live interviews or have guests this would be on Saturday). Yeah last week we had some family in town and I had to put the channel on hold for a bit.
@hanktothehendrix
@hanktothehendrix 3 жыл бұрын
This comment is bizarre.
@alexxx4434
@alexxx4434 Жыл бұрын
If it works - don't touch :D
@godmode3611
@godmode3611 4 ай бұрын
This is how a Junior thinks 😅
@alexxx4434
@alexxx4434 4 ай бұрын
@@godmode3611 Quite the opposite, it's how a veteran pragmatically thinks 😂. Junior's naive idealism drives him to redo things, thinking they can do better (while often not actually comprehending the full complexity).
@cadaankaa
@cadaankaa 3 ай бұрын
I rarely find code to be classifiable in such a black/white form. Don't be too quick to refactor, especially if you're new to the system. But sometimes it's worth the effort and risk.
Why Are You Making Programming HARDER?
17:10
Healthy Software Developer
Рет қаралды 50 М.
Why Does Scrum Make Programmers HATE Coding?
16:14
Healthy Software Developer
Рет қаралды 482 М.
Эта Мама Испортила Гендер-Пати 😂
00:40
Глеб Рандалайнен
Рет қаралды 8 МЛН
Айттыңба - істе ! | Synyptas 3 | 7 серия
21:55
kak budto
Рет қаралды 1,6 МЛН
Can You Draw The PERFECT Circle?
00:57
Stokes Twins
Рет қаралды 37 МЛН
This Is Why Managers Don't Trust Programmers...
28:04
Healthy Software Developer
Рет қаралды 113 М.
Don't Believe The AI Hype! Do This Instead...
22:53
Healthy Software Developer
Рет қаралды 77 М.
How Senior Programmers ACTUALLY Write Code
13:37
Healthy Software Developer
Рет қаралды 1,3 МЛН
how NASA writes space-proof code
6:03
Low Level Learning
Рет қаралды 2 МЛН
5 Design Patterns That Are ACTUALLY Used By Developers
9:27
Alex Hyett
Рет қаралды 149 М.
5 Big Lies The Software Industry Tells You
12:06
Healthy Software Developer
Рет қаралды 160 М.
Programming Burnout Is Real - But You CAN Heal
44:56
Healthy Software Developer
Рет қаралды 33 М.
5 Signs of an Inexperienced Self-Taught Developer (and how to fix)
8:40
Why Most Programmers DON'T Last
18:56
Healthy Software Developer
Рет қаралды 222 М.
МОРСКИЕ РАЧКИ С ВАЙЛДБЕРИЗ ЧАСТЬ 3
0:50
Натали Макколи
Рет қаралды 2,8 МЛН
двигатель от мотоблока на оке
0:55
ПЕРВЫЙ ДЕРЕВЕНСКИЙ
Рет қаралды 7 МЛН
Evolution of our product🤩 👆Get yours now link in bio🛍️👆
0:17
Mom doesn't allow large chocolate spread
0:10
Super Max
Рет қаралды 15 МЛН