News for hackers. Stuff that matters.
Re:Fixing C by rootlocus on Tuesday April 12, 2016 @05:49AM (#11478251)
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.

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>
Re:Fixing C by bpchaps on Tuesday April 12, 2016 @03:02PM (#11482518)
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

Re:Fixing C by ludamad on Tuesday April 12, 2016 @04:51PM (#11483471)
I'm confused, this is just counting starting braces no?
Re:Fixing C by Cpoll on Wednesday April 13, 2016 @01:34PM (#11490313)
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.

Re:Fixing C by bpchaps on Thursday April 14, 2016 @04:48PM (#11500223)
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.
Re:Fixing C by Sinergy on Tuesday April 12, 2016 @06:41AM (#11478413)
Inline functions.
Re:Fixing C by Gibbon1 on Tuesday April 12, 2016 @03:32PM (#11482815)
MACRO's
Re:Fixing C by jandrese on Tuesday April 12, 2016 @03:33PM (#11482823)
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.

Re:Fixing C by na85 on Tuesday April 12, 2016 @08:28PM (#11484767)
>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.

Re:Fixing C by Gibbon1 on Tuesday April 12, 2016 @06:29AM (#11478370)
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.

Re:Fixing C by lmm on Tuesday April 12, 2016 @06:39AM (#11478407)
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.
Re:Fixing C by XorNot on Tuesday April 12, 2016 @06:21AM (#11478334)
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.
Re:Fixing C by Gibbon1 on Tuesday April 12, 2016 @06:36AM (#11478397)
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.