Write BETTER Code! 7 Tips to Improve Your Programming Skills

Поділитися
Вставка
  • Опубліковано 3 лип 2024
  • I've compiled seven programming tips for anyone who is new to coding that will help make your code more readable and easier to work with. These tips are based on some clean code principles but I've tried to distill them into a simple concept for beginners.
    P.S. Apologies for my face being blurry. The focus was not set correctly. Hopefully it's not too distracting! :-P
    ** DOWNLOAD THE FREE REPORT **
    For my free report on the five best programming languages in 2019 (for beginners) go to: andysterkowitz.com/report
  • Наука та технологія

КОМЕНТАРІ • 357

  • @jean-pierregygax3415
    @jean-pierregygax3415 4 роки тому +203

    30+ years of coding - and I still needed to hear this...

  • @InfallibleCode
    @InfallibleCode 5 років тому +322

    Great video! Your tips encapsulate my all-time favorite quote:
    "Any fool can write code that a computer can understand. Good programmers write code that humans can understand." - Martin Fowler

  • @2FLUo115o1oECG
    @2FLUo115o1oECG 5 років тому +301

    Good tips man! Definitely a good watch!
    1. Avoid abbreviating variables (pw => password)
    2. Limit function arguments (aim for 3)
    3. Simplify conditional expressions
    4. Declare variables close to their usage
    5. Avoid unintended consequences in functions
    6. Functions should do one thing (avoid long functions)
    7. Stop writing zombie code

    • @mzsmunna6002
      @mzsmunna6002 5 років тому +5

      there should be another one at no 8. Don't repeat yourself!

    • @tapslos
      @tapslos 5 років тому

      +1 for you but it would be even better with timestamp links

    • @HealthInspectorz
      @HealthInspectorz 5 років тому +2

      Write good comments! Practice commenting while coding your program. It really helps explaining your code to someone else when you comment

    • @thorham1346
      @thorham1346 5 років тому +1

      No, don't leave commented code in a release version of the source code. There's nothing wrong with commenting out code for testing purposes.

    • @thorham1346
      @thorham1346 5 років тому +2

      @@HealthInspectorz Yes, but don't over do it or you'll find that maintaining the comments can become a second job.

  • @JHVOGamers
    @JHVOGamers 5 років тому +58

    if (true == true) {
    return true;
    }
    I never saw so good code like this in my life.

    • @brandishwar
      @brandishwar 5 років тому +13

      I've seen this more times than I care to admit:
      if(someCondition)
      return true;
      else
      return false;

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

      Return true==true; stop making these ugly if else statements!

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

      I use python.
      I am a beginner
      I write very short codes that make the same result as very long ones
      Like my teacher
      She made a 50 line code that I made in 28
      My teacher liked mine a lot

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

      Bem inesperado encontrar um jogador de RotMG num vídeo de programação. KKKKKKKK

  • @Omniwoof
    @Omniwoof 5 років тому +175

    Yes.. For newbies only..
    *quickly deletes zombie code*
    Definitely good tips!

  • @shehabmostafamohamed9760
    @shehabmostafamohamed9760 5 років тому +87

    I have been coding in C++ for 5 years and I gotta say your video is great and really covers all the essential tips. I didn't know about the last two tips! Very resourceful.

    • @kostas71374
      @kostas71374 5 років тому

      Hello what kind of project have you worked on?

  • @joshuastevenson5140
    @joshuastevenson5140 5 років тому +15

    Holy crap. These were *really* useful tips. I've been coding since high school, but I still find myself making the "mistakes" of tips 1 and 6. This one will have to be shared.

  • @zezeandjr4110
    @zezeandjr4110 5 років тому +6

    Yes Andy, yes, I always enjoy your videos, advice and your honest take on programming techniques.

  • @brandonlind5700
    @brandonlind5700 5 років тому +6

    Hey man I’ve been subscribe for a few months now but just started watching you videos. I wish I started watching a year ago, you videos are very clear and to the point and offer a lot of info of very important info that is commonly over looked!! Thanks!! Your videos are a huge help!

  • @DB4331
    @DB4331 5 років тому +3

    "Signal to noise ratio"...good audio analogy. A great way of explaining a code file being too "busy"/distracting looking. Never heard it explained like that before, I like it.

  • @nikolajacques5982
    @nikolajacques5982 5 років тому +10

    YES. Simple tips with immediate pay-off, bite-size and highly nourishing. Thanks for the quick feast!

  • @zachjones2374
    @zachjones2374 5 років тому +1

    Loving the videos, Andy! Keep up the great work, and keep being an inspiration!

  • @stephennardone5437
    @stephennardone5437 5 років тому +2

    One of the absolute most valuable videos! Thank you so very much and keep up the good work Andy!!

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

    This was such an incredible thought out video.
    Amazing content Andy!

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

    This is by far one of your best videos since it had clear, tangible examples with code visualizations added to get your point across. Please make more content like this since your newer stuff is a bit loaded with fluff.

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

    Im being programing for many many years and still found it usefull, thanks so much

  • @whaaaaaaaaaaaaaaaaaaaaaaaaaat
    @whaaaaaaaaaaaaaaaaaaaaaaaaaat 5 років тому +1

    Nice video, man! UA-cam recommendations can be a blessing, after all. Earned a new sub for the quality! 😁

  • @JousefM
    @JousefM 5 років тому +1

    Besides the nice tips your room is fucking dope! Especially the bright laptop and you with the dawn (!?) in the background is sooo amazing!

  • @richardoliver9073
    @richardoliver9073 5 років тому +1

    I really appreciate your coding tips. Thanks for getting us on the right path. Finding great info on your site. Thanks and keep up the great work.

  • @abhashization
    @abhashization 5 років тому +3

    You earned yourself a new subscriber! Keep uploading such videos! :D

  • @tinashedzawara41
    @tinashedzawara41 5 років тому

    Thanks Andy I matured from videos and I want say thanks again from the tutorial purgatory video you did I started to get some change and am now improving fast

  • @krisitak
    @krisitak 5 років тому +1

    I can confirm that these tips are LEGIT! Good video.

  • @code8180
    @code8180 5 років тому

    Amazing tips! Thank you Andy! :)

  • @jackwright7014
    @jackwright7014 5 років тому

    Fantastic video! There are definitely some new points I have learned. Thank you!

  • @cylink1
    @cylink1 5 років тому +1

    Excellent advice! Thanks so much

  • @anuadebayo7267
    @anuadebayo7267 5 років тому +1

    Thank you sir for this video, I have been waiting a long time for this

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

    Well written. well explained, nicely edited, and dude! that background! Nice.

  • @shawnhutchins8662
    @shawnhutchins8662 5 років тому

    Love the tips, and examples!

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

    Thank you very much; this was a very informative video to watch. The necessity of clear, concise code and the rest of the points made were really good to know, as a beginner coder. Thanks again.

  • @ferfykins
    @ferfykins 5 років тому

    Great tips, thanks andy!

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

    Thank you that was very helpful, especially the part with long functions. I sometimes have tendencies to overcomplicate things.

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

    Never gets old, these tips are immortal :) Thanks.

  • @colinmaharaj
    @colinmaharaj 5 років тому

    Yes, I am (was) trying to make heads / tails from my thousand line function. I wanted to add a new feature but no clue where to do this.
    Now I am talking apart the pieces and places in sub functions to see the logic a bit clearer.

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

    Nice and very informative tips. Please give us more. Thank you for sharing!

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

    you are like the "Helpful Coding Andy". Really helped!

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

    I enjoy so much your videos!

  • @jorgeartaza9030
    @jorgeartaza9030 5 років тому

    you are awesome! you have really inspired me too work hard on coding and become a software developer. you also have inspired me to work hard in different aspect of my life thank you so much keep it up.

  • @sunlighthurtsmyeyes9269
    @sunlighthurtsmyeyes9269 5 років тому

    I love your videos, keep it up man!

  • @MrStealthWarrior
    @MrStealthWarrior 5 років тому

    Great video, few of these tips are new to me and realy helpful.

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

    Quite Helpful! Thanks

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

    I've been programming since the 1970's. You nailed it. Well done! I particularly enjoyed your observations on zombie code and practice, practice, practice. I would add, and have added to numerous coding style documents, some of these:
    0) NEVER, EVER, EVER use the TAB key! I worked at one company where a guy set his tab stop to 2 spaces - so what looked good to him went far to the east for everybody else.
    1) learn and use the coding style of the corporation for whom you work,
    2) use a consistent coding style,
    3) use consistent code formatting - e.g. always indent 2,3, or 4 spaces,
    4) make your code as easy to read as possible (e.g. for a long list of assignments, line up all the equal signs,
    person[firstName] = "Bob"
    person[middleName] = "Andrew"
    person[lastName] = "Smith"
    person[phoneNumber] = "1-555-123-4567"
    person[Street_Number] = "9827"
    person{Street_Name] = "West First St."
    person[City] = "Toledo"
    person[state] = "OH"
    person[zip] = 49208
    )
    5) Make your code readable and maintainable. Don't be afraid to do the right thing:
    if ( x == 1 )
    {
    func1( args1...)
    }
    else if ( x ==2 )
    {
    func2( args2 )
    }
    else if ( x == 3 )
    {
    func3( args3 )
    }
    becomes
    if ( x == 1 ) { func1( args1 ) }
    else if ( x == 2 ) { func2( args2 ) }
    else if ( x == 3 ) { func3( args3 ) }
    which is infinitely easier and faster to read, understand, and maintain.
    5) Don't make files with hundreds of code lines
    make code files that contain associated functionality: employee_details.code, company_product.code, taxes_federal.code, taxes_state_WI.code, taxes_state_IL.code, taxes_local.code, taxes_SS.code, taxes_medicare.code
    6) Read books, papers, and online articles on good programming style.
    7) Read the code of senior staff.
    8) Force yourself to look at the code you wrote 6/12/18 months ago and try to figure out what it does. This is a great way to learn how to write better code.

  • @MuhammadAhmed-wh5kv
    @MuhammadAhmed-wh5kv 5 років тому +1

    That was so helpful, many thanks :)

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

    Thank you. Very useful tips.

  • @Khalyomede
    @Khalyomede 5 років тому

    Thank you for those tips, great advices, always good to get a reminder of what we should not do to keep a clean code base!

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

    Great video, simple tips but with deep value

  • @SudhanshuSrivastavaIndia
    @SudhanshuSrivastavaIndia 5 років тому

    Fantastic tips.

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

    beginner coder here and this video was fantastic, I was committing all these offences barring like 1 (I don't abbreviate my variables) thanks for improving my practice!

  • @md.farzan5596
    @md.farzan5596 Рік тому

    Great tips. I am a junior web developer and looking for tips to improve my coding, while searching I suddenly found your video. Your tips are really helpfull. 🌟👍

  • @zielbird
    @zielbird 5 років тому

    This is SUCH a good set of tips. If everyone followed these... Man. That would be amazing.

  • @guitarman813
    @guitarman813 5 років тому

    Very useful advice and info in this video. While I'm not a complete beginner in programming, I'm currently trying to find better ways for writing cleaner code for my latest Java project. I'm glad to say based on the above that I don't make a lot of these mistakes mentioned. But regarding the last three tips mentioned, I'm prone to making errors on those. From now on therefore I will aim to amend these errors and get into better programming habits overall.

  • @allaheadflank
    @allaheadflank 5 років тому +1

    Great tips!

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

    Awesome video! I also recommend to use the SOLID principles!

  • @VTdarkangel
    @VTdarkangel 5 років тому +6

    I find your tip #4 to be interesting. It directly contradicts what I was taught in school. My professors wanted all of our variables declared at the top of their relevant functions, although they also demanded descriptive names and comments for each.

    • @BertoldSzekeres
      @BertoldSzekeres 5 років тому

      Sometimes it's considered as a good practice, e.g. when declaring properties in classes. Otherwise when declaring constants, or just simple variables that will be used right from the beginning of the process.

    • @klausedwin
      @klausedwin 5 років тому

      Some language demands it. In a class I would always declare my variables in the top of file. But I a function I would declare it as close to there it used.

    • @kiddhkane
      @kiddhkane 5 років тому +1

      That might come from "older times". For example in C (not C++, but pure C) you actually had to declare all the variables before you could do anything. If they got used to it, it feels natural for them now.

    • @VTdarkangel
      @VTdarkangel 5 років тому

      @@kiddhkane That makes sense. The language that was used at my college was C/C++. This was probably because the CS department was part of the Electrical and Computer Engineering college at the time. We had a lot of engineers (including me) who were learning to program for the purpose of using it in embedded computer control systems. It was likely that my professors were old C programmers.

    • @FlavourlessLife
      @FlavourlessLife 5 років тому

      I was told to teach students this by a really old professor. He was a fortran/C guy. He also told me not to declare variables within the body of a loop because it uses more resources, which is just plain wrong. Maybe compilers back in his day were poorly optimised.

  • @loouislow
    @loouislow 5 років тому +2

    a very great video, explaning like a pro

  • @nakrull1194
    @nakrull1194 5 років тому

    ty man, very good and useful tips!

  • @slogger1233
    @slogger1233 5 років тому

    Im studying IT for 3 years now. Some of theese tips were mentioned. But man this really helps out a lot. I’m gonna write them down until i internalized them!

  • @SteelVoltagerpg
    @SteelVoltagerpg 5 років тому

    Super useful tips!

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

    though these things seem common sensiscle..... they are so rare in code bases. great video!

  • @deangreenhough3479
    @deangreenhough3479 5 років тому +1

    Great tips thank you 🏴󠁧󠁢󠁥󠁮󠁧󠁿👍

  • @anjalikukda3653
    @anjalikukda3653 5 років тому

    Great video with great experience of coding 👌👌👌

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

    Thanks for your teachings! :-)

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

    I am definitely guilty of too many function arguments, great video

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

    Hey Andy, you do great videos, I enjoy the consistency and flow of the videos. One piece of feedback I would suggest is to place timestamps as you are talking about certain topics. If you could write a brief, too it would be excellent.

  • @rondagatts8960
    @rondagatts8960 5 років тому +1

    Good tips!

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

    Great! Thanks a lot.

  • @hassanelakhloufi8073
    @hassanelakhloufi8073 5 років тому

    You have an amazing view. I wish I had a similar office

  • @williamcoleman2128
    @williamcoleman2128 5 років тому

    Great, great points here.

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

    Good work bro..

  • @dhineshbabu9376
    @dhineshbabu9376 5 років тому

    Really helpful. Thanks bro..

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

    Tremendously useful

  • @aerialdarkguy
    @aerialdarkguy 5 років тому

    These are good tips to keep in mind! You should check out the book code complete if you want more examples of better code practices.

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

    I'm about to master coding within a few months the for the tips keep up the good work

  • @joshuaevans4301
    @joshuaevans4301 5 років тому +104

    My biggest piece of advice is to embrace comments (not zombie code). The first thing I always do before beginning any difficult program is write a paragraph / list at the top describing exactly what I plan to do. Then I can go back to this original plan whenever I get lost
    This is also super useful when I come back later and have completely forgotten what I was doing
    I also use in-line comments to describe what I am doing whenever I am doing something that might be even a little confusing, especially to somebody with less programming experience. A good example is regex - it's super confusing if you don't understand it, so I always pop a comment in describing exactly what the regex does

    • @pagameba
      @pagameba 5 років тому

      I also do this, its very helpful to frame your thoughts and break down a complicated piece of code into a set of steps you are intending to follow. Can also be helpful in decomposing your code into functions! highly recommend this practice.

    • @mattymattffs
      @mattymattffs 5 років тому +2

      Imo, better to use a issue tracker for your todo list

    • @davidshor2719
      @davidshor2719 5 років тому +10

      The problem with comments is that it is practically duplicated code. If you need to change the code later, you need to change the comments later.
      You can write a document describing what you are planning to do,but your code should be written in a way you don't need comments in the code to understand it.

    • @tomixtomi12
      @tomixtomi12 5 років тому +2

      What about descriptive function names and small functions? Say you have a regex that looks for pattern A. You could create a function that is called getPatternARegex() that returns the regex. No comments, and perfectly clear what the function does. I find that you can use small functions instead of comments in many scenarios.

    • @joshuaevans4301
      @joshuaevans4301 5 років тому

      @@tomixtomi12 Depends on the complexity of what I'm doing. It takes a lot longer to create a brand new function (especially when using jsdoc) then to just throw in the regex and move on. It's also the case that regex _should_ be known by most programmers because of it's extreme usefulness and commonality
      In some cases, especially for _particularly_ complicated regex, a standalone function makes a lot of sense

  • @MrLycanized
    @MrLycanized 5 років тому

    Hej. Very nice video. And good advice(s) :) I would like to point out the need for guard(s) in code, as well as rudimentary error handling.. :)

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

    I'm familiar with CleanCode and I've been a software engineer at Microsoft for 3 years and at first I was like "meeh why is this beginners video on my recommendations?" Haha DUDE! All these tips were super useful and well explained. I learnt a lot from you. Thank you
    I wish more "advanced" programmers could see this video. Subscribed

  • @diastrus1236
    @diastrus1236 5 років тому

    Great vid!

  • @NickHamilton88
    @NickHamilton88 5 років тому

    Good stuff, can relate.

  • @CodeMonkeyG2011
    @CodeMonkeyG2011 5 років тому

    Preach it brother!

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

    Thanks, again.

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

    very useful!

  • @badkittyradio2082
    @badkittyradio2082 5 років тому +1

    I'm literally just starting out and I could understand most of this. Your videos are very informative. Please keep creating content!!

  • @maskman4821
    @maskman4821 5 років тому

    fantastic video, I have learned somethings...

  • @simonolofsson7488
    @simonolofsson7488 5 років тому

    As a bit more seasoned junior, I attest to all the tips in this video. You will benefit a lot from keeping your functions short with minimal arguments, abstract the task at hand which makes it easier to develop tests and creates software easier to debug.
    If I were to add one thing it would be to encourage early on test development. While you’re writing a function, in parallel or even before: try to write code that tests your new function that expects a certain output. When you get this down, you’ll integrate with the test framework in your language of choice much easier, your tech lead will thank you for having a Test-driven development approach.

  • @Grempington
    @Grempington 5 років тому +1

    You forgot to mention that another reason why people use dead code is for debugging or testing purposes. Some people leave dummy implementations of certain things in order to check them much faster when debugging a different issue.
    The solution to that, to avoid this dead code, is to use testing classes with implementations of the classes you need to inject (dependency injection), and thus leave testing-specific code only within the scope of your testing root folder.
    Edit: Sorry - I usually see the negative as I take the positive for granted - but the tips given were great and it's really important for beginners to get rid of these bad habits as soon as possible, so good video!

  • @sergioangel8362
    @sergioangel8362 5 років тому +1

    Thank you sir

  • @divinedela9125
    @divinedela9125 5 років тому +1

    i luv the tip on zombie code!

  • @jakubpoliszuk953
    @jakubpoliszuk953 5 років тому +4

    Very good video, but I have one notice for you ;)
    2nd tip, 3:18 - variable should be named "userData", and it should be structure with data (or simple class if structures are not available)

  • @feedbacker
    @feedbacker 5 років тому +1

    best vid ive seen of yours

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

    Good tips.

  • @supersonicstep
    @supersonicstep 5 років тому +17

    Thanks boss, im on my road to self taught

  • @roros2512
    @roros2512 5 років тому

    those are excelent advices for us beginners
    I think it would be useful if you let the window with the advice on screen or maybe show it again at the end of every advice, maybe for a second version on more advices?
    thanks again

  • @CryptoFeez
    @CryptoFeez 5 років тому

    I just started a new python course !!! I just did my hello world lab can’t wait for second lab!!!

  • @davidhuman4992
    @davidhuman4992 5 років тому

    More like this please

  • @dadlord689
    @dadlord689 5 років тому

    As far as I see it from my perspective - everything that helps you with managing code even a little - is very handy and worth of effort. Because coding is so quickly brings you the stage, where project is gientic. Your level of attantion just WILL reach it limit and it is very painfull (like to wait for loading almost for evey action). And the worst case is visual scripting.

  • @franchello1105
    @franchello1105 5 років тому

    great tips. I have been a developer going almost 12 years and number 1 and number 7 are my 2 big pet peeves. another big thing I hate is database tables that are related that dont share the same column name. in one table its user id and the other table its username, but for a given user it stores the same value (johnsmith).

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

    Having a standard and logical convention for naming your variables is helpful not only for other people who might be reading your code, but also helpful for yourself. Like if you're trying to remember specifically what was the name of that variable. If you don't want to have to go look (wasting precious seconds) you can just think, "well, what WOULD I have named it?"

  • @sebastianb7547
    @sebastianb7547 5 років тому

    Very good video. One remark: In example #3 (return conditionals) the improved code contains a typo. It should be "person.age >= 21" (not personAge >= 21), just like in the longer code.

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

    good practical tips

  • @TheDevMethod
    @TheDevMethod 5 років тому

    Great tips! I love the part about Zombie Code. I didn’t know it had a name but I’ll start calling it that!

    • @GoobNoob
      @GoobNoob 5 років тому

      It's actually called spaghetti code. But this guy isn't s computer scientist

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

    I learned that sometimes rewriting code is a good idea and fewer lines is better.