5 ms·
Removing curly braces? I have to paraphrase Torvalds on this: > The answer to that is that if you need > more than 3 levels of indentation, you're screwed
by rootlocus 11y ago
Removing curly braces? I have to paraphrase Torvalds on this:
> The answer to that is that if you need
> more than 3 levels of indentation, you're screwed anyway,
> and should fix your program.
Breaking the code into manageable chunks is a huge part in writing clear, maintainable software. A high amount of curly braces implies deep nested loops and/or branches, which also implies a high complexity (measured by cyclomatic complexity).
Also, IDEs can auto insert braces and indent the code. Unless you're using notepad, I don't see the problem.
- XorNot 11y agoDoesn't this equally imply the opposite argument? You could get away with enforced indenting, remove the curly braces, and there should still be no problem.
- Gibbon1 11y agoProblem is you end up like python where writing tooling is hard/impossible because the syntax doesn't have enough redundancy. I look at python and get the feeling the guy tried to make it work with just indenting, and then had to punt and add colons.
- Gibbon1 11y agoI don't really see the problem either. A lot of this stuff I see seems to be centered around stuff that 'trips up beginners' What I would like would be a way to portably create a stack frame and pass it around as an object and then call a function with it.
- lmm 11y agoJust having a standardized way to do tail calls would be a big step in the right direction. The likes of Java could do with that too.
- JulianMorrison 11y agoIf it's embedded code, it's quite possible you can't just decompose code into little bitty chunks to avoid nesting, because your maximum stack depth is fixed and very small.
- Sinergy 11y agoInline functions.
- Gibbon1 11y agoMACRO's
- jandrese 11y agoIt is also definitely possible to go overboard with chopping up your code. I'm sure everyone has read that file where damn near every single line ended up in its own little function (in its own file with some big framework around it) and you're jumping all over the place trying to figure out what its actually doing. Everything should be made as simple as possible, but not simpler.
- na85 11y ago>I'm sure everyone has read that file where damn near every single line ended up in its own little function (in its own file with some big framework around it) and you're jumping all over the place trying to figure out what its actually doing. Sounds like node and its moronic packaging ecosystem.
- paulddraper 11y agoYOUR ACTIONS SPEAK SO LOUD I CANNOT HEAR WHAT YOU ARE SAYING. git clone --depth=1 git@github.com:git/git.git find git -name '*.c' -type f | xargs grep -P '^( {4}|\t){4}' | wc -l 11375 git clone --depth=1 git@github.com:torvalds/linux.git find linux -name '*.c' -type f | xargs grep -P '^( {4}|\t){4}' | wc -l 732937 Stupid shitty broken software. </s>
- bpchaps 11y agoOh, stop :p "$ find git -name .c -type f | xargs fgrep '{' | wc -l" 19288 "$ find linux -name .c -type f | xargs fgrep '{' | wc -l" 1408368
- ludamad 11y agoI'm confused, this is just counting starting braces no?
- Cpoll 11y agoI think the idea is that Linux has two orders of magnitude more loops, so one order of magnitude more 4-level-indentations is actually an improvement over Git's code, by ratio. It's not as if Torvalds wrote the entire codebase by himself, anyway.
- paulddraper 11y ago? Git and linux were both written (originally) by Torvalds. And both use a fair amount of deep indentation.
- bpchaps 11y agoRight. I wasn't really commenting on whether git/linux were coded "correctly" in either case, just that it's not a very helpful metric for the larger conversation.