OK. Let me fix your IF STATEMENTS

Поделиться
HTML-код
  • Опубликовано: 6 сен 2024

Комментарии • 117

  • @blushing_wolf229
    @blushing_wolf229 2 года назад +76

    This technique has several names:
    - defensive programming
    - fail-fast strategy
    in any case it's so much clearer.
    instead of focusing on the nominal case which is usually trivial it focuses on the negative cases which document under which conditions this behavior can't happen.
    this has the below benefits:
    - it's easier to test
    - it's easier to log
    - it's self documenting
    - it's easier to read, therefore easier to review and maintain.
    this style is one key difference between professional vs unprofessional code

    • @DrIngo1980
      @DrIngo1980 2 года назад +4

      Yeah, this is a good explanation of the technique and its upsides.
      It literally has only one downside that I experienced first hand in my career: the professor who was teaching the C programming language course I had to attend at university apparently thought this was the Anti-Christ and "awarded" you negative points when you used it in any homework programs that you had to hand in.
      To her (yes, a woman, and no, I am not sexist here, I had a C++ prof that was male and equally inept) there was no doubt about the superiority of nested if-statements to guide the lucky/no-errors-path.
      I, at that point in time, already had 3 or 4 years of professional programming experience outside of university, so I challenged her during class on this (I was in my mid-20s at the time I think - yeah, prolly my most rebellious phase in life). She dismissed all my arguments. Saying "that's not part of the C89 standard!" - whatever the fuck that meant, but clearly, she didn't want to hear my arguments is what I felt at the time. So yeah, I didn't challenge her on that (what I now know is a) ridonkulous answer, since it took me completely by surprise.
      The moral of my story is thus this: wizards/sorceresses in their ivory towers don't care about readable and maintainable code.

  • @tamalesimonpeter8606
    @tamalesimonpeter8606 2 года назад +65

    I really like this new series where u are helping us write better code

  • @Ben-xf5ix
    @Ben-xf5ix 2 года назад +11

    If you do code refactoring, start from bottom to top.
    It avoids displacements of bookmarks and search results.

  • @user-qo9oy4re5e
    @user-qo9oy4re5e 2 года назад +1

    Very good advice! Any video that shows how to clean up code and make it more readable or efficient is vey much appreciated.

  • @stevend1070
    @stevend1070 2 года назад +6

    I would love to see some Golang on this channel! I started learning last year, but haven't done much with it since.

  • @alepereira806
    @alepereira806 2 года назад +1

    Shout out from Brazil ma man, thanks for all content pls keep the good job

  • @stefan-d.grigorescu
    @stefan-d.grigorescu 2 года назад +1

    Thanks for this video, it is indeed a very clean way of providing code, I will be using it from now on!

  • @sekhafrid3459
    @sekhafrid3459 2 года назад +2

    Optionals helped here a lot also the practice you showed here is a great addition to improve code readability.

  • @feolinaresm
    @feolinaresm 2 года назад

    I love your channel brother, every day I open youtube and I get one of your videos and I have no choice but to watch it.

  • @shivamsingh1221
    @shivamsingh1221 2 года назад +2

    Superb content!!! I am a very big fan of readable & clean code and I must say last couple of your videos are very helpful.
    Keep creating these code refactoring series.

  • @blissweb
    @blissweb 2 года назад

    This goes against everything I was taught back in the good ol' days. However, I can see it definitely has its advantages. Very well explained.

  • @mark22390
    @mark22390 2 года назад +1

    Please keep doing these code reviews. Love your channel man

  • @denilsonmucavel8150
    @denilsonmucavel8150 2 года назад

    Thank you Nelson one more time u brought us a better way to write our code, HUGS From South Africa Mozambique💯

  • @manitro337
    @manitro337 2 года назад

    Jazaka allahu khairan.
    Thank you brother.

  • @mountainofgeese
    @mountainofgeese 2 года назад

    I LOVE this series! I myself am looking for opportunities to improve and expand on technique and patterns especially now at the beginning of my career; I did not know this approach was even coined a name. Thank you so much for investing time in this content!

  • @bogdanbilcan8335
    @bogdanbilcan8335 2 года назад

    Hello. This one is way better than the video about for loops. This really improves the coding and has good reasons and a logic behind the changes. Big up, and keep up the good work.

  • @farooqmss
    @farooqmss 2 года назад

    @4:36 this is how I use if statements like a boss 😎
    Jazakallah kher

  • @eufraniodiogo50
    @eufraniodiogo50 2 года назад

    I'm really liking those kind of videos, like a serie in netflix but of coding, teaching good ways to make a better code

  • @michelchaghoury9629
    @michelchaghoury9629 2 года назад +5

    Please w need Golang Videos Like the Java/Spring Boot Ones, and Please some AWS (the always Free Services so we can practice more), and some Python Machine Learning with Tensorflow, pleasee and Thank you keep going

  • @omaradrian80
    @omaradrian80 2 года назад

    Great video!!! I love the style. I think I did not see other guy doing this!!! That’s why I bought one of your courses!!! So far happy with it

  • @cloey_b
    @cloey_b 2 года назад

    Wow, I'm learning a lot with your videos. Thank you so much!!!

  • @modoulaminceesay9211
    @modoulaminceesay9211 2 года назад

    This shows why is important to write clean code it’s hard but more efficient

  • @soufelk4943
    @soufelk4943 2 года назад

    Tank you and جزاك الله خيرا أخي

  • @alexanderrjakhov6301
    @alexanderrjakhov6301 2 года назад +1

    Well, it's perfect. Thank you for the small clean code

  • @markuspfeifer8473
    @markuspfeifer8473 2 года назад

    In Swift, the guard keyword even enforces that you leave the current scope. And you can unwrap optionals that way without introducing a new scope. E.g.
    for foo in bars {
    guard let baz = foo.optionalMember else {
    continue
    }
    // do something with baz which is no longer optional
    }

  • @astralsailor4824
    @astralsailor4824 2 года назад +2

    I really don’t understand why you don’t explain the reasoning that you think if-else is inferior to using guard clauses. It’s a different pattern and it’s a few less lines to write sure, but that alone does not make better..
    I really wish you’d explain what makes guard clauses better from a programming perspective, going more in-depth into the reasoning.

  • @wildjoe6259
    @wildjoe6259 2 года назад +2

    Thx !! More video about Golang please!!!

  • @Martin-bldm
    @Martin-bldm 2 года назад

    Early return is really useful for making your code cleaner, thanks for sharing

  • @lesquatrecentscoups
    @lesquatrecentscoups 2 года назад

    thanks Nelson for this one! is very useful

  • @dzakirozaan4601
    @dzakirozaan4601 2 года назад +2

    waalaikumsalam my moslem brother wuzzup

  • @mistymu8154
    @mistymu8154 Год назад

    This is also very common in a language like Swift which has a specific guard statement, checks the statement is true or the value is not null, else return and bail out early. I have moved over to Java Spring Boot recently and try to do the same thing in Java. The way more modern languages like Swift and Kotlin handle null values with optionals is just nicer in general.

  • @aliham4219
    @aliham4219 2 года назад

    I don't understand but it look smart. And i like it

  • @Sasikumar-kr7xy
    @Sasikumar-kr7xy 2 года назад +1

    Great video !!. Loved the reversal execution. Recommending to do how to get data from db, chain it to dto and then send to ui , viceversa

  • @matinparsapour9219
    @matinparsapour9219 2 года назад

    Thank you so much for this video I learned new methods, thanks 🌹🌹🌹🌹

  • @amralaaeldin
    @amralaaeldin Год назад

    Great tips, brother 👏👏

  • @paulboncar
    @paulboncar 2 года назад +1

    Basically, I think all "else" statements that returns an error or exit the current process can be replaced by somthing like : **if (!condition) return;**
    It's like an evidence for us, but when I look at a new programmer's code, I still wonder why tf it doesn't make sense in their mind :/
    Very good video :)
    EDIT : typo

  • @shivanshugautam1381
    @shivanshugautam1381 2 года назад +2

    Sir please make a video on Java OOPS concept

  • @TadeuRodrigues
    @TadeuRodrigues 2 года назад +1

    Great video Nelson, this series isbeing amazing to provide realistic examples of thinking about and architecting high quality code.
    Thank you.

  • @AkhileshKumar-cs2kh
    @AkhileshKumar-cs2kh 2 года назад

    Thanks
    Teach everyone better code so that we can get rid of bad code and go home from office earlier. Poor if statements are most common sources of bugs !!

  • @thereals7530
    @thereals7530 2 года назад +2

    Assalam alykum bro. I am Tajudeen Riliwan from Nigeria. I don't know anything about coding but will love to start. Do you have a course/training for complete beginners?

  • @yhogiandianggara8514
    @yhogiandianggara8514 2 года назад

    Thank you, waalaikumsalam.

  • @usmanmuhammad525
    @usmanmuhammad525 2 года назад

    Nelson please do u have a course on maven?

  • @kostiantynjohanlanguedoc3155
    @kostiantynjohanlanguedoc3155 2 года назад +1

    I like your classes 😉 very much! Thank you ❤️ for_Ever))

  • @TariqSajid
    @TariqSajid 2 года назад

    Can you make video on jdbc template with relationship advance

  • @edubrusch
    @edubrusch 2 года назад

    for java since 8 you can use optional and orElseThrows then you don't need the if statement.

  • @non_holy6286
    @non_holy6286 2 года назад +2

    Большое спасибо! Твои видео очень помогают!

  • @me-heer
    @me-heer 2 года назад

    Love your refactoring videos!
    Have a nice day.

  • @manoeltune
    @manoeltune 2 года назад

    Thanks good tip to use. I'll use it, thanks my friend

  • @gregs94
    @gregs94 2 года назад

    You reading in my mind 😜 On my last recrutation I have got task with 5x if in method and they gave me a question"What is wrong or not with this code?"

  • @nguyenhavu7542
    @nguyenhavu7542 2 года назад

    So good but where can I find this project, Is it public ? I hope you reply my comment

  • @nap4lm238
    @nap4lm238 2 года назад

    Do you have a video somewhere detailing more about 4:02? Thanks

  • @ringi1123
    @ringi1123 Год назад

    please make more code review & fix video XD

  • @javohiruralov1812
    @javohiruralov1812 2 года назад

    Thank you Amigos 😁👍👍

  • @AsimMughal9
    @AsimMughal9 2 года назад

    at least I learned how efficiently one can get rid of else block by negating if block

  • @bluex217
    @bluex217 2 года назад

    I know you said this wasn't the main contact but when you said we should be using joins on our query do you mean in terms of RDBMS/SQL? Like Inner/outter joins

  • @mikhailkulak3203
    @mikhailkulak3203 2 года назад

    If we have > 2 if statements ? Is it right to write them in service methods or its better to create some helper class to exclude condition logic from service with large methods

  • @arahnid_9844
    @arahnid_9844 2 года назад

    thanks, it's usefull

  • @lifeTechnicolorGuy
    @lifeTechnicolorGuy Год назад

    Nice video.

  • @coderider3022
    @coderider3022 2 года назад

    This is basic reshaper defaults , your best to buy a tool which offers you these change.

  • @aminetali7388
    @aminetali7388 2 года назад

    Good job Nelson

  • @dd1.d
    @dd1.d 2 года назад

    By default, I was doing this (bailing out) to prevent useless executions

  • @faketrump3605
    @faketrump3605 2 года назад

    what's your goal? removing else should not be the goal. the goal is about readability. following the logic flow of thoughts. if it reads better, use else.

  • @siakacamara7607
    @siakacamara7607 2 года назад

    Great teachings

  • @danielniels22
    @danielniels22 2 года назад

    do you teach OAuth with Java?

  • @Mac1355
    @Mac1355 2 года назад

    tks

  • @gabrielalvesgoncalves9959
    @gabrielalvesgoncalves9959 2 года назад

    Great video!

  • @maxfrischdev
    @maxfrischdev 2 года назад +1

    Da ist ein Bommel auf der Mütze! 😂

  • @amarjavid1
    @amarjavid1 2 года назад

    Just Amazing!

  • @Tidbit0123
    @Tidbit0123 2 года назад

    How do I join your discord? Tells me the invitation is invalid

  • @wiper123ful
    @wiper123ful 2 года назад

    Do a video on nested ifs

  • @Khantia
    @Khantia 2 года назад

    What do we get by this? Does it improve the code's performance or only its readability/length?

    • @konqi6957
      @konqi6957 2 года назад

      I don't think it gives better performance because the conditions are still evaluated.

    • @Khantia
      @Khantia 2 года назад

      @@konqi6957 from what I've heard from other sources, when there's an if/else statement, the computer prepares the code from one of the sides, and if it didn't guess correctly which side is gonna be called, it needs to flush the code and load the one from the other side.
      I can see how it COULD improve performance if there's never an 'else' statement, and it always loads the same code, but if the condition isn't met, it just flushes it...
      However, I can't be 100% sure if that is indeed the case.
      As for readability, my code doesn't always become more readable when I do it like this :P

  • @rajab1365
    @rajab1365 2 года назад

    Never give up 🥉

  • @universecode1101
    @universecode1101 2 года назад

    Thanks very useful ... as a JS developer, right now I'm learning Python 😜

  • @IslamAudioStation
    @IslamAudioStation 2 года назад

    nice hat my bro.

  • @ovskihouse5270
    @ovskihouse5270 2 года назад +1

    وعليكم السلام

  • @ahmedelzubair6907
    @ahmedelzubair6907 2 года назад

    Thanks brother 👌
    I wonder what it's your real name ?
    Your brother Ahmed from sudan 🇸🇩

  • @sumairsaeed1466
    @sumairsaeed1466 2 года назад

    Wa elikumassala

  • @futile2try
    @futile2try 2 года назад

    wa alaikum assalam

  • @arane16815
    @arane16815 2 года назад

    good

  • @Momosun2018
    @Momosun2018 2 года назад

    Cute hat hehe :)

  • @abdulrahamnali2839
    @abdulrahamnali2839 Год назад

    Walaikumusalam

  • @anticipayo
    @anticipayo 2 года назад

    An if else on the top level is cleaner not less clean

  • @humoyunmirzomurodullayev6750
    @humoyunmirzomurodullayev6750 2 года назад

    Good evening . In want you ask something. How long it takes me to learn java if i tried hard

    • @intensedev
      @intensedev 2 года назад +2

      Forever 🌝

    • @sreedarshshaji5951
      @sreedarshshaji5951 2 года назад +2

      That might depend on your present knowledge. If you are already coding in some other language, you already know so much and learning time would be significantly shorter for you.
      If you are new to programming, you might have to invest some time in the fundamentals. Treat programming like mathematics. Just don't look into the theory and learn things, write some code and see what works and what doesn't.
      Learning how to fix things is really important as you would be doing this for half of your time.
      Amigoes code already have a roadmap for java developers. That looks cool and I use that to upskill. I would recommend that you can start looking for a job as soon as you can write your own code.
      Also, you will be learning a lot of things daily. Good luck.

    • @humoyunmirzomurodullayev6750
      @humoyunmirzomurodullayev6750 2 года назад

      @@sreedarshshaji5951 Thank you so much for the complete answer. I did not expect such an answer. I have learned java core OOP, Telegram bots . And I am trying to learn spring boot. As I you said I know a little about java. But I think Nobody accept juinior developers like me. Thanks for your reply anyway 😃😃😃👍👍

    • @sk3ptik0s49
      @sk3ptik0s49 2 года назад

      Years.

    • @sreedarshshaji5951
      @sreedarshshaji5951 2 года назад

      @@humoyunmirzomurodullayev6750 I was accepted as a junior developer in j2me since they couldn't find an experienced developer willing to take up the role. I wasn't the brightest, but took some effort and made things happen with that role.
      So, brother keep learning things and never let the hope down. All the best

  • @lyline_bzh
    @lyline_bzh 2 года назад

    Good video 👍👍👍
    I see that you use exception classes everywhere.... I hate exception class...
    Question : development without exception VS development with exception
    Good or bad practices ?

    • @Supreme_Schorpioen
      @Supreme_Schorpioen 2 года назад

      I just started with java few monthes ago, what else can we use if we don't use exceptions?

    • @lyline_bzh
      @lyline_bzh 2 года назад +1

      @@Supreme_Schorpioen you must manage the errors without crash your application, but the methods extends to exceptions and must be required for all methods that use this exception. If you have an exception into repository method, you must extends exception into service...
      Or if you don't like this way, you use a try...catch Block, and that's very not pretty

  • @BloodyScythe666
    @BloodyScythe666 2 года назад

    ok but my IDE suggests these improvements automatically

  • @mrjfa100
    @mrjfa100 2 года назад

    Return early rather than nest deeply...

  • @h4wk742
    @h4wk742 2 года назад

    4:10 xD

  • @amisckass9550
    @amisckass9550 2 года назад

    Javascript, we need just ( true? 'true' :'falsy')

  • @voomastelka4346
    @voomastelka4346 2 года назад +2

    This if-else thing seems to be some new fad. Generally, juggling with if-statements won't make much difference to the readability or really to anything at all. Any developer with at least two brain cells can follow the if-else statements just as easily as they can follow the function exit points. It's mostly a matter of taste and personal style. There are a lot more important things in your code base you could improve instead, better tests for instance.

  • @s.m.a1304
    @s.m.a1304 2 года назад

    the discord server is so big that discord always crashes

  • @Brook.99
    @Brook.99 2 года назад

    3rd

  • @ahmadalghali90
    @ahmadalghali90 2 года назад +1

    first

  • @haroldpepete
    @haroldpepete 2 года назад

    now result that else statement is going out due to all youtubers, else statement is the worst in the galaxy, it must die, lol

  • @georgekovalyov5767
    @georgekovalyov5767 2 года назад

    I think this is an antipattern

  • @user-pk5zk3ko6g
    @user-pk5zk3ko6g 2 года назад

    I don't know about Java and Go, but it's bad practice in Python. “Explicit is better than implicit” - The Zen of Python.

  • @Motive8Maven
    @Motive8Maven 2 года назад

    First

  • @moathdw910
    @moathdw910 2 года назад

    What's the point of the religious behavior and greetings! It's the only reason that keeps me away from this channel you act like an Imam lol.
    Don't understand why it's hard for some people to act professional and keep their beliefs to themselves

  • @dennisgithinjiwakahia3916
    @dennisgithinjiwakahia3916 2 года назад

    good work nelson.i have looked for you in your fb messenger and discord account but no response