Good refactoring vs bad refactoring

  Рет қаралды 18,753

Steve (Builder.io)

Steve (Builder.io)

Күн бұрын

Пікірлер: 44
@Steve8708
@Steve8708 2 ай бұрын
Read more on this in my latest blog post: www.builder.io/blog/good-vs-bad-refactoring
@kumailn7662
@kumailn7662 2 ай бұрын
finally some one talking... great Steve. You explain it very well. 🙂
@damonholden
@damonholden 2 ай бұрын
The fact that first example made it through a code review in the first place is wild. Imagine reviewing a refactor that requries 2 new dependencies and going "yeah lets get that merged in".
@PraiseYeezus
@PraiseYeezus 2 ай бұрын
Good advice, good examples. One I would add to the list is that if there's funky looking code that looks odd but is there for a specific business requirement, inline comments can do a lot to help both other devs and your future self be aware of it before you try to refactor it blindly
@rand0mtv660
@rand0mtv660 2 ай бұрын
I like to leave comments that explain "why" something was implemented. If I had to create some hack/workaround or something is just business specific, leaving a comment as to "why" it was done that way helps a ton. I always appreciate it when I run into these types of comments and other devs told me they appreciated it when they ran into comments that I left.
@bennobuilder
@bennobuilder 2 ай бұрын
Love it 🚀 Another point could be: Improving something that should not exist in the first place e.g. recreating libraries, refactoring unnecessary code 👉 Because the best code is no code.
@gauravvarma3645
@gauravvarma3645 2 ай бұрын
Shots fired at whoever he hired lmaoo
@markshinkai598
@markshinkai598 2 ай бұрын
can't like this video enough, solid points and suggestion.
@StephenRayner
@StephenRayner 2 ай бұрын
YES, 🎉! Perfect! 👌 Sharing this with my developers. So well communicated. Also ran into these issues and it’s time consuming communicating this, but necessary and fun. This helps communicate the importance faster. ❤
@mr.daniish
@mr.daniish 2 ай бұрын
Steve dropping pure gold!
@alvaronaranjo2589
@alvaronaranjo2589 2 ай бұрын
3:33 great point, man
@tyulen-vn6qj
@tyulen-vn6qj 2 ай бұрын
Before even watching this all I’m thinking is this exactly me.
@gauravvarma3645
@gauravvarma3645 2 ай бұрын
The fault really lies on whoever approved of those pull requests
@ryanngalea
@ryanngalea 2 ай бұрын
Great advice, thanks! I'm guilty of making my code overly verbose, this is a good reminder.
@mylesy4048
@mylesy4048 2 ай бұрын
Over abstracting tests can be painful when implementing patterns that the team is unfamiliar with. Forcing other devs to pick up patterns that don’t have buy in leaves a desire to revert the PR.
@parlor3115
@parlor3115 2 ай бұрын
I swear, if I see one more pile of Ramda code
@m1dway
@m1dway Ай бұрын
It'll be great if you make a video on how to write better alternatives. Still learning react here..
@blooperr
@blooperr 2 ай бұрын
This is gold 🙌
@tonyjaradev
@tonyjaradev 2 ай бұрын
Nailed it 🎯🎯
@Monstermash355
@Monstermash355 2 ай бұрын
I think the first 2 points are debattable. the way you're using ramda in your example is bad, pipe is amazing, composition is amazing, people should use composition a lot more. Your example should be pipe(filterFn, mapFn)(data), it's just so much cleaner than just chaining filter map sort and such.
@macchiato_1881
@macchiato_1881 Ай бұрын
I think the 3:53 example was a bit contrived. I don't think even junior devs would remove caching logic for no reason. Unless, they REALLY were a "special" type of person.
@asagiai4965
@asagiai4965 2 ай бұрын
Isn't the goal of refractoring to change your earlier code for the better? I think before you fault those refractors, there should be guidelines. Because if there isn't, it is not the person's fault.
@fahadahmad9434
@fahadahmad9434 2 ай бұрын
super helpful
@Ivan-wm6gm
@Ivan-wm6gm 2 ай бұрын
how would you handle errors?
@yojou3695
@yojou3695 2 ай бұрын
meh, i wouldnt shit on the hired guy. He refactored as best he could, and the refactor exposed a problem in the codebase. That allowed you to make things a better refactor in the end. Happens all the time.
@u007james
@u007james 2 ай бұрын
use cody to generate unit test
@Xamy-
@Xamy- 2 ай бұрын
Sin 8: testing everything?
@doc8527
@doc8527 2 ай бұрын
I agree every point, but I will be more aggressive on the api wrapper refactor, I think it's completely unnecessary to create such a wrapper to just save few keystroke, Probably see enough failures of api wrapper in codebase in my life, none of them worked out really well. All failed miserably as business requirement changes. and ppl keep glue weird hacks on top of that wrapper.
@goosydev
@goosydev 2 ай бұрын
I think its not really a "api wrapper" thing and heavily depends on what exactly you are doing. For example frappe (erp framework) uses a wrapper to wrap away ajax calls with common headers, error handling, response parsing, permission checking, ... You dont want to do this all the time for every api call. On top of that we are currently using a wrapper around that to add typing and schema validation support. That saves a TON of time knowing what you'll receive and having that intellisense especially with long complex prop names. And the wrapper is like 30 lines of code. So of course you shouldnt wrap everything in something, but do it where it makes sense
@Steve8708
@Steve8708 2 ай бұрын
I agree, though we did eventually switch to using google cloud gen2 functions and the wrapper made it really easy to change them all at once vs file by file (we have like 50 APIs)
@drugoviic
@drugoviic 2 ай бұрын
bro is ai
@ulietaight
@ulietaight 2 ай бұрын
why you go through the loop twice instead of once in first example, what if array had 1 billion elements
@son1ss
@son1ss 2 ай бұрын
You need to optimize things when its necessary. In terms of asymptotic complexity they does not differ this much. And if there is billion elements you are probably not using JS/TS btw), if it is in browser you have way more problems other than filtering and then mapping through
@PraiseYeezus
@PraiseYeezus 2 ай бұрын
then you would do it at the DB level, not in JS code. (tbh I probably wouldn't be a fan of changing it to a chained map and filter either, that code just needs to be within a util function that makes it clear what it's doing)
@goosydev
@goosydev 2 ай бұрын
If you are rendering 1 billion users then there are prob other questions you should ask yourself (Assuming its frontend cuz having this in backend is weird as Yeezus said, filter on DB level and on top of that youll prob have a limit=50 on that either way). And time complexity wise 2n doesnt differ much from n.
@foolmoron
@foolmoron 2 ай бұрын
What if the array had 10 items? The most important question when optimizing is the range of input sizes. If you're doing this in JS it's clear the sizes are reasonable.
@Kenbomp
@Kenbomp 2 ай бұрын
That or people can try to learn something new
@asagiai4965
@asagiai4965 2 ай бұрын
Wow 512MB i wonder what you are asking to ask for that many.
@Steve8708
@Steve8708 2 ай бұрын
puppeteer
@asagiai4965
@asagiai4965 2 ай бұрын
@@Steve8708 lol
@Tom-cv2cx
@Tom-cv2cx 2 ай бұрын
nit: in lots of the examples shown you don't need the curlies and return keyword e.g. Change this: const foo = () => { return bar } To this: const foo = () => bar Much nicer!
@azizsafudin
@azizsafudin 2 ай бұрын
This is just linting. Not an actual refactor.
@lamhung4899
@lamhung4899 2 ай бұрын
Stay consistent, 😂 Implicit returning makes ppl losed the context, thought it would be best choice in simple logic or in middleware functions
The Secret Language Scaling WhatsApp and Discord
28:32
Theo - t3․gg
Рет қаралды 167 М.
The Only Database Abstraction You Need | Prime Reacts
21:42
ThePrimeTime
Рет қаралды 219 М.
Каха и лужа  #непосредственнокаха
00:15
2 MAGIC SECRETS @denismagicshow @roman_magic
00:32
MasomkaMagic
Рет қаралды 29 МЛН
Seja Gentil com os Pequenos Animais 😿
00:20
Los Wagners
Рет қаралды 90 МЛН
Trapped by the Machine, Saved by Kind Strangers! #shorts
00:21
Fabiosa Best Lifehacks
Рет қаралды 14 МЛН
A Jr Dev For Life?? | Prime Reacts
21:33
ThePrimeTime
Рет қаралды 318 М.
The Most Important Design Pattern in React
35:04
Cosden Solutions
Рет қаралды 95 М.
Coding Shorts 111: Was I Wrong About Blazor?
16:35
Shawn Wildermuth
Рет қаралды 16 М.
Microservices are Technical Debt
31:59
NeetCodeIO
Рет қаралды 603 М.
Why is everyone LYING?
7:56
NeetCodeIO
Рет қаралды 332 М.
I'm Ditching Try/Catch for Good!
10:29
Web Dev Simplified
Рет қаралды 166 М.
Google Drive hates developers now
23:56
Theo - t3․gg
Рет қаралды 144 М.
Refactoring a React Component (Design Patterns)
28:20
Cosden Solutions
Рет қаралды 16 М.
Zig for Impatient Devs
9:48
Isaac Harris-Holt
Рет қаралды 100 М.
Каха и лужа  #непосредственнокаха
00:15