Тёмный

EVERY programmer should follow this principle 👩‍💻  

Coding with Lewis
Подписаться 599 тыс.
Просмотров 3,5 млн
50% 1

Опубликовано:

 

14 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 1,1 тыс.   
@Kaitokid730
@Kaitokid730 2 года назад
"you gotta think lazy" is the best description ever of programmers and is the most true 😂
@mvnkycheez
@mvnkycheez 2 года назад
work smart not hard 😏
@cerulity32k
@cerulity32k 2 года назад
Think smart, not hard.
@krasimirlukanov6726
@krasimirlukanov6726 2 года назад
Not lazy, effectively.
@idoredid3831
@idoredid3831 2 года назад
That's a good slogan for a programmer. Maybe I should use it 😅🤣
@aaaaaa-hh8cq
@aaaaaa-hh8cq 2 года назад
@@cerulity32k yes
@savirananda8337
@savirananda8337 2 года назад
"You gotta think lazy" Me: coding for hours to automate 5 minutes tasks.
@MightyAnik
@MightyAnik 2 года назад
Proceeds to use the automated program for 5days and does all the work while people do half the work in 10days
@maxbaugh9372
@maxbaugh9372 2 года назад
@@MightyAnik In grad school one of my friends said: "if you do it twice you'll do it 10 times, just automate it"
@savirananda8337
@savirananda8337 2 года назад
@@MightyAnik definitely worth it!
@Maleko48
@Maleko48 2 года назад
I spent 6 months building some macros / scripts / automation in AHK for my day job (a little bit each day, 100% outside the scope of my actual job's duties) but damn does it make me faster than everyone else who does my job, and with way less typing/repetitive actions. Not to mention others come to me for bulk order entries since our outdated scheduling system makes doing those rather painful.
@KilgoreTroutAsf
@KilgoreTroutAsf 2 года назад
hah no kidding
@moinali828
@moinali828 2 года назад
Be DRY don't be WET ( We Enjoy Typing)
@rhoynarr
@rhoynarr 2 года назад
Write Everything Twice
@shivangrathore
@shivangrathore 2 года назад
@@rhoynarr You mean Thrice?
@callumhaynes1384
@callumhaynes1384 2 года назад
"Waste everyone's time"
@sanyamkothari4469
@sanyamkothari4469 2 года назад
@@shivangrathore T Times
@goutgueule9197
@goutgueule9197 2 года назад
@@shivangrathore this doesn't exist
@andrewwood1502
@andrewwood1502 2 года назад
"Don't repeat yourself is aimed at encouraging programmers to not repeat themselves"
@aheendwhz1
@aheendwhz1 2 года назад
Wiser words never have been spoken
@LetoDK
@LetoDK 2 года назад
The American way of thinking, exemplified. Also: "Use DRY in order to avoid having to refactor How to use DRY instead: you simply refactor the code"
@Lymphaofallcolours
@Lymphaofallcolours Год назад
Underrated.
@akiraigarashi2874
@akiraigarashi2874 Год назад
People die if they are killed
@hamster8706
@hamster8706 Год назад
Profile picture checks out
@Goose____
@Goose____ 2 года назад
Oh don't you worry, im lazy alright, too lazy to even start coding
@CodingWithLewis
@CodingWithLewis 2 года назад
The best code is NO code at all
@Goose____
@Goose____ 2 года назад
@@CodingWithLewis Truer words were never spoken
@ibrahimkalmati9379
@ibrahimkalmati9379 2 года назад
@@CodingWithLewis isn't it that why we are Building A.Is
@abdirahmann
@abdirahmann 2 года назад
@@CodingWithLewis 🤣🤣🤣🥲
@Ommarrie
@Ommarrie 2 года назад
Start bro
@montenegrodrd
@montenegrodrd 2 года назад
Well, sometimes readability takes precedence over DRY. :)
@ВикторЛюбезный-ч2ы
Agree. When using a double code with the different data, including possibly incorrect, you can see, which line of your script throws an exception, and understand easier, where is the problem. Other case is when the count of the parameters may be extended for the single case. If the code is in the function with parameters as arguments, then you need to add a function argument and, when impossible to set the default argument value, set this value to all of the function calls.
@joejjj4378
@joejjj4378 Год назад
@@ВикторЛюбезный-ч2ы Many languages allow optional parameters, and those that don't will allow you to pass JSON objects with as many parameters as you like. In reality, the times you don't want to write reusable code for everything would be when you create a function for one thing, then extend it for another case, then keep extending it until the function becomes too complicated and difficult to maintain.
@joejjj4378
@joejjj4378 Год назад
@@ВикторЛюбезный-ч2ы Oh and you can also create optional parameters in the Java sense, which doesnt have optional parameters but you can create haave multiple headers for a function doSomething(int x){ doSomething(x, -1); } doSomething(int x, int y){ .... }
@GldnClaw
@GldnClaw Год назад
Is there an efficient way where you can have it display everything it refers back to without repeating? (I know nothing about coding)
@caribbeanman3379
@caribbeanman3379 Год назад
@@GldnClaw The example given, could be made even simply by passing the math operators as an argument to an all-purpose binary operation function: def binaryCalc(x, op, y): Only thing is I'm not sure if this programming language (Python I presume?) allows for passing operators as arguments. Maybe the operator could be passed as a string and you could use a decision structure to handled the 4 different operator cases. I think one function that decides between 4 different versions of an argument is drier than 4 different functions for each operator.
@magne6049
@magne6049 2 года назад
There’s nuance here: «Prefer repetition over the wrong abstraction.» «Avoid hasty abstractions» See the talk by Sandy Metz.
@jrgptr935
@jrgptr935 3 месяца назад
Meide die Eierlegende Wollmilchsau wie den Teufel. Schreib lieber fünf einfache, aber richtig angeordnete IF...ELSE-Abfragen als eine dreifachverschachtelte, deren Sinn nach 30 Jahren der dann zuständige Mensch nicht herausfindet. Ein Programm wird nur einmal geschrieben, muß aber von ANDEREN oft gelesen und verstanden werden, wenn der ursprüngliche Programmierer längst zu den Ahnen gegangen ist. Avoid the egg-laying wool-milk sow like the devil. It is better to write five simple but correctly arranged IF...ELSE queries than one triple-nested one, the meaning of which the person responsible will not be able to figure out after 30 years. A programme is only written once, but has to be read and understood many times by OTHERS when the original programmer has long since gone to the ancestors.
@Zeero3846
@Zeero3846 2 месяца назад
Basically, don't repeat yourself, but only when things are supposed to change together.
@Matthias53787
@Matthias53787 2 месяца назад
The only valid use cases for DRY are covered by common sense. So don't even teach DRY. DRY considered harmful
@stephens3909
@stephens3909 Год назад
Make sure not to use DRY programming in test cases, they are meant to be repetitive otherwise you will need to write tests for your tests.
@dixie-pixie
@dixie-pixie 2 года назад
"You gotta think lazy" Me: goes to stack overflow then copy-paste
@AppleYoJo
@AppleYoJo Год назад
ChatGpt entered the chat
@abskhairoun
@abskhairoun Год назад
Now that's more like it
@rinzler9775
@rinzler9775 Год назад
Just Chat GPT - and hope whatever it created never breaks - at least while your around.
@i_zoru
@i_zoru Год назад
@@AppleYoJo nah bro i prefer google bard, more updated data
@AppleYoJo
@AppleYoJo Год назад
@@i_zoru FR? I’ve seen some reddit posts about Bard a few months ago and its answers were often rubbish, did it get better?
@RiderThatOneIdiot
@RiderThatOneIdiot 8 месяцев назад
As someone who just started c# this help a lot. Thx!
@jasonpepas4290
@jasonpepas4290 2 года назад
The level beyond this is knowing when to break this rule, understanding the trade-off.
@ChaoticNeutralMatt
@ChaoticNeutralMatt Год назад
Like learning writing rules.
@Daniel_WR_Hart
@Daniel_WR_Hart Год назад
Yep, don't use DRY in cases where you have code duplication but you're not entirely sure if those pieces of code absolutely need to be the same, because maybe they're just coincidentally the same at the moment. If you find yourself abstracting your code into a function then adding a boolean flag to change how it behaves, you just created a crappy abstraction
@pixels_per_minute
@pixels_per_minute 4 месяца назад
​@@Daniel_WR_HartAn easy example of this in game dev is player variables. Walk speed might coincidentally be the same as jump velocity. You wouldn't merge those two into one variable, because you might need to change them independently of each other later on.
@Daniel_WR_Hart
@Daniel_WR_Hart 4 месяца назад
@@pixels_per_minute For sure, like if you decide to add running, powerups that only effect speed or jump height, upside-down gravity in some areas, or muddy ground that affects speed a bit more than height. It could even be as simple as having the controls feel just a bit nicer when walk speed is 90-95% of jump speed depending on the level layout
@rujn
@rujn 4 месяца назад
Yes exactly, I disagree with pretty much every point in this video. Don't start with abstraction, let it come naturally. Start WET (write every time) then encapsulate from there. Stop telling programmers to be lazy! They need to be disciplined. Blindly following a rule does not improve the industry.
@voidpointer398
@voidpointer398 Год назад
Ca you make video explaining SOLID principles? Your explaining skill is great
@uuu12343
@uuu12343 2 года назад
My principle is "If it doesn't look good, it's not good" Fitting with the example of the class init
@godnyx117
@godnyx117 Год назад
Love that! I think the same way and it's just our instinct telling us that our code sucks!
@samueljehanno
@samueljehanno Год назад
​@@godnyx117same
@ujk4887
@ujk4887 2 года назад
There is no “DRY” npm package. Am I supposed to do this by thinking?
@CodingWithLewis
@CodingWithLewis 2 года назад
It’s a way of thinking :)
@shadowplay1211
@shadowplay1211 2 года назад
I can make one 😂 But what should I put in it?
@someone-wv3ds
@someone-wv3ds 2 года назад
@@shadowplay1211 x = 10 y = 10
@adityaanuragi6916
@adityaanuragi6916 2 года назад
-- WARN -- WARN Downloaded 7 audit files Sry if that's a little inaccurate I'm a noob at web dev right now
@ControlAllDa1337
@ControlAllDa1337 Год назад
Ask stackoverflow
@bassam_salim
@bassam_salim 2 года назад
My professor always says: " start where others reached", that's why I used my classmates' graduation project's code to build my own, it was a php website and he had all the oop stuff ready so why spend time and effort writing it when they already did.
@azhagurajaallinall126
@azhagurajaallinall126 2 года назад
That's the thing,.. that's what business corps learned to do quick & my college HOD pushed us to do IEEE projects(which was done by professors & phd students which i can't afford the project requirements) still those projects meant to cash in by corps than we actually ddo something for us(personal use) and/or to start our business from it.. Still that's the thing.. why go from beginning to just make it different at the end.. get a done project,real world application,try to change few things little by Little,eventually we learn much & quick(that's how Engineering & reverse enginnering works) At the end every little change we made often,make it really different,unique & really usable than the original 😃 just go for it 😃 As one legend says "if you're good at something,don't do it for free" (joker ofcourse)😇 since you can sell any of your work in Computer Programming,just go for it than stayed at one 😃 Its about how much we can do program our own ideas anytime & make it worth,build your career,happiness & life out of it.. i am putting this here,to anyone who has ideas to do something,just go for it,build it,sell it,a same product differs tto each one,its your style & usability counts.. see y'all success,happy days ahead in our life 😃🌟✨🙌 24.08.2022 03:12 pm ist
@SahilP2648
@SahilP2648 2 года назад
Php in 2022? Lol
@rschool5386
@rschool5386 2 года назад
@@SahilP2648 I was about to say the same thing 😂
@victorbitencourt9481
@victorbitencourt9481 2 года назад
@@SahilP2648 php is still prevalent all over the web
@SahilP2648
@SahilP2648 2 года назад
@@victorbitencourt9481 yes because we didn't have better technology available back in 2000s but now it's not an excuse to not use newer tech which is just better overall in terms of development, security, versatility, and performance.
@gligoran
@gligoran 2 года назад
In my experience DRY leads to premature refactorization. Instead I rather use the rule of three - 2 instances of similar code are OK, but when doing a 3 instance it should be refactored.
@sbkates
@sbkates Год назад
3 strikes and you're turned into a function
@sabientje65
@sabientje65 Год назад
Learned this the hard way. Not a fan of the 'always do X' or 'always do Y' crowd. Almost every decision requires at least some nuance and thought.
@homelessrobot
@homelessrobot Год назад
@@sabientje65 yeah buy then you have to think your thoughts more than once each, and thats not DRY.
@Tsunami14
@Tsunami14 4 месяца назад
Exactly!! DRY is an important principle to strive for. But the way it's presented, and the example given, can easily lead people astray.
@tamaraoweibo
@tamaraoweibo 2 года назад
“Gotta think lazy”… that’s what I’m doing when I repeat myself. It’s out of laziness… efficiency is hard.
@blackcloud415
@blackcloud415 Год назад
This is good advice for code you know you're gokng to use again. Sometimes you just have bulk operations that need to get done in a specific way that doesn't pertain to another scenario.
@SkyTheHusky
@SkyTheHusky Год назад
"Don't repeat yourself is a software development principle aimed at reducing repeating yourself." *ah yes, the floor is made out of floor here*
@zawadlttv
@zawadlttv 8 месяцев назад
if you dont want to use objects in this case, you can pass a function to a wrapper function that does the setup def wrapper(operation): x = 10 y = 10 return operation(x, y) def add(a, b) return a + b and use like this: wrapper(add)
@RoyalYoutube_PRO
@RoyalYoutube_PRO 2 года назад
Did he really repeat the functions in order to not repeat the function?
@TR_Arial
@TR_Arial Год назад
If he ever needs to change x and y values, he only needs to change it once rather than in every function
@jaretsanchez1900
@jaretsanchez1900 Год назад
@@TR_Arial Depending on the requirements if there is user input the user can decide which function is chosen. That deletes all extras and consolidates that down to one function. So choose this, case statement based off what was chosen then the function variables x and y.
@aditopguy9785
@aditopguy9785 Год назад
Exactly what I was thinking
@simonwochner3708
@simonwochner3708 Год назад
@@TR_Arial but why does the function has 2 arguments x and y? Just remove the overwriting part and done
@fifty-plus
@fifty-plus 6 месяцев назад
It was a terrible example, the tests didn't assert anything and you want to use fixure values over hard coded values but even if you did use hard coded values you should be keeping them within the test.
@abhinavap7301
@abhinavap7301 Год назад
"You're a programmer, you gotta think lazy" man this line will stick with me for the rest of my life.
@MidnightSt
@MidnightSt 2 года назад
No. There's a great talk by Casey Muratori on his channel explaining how he rewrote a navmesh generating function so that instead of taking half a minute each time it ran, it was possible to run it in realtime, at 30 FPS. How did he achieve such an incredible optimization? By not reusing functions that did what he needed to be done, but they did it in a way horribly unsuitable for the task, since their primary use was for different tasks. My point is, there's no universal "every programmer should always do this". Following even the most obviously-sounding "principles" religiously, without thinking what is their purpose, and how does that purpose align with the purpose of what you're currently doing, is a surefire way to end up in horrible places. DRY is a suggestion suitable for most programmers, and many situations, but not for everyone, nor everywhere. Same as all the other "good code practices". They're suggestions to consider and use if suitable for the specific thing you're doing.
@BrunoMoreira991
@BrunoMoreira991 2 года назад
Absolutely, while you definitely want to keep your code organized and improve readability it's important not to overdo it, especially in intensive applications where performance is key, adding a bunch of function calls will introduce overhead so it's something to keep in mind. Every situation will be different and needs to be properly studied/considered.
@sven_527
@sven_527 Год назад
Then just use functions that are suited for the task. Break it down into smaller functions.
@BurninVinyl
@BurninVinyl 7 месяцев назад
100%. This DRY thing sounds more like an religion.
@rmt3589
@rmt3589 Год назад
Code Monkey teaches this in his course. It's helping me a lot.
@rafagd
@rafagd 2 года назад
I thought the wisdom on testing specifically was Do Repeat Yourself A Little Bit, so you don't break all tests by reusing code that wasn't supposed to change in the first place...
@raphaeld9270
@raphaeld9270 2 года назад
You are right. You also should only consider repetition of intent not just repetition of code itself. If the same code is used for separate intents, we tend to add boolean parameter to the function, instead of just splitting that multiple-intent function into multiple smaller functions that call shared lower-level constructs.
@DmytroKlieshchov
@DmytroKlieshchov 2 года назад
Agreed, example in the video is not the best since you’re asserting for different constant values in the end. And if you change values in the init, you need to go and change all the tests, which you most likely do not want to do..
@CodingCenter1
@CodingCenter1 Месяц назад
We can use constructor in class which are just where we give unique properties to the objects in our class, then use it in other functions within the class
@loupax
@loupax 2 года назад
It took me almost a decade to get this idea removed from my head
@sven_527
@sven_527 Год назад
No you should just know when not to use it.
@efeminella
@efeminella 2 года назад
I spend a considerable portion of my day conducting code reviews and continually emphasizing points such as this. If developers would just take a step back to really grasp fundamental design principles; specifically: encapsulation, single responsibility, separation of concerns, principle of least knowledge, and DRY, they would significantly expedite their domain of expertise and that knowledge will always carry across any language or platform.
@glezisbauk4732
@glezisbauk4732 2 года назад
I started coding seriously pretty recently and had this concept in mind, I didn't know people called it this way lol, it's like creating lego pieces you can combine in different ways to obtain completely new things
@TheDaruiKumo
@TheDaruiKumo 2 года назад
It's more commonly known as object oriented programming, and it was definitely a big upgrade in the 90's. But there are a lot of problems with strictly adhering to this, I would recommend searching RU-vid for something like "problems with object oriented programming"
@Nofxthepirate
@Nofxthepirate Год назад
DRY, aka: "If you reuse it, encapsulate it in a function" Functions are also really good for making your code look clean
@Champagnerushi
@Champagnerushi 2 года назад
I prefer wet ( write everything twice). The third time you have different use cases and can create a better abstraction.
@legowyn24
@legowyn24 2 месяца назад
I taught myself this a few days ago and I absolutely love it
@bettercalldelta
@bettercalldelta Год назад
"You gotta think lazy" So true, I'd rather waste 5 hours failing to automate a simple task rather than taking 5 minutes to do it manually.
@pessimistic5579
@pessimistic5579 Год назад
learning design principles is one of the most productive things you can do as a new programmer when you feel like theres not much else you need to learn in terms of syntax in your preferred language. Learn things like SOLID, KISS, DRY, YAGNI, and others. theyre all very easy concepts and will take your code to the next level
@klarenzcobie6595
@klarenzcobie6595 Год назад
"I'm a programmer, I'm too lazy to think lazy"
@samueljehanno
@samueljehanno Год назад
😂
@demarcorr
@demarcorr Год назад
very context dependent, but sometimes the cost of repeating yourself doesnt outweigh the cost of refactoring to be DRY. Again, also very context dependent but you can risk tighter coupling by trying to be too DRY
@tbuk8350
@tbuk8350 2 года назад
In this case, you don't even need to do anything with classes (though you should). You could just use variables in the intended way, and if x and y will always be the same, just initialize them outside the scope, and add them within those functions.
@thecwd8919
@thecwd8919 Год назад
Yea i dont know why hes asking for inputs if hes just redefining them
@Tom-vc4yq
@Tom-vc4yq Год назад
I am learning how to use magic methods now. this short helped me to understand the use a bit more. thankyou!
@kuratse205
@kuratse205 2 года назад
"you gotta think lazy" the one guy who overengineers simple code to save on doing the task multiple times: 👁️👄👁️
@HotNoob
@HotNoob Год назад
this.
@draco_lich
@draco_lich Год назад
There was once a science survey, which proved if u have a task which u want simplified or reduce the time of effort required, just hand it over to a lazy person, he'll automatically create the most efficient and time energy saving way to do that work, Some say even the tv remotes were made that way cuz some lazy person didn't want to stand up and walk to tv to change channels and instead wanted to change it while lying leisurely on sofa...
@max_ishere
@max_ishere 2 года назад
That might lead to a bug if you reuse the SE test object for all tests. Now you have to make sure that your test runner kills the object before next test so you may need another test for that
@bedtimestories1065
@bedtimestories1065 2 года назад
I don't get the impression that this video is for professional developers. I was thinking the same thing lol
@BrandNewByxor
@BrandNewByxor Год назад
Sometimes identical code snippets exist for different purposes. I advise AGAINST de-duping these ones or you'll make it hard to modify one snippet without modifying the other. It's very hard to know when this applies or not, but you will encounter these situations when you overapply DRY principle
@makezdtem
@makezdtem 2 года назад
You are really inspiring 10/10
@CodingWithLewis
@CodingWithLewis 2 года назад
🥺🥺🥺
@nothanniballecktor9633
@nothanniballecktor9633 5 месяцев назад
I thought that was the point of the editing process. You design the logic ahead of time then go back in and do alterations to modulate it and make it better. It’s just like writing an essay, you wouldn’t turn it in without an editing process, would you?
@twitch7657
@twitch7657 2 года назад
And vice versa Don't follow WET We Enjoy Typing
@astola_studio_official
@astola_studio_official 2 месяца назад
“A Lazy Programmer is an Easy Programmer” - Astola Studio
@vincentlegaspi1329
@vincentlegaspi1329 2 года назад
I think it is okay to start with a mess long line of code and then think to re-write it with a shorter one. I remember while creating neural network I write every single weights and outputs cuz I wanna know how it works, after it works I re-write with a shorter line of code.
@homelessrobot
@homelessrobot Год назад
right. "Don't repeat yourself if you know exactly what you are doing", which is after you have come to the conclusion that you know what you are doing, which should be almost never, lol.
@prospekt_1
@prospekt_1 Год назад
Refactoring and abstracting is not “thinking lazy” - quite the contrary, as saving time long term takes a lot of effort up front.
@BeardBarians
@BeardBarians 2 года назад
yeah I gotta do this with my code at some point - but I also think make it work, then tidy it up
@JordanMetroidManiac
@JordanMetroidManiac 2 года назад
You’re right. Making it work comes first because you never know what you’re going to have to add later that might not fit your current modular design. They say that premature optimization is the root of all evil.
@m.a.daquatics4588
@m.a.daquatics4588 Год назад
I just learned the lazy bit last night. I over complicated my code and have been struggling to get it to work. So I took out some extra bits and it works
@CodingWithLewis
@CodingWithLewis 2 года назад
What programming principle do you follow? 🤔
@samucancld
@samucancld 2 года назад
DRY and KISS mostly
@redthered279
@redthered279 2 года назад
@@leshtiz440 What is it?
@redthered279
@redthered279 2 года назад
@@leshtiz440 So what you saying is, if I ever encountered a bug, I should leave it for later?
@redthered279
@redthered279 2 года назад
@UCk45TyHC6P97yuqKHSP6DoA Lol thank you for the explanation, kind stranger.
@redthered279
@redthered279 2 года назад
Uh the tag broke lol.
@jaysonbunnell8097
@jaysonbunnell8097 2 года назад
The object isn’t bad, but it’s still more typing than I like. I prefer to create a test(a,b,callback) and inside just call my various functions, seeing as they all take the same parameters. In my main() I’ll just have a few calls like so: function test(a,b,callback) return callback(a,b) //could also just be this: // const test = (a,b,callback) => callback(a,b) const a = 10; const b = 10; const add_val = test(a,b,test_add); console.log(add_val); OR in python: test = lambda a, b, callback : callback(a,b) # could also be this: # def test(a,b,callback): # return callback(a,b) a, b = 10, 10 add_val = test(a,b,test_add) print(add_val)
@grapes008
@grapes008 2 года назад
Copy paste seems pretty lazy to to me
@NathanHedglin
@NathanHedglin 2 года назад
Often safer too
@iVo42928f
@iVo42928f Год назад
If you want to be very strict in this principle, you should also factor out the `x y` pattern. In reality, there is quite the grey area between what counts as a code clone and what doesn't.
@realcryptc
@realcryptc 2 года назад
“Don’t repeat yourself is a software development principle aimed at reducing repeating yourself” It’s the dry humor for me 😂
@pickinandgrinin7535
@pickinandgrinin7535 Год назад
One of the first lesson in any good programming class.
@nox5282
@nox5282 Год назад
Yet professionals seems to forget it
@Daysalin
@Daysalin 2 месяца назад
Had no Idea of the absolute genius I'd encounter on youtube today.
@RickyRoundhouse777
@RickyRoundhouse777 Год назад
When writing tests, be careful not to confuse code that looks the same but is testing different things as repetition that should be abstracted. Too much abstraction can create dependencies where your tests aren't completely isolated from each other and which can lead to problems.
@NatanStarke
@NatanStarke 4 месяца назад
I also prefer to name variables in a way i know exactly what each function is doing and what the variables mean, i avoid "x and y", and instead write like " damage" or " health"
@byakuyatogami2905
@byakuyatogami2905 Год назад
That's what first got me using lists. I'm someone who gets bored writing and typing the same thing multiple times. Glad to know I'm on the right track
@jbird4478
@jbird4478 Год назад
Like most rules there are situations in which it's perfectly okay to break them. Sometimes ctrl-c ctrl-v really is preferable to wasting time on some generic solution.
@acelyon5221
@acelyon5221 Год назад
True, to be honest I end up finding ways to make my program more dry. For instance I would have 2 different outcomes that need to do different things, and when I look back on it I can see that most of the code within them are technically the same in some way. so I would try and put it all into a function and then once I do that, I can add many different outcomes I just need to pass in all the needed stuff to the function. Made my code much cleaner and no repeats
@e0nema0tak1v
@e0nema0tak1v Год назад
Good tip for someone that is just starting.
@makarambles
@makarambles Год назад
in compsci classes in university we actually got MAJOR points off for not following DRY. I thought it was a pain in the butt but now that I'm working as a SWE I'm super thankful for having this drilled into me
@silvermonad1
@silvermonad1 2 года назад
debatable sometimes going DRY from the start can make a wreck of large code bases, it's rather a situational thing it should specifically be used for parts that are actually repeated not just dividing any function cuz we can.
@tomjerry0796
@tomjerry0796 Год назад
An another way is declare x and y as global variables And use it on all functions
@sharpfang
@sharpfang 2 года назад
And then you get a framework that requires you to write 200 instances of the exact same boilerplate for 200 different dialog boxes but now it's not considered bad practice because it's no longer business logic, it's just boilerplate and you'll never need to refactor it except in a week when the framework announces API change.
@10101amit
@10101amit 2 года назад
Lol, totally agree dry doesn't usually work specially in UI when you eventually have to write each case code inside the common function .. The only principle i follow is to not have any principles .. and that from people who have to make videos regularly ..
@Biriadan
@Biriadan 3 дня назад
Things that change together should be grouped together. You should trade a bit of repetition for a bit of coupling if there’s a chance that you’ll have to change one spot but not the other.
@eradubbo
@eradubbo Год назад
A lot of times following this could make some code unecessarily diffucult to read, so it depends on the context.
@grzegorz.kocjan
@grzegorz.kocjan 10 месяцев назад
DRY is good for the beginning but later you need to understand also separation of concerns. It tells you when it is good to repeat your code :)
@RickGladwin
@RickGladwin 4 месяца назад
The example he gives has what I sometimes call “mountain range” code smell. If you glance at a page of code and see a repeating pattern in the shape of the lines, check and see if you can separate the data from the functionality. In this example, those x and y parameters are data, and can be extracted, keeping the common functionality in its own DRY method.
@minecraft4life525
@minecraft4life525 Год назад
On the contrary, dry code can lead to very bad maintainability if done incorrectly. Specifically in systems where decoupling is something you want. Also, one of the main promises of dry code is "change it once and you're done", but if the code is used in enough places, a basic change introduces the need to retest the entire application. I don't mean to say that everyone should run out copying and pasting the same code, I just want people to put a bit of thought and reason into whether or not DRYing a specific piece of code really makes sense and not follow the principle blindly.
@reinux
@reinux Год назад
DRY is way, way overstated. What's important is having a single source of truth, not being lazy. You need to be ready to express subtle differences by replicating different parts of code, not just obsessing over commonalities.
@LittlesProductReviews1
@LittlesProductReviews1 Год назад
I like to think in my head I came up with this idea first which is one of the reasons I don't take advice from programmers on the internet. But look for the answers myself on their coding. And I think I would find it fascinating how people solve different problems.
@doktoracula7017
@doktoracula7017 2 года назад
Overall this is a good tip, but some people take it too far and too early. You can allow some duplication, because over time you might see that repetition was temporary and with more requirements things start to drift apart. Same with simple things repeating once or twice, it doesn't make it any harder to read code or maintain it, so there's no need to deduplicate it (sometimes). Overall be lazy but think about what you do. But don't overthink it, go for good enough at first and then refine it.
@Duck_side
@Duck_side 4 месяца назад
Sometimes it makes more sense to spend 5 hours repeating yourself than spending 5 hours setting up a function to do what you need in a reusable way, then only using it once
@Joshinken
@Joshinken Год назад
You’re right. From now on all my code will only contain the word „if“ a single time and i refuse to repeat it.
@jongeduard
@jongeduard Год назад
Real world developer tip! There exist still scenarios where you absolutely have to do things repeatedly, for various reasons. In such cases, you can also choose to go for code generation, either by using code generators or by scripting such a thing yourself. So DRY here means to not actually write the repeated code by hand.
@le9038
@le9038 Месяц назад
I have some skepticism over this approach over the factor of speed... When you take a repeated string of code and make it a function. you have it so that instead of running just that code, you have to perform a jump to that place in memory in order to execute what you want. If you are gonna make it a function, you should probably just inline it though the compiler may not agree with you...
@Arken119
@Arken119 10 месяцев назад
“You gotta think lazy” bro resumed my whole life in 4 words 💀
@DariGamesTM
@DariGamesTM 2 года назад
i do this all the time, its a great way to make things way more easy.
@evan_game_dev
@evan_game_dev 2 года назад
don't go overboard though, functions should really only be used when you actually have repeating code. don't be intimidated by long functions. separating a function that has pieces that aren't used anywhere else into separate functions is hell to debug
@2RosarioVampire
@2RosarioVampire 2 года назад
Software engineer here. Please don't do this in actual unit tests with complicated inputs. Unit tests are not meant to be efficient. It's meant for anyone to just come in and see what problems there are at that moment ASAP. Especially considering there might some small variant in a unit test; this is especially true for unit test on functions that create large csv files. Edge cases will require you to repeat yourself -quite a bit. Make generic builder functions for unit tests but please repeat yourself for unit tests. Able to pinpoint immediately on individual unit tests is extremely important.
@arekxv
@arekxv 2 года назад
DRY is good for code which is meant to coexist together, it is HELL for code which must be kept separate.
@cyrusol
@cyrusol 5 месяцев назад
This principle is overutilized, not under-. There are valid cases to duplicate code. Especially if it's about 2 distinct business rules that may change independently from each other and are just accidentally relying on the same logic right now.
@justinpatterson5291
@justinpatterson5291 2 года назад
A correlation to this would be building physical modules of a vehicle that clip together, each responsible for it's own task. Like a wheel hub that steers, absorbs shock and provides drive.
@beepbeepgamer1305
@beepbeepgamer1305 2 года назад
welcome to step one in Machine Learning.
@jamesgarofolo7576
@jamesgarofolo7576 2 года назад
I can always tell the difference between beginners and experienced programmers, and this is almost always it. Copied and pasted blocks of code in every direction you look, and single simple changes taking hours to implement because it involves fifty literals across thousands of lines instead of fifty references to one global variable right at the top with the rest of the “just make this one little tweak real quick for me” stuff. Remember kiddos, it’s not about how fast you code, it’s about how well you code fast
@josephbousaada9796
@josephbousaada9796 Год назад
This is a solid advice for almost all cases, but sometimes you need to sacrifice DRY for clarity
@ThatJay283
@ThatJay283 5 месяцев назад
i dont follow "dry" or "clean". i just follow what looks good. one thing ive found to be consistently true instead is if i need more than 3 levels of nesting, my code is bad and needs to be fixed. but your thing of adding an __init__ is still the correct thing to do because it increases readability and maintainability. your improved version also removes the confusing bit of why x, y were even parameters when you weren't even using them. dont be dry or clean, just be lazy. long functions can always be broken up later down the track anyways if you need to reuse components of them, and repeating yourself sometimes isnt always bad.
@flamehiro
@flamehiro 2 года назад
Don't repeat yourself long as it doesn't drive you nuts. I got too ocd into don't repeat yourself that it actually made things worse at one point.
@proohit99
@proohit99 2 года назад
DRY isn't always the best way to go **when testing**. Tests should be as independent as possible and repeating is Ok. Doesn't apply for regular production code.
@w01dnick
@w01dnick 2 месяца назад
But important note, sometimes its better to repeat than introduce complex abstraction to save 2 lines.
@w01dnick
@w01dnick 2 месяца назад
So, basically, don't be fanatic of any approaches.
@hugazo
@hugazo Год назад
Thinking lazy is what brought me to development
@brightlyvirya7500
@brightlyvirya7500 Год назад
it is called modular coding. we put a multiple used code in a module that we can call by a variable
@Gigasaur
@Gigasaur Месяц назад
Honestly amazing tip
@silasmayes7954
@silasmayes7954 4 месяца назад
"You gotta think lazy" applies to a lot of IT.
@adlaimurata2212
@adlaimurata2212 2 месяца назад
"Don't repeat yourself is a principle aimed at reducing repeating yourself" is possibly the funniest statement I've heard
@haiderabbas6175
@haiderabbas6175 2 года назад
Keep posting man. You rock
@Pwanchi
@Pwanchi 2 года назад
"You gotta think lazy" is probably the best quote to sum being a programmer up. Somebody put that on a shirt.
Далее
Naming Things in Code
7:25
Просмотров 2,2 млн
Why Are Open Source Alternatives So Bad?
13:06
Просмотров 652 тыс.
Why You Shouldn't Nest Your Code
8:30
Просмотров 2,7 млн
Making a Game with Java with No Experience
8:41
Просмотров 444 тыс.
Coding Interviews Be Like
5:31
Просмотров 6 млн
This is Why Programming Is Hard For you
10:48
Просмотров 906 тыс.
My 10 “Clean” Code Principles (Start These Now)
15:12
So, you want to be a programmer?
20:43
Просмотров 345 тыс.
Every Programming Language Explained in 5 minutes
5:18
C++ Developer Learns Python
9:26
Просмотров 2,7 млн