These clean code videos are so good 😋 Edit: Here are the tips he gave: 1) Avoid unnecessary indentation, smartly handle conditional code using if statements at the beginning 2) Maintain consistency throughout the project your are working on, this includes variable names, file names, function names, directory structure, etc, nothing should be randomly done 3) Try to write self explanatory code that makes sense to even a junior developer and in case of complex code/logic, document using the comments properly
Definitely we need part 3. Part 1 literally changed the way I see and write code. Those tips were game changers. Part 2 as well from now on. Just make it dude. Part 3.
1. remove indentations by inverting if statements 2. be consistent with variable, method, and class names 3. if you can do a thing in multiple ways (async/await or .then), pick one and stick with it 4. be consistent with abbreviations 5. your functions should do exactly what they are named, otherwise write a comment to explain what is happening
19:52 0 milliseconds will also work by the way. The reason is we ensure the code inside setTimeout will be executed after all pending executions in the stack will be completed for the current event loop. Great video as usual.
The "if condition: continue" and "if condition: return" statements from tip #1 are called Guard clauses :D they're widely known to make your code cleaner.
Related to consistency: Something that has always annoyed me is when people needlessly abbreviate things. For instance "hme" instead of "home", drives me nuts especially when it's not 100% clear what the abbreviation is abbreviating or is not consistent. Something I sometimes do is use an abbreviation when I'm first writing the code and when I'm close to having it do what it should I rename the variable so it has a longer self descriptive names. So I might have a parameter or variable called 'a' that I then rename to 'agentName'. It kills two birds with one stone. Saves typing during the initial coding but also achieves clarity in the finished code. Also, in keeping with avoiding needless abbreviation, it will be 'agentName' and not 'agntNme', 'agtName', nor 'name' (unless that is really clear). A couple of extra letters can save someone a lot of grief.
This is genius! I will use this method in the future :) thanks for sharing Btw, how do you guarantee that you have substituted all the instances of a variable?
Awesome stuff. Us JetBrains users are very lucky we have products like ReSharper, IntelliJ, or Rider that do code improvement suggestions for most of the tips mentioned here. It's like having a personal coding coach backing you up all the time. So as a ReSharper user I am very used to the tips Clem is giving here. They are all right in the spot.
It is funny how I started learning Python with about 2 years of exposure. I can only code in Python now, but it is amazing that I'm already doing this, and even managed to get a friend to code in Python. I don't like code that doesn't need to be there or can be changed. I always make my file structure organized with similar files based on their general usages. I'm always rewriting my code to use the current knowledge I have and refactor the things I made a while back when I knew a lot less. I love Python all together. I've tried C and it's very hard to figure out what functions to use. Coming from Python to C, with Python, you generally can make whatever you want with a few libraries, or just making your own. So, Python to me is like reading a book, you're paying attention to the text, you're reading it in your head, and a few minutes later, just completely forgot like 90% of that last chapter. With C, it feels like I know what I want to do, but the completely different method of naming. So, it feels more foreign to me since the functions in C aren't regular words you may use. But, although C is low-level, I know it's a much closer look at how the computer runs code, having so many numbers to deal with and worry about memory (is there even a way to prevent any sort of overflow? Neural networks?). I'm worried if I don't broaden my programming in terms of the language, I'm not going to be able to apply to whatever positions. Python works for a lot of stuff, but I know it's also slow too, and apparently, much more experienced developers don't like Python, and I say, huh? Anyway, just want to know what I should continue doing. I'm only doing this as a hobby, but I'd like to land somewhere as a developer of some sort, exploiting in particular.
For tip 1, I believe instead of working with those extra indentations, just extract eveythimg out to separate functions.. Makes code cleaner and it helps with the flow while reading
Really solid examples.. especially the documentation. Some people just write comments for the sake of comments, really should be used for the unusual cases (otherwise you have to maintain the code and comments!).
funny, after purchasing algoexpert and systemexpert, every other content seems slow to me, so much goodies you got there! thanks for your contributions clem! :) P.S. i feel like hungry after seeing you eat that thing in the beginning. :P
Typically what I do for no.3 is break the confusing code out to a descriptively named function. For the first example, I would have made a wrapper called deferDisplay. This idea can extend to literally any situation where you'd use comments except perhaps a file header. So you could avoid them completely outside of that if you wanted.
Excellent content. I would also add: when naming a function - name should state what function does, not what function does not do. I see many people call their functions "partialTransaction()". This is not a good name. The name should state what the transaction does... the "partial" does not have any meaning to the one reading your name.
Hi Clement, just a random thought that occured to me. Right now your Coding and System Designs courses are very heavily marketed as code interview-prep courses. But if I were already an existing dev just wanting to grow my knowledge in these areas, I might think these aren't for me, whereas they absolutely do provide useful knowledge regardless. Just wondering if there's a way you can broaden the appeal of your courses.
How do you learn to code quick but also be good at it? So like instead of only knowing how to code, also being able to solve the algebraic/coding problems. Like knowing the formula to Pythagoras Theorum AND being able to solve the questions on it by implementing the formula. Hope you understood :)
Clear the fundamentals of the programing language that you want to use, learn how things are represented using them, follow basic tutorial, and after doing this, try to put that Pythagoras formula into an algorithm, I bet you can do that within few minutes, believe me I was very bad at maths and still I was able to do it
For the first tip, it is only applicable when the continue is at the beginning of the if-else / for block. I have seen people doing continue / break in the middle of a big code block and makes it super hard to debug.
Something I do to remove indentation of nested if/if elses, in the context of lets say, validating something that needs to pass 10 conditions, then you put at the top errorMsg="", then wrap every if inside if(!errorMsg), and if the check passes you simply don't change the errorMsg variable and change it when it fails to make the other x9 ifs not fire. I use this all the time, works with booleans too. Happy not nesting everyone!.
Great video as always :-) Btw the display none stuff is probably to avoid glitches of some kind, In which case you could use a decorator called avoidDisplayGlitches that wrapps the function with the display code
I disagree with tip#1 a little bit. While I do often use the if/continue thing to avoid indents for relatively simple code. If you're doing a lot of if statements + conditional jumping, I'd say to just keep all the indents because it makes it way easier to understand exactly where you are in the branching logic structure. The best thing to do here is either try and avoid having to do this in the first place. Either by separating things into another function, or even changing up the algorithm a bit.
Just the other day I design to create an application to do something very particular to stock market data. I stopped coding in 2006, cold turkey, because it was interfering with my marriage. I was never a paid programmer, it was a hobby. So 14 years later I resume where I left off. My Computational logic way of thinking is still spot on. But I was...am...(maybe still) having issues with syntax and deep nested loops. I love the continue getting rid of the else. A question I have is what is the editor feature called let's you better visually see where blocks begin and end (the indenting) by drawing the virtual lines. And can I get that with borland delphi 7? By the way I'm currently a truck driver. And would absolutely love to make the switch to being a paid programmer. Coding draws me in, it is entertaining. When I'm Coding I don't even think of other forms of entertainment I could do like "watching Netflix", playing a game, etc. Coding for me replaces all that. So once I get my skills back up, an employer would absolutely love me! Literally I would spend every moment of my free time into coding. Thats why I didn't resume coding after my marriage failed, stopping coding didn't save it. And I didn't resume coding because I know it will suck me back in, but I was/am actually happy with that... P.S. my next girlfriend must love coding as much as I do.
What about the perspective of comments? I often see(and you also did it the video) the "We" perspective(for instance, "We have to check that because..."). Is it a difference to the reader?
I’m getting my bs in physics this may but I’m really interested in learning how to code! Thanks for your videos, I’ll do my best to get a handle by may!!
You got this Jonathan! Some unsolicited advice from someone who also did a non-CS STEM major: definitely do learn to code! It'll be the best decision you make!
I am just a noob in coding so I dunno if I am right or not but whenever I face situation #1 where I have to do a lot of indentation, I basically make function calls after every 2-3 indentations. (Even though I might not use that code elsewhere) . This way, I don't get lost in the maze of loops and conditions. Please tell me if that's a good coding practice or not. Thanks!
hey clement could you give any tips to get into google as machine learning engineer or could connect us with any of google engineer ? Thanks in advance
I have a question... first i learn c++ then i master it. Then i learnt python but i forgot c++ syntax. So i revised it...now its a mess...it become python ++ Can you help me with that, how to gain grip at 2 language at same time?
Is consistency really more important than having a McFlurry with Oreos? During the video I checked my fridge twice if there is anything like Oreos or a soft ice... But to answer your question, yes a third part would be great :-)
this is just focus on easier to read, but your description of clean code is much more than that, I think maybe you should focus more on the architect, because it help you easier to maintain and expand
First lecture of programming 1 course, degree in computer science: I was taught not to use the "continue" keyword. Actually, my professor said that is one of the worst things to see in a code base (the course was taught in C++, but I think it applies for any programming language), and imho I fully agree with that, especially when you are reviewing or debugging someone else's code, it's so helpful to visually see that a (big) portion of code is under a conditional statement. Furthermore, the more complex is the code you are dealing with, the more is useful not to use keywords like "continue" or sudden "return". But again, this is just my opinion (an the way I'm used to code), thanks for sharing yours.
3:50 I complete disagree. You introduce a new statement here and and I kind of additonal logic. If there is something to be done if a conditions is true, this should be an enclosing if. If the stuff is to be done in most cases but you need to add some checks than this kind of formulation is fine.
Very good point on #1. Too much nesting makes code REALLY ugly and hard to read. And it's often unnecessary with a little thought. I've had to debug code from developers that had their else statements literally hundreds of lines away from the original "if". Simply impossible. You have to try to fit all the spaghetti into your head. Can't untangle the web of spaghetti fast enough to fix a critical bug? Too bad! In a function that is 2,000 lines of code with multiple if's, loops and other logic. Nonsense.
Good point on example 3 as well. You will run into cases where you have to revisit your own code six months later and you will have no idea why you did something the way you did it and without comments you'll be just as lost as if somebody else wrote it.
I love the fact that I don’t know any of those languages but completely understand it. Clean code is clean code.
Nobody:
Clément: for(let i=0; i
These clean code videos are so good 😋
Edit: Here are the tips he gave:
1) Avoid unnecessary indentation, smartly handle conditional code using if statements at the beginning
2) Maintain consistency throughout the project your are working on, this includes variable names, file names, function names, directory structure, etc, nothing should be randomly done
3) Try to write self explanatory code that makes sense to even a junior developer and in case of complex code/logic, document using the comments properly
1) is fkn funny if you code in python
Definitely we need part 3. Part 1 literally changed the way I see and write code. Those tips were game changers. Part 2 as well from now on. Just make it dude. Part 3.
1. remove indentations by inverting if statements
2. be consistent with variable, method, and class names
3. if you can do a thing in multiple ways (async/await or .then), pick one and stick with it
4. be consistent with abbreviations
5. your functions should do exactly what they are named, otherwise write a comment to explain what is happening
19:52 0 milliseconds will also work by the way. The reason is we ensure the code inside setTimeout will be executed after all pending executions in the stack will be completed for the current event loop.
Great video as usual.
The "if condition: continue" and "if condition: return" statements from tip #1 are called Guard clauses :D they're widely known to make your code cleaner.
Related to consistency:
Something that has always annoyed me is when people needlessly abbreviate things.
For instance "hme" instead of "home", drives me nuts especially when it's not 100% clear what the abbreviation is abbreviating or is not consistent. Something I sometimes do is use an abbreviation when I'm first writing the code and when I'm close to having it do what it should I rename the variable so it has a longer self descriptive names.
So I might have a parameter or variable called 'a' that I then rename to 'agentName'. It kills two birds with one stone. Saves typing during the initial coding but also achieves clarity in the finished code. Also, in keeping with avoiding needless abbreviation, it will be 'agentName' and not 'agntNme', 'agtName', nor 'name' (unless that is really clear).
A couple of extra letters can save someone a lot of grief.
This is genius! I will use this method in the future :) thanks for sharing
Btw, how do you guarantee that you have substituted all the instances of a variable?
Signed my full time offer with Google last week and posted on my channel!
Thanks for all the advice clement!
Awesome stuff. Us JetBrains users are very lucky we have products like ReSharper, IntelliJ, or Rider that do code improvement suggestions for most of the tips mentioned here. It's like having a personal coding coach backing you up all the time. So as a ReSharper user I am very used to the tips Clem is giving here. They are all right in the spot.
Write cleaner code by rewriting the clean code.
that's right
@@mustaches9492 again and again.
Just as thermodynamics tries to make the universe consistent by causing heat death
Yes, we definitely need 3rd, 4th, and 5th videos. Great content!
Love this video! Just started coding, and I'm going to try implementing this as I learn. Thank you!
Cat : Clement slow down I wanna write these advices somewhere.. also do give me Oreo
Clement : This is my cat 🐈
It is funny how I started learning Python with about 2 years of exposure. I can only code in Python now, but it is amazing that I'm already doing this, and even managed to get a friend to code in Python. I don't like code that doesn't need to be there or can be changed. I always make my file structure organized with similar files based on their general usages. I'm always rewriting my code to use the current knowledge I have and refactor the things I made a while back when I knew a lot less. I love Python all together. I've tried C and it's very hard to figure out what functions to use. Coming from Python to C, with Python, you generally can make whatever you want with a few libraries, or just making your own. So, Python to me is like reading a book, you're paying attention to the text, you're reading it in your head, and a few minutes later, just completely forgot like 90% of that last chapter. With C, it feels like I know what I want to do, but the completely different method of naming. So, it feels more foreign to me since the functions in C aren't regular words you may use. But, although C is low-level, I know it's a much closer look at how the computer runs code, having so many numbers to deal with and worry about memory (is there even a way to prevent any sort of overflow? Neural networks?). I'm worried if I don't broaden my programming in terms of the language, I'm not going to be able to apply to whatever positions. Python works for a lot of stuff, but I know it's also slow too, and apparently, much more experienced developers don't like Python, and I say, huh? Anyway, just want to know what I should continue doing. I'm only doing this as a hobby, but I'd like to land somewhere as a developer of some sort, exploiting in particular.
I love the visible pause where your cat meow’d and you were trying to determine if you needed to re-record or not 😂
For tip 1, I believe instead of working with those extra indentations, just extract eveythimg out to separate functions.. Makes code cleaner and it helps with the flow while reading
But I get your point on guard clauses though.
Really solid examples.. especially the documentation. Some people just write comments for the sake of comments, really should be used for the unusual cases (otherwise you have to maintain the code and comments!).
funny, after purchasing algoexpert and systemexpert, every other content seems slow to me, so much goodies you got there! thanks for your contributions clem! :)
P.S. i feel like hungry after seeing you eat that thing in the beginning. :P
Typically what I do for no.3 is break the confusing code out to a descriptively named function. For the first example, I would have made a wrapper called deferDisplay.
This idea can extend to literally any situation where you'd use comments except perhaps a file header. So you could avoid them completely outside of that if you wanted.
As someone fairly new to coding those tips are super useful - thanks Clement!
Excellent content. I would also add: when naming a function - name should state what function does, not what function does not do. I see many people call their functions "partialTransaction()". This is not a good name. The name should state what the transaction does... the "partial" does not have any meaning to the one reading your name.
I like how passionate you are about this :)
Hi Clement, just a random thought that occured to me.
Right now your Coding and System Designs courses are very heavily marketed as code interview-prep courses.
But if I were already an existing dev just wanting to grow my knowledge in these areas, I might think these aren't for me, whereas they absolutely do provide useful knowledge regardless.
Just wondering if there's a way you can broaden the appeal of your courses.
How do you learn to code quick but also be good at it? So like instead of only knowing how to code, also being able to solve the algebraic/coding problems. Like knowing the formula to Pythagoras Theorum AND being able to solve the questions on it by implementing the formula. Hope you understood :)
Clear the fundamentals of the programing language that you want to use, learn how things are represented using them, follow basic tutorial, and after doing this, try to put that Pythagoras formula into an algorithm, I bet you can do that within few minutes, believe me I was very bad at maths and still I was able to do it
@@mayank_upadhyay_19 Thank you for the reply!
You definitely should make the 3rd part of clean code tips. Thank you for 2 parts
Learning from the best is always a pleasure 😎
8:20 Let's just take a moment to appreciate Clement typing at the speed of speech!
For the first tip, it is only applicable when the continue is at the beginning of the if-else / for block. I have seen people doing continue / break in the middle of a big code block and makes it super hard to debug.
Fair point!
Thanks for the second video, looking forward to more of these!
Video Request: How to make an effective product roadmap/requirements document
Finally bought the algoexpert and system expert bundle !!!!!!!
Something I do to remove indentation of nested if/if elses, in the context of lets say, validating something that needs to pass 10 conditions, then you put at the top errorMsg="", then wrap every if inside if(!errorMsg), and if the check passes you simply don't change the errorMsg variable and change it when it fails to make the other x9 ifs not fire. I use this all the time, works with booleans too. Happy not nesting everyone!.
Great video as always :-) Btw the display none stuff is probably to avoid glitches of some kind, In which case you could use a decorator called avoidDisplayGlitches that wrapps the function with the display code
I disagree with tip#1 a little bit. While I do often use the if/continue thing to avoid indents for relatively simple code. If you're doing a lot of if statements + conditional jumping, I'd say to just keep all the indents because it makes it way easier to understand exactly where you are in the branching logic structure. The best thing to do here is either try and avoid having to do this in the first place. Either by separating things into another function, or even changing up the algorithm a bit.
I can't believe that I can access to this kind of clean code advice right at the start of my cs degree
Another VALUABLE content! Putting your advice into action right away... McFlurry part made me laugh; craving for one now. LIKE for part 3.
I literally looked around to see if my cat was asking me something, she was asleep, then I hear Clément "that's my cat" lol
0:52 I was listening to the video on background and had to switch back to confirm I was listening to the correct video. XD
Thanks for the video, i wrote down all tips to remember for all coming projects i will do
Really nice tips, looking forward to watch part 3~good job~
This is an awesome video! I'm really looking forward to part 3!
1. Clean your logic to make code more readable
2. Consistency in workflow
3. Document code that isn't self-explanatory
nits: I thought most programming languages were 0 indexed. Also that a less than is not the inverse of a greater than and vice-versa (from part 1).
I think using continue word a lot may weakens the perceived logic (this depending on the scenario).
Great content! Looking forward to other videos like this one.
Superb tips. Waiting for part 3
In the second example, what if the "for" statement starts at 1 rather than zero. Thus, the "if (i ===0) continue" statement isn't needed.
Just the other day I design to create an application to do something very particular to stock market data.
I stopped coding in 2006, cold turkey, because it was interfering with my marriage.
I was never a paid programmer, it was a hobby.
So 14 years later I resume where I left off.
My Computational logic way of thinking is still spot on.
But I was...am...(maybe still) having issues with syntax and deep nested loops.
I love the continue getting rid of the else.
A question I have is what is the editor feature called let's you better visually see where blocks begin and end (the indenting) by drawing the virtual lines. And can I get that with borland delphi 7?
By the way I'm currently a truck driver.
And would absolutely love to make the switch to being a paid programmer.
Coding draws me in, it is entertaining.
When I'm Coding I don't even think of other forms of entertainment I could do like "watching Netflix", playing a game, etc.
Coding for me replaces all that.
So once I get my skills back up, an employer would absolutely love me!
Literally I would spend every moment of my free time into coding. Thats why I didn't resume coding after my marriage failed, stopping coding didn't save it.
And I didn't resume coding because I know it will suck me back in, but I was/am actually happy with that... P.S. my next girlfriend must love coding as much as I do.
Go into it ! It is very fun as you said and it is compensated well!
This series is really good man
What about the perspective of comments? I often see(and you also did it the video) the "We" perspective(for instance, "We have to check that because..."). Is it a difference to the reader?
Thanks for the video, please do part 3 of these tips
Recursion in terms of videos: i see what clement's doing
Thanks for making a very insightful video about this topic
I’m getting my bs in physics this may but I’m really interested in learning how to code! Thanks for your videos, I’ll do my best to get a handle by may!!
Didn't know they had a bullshit in physics course😅
@@meikamandoliini moose shit
You got this Jonathan! Some unsolicited advice from someone who also did a non-CS STEM major: definitely do learn to code! It'll be the best decision you make!
I am just a noob in coding so I dunno if I am right or not but whenever I face situation #1 where I have to do a lot of indentation, I basically make function calls after every 2-3 indentations. (Even though I might not use that code elsewhere) . This way, I don't get lost in the maze of loops and conditions. Please tell me if that's a good coding practice or not. Thanks!
hey clement could you give any tips to get into google as machine learning engineer or could connect us with any of google engineer ? Thanks in advance
yeah, good content and of course waiting for part 3
Dang, now I want a McFlurry... did McDonald's sponsor you?
I wish! That would be awesome.
What tools you use to record screen + your video and edit your videos?
Code sent to Clément for review.
Clément : I'm not trying to be nit-picky but........................ (to be continued)
Pls make a video about breaking big problems down in code
Do I want a part 3 to this series???? Not even a question 😎 ofc I do !
Thanks Clement!!!, Please more on TS.....
I have a question...
first i learn c++ then i master it.
Then i learnt python but i forgot c++ syntax.
So i revised it...now its a mess...it become python ++
Can you help me with that, how to gain grip at 2 language at same time?
Is consistency really more important than having a McFlurry with Oreos? During the video I checked my fridge twice if there is anything like Oreos or a soft ice...
But to answer your question, yes a third part would be great :-)
Excellent video!! Thank you
Can you please tell me how to get prepared for network engineer intern at Facebook
First comment ! I love this man's videos!
This video is a good example of how most programmers have serious OCD issues.
You're my inspiration Clement
this is just focus on easier to read, but your description of clean code is much more than that, I think maybe you should focus more on the architect, because it help you easier to maintain and expand
Damn...that code was cleaner than my room
Great video Clem
awesome stuff fam!
First lecture of programming 1 course, degree in computer science: I was taught not to use the "continue" keyword. Actually, my professor said that is one of the worst things to see in a code base (the course was taught in C++, but I think it applies for any programming language), and imho I fully agree with that, especially when you are reviewing or debugging someone else's code, it's so helpful to visually see that a (big) portion of code is under a conditional statement. Furthermore, the more complex is the code you are dealing with, the more is useful not to use keywords like "continue" or sudden "return". But again, this is just my opinion (an the way I'm used to code), thanks for sharing yours.
Clement : "This is my cat"...
That's all and suddenly we all open the comment section. 😂
nop
Food and coding...Good mix. Next video you can show us another food haha
Where's part 3
Thanks, that were very helpful tips!
Why you didn't add Ex-google here?🤔
Isn’t the first point called, returning early.
hi what programming language do you know thanks
Thanks, for the video, like you a lot!!
Thanks!
A video on c++ clean code please
3:50 I complete disagree. You introduce a new statement here and and I kind of additonal logic. If there is something to be done if a conditions is true, this should be an enclosing if.
If the stuff is to be done in most cases but you need to add some checks than this kind of formulation is fine.
Part 3... When??
Very helpful
Thank you!
WE WANT PART 3!!
From tip #1: start let i = 1 and remove if ... continue
Clement please tell me how to buy algoexpert for 1 month please 🙏🙏🙏🙏🙏🙏🙏🙏
AlgoExpert can only be purchased for one year at a time
Personally I think "It's what it is" reads a lot better than "It's what it's", but I think I get where you're coming from lol
Darn it, I don’t think I ever used “continue” in an if statement. 😳
Very good point on #1. Too much nesting makes code REALLY ugly and hard to read. And it's often unnecessary with a little thought. I've had to debug code from developers that had their else statements literally hundreds of lines away from the original "if". Simply impossible. You have to try to fit all the spaghetti into your head. Can't untangle the web of spaghetti fast enough to fix a critical bug? Too bad! In a function that is 2,000 lines of code with multiple if's, loops and other logic. Nonsense.
Good point on example 3 as well. You will run into cases where you have to revisit your own code six months later and you will have no idea why you did something the way you did it and without comments you'll be just as lost as if somebody else wrote it.
consistency consistency consistency consistency consistency
Stellar thumbnail
Number 3 my lord!
When you code and it finally gives a valid output 0:56
Today's video is brought to you by McDonald's.
(You're killing it with the subliminal advertising by the way)
Haha that would be amazing. And thank you! 😎
I call your first tip RASAP - return as soon as possible.
Video title: More tips to writing clean code
Video content: Mmm, so, so, so, so, soooo good!