Code Formatting (EP 51)

Поділитися
Вставка
  • Опубліковано 15 жов 2024
  • Doctor Plague talks about code formatting and explains why he formats code the way he does.
    See if you can find J.S. Bach before the end of the video! Be sure to watch to the end to see if you were correct!
    Category: Technical
    Please subscribe, and peck at the bell to be notified of new videos as they become available.

КОМЕНТАРІ • 5

  • @ellisgl
    @ellisgl 10 місяців тому +1

    My style has changed so many times over the last 25 years so.

    • @DoctorRGPlague
      @DoctorRGPlague  10 місяців тому +2

      This seems like par for the course. Thanks for watching!

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

    I feel like putting the bracket on the next line is more complex. If you want a single-line if, you'd put the code line as the second line. And you'd indent it (as it would be unreadable not to indent that one code line). But that means that an if needs indentation in the next line. So if you want a multiline if body with brackets, the bracket in the next line should also be indented. But it's not. This is inconsistent, and means you have different indentation rules for block ifs and for single line ifs. On the other hand, if I do a single-line if, I do it on one line, both the condition and the code line. And if that one code line is replaced by a block, my rules don't change, the block opening bracket is exactly where I'd put the single line of code, right after the condition. No exceptions, single rule for indentation whether multiline or single.
    Of course this is just my preference, I read both styles all the time without an issue. Even though I justify it as being simpler in terms of indentation rules I'm sure my preference is mostly habitual at this point.
    I'm also writing a lot of Lua which doesn't have brackets and putting a "then" in a like by itself to open a block would be weird. 😅

  • @alexv3000
    @alexv3000 Рік тому +4

    You’re stepping into one of the oldest and unsettled topics since the invention of computer languages: coding style. The exact prevalent style is constantly shifting, and in general it is a generational thing. Even now with code reformatting tooling for every conceivable language, these reformatting tools have so many stylistic parameters providing evidence this topic will remain unsettled for generations to come.

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

    I like the way some other languages are moving, with having a single "correct" style and a reformatter that output's the "correct" style. In my experience the first couple of weeks using the "correct" style are horrible, but you get used to it and eventually wonder what all the fuss was about. And it instantly ends all the arguments and makes it impossible for people to comment on this video saying "NO! YOU'RE WRONG, IF YOU INDENT THAT WAY YOU WILL GO TO HEEEEEEEELL!" Sadly thought, I don't see how this could ever work for C because of the huge amount of legacy code and emotional baggage that C has to carry around with it.