The 2 Laws of Writing Well Organized Code

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

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

  • @creamyhorror
    @creamyhorror 2 месяца назад +37

    Good work on the presentation. It's an essential lesson for junior devs, though I'd expect seniors to already know this. Code in a function should be at the same approximate level of abstraction, and function names should reflect exactly what they're doing, such that you can read a function and instantly grasp the overall logical flow.

    • @kantancoding
      @kantancoding  2 месяца назад +1

      Thank you! All very good points 💯

    • @sanglin9387
      @sanglin9387 2 месяца назад

      the basic inline - easier to maintain , the more abstraction / interface making the code hard to manage . Once we work company like that , every month programmer run away because too way many abstraction / interface . Keep is simple s *** . A junior will think good but not .

  • @MaxPicAxe
    @MaxPicAxe 2 месяца назад +28

    One suggestion I would have is to increase your font size a bit in certain parts of the video, good work though

    • @kantancoding
      @kantancoding  2 месяца назад +2

      It’s a good suggestion and you’re right. Sometimes I had to zoom out to show what the entire function looked like but it probably would have been better to just use a smaller function. Thanks for the tip!

  • @hagalaz793
    @hagalaz793 2 месяца назад

    Most importantly those segments are testable! Unit testing is a must to writing well organized code

    • @kantancoding
      @kantancoding  2 месяца назад

      Yes! We are 100 percent on the same page :)

  • @TannerBarcelos
    @TannerBarcelos 2 месяца назад +8

    Make functions that do a single thing (single responsibility) and give them a name that self-explains what the function does. As an extra effort of good developer experience, write doc strings above the function signature so your editor can show the explanation of the function when hovering over it.

    • @kantancoding
      @kantancoding  2 месяца назад +2

      Good point about doc strings above the function sig!

  • @dihshop3621
    @dihshop3621 2 месяца назад

    amazing video. btw what video editor do you use?

  • @hamentkumar9834
    @hamentkumar9834 Месяц назад +1

    Which vscode yheme did u use in this video

    • @kantancoding
      @kantancoding  Месяц назад +1

      I think gruvbox. The king of themes

  • @bugsbunny3354
    @bugsbunny3354 2 месяца назад +2

    amazing video. btw what's the font name?

  • @TheErickds
    @TheErickds 2 месяца назад

    hey! what vscode theme are you using? nice video btw!

    • @kantancoding
      @kantancoding  2 месяца назад +1

      Hey! Thanks for watching. The theme is Gruvbox most likely :)

  • @modolief
    @modolief Месяц назад

    Excellent pedagogy!

    • @kantancoding
      @kantancoding  Месяц назад

      Thank you! I’m happy you think so 😊

  • @TealTheCuteness
    @TealTheCuteness 22 дня назад

    You sometimes use inline and sometimes you extract methods, it depends on the application

  • @kishorsharmashutihar9176
    @kishorsharmashutihar9176 2 месяца назад +20

    I don't know dude, I think you ended up with same level of deep function calls or am I missing something

    • @cryptonative
      @cryptonative 2 месяца назад

      It’s different whem functions are on the same file

    • @kantancoding
      @kantancoding  2 месяца назад +4

      @squishy-tomato yes, you are correct. I tried my best to show your point about what the video should have focused on. But you’re right, I should have tried to emphasis that point more.

    • @kantancoding
      @kantancoding  2 месяца назад

      @cryptonative how so?

    • @cryptonative
      @cryptonative 2 месяца назад +1

      @@kantancoding Indirection is a problem when you have to context switch. This is bad when you have to go through several files. When functions are on the same file the problem mostly goes away.

    • @kantancoding
      @kantancoding  2 месяца назад

      I see! In the example the functions are not in the same file. Here is the code: github.com/docker/compose/blob/main/cmd/compose/compose.go#L683

  • @adambickford8720
    @adambickford8720 2 месяца назад +4

    Inlining is great, just not with screeds of imperative code. The problem is people try to abstract things down to 1 line, putting us back in the first scenario of too much useless abstraction.

    • @kantancoding
      @kantancoding  2 месяца назад

      I’m curious, why do you say that the abstraction in the first example is useless?

  • @adityaghadge2067
    @adityaghadge2067 2 месяца назад +2

    Thanks for this helpful content.

    • @kantancoding
      @kantancoding  2 месяца назад

      Thank you for watching brother!

  • @khashe
    @khashe 2 месяца назад +1

    Love these videos.

  • @aghileslounis
    @aghileslounis 2 месяца назад +15

    It actually depends A LOT on what you're doing. Sometimes it's just better to inline, even if it's complex.
    It's called software engineering. You need to engineer a solution BASED on your context, not on some well-defined general rules.

    • @kantancoding
      @kantancoding  2 месяца назад +5

      I see your point and it’s a good one but I think that people get the idea and as engineers will be able to determine the extreme cases on their own.

    • @aghileslounis
      @aghileslounis 2 месяца назад

      @@kantancoding I don’t know about that. I see a lot of engineers get their brain lobotomised by some clean code and TDD books 😄 and can only think that way.

    • @Grahamaan27
      @Grahamaan27 2 месяца назад +1

      I agree and who says there are two laws to programming?

    • @og-ncho
      @og-ncho 2 месяца назад +1

      I'm curious of what cases you are thinking about, because what is exposed here is quite general. I wouldn't say it depends A LOT. As for me, I would consider inlining in scripts code but in application code, most of the time, I go for abstracting complexity as shown in the video

    • @aghileslounis
      @aghileslounis 2 месяца назад +1

      @@og-ncho yeah true, without an example it’s difficult to visualise. What I meant is like not abstracting too much and everything, especially if it’s not much reused. It will just make things way harder to understand and maintain, because things will become more coupled.
      I was thinking about the fanatics that says SOLID, hexagonal architecture and CLEAN CODE are the absolute way to go. While none of the FAANG compagnies uses that bullshiet (confirmed publicly on Reddit and others forums by directors of engineering at Google, Apple…). They think they write the best code with 10000 deep abstractions.

  • @Endou47
    @Endou47 2 месяца назад +1

    Love your content, bro. Keep it up!

  • @iamme670
    @iamme670 Месяц назад

    What color theme is this?

  • @cosname
    @cosname 2 месяца назад

    Nice video! I love it, very deliberaate

    • @kantancoding
      @kantancoding  2 месяца назад

      Thank you! And thanks for watching :)

  • @jayachandrank2875
    @jayachandrank2875 2 месяца назад

    What software do u used to make presentation ??

  • @samuelopeyemi8377
    @samuelopeyemi8377 2 месяца назад

    Please can you create a full backend course with lots of feature or just have a skool platform with quality courses?

    • @kantancoding
      @kantancoding  2 месяца назад

      Hmm I already have a few free backend courses on my channel. Just look for the really long videos (like 4 hours)

  • @arkantos14821
    @arkantos14821 2 месяца назад

    I think you emphasis on "high cohesion, low coupling" but not on code modules but on code segments. Am I right?

    • @kantancoding
      @kantancoding  2 месяца назад +1

      @arkantos14821 hey! You’re still here 😊 thanks for watching. And yes, you are correct.

  • @jonathanjeshualaniba5958
    @jonathanjeshualaniba5958 2 месяца назад +1

    what is this font?

  • @name128ewa
    @name128ewa Месяц назад

    I like your accent. Which part of India are you from?

    • @kantancoding
      @kantancoding  Месяц назад +1

      The part called California, USA 😂

    • @name128ewa
      @name128ewa Месяц назад

      @@kantancoding Great. But where are your parents from?

    • @kantancoding
      @kantancoding  Месяц назад +1

      They’re also American. My accent is from California.

  • @sirsaikoplays
    @sirsaikoplays 2 месяца назад

    OMG! This is some pulp fiction level of story telling. Entire video I was getting mad at whatever you were saying, aren't we going back or something to the problem we're solving.
    But I all went away with the last scene.
    Moral of the story: Just read through the fucking chain and if you hate it try to do that linearly but you'll always fall into this trap of going back.

  • @JunHamamura
    @JunHamamura 2 месяца назад

    excellent video!

    • @kantancoding
      @kantancoding  2 месяца назад

      Glad you liked it! Thanks for watching :)

  • @JoernBernhardt
    @JoernBernhardt 2 месяца назад +2

    That's a long, but useful explanation why you need to give your functions good names.
    If I'm using more generic functions that I can't rename, I like to define variables that explain what is being done. Sometimes, I even split things up, even if I could chain them, if it's not causing big performance losses. This makes my code look more like "const, const, const, ..., return". You should only have to understand the left side then and can put debug statements in there easily. Here's an example in JS:
    function getAllMembersEligibleForBadge(badgeName) {
    const allPeople = getAllPeopleFromDatabase();
    const allMembers = allPeople.filter(isMember);
    const badge = getBadgeByName(badgeName);
    const eligibleMembers = allMembers.filter(p => isEligibleForBadge(badge, p));
    return eligibileMembers;
    }

    • @kantancoding
      @kantancoding  2 месяца назад

      Good observation! I like your example. Also, my hat goes off to anybody who can explain why it’s important to give functions good names in under 4 minutes 😂😅

    • @goobus_floobus
      @goobus_floobus 2 месяца назад

      My lead dev might murder me if I write four one-time-use variables when I could inline. But his code is a mess of terrible names and nested function calls. So I settle for a good comment explaining what my one-liner does. I may have less job security, but hopefully my coworkers won't hate me when they have to fix my bugs 😂

  • @awesomedavid2012
    @awesomedavid2012 2 месяца назад

    Good video!

  • @gustionusamba90
    @gustionusamba90 2 месяца назад

    what font do you use?

  • @jurajhprobyt2107
    @jurajhprobyt2107 2 месяца назад

    If you will write too much code you will not get much more money because of it.😊

  • @mvargasmoran
    @mvargasmoran 2 месяца назад +1

    Man I honestly think that indirection is way worse than inline code.
    Is well known that the average person can remember about 7 items in a list on the fly (RAM), so I can spend my 7 slots jumping around or just use about 2, jus reading the function, that say, if the function is about a "screen" long. That's what I have come to.
    And please no arbitrary function extraction, a good excuse to create a function is that the code inside will used in at least 2 separate places.

    • @coolcodingcat
      @coolcodingcat 2 месяца назад

      You dont need to approach it like this. Each function small should stay at the same level of abstraction and be well named verbs for action functions or a noun for a query fuction or a is/has/should prefixed function name for a function that returns a boolean. Then you can quickly grep the code at a high level and treat the inners as a black box to be inspected piecewise when needed.

    • @mvargasmoran
      @mvargasmoran 2 месяца назад +1

      @@coolcodingcat Everybody does that kind of stuff, tell me something I don't know. Just stop preaching for people to cut the code into small pieces, I've even seen a function to abstract a , it's nonsense, but they claim "clean code"

    • @ProtectedClassTest
      @ProtectedClassTest 2 месяца назад

      Funny thing is inline code is the same mess as indirection.. it takes a good developer to balance both and convey an easy to understand mental model of the process

    • @mvargasmoran
      @mvargasmoran 2 месяца назад

      @@ProtectedClassTest yes, for sure, there aren't shortcuts or laws, just rules of thumb and later experience in conveying ideas

    • @mvargasmoran
      @mvargasmoran 2 месяца назад

      @@ProtectedClassTest I'm sticking with a
      talk by Avdi Grimm: Confident Code.

  • @nitishmishra598
    @nitishmishra598 2 месяца назад

    I just want to say that I just completed " Go for absolute beginners " taught by you on from freecodecamp yt channel, and I am really amazed by the golang. So what should I do next in order to get strong in Go language from the jobs point of view. And i just saw a playlist on your channel about Devops, so I just want to ask that whether the playlist is complete or not. I am in a really bad situation right now and I seriously want to study from where I can land a job.
    Please answer. Love from India ❤

    • @kantancoding
      @kantancoding  2 месяца назад

      Hey bro. The DevOps series won’t be getting any new videos due to low demand. But, you can actually learn a lot from what’s there so if you are interested in DevOps, by all means, give it a shot!
      As for your other question, try to build things on your own using the language.

    • @nitishmishra598
      @nitishmishra598 2 месяца назад

      @@kantancoding Got it. Thanks buddy!!

  • @abdulkhaliq-lo8gu
    @abdulkhaliq-lo8gu 2 месяца назад

    thnks

  • @hlubradio2318
    @hlubradio2318 2 месяца назад

    The problem here is I'm not into JS. I'm pythonic

    • @kantancoding
      @kantancoding  2 месяца назад +1

      It’s Go 😉

    • @hlubradio2318
      @hlubradio2318 2 месяца назад

      @@kantancoding really?

    • @kantancoding
      @kantancoding  2 месяца назад

      Yes. But actually, this isn’t a language specific topic so it wouldn’t really make a difference even if it was Python

  • @tjscorp
    @tjscorp 2 месяца назад

    Did this man just tell us not to use function just so he can tell us to use functions?

  • @gethermedel3620
    @gethermedel3620 2 месяца назад

    what language is this? hahaha

  • @しめい-l4m
    @しめい-l4m Месяц назад

    × goto definition multiple times and lose track
    ○ .d.ts