Refactoring a Command Line Shell | Code Roast Part 1

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

КОМЕНТАРІ • 80

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

    👷 Join the FREE Code Diagnosis Workshop to help you review code more effectively using my 3-Factor Diagnosis Framework: www.arjancodes.com/diagnosis

  • @filippopisello
    @filippopisello Рік тому +40

    I have been following the channel since its debut and got significantly better at coding in the meantime.
    While it is more and more rare for me to find enriching concepts in the “I explain you something” kind of videos, I still learn a lot from the refactoring ones.
    Bottom line is that I would like to see more of these videos!
    Hope it helps in your audience targeting 😉

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

      Thank you for sharing this!

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

      100% filipopisello, totally agree with this. Thanks again @Arjan for another great video

  • @vuongviethung262
    @vuongviethung262 Рік тому +23

    I was worried that the Code Roast series is falling off because recently entries were pretty decent written code, actually. This episode truly bring back the good-old Code Roast, code that is written by someone who is obviously knowledgeable in programming and Python but has very questionable design choices, I love it! Shout out to the code author for the submission so us all can learn from your mistakes.

    • @ArjanCodes
      @ArjanCodes  Рік тому +1

      Thank you, glad you enjoy the series!

  • @MarkusSoruleus
    @MarkusSoruleus Рік тому +26

    Some people prefer light roast coffee, some people prefer dark roast coffee, but the only roast I like is a CODE ROAST!

    • @costelinha1867
      @costelinha1867 Рік тому +5

      Code Roast with a cup of coffee.

    • @dragonfly-7
      @dragonfly-7 Рік тому

      Well said ... written I mean ... 😉

    • @leila-codes
      @leila-codes Рік тому

      ​@@costelinha1867Woah! That's too much of a good thing! 😂😂😂

  • @petercrowder6867
    @petercrowder6867 Рік тому +1

    Thanks!

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

      Thank you, Peter! I really appreciate your support.

  • @dannorris1406
    @dannorris1406 Рік тому +8

    Great video as always Arjan. I'm looking forward to part two! In this code, it was absolutely right to replace "command" with a tuple but I think there is a case for using dataclasses like this. It can make code much more readable as you don't need to remember what each positional member is and if you want to add more members in the future, you don't end up with lots of tuple[0], tuple[1] code.

  • @horoshuhin
    @horoshuhin Рік тому +2

    I was waiting for another code roast. thank you, Arjan. honestly, I don't mind if you make longer videos cuz they bring a lot of value.

  • @hugo-onzakorderra8851
    @hugo-onzakorderra8851 Рік тому +4

    I love refactoring as a hobby. You get raw ideas and wild code and make good art out of them. Until someone finds your ideas raw and your code wild.

  • @thisoldproperty
    @thisoldproperty Рік тому +1

    What i like about code review is the opportunity to improve and simplify code that (should) already work.
    One of my mottos: First make it work, then make it better.
    Thanks Arjan; another terrific start to a video.

    • @ArjanCodes
      @ArjanCodes  Рік тому +2

      Thank you - glad you liked it!

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

      Refactoring - Martin Fowler made a great book on it - it contains techniques most people haven't heard of, and are missing in most IDEs.

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

      @@NostraDavid2 I'll go check it out. Thanks for posting.

  • @yousofthelord
    @yousofthelord Рік тому +2

    finally again!!!! the most i learn from are code roasts

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

    I like this series a lot!

  • @rrwoodyt
    @rrwoodyt Рік тому +2

    Ack-- I didn't notice this was a two-parter! Looking forward to the dramatic conclusion to this cliffhanger next week. So far, it's deeply satisfying to watch you ripping out huge chunks of code and seeing how much simpler things can be...

    • @ArjanCodes
      @ArjanCodes  Рік тому +1

      Thank you Roy! I’ll post the second (final) part next Friday!

  • @JohnFallot
    @JohnFallot Рік тому +3

    Let's goooo!!

    • @ArjanCodes
      @ArjanCodes  Рік тому +3

      Yes!

    • @JohnFallot
      @JohnFallot Рік тому +1

      @@ArjanCodes Watched the whole thing and I have a questions: why have a help_shell function at all if it's just (so it seems) returning a print statement?
      Other than that, I'm going to see about removing some fairly basic dataclasses that I have in my own code using the example of Command = tuple[str, int] that you provided. :D

  • @soheylaranjbar2838
    @soheylaranjbar2838 Рік тому +2

    Could you please make another video about Asyncio with the advanced concepts and also learning videos about cloud design patterns?

  • @nrm604
    @nrm604 Рік тому +3

    All I wanna do is watch your code roasts. Moar pls :)

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

      To be fair, I do have some pretty big python spaghettis that he could probably review...... specially on my earlier projects....

    • @aflous
      @aflous Рік тому +2

      ​@@costelinha1867I plan on starting a UA-cam channel to do this kind of stuff (code roasts). Do you think you'd enjoy that?

    • @costelinha1867
      @costelinha1867 Рік тому +1

      @@aflous Maybe... I could check it out.

  • @JeremyLangdon1
    @JeremyLangdon1 Рік тому +1

    I felt like I was at the theater watching an action movie and right at the climax, they stopped the video and turned on the lights and I was pulled back into reality! Ok, maybe I’m exaggerating… looking forward to part 2!

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

    I love this series

  • @marcotroster8247
    @marcotroster8247 Рік тому +1

    Damn, the final version is looking really clean. I can't wait to see how you're typing the code into the editor and experience a free time travel 😂

  • @franco-gil
    @franco-gil 8 місяців тому

    Love this series!

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

      I'm glad you're enjoying the content!

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

    Nooooo I didnt know it was split into 2 videos 😆 I cant wait until the next video, great work!

    • @ArjanCodes
      @ArjanCodes  Рік тому +1

      Thanks! Coming this Friday! :)

  • @alexandarjelenic2880
    @alexandarjelenic2880 Рік тому +6

    I wish I had the confidence of deleting something when you don't know what it is, and deleting something for completeness such as @ 11:00 .

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

    The best rubric. I love it

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

    Such a funny intro 😂😂😂. Love that

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

    For the shell component: why not use argparse from the stdlib or even better, typer from the same author of fastapi?
    Unless it's a learning opportunity, a lot of the code could be golfed by using libraries that are battle tested and provide better functionality.

  • @jeancerrien3016
    @jeancerrien3016 Рік тому +3

    @17:40: What is there to strip? More precisely, if you a string split on a space, will any part ever start/end in a space?

    • @kicknotes
      @kicknotes Рік тому +2

      Good catch, and to your question, no. If you split on a space (the default: sep=None), none of the sub-parts will contain any trailing or leading whitespace.

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

    'BASH'ing other people's code ++ Need more linux converts. ;)

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

    when editing variable names: ctrl+D or ctrl+shift+D is... gold.

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

      Even better: F2 (Rename Symbol)

  • @manomancan
    @manomancan Рік тому +1

    God I love Code Roasts hahah. And I loved the intro! 😂 Also, did you lose some weight by the way man; really fits you!

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

      Thank you! Yes, I lost some weight. I've been prioritizing my health for the last year! :)

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

    Half an hour isn't that long. We're also long over that mantra, that youtube consumers don't watch anything more than 10 minutes. I know a list of other channels, that feature hour long videos. So if it's not for the reason, that you want to split up content over several weeks, I'd just go with a full roasting session one at at time, no matter how long :) I suppose there will be other projects in need of some roast for the forseeable future!

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

    about the auto formatter, make sure everyone use the same rules, and always format before committing otherwise you create a terrible pull request review experience :( (thousands of changes related to formatting...)
    There are ways to reinforce formatting before committing

  • @guille.hoardings
    @guille.hoardings Рік тому

    Regarding the Command type, wouldn't it be better to use an explicit TypeAlias as per PEP 613?

  • @matheusaugustodasilvasanto3171
    @matheusaugustodasilvasanto3171 6 місяців тому

    Where are the tests? Did I just catch somebody doing manual refactorings without the safety net of tests? Living on the edge.

  • @joshward9182
    @joshward9182 Рік тому +1

    "bashing other people's code".
    Pun intended? 👀😂

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

      In a nutshell, there was no good use of bash commands in this code so far

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

    Please upload part 2 today, else I will start panicking 😣

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

    Any particular reason you didn't use the the Rename Symbol feature instead of manually renaming things in multiple places?

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

    Help, I'm stuck in a loop, while end_of_roast is False: ... 😂

  • @kamikaze_jb
    @kamikaze_jb Рік тому +1

    As a developer myself, I really like your channel, Arjan, but it pains me to see you manually fixing the imports after rename operations. It gives me a bad vibe when I see people not fully utilizing their IDE or not knowing the shortcuts :D:D

  • @dokick2746
    @dokick2746 Рік тому +2

    My approach: Delete everything and use argparse

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

    26:21 line 84?
    else:
    pass

  • @ErikS-
    @ErikS- Рік тому

    22:59 - Why is it that Python does not accept "None" as type hint when a function doesn't have any parameters?
    I.e. why can't you write: def help_shell(None) -> None:
    I personally think it's strange since on the output side, "None" is allowed...

    • @NostraDavid2
      @NostraDavid2 Рік тому +1

      Because None is a value, not a type.

    • @NostraDavid2
      @NostraDavid2 Рік тому +1

      You can't write `def Help(1): ...` either, for example.

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

      The type hint of the return value of a function is given after the -> arrow. As to the arguments of a function: a function can have NO arguments and in that case there is only white space between the opening and closing parentheses. Or a function can have 1 or more comma separated formal arguments, each of which is identified by an identifier. Python keywords (None, from, import, in, class, ...) are not allowed as identifiers.
      So: seeing None between parentheses means the function has 1 one formal argument. But it's identifier, None, is not allowed (try it out, you would get 'invalid syntax'). So: a function without arguments can be recognized by really having NOTHING between its parentheses (well, white space is allowed).

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

      As others have said, but also, why would you want to write None as a type hint?
      "def help_shell()" has nothing in the arguments, so it serves the same purpose you expect
      Although you can set the default value of an argument as None like this:
      from typing import Optional
      def help_shell(value: Optional[int] = None):
      pass

  • @kicknotes
    @kicknotes Рік тому +10

    Between the poor adherence to convention and the overly-complex design, it's pretty obvious the original author was (a) coming from another language and/or (b) isn't terribly experienced and went overboard trying to put "fancy" code into the public domain.

    • @aflous
      @aflous Рік тому +5

      I would love to see a code roast for a code written by an experienced python dev for once. I have a couple of projects I would like to submit but not sure this would fit this series tbh

    • @rrwoodyt
      @rrwoodyt Рік тому +2

      @@aflous Yes! That would be great!

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

      yeah, but I bet every python dev can remember the feeling when your code started thunder with all the __dunder__

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

      It feels like "baby's first Programming Pattern", and that the author tried to slap as many patterns into his code as possible. Can't knock them too hard though, as I've been there, done that too. 😂

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

    Am I the only one that was driven absolutely mad by the colored squiggle lines on every line? What is up with the editor?

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

    Congratulations, you have just totally ruined all his unittests! ;)