Re:Fixing C
by paulddraper on Tuesday April 12, 2016 @01:22PM
(#11481528)
YOUR ACTIONS SPEAK SO LOUD I CANNOT HEAR WHAT YOU ARE SAYING.
git clone --depth=1 [email protected]:git/git.git
find git -name '*.c' -type f | xargs grep -P '^( {4}|\t){4}' | wc -l
11375
git clone --depth=1 [email protected]:torvalds/linux.git
find linux -name '*.c' -type f | xargs grep -P '^( {4}|\t){4}' | wc -l
732937
Stupid shitty broken software. </s>Oh, stop :p
"$ find git -name .c -type f | xargs fgrep '{' | wc -l"
19288
"$ find linux -name .c -type f | xargs fgrep '{' | wc -l"
1408368
I'm confused, this is just counting starting braces no?
I 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.
Re:Fixing C
by paulddraper on Thursday April 14, 2016 @01:44PM
(#11498865)
?
Git and linux were both written (originally) by Torvalds.
And both use a fair amount of deep indentation.
Right. 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.
Re:Fixing C
by paulddraper on Thursday April 14, 2016 @11:41PM
(#11501937)
Fair enough. And my (flippant) comment was on two very large, very successful projects written predominantly in C with thousands of contributors.
Whether >3 level of indentation is "good", IDK. But it happens a lot. And I'm a practical man.
Re:Fixing C
by JulianMorrison on Tuesday April 12, 2016 @06:35AM
(#11478393)
If 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.
Inline functions.
It 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.
>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.
I 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.
Just 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.
Doesn'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.
Problem 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.
Also, IDEs can auto insert braces and indent the code. Unless you're using notepad, I don't see the problem.