3 More Tips To Write Clean Code (from an ex-Facebook software engineer)

Поділитися
Вставка
  • Опубліковано 30 жов 2024

КОМЕНТАРІ • 174

  • @MSHOCKER2
    @MSHOCKER2 4 роки тому +53

    I love the fact that I don’t know any of those languages but completely understand it. Clean code is clean code.

  • @mpb0406
    @mpb0406 3 роки тому +3

    Nobody:
    Clément: for(let i=0; i

  • @mayank_upadhyay_19
    @mayank_upadhyay_19 4 роки тому +41

    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

    • @sorvex9
      @sorvex9 2 роки тому

      1) is fkn funny if you code in python

  • @hemanthkotagiri8865
    @hemanthkotagiri8865 4 роки тому +16

    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.

  • @immathiasyde
    @immathiasyde 3 роки тому +11

    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

  • @zerdnelemo
    @zerdnelemo 3 роки тому +1

    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.

  • @sadhlife
    @sadhlife 4 роки тому +9

    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.

  • @MrVoid
    @MrVoid 4 роки тому +1

    Signed my full time offer with Google last week and posted on my channel!
    Thanks for all the advice clement!

  • @littlefluffybushbaby7256
    @littlefluffybushbaby7256 3 роки тому +1

    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.

    • @maakkz
      @maakkz 2 роки тому

      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?

  • @willoyd
    @willoyd 4 роки тому

    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.

  • @kevinandeleven
    @kevinandeleven 4 роки тому +1

    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

    • @kevinandeleven
      @kevinandeleven 4 роки тому

      But I get your point on guard clauses though.

  • @jordansumitomo2357
    @jordansumitomo2357 4 роки тому +26

    Write cleaner code by rewriting the clean code.

    • @manu-singh
      @manu-singh 4 роки тому

      that's right

    • @saiprashanth3597
      @saiprashanth3597 4 роки тому +1

      @@mustaches9492 again and again.
      Just as thermodynamics tries to make the universe consistent by causing heat death

  •  4 роки тому

    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 (and the way I'm used to code), thanks for sharing yours.

    • @clem
      @clem  4 роки тому

      That's definitely a fair point! This is where I do think that, like I mentioned near the end of tip #1, a lot of clean-code tips aren't actually carved-in-stone rules. There's definitely room for differing opinions / preferences!

    • @wulymammoth
      @wulymammoth 4 роки тому

      These are all merely guidelines. In Ruby, it's very common to flatten code but Ruby also makes use of unless (not if). With Clement's example, when there are big chunks, it just may be easier to move the entire block to a helper function, so it's easy to see what is called under what condition. It's always easier to see multiple branching logic clustered together such that the conditions can be easily read w/o having to scroll past a bunch of code to see the next expression being evaluated

  • @hellowill
    @hellowill 4 роки тому

    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!).

  • @TheManyfaced
    @TheManyfaced 3 роки тому

    As someone fairly new to coding those tips are super useful - thanks Clement!

  • @chithebot
    @chithebot 4 роки тому +1

    Love this video! Just started coding, and I'm going to try implementing this as I learn. Thank you!

  • @MrItrollaround
    @MrItrollaround 3 роки тому

    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.

  • @muratx10
    @muratx10 3 роки тому

    You definitely should make the 3rd part of clean code tips. Thank you for 2 parts

  • @shyam5631
    @shyam5631 4 роки тому

    Finally bought the algoexpert and system expert bundle !!!!!!!

  • @jubaidhasanchowdhury9942
    @jubaidhasanchowdhury9942 4 роки тому

    Yes, we definitely need 3rd, 4th, and 5th videos. Great content!

  • @NickCombs
    @NickCombs 2 роки тому +1

    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.

  • @rakibulhaq
    @rakibulhaq 4 роки тому

    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

  • @vulturebeast
    @vulturebeast 4 роки тому +12

    Cat : Clement slow down I wanna write these advices somewhere.. also do give me Oreo
    Clement : This is my cat 🐈

  • @jacksonl.358
    @jacksonl.358 4 роки тому

    I can't believe that I can access to this kind of clean code advice right at the start of my cs degree

  • @Grr1967
    @Grr1967 4 роки тому +2

    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.

  • @JustinHammond
    @JustinHammond 4 роки тому +1

    I love the visible pause where your cat meow’d and you were trying to determine if you needed to re-record or not 😂

  • @sanyo_neezy
    @sanyo_neezy 8 місяців тому

    I like how passionate you are about this :)

  • @Ou8y2k2
    @Ou8y2k2 4 роки тому

    1. Clean your logic to make code more readable
    2. Consistency in workflow
    3. Document code that isn't self-explanatory

  • @frozen7535
    @frozen7535 4 роки тому

    Thanks for the video, i wrote down all tips to remember for all coming projects i will do

  • @thedoublehelix5661
    @thedoublehelix5661 3 роки тому +1

    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.

  • @harispapadopoulos4295
    @harispapadopoulos4295 4 роки тому +1

    Learning from the best is always a pleasure 😎

  • @jonathanshitrit6344
    @jonathanshitrit6344 4 роки тому

    Thanks for the second video, looking forward to more of these!
    Video Request: How to make an effective product roadmap/requirements document

  • @FahmiEshaq
    @FahmiEshaq 4 роки тому

    Another VALUABLE content! Putting your advice into action right away... McFlurry part made me laugh; craving for one now. LIKE for part 3.

  • @Morpheus396
    @Morpheus396 3 роки тому +1

    8:20 Let's just take a moment to appreciate Clement typing at the speed of speech!

  • @mskyba
    @mskyba 4 роки тому +15

    Dang, now I want a McFlurry... did McDonald's sponsor you?

    • @clem
      @clem  4 роки тому +2

      I wish! That would be awesome.

  • @migueldomingos4570
    @migueldomingos4570 4 роки тому +1

    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

  • @keltoid6591
    @keltoid6591 4 роки тому +1

    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 :)

    • @mayank_upadhyay_19
      @mayank_upadhyay_19 4 роки тому +2

      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

    • @keltoid6591
      @keltoid6591 4 роки тому

      @@mayank_upadhyay_19 Thank you for the reply!

  • @ajax333221
    @ajax333221 4 роки тому

    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!.

  • @rinatriyanov8015
    @rinatriyanov8015 4 роки тому

    Thanks for the video, please do part 3 of these tips

  • @ganeshchowdhary3024
    @ganeshchowdhary3024 4 роки тому

    Superb tips. Waiting for part 3

  • @abdelsalammegahed4497
    @abdelsalammegahed4497 4 роки тому

    Thanks for making a very insightful video about this topic

  • @starmanicy465
    @starmanicy465 4 роки тому

    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.

    • @clem
      @clem  4 роки тому +1

      Fair point!

  • @NaveenKedilaya
    @NaveenKedilaya 4 роки тому +2

    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

  • @theteacher010
    @theteacher010 4 роки тому +3

    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.

  • @cervzzz3262
    @cervzzz3262 4 роки тому +1

    Do I want a part 3 to this series???? Not even a question 😎 ofc I do !

  • @zhewu1212
    @zhewu1212 3 роки тому

    Really nice tips, looking forward to watch part 3~good job~

  • @BladeScuffer
    @BladeScuffer 4 роки тому

    This video is a good example of how most programmers have serious OCD issues.

  • @BaRToLoMaSi
    @BaRToLoMaSi 4 роки тому

    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

  • @AlbertoRivas13
    @AlbertoRivas13 4 роки тому

    This series is really good man

  • @aryannsarkari1350
    @aryannsarkari1350 4 роки тому +1

    Recursion in terms of videos: i see what clement's doing

  • @EmphaticTrain
    @EmphaticTrain 4 роки тому +5

    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!!

    • @hackweiser4127
      @hackweiser4127 4 роки тому +3

      Didn't know they had a bullshit in physics course😅

    • @meikamandoliini
      @meikamandoliini 4 роки тому +1

      @@hackweiser4127 What does then Ms stand for?

    • @snail-bait3229
      @snail-bait3229 4 роки тому +1

      @@meikamandoliini moose shit

    • @clem
      @clem  4 роки тому

      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!

  • @Davegaeth
    @Davegaeth 4 роки тому

    Great content! Looking forward to other videos like this one.

  • @edwardgonzalez6331
    @edwardgonzalez6331 4 роки тому

    This is an awesome video! I'm really looking forward to part 3!

  • @bineetnaidu5146
    @bineetnaidu5146 4 роки тому +1

    Thanks Clement!!!, Please more on TS.....

  • @rdalago
    @rdalago 2 роки тому

    Excellent video!! Thank you

  • @divyamolm8393
    @divyamolm8393 4 роки тому

    yeah, good content and of course waiting for part 3

  • @maxnix9256
    @maxnix9256 4 роки тому

    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 :-)

  • @okletsdoitt
    @okletsdoitt 4 роки тому +1

    Code sent to Clément for review.
    Clément : I'm not trying to be nit-picky but........................ (to be continued)

  • @stabelgapler5396
    @stabelgapler5396 4 роки тому

    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?

  • @MrJamesb192
    @MrJamesb192 3 роки тому

    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).

  • @abdulkamara5841
    @abdulkamara5841 4 роки тому

    Pls make a video about breaking big problems down in code

  • @ashishmadhu7829
    @ashishmadhu7829 4 роки тому

    You're my inspiration Clement

  • @zachalbers6628
    @zachalbers6628 4 роки тому +1

    Stellar thumbnail

  • @carlosalarcon2737
    @carlosalarcon2737 3 роки тому

    Food and coding...Good mix. Next video you can show us another food haha

  • @davidprock904
    @davidprock904 4 роки тому

    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.

    • @migueldomingos4570
      @migueldomingos4570 4 роки тому

      Go into it ! It is very fun as you said and it is compensated well!

  • @guitar300k
    @guitar300k Рік тому

    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

  • @elmehdisaniss2731
    @elmehdisaniss2731 3 роки тому

    I think using continue word a lot may weakens the perceived logic (this depending on the scenario).

  • @TanUv90
    @TanUv90 4 роки тому

    Today's video is brought to you by McDonald's.
    (You're killing it with the subliminal advertising by the way)

    • @clem
      @clem  4 роки тому +1

      Haha that would be amazing. And thank you! 😎

  • @yyl6474
    @yyl6474 Рік тому

    Very helpful
    Thank you!

  • @josephwong2832
    @josephwong2832 4 роки тому

    Great video Clem

  • @MrNukenin16
    @MrNukenin16 4 роки тому

    WE WANT PART 3!!

  • @BrainOnRoids
    @BrainOnRoids 4 роки тому +7

    Thanks, for the video, like you a lot!!

    • @clem
      @clem  4 роки тому +1

      Thanks!

  • @anshulsingh1265
    @anshulsingh1265 4 роки тому +1

    Clement : "This is my cat"...
    That's all and suddenly we all open the comment section. 😂

  • @denisestevez5578
    @denisestevez5578 4 роки тому

    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.

  • @ambujmittal6824
    @ambujmittal6824 3 роки тому

    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!

  • @ADBraimah93
    @ADBraimah93 4 роки тому

    Damn...that code was cleaner than my room

  • @luchorera2985
    @luchorera2985 4 роки тому +1

    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

  • @GauravKumar-sr6bt
    @GauravKumar-sr6bt 4 роки тому

    What tools you use to record screen + your video and edit your videos?

  • @victorklimov5254
    @victorklimov5254 4 роки тому

    Thanks, that were very helpful tips!

  • @CodeRay
    @CodeRay 4 роки тому

    awesome stuff fam!

  • @bryanurizar
    @bryanurizar 4 роки тому

    Part 3 please!

  • @anubhavanand8457
    @anubhavanand8457 4 роки тому

    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?

  • @kobunnight
    @kobunnight 3 роки тому

    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

  • @sid5733
    @sid5733 4 роки тому

    consistency consistency consistency consistency consistency

  • @aishwaryarathod5421
    @aishwaryarathod5421 4 роки тому

    A video on c++ clean code please

  • @23inator
    @23inator 4 роки тому

    I call your first tip RASAP - return as soon as possible.

  • @B00Mnation
    @B00Mnation 4 роки тому

    Number 3 my lord!

  • @davidkezi6086
    @davidkezi6086 4 роки тому +1

    Isn’t the first point called, returning early.

  • @maedre9330
    @maedre9330 3 роки тому

    Lmao why the fuck am i getting algoexpert ad on ur videos

  • @jakebuster2042
    @jakebuster2042 3 роки тому

    Next: 3 More Tips To Write Clean Code (from a startup Founder/CEO)

  • @Cookie82772
    @Cookie82772 18 днів тому

    I just pressure wash my computer

  • @briankarcher8338
    @briankarcher8338 4 роки тому

    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.

    • @briankarcher8338
      @briankarcher8338 4 роки тому

      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.

  • @jeremyc1731
    @jeremyc1731 4 роки тому

    Very cool, thank you.

  • @cyberdash
    @cyberdash 4 роки тому

    Video title: More tips to writing clean code
    Video content: Mmm, so, so, so, so, soooo good!

  • @rafageist
    @rafageist Рік тому

    From tip #1: start let i = 1 and remove if ... continue

  • @sudharshanv9443
    @sudharshanv9443 4 роки тому

    Can you please tell me how to get prepared for network engineer intern at Facebook

  • @Cognitoman
    @Cognitoman 4 роки тому

    You have a good heart

  • @Ayasir-lo3ir
    @Ayasir-lo3ir 4 роки тому

    hi what programming language do you know thanks

  • @roshanmhatre8810
    @roshanmhatre8810 4 роки тому +1

    Why you didn't add Ex-google here?🤔

  • @fggamesoft4949
    @fggamesoft4949 4 роки тому

    great video