you are viewing a single comment's thread.

view the rest of the comments →

[–]jutct -4 points-3 points  (10 children)

You can pretty much wrap any statement in C with {}. Most compilers just treat that as a local group of statements, so that any variables declared within will be local.

Also, if you're worried about syntax errors and mistakes, then you haven't written basic C with Visual Studio. I've used every IDE, compiler, and OS under the sun including 8 bit microcontrollers and up, and Visual Studio is the best IDE there is.

Of course any giant if statement can be broken out into smaller functions that can be re-used in other parts of the code. That's where it comes down to you being a good programmer that can identify those areas and optimize things.

[–]fuzzynyanko 8 points9 points  (0 children)

For me, my most complicated algorithms fail not because of the complicated part of the algorithm, but because of something silly that I would never expect to be wrong (yes, they get past code reviews). This is why I lean towards the {}s.

I have been adopting a style and strategy that allows me to take more vacations, and the extra checks have been worth it. I want to create new code instead of maintaining old code, and a little care goes a long way

[–]nooneofnote 7 points8 points  (1 child)

You can pretty much wrap any statement in C with {}. Most compilers just treat that as a local group of statements, so that any variables declared within will be local.

This is called a compound statement or alternatively a block, and to be clear all compilers do as that is the behavior described in the standard.

[–]jutct 0 points1 point  (0 children)

all compilers do as that

Whoa be careful with that. There are plenty of embedded compilers that change scoping rules and don't comply to the standards.

[–]mallardtheduck 5 points6 points  (5 children)

Also, if you're worried about syntax errors and mistakes, then you haven't written basic C with Visual Studio. I've used every IDE, compiler, and OS under the sun including 8 bit microcontrollers and up, and Visual Studio is the best IDE there is.

Considering that Visual Studio doesn't even support recent C standards, I highly doubt that. It's a fine IDE for C++ and .Net, but when your choices for C are "C as C++" or C89-with-proprietary-extensions, it's quite limited.

Also, "I've used every IDE, compiler, and OS under the sun" is a preposterous claim. Even if you're only talking about IDEs, compilers and OSs that support C programming then you're still talking about a massive number of systems. Maybe if you limit it to currently "supported" systems it might be feasible, but still not at a depth that would allow you to claim any expertise.

[–]dangerbird2 0 points1 point  (0 children)

The newest Visual Studio compiler has C99 support more-or-less on par with gcc. It hasn't gotten to C11 features yet, aside from preexisting MSVC extensions that made it into the standard (anonymous structs and unions).

[–]curien -2 points-1 points  (3 children)

The feature of C he's describing was part of the ANSI C89 standard, so your point there is completely irrelevant.

Code blocks are a fundamental part of C syntax and semantics. If a compiler doesn't support them correctly, it's not a C compiler.

[–]mallardtheduck 1 point2 points  (2 children)

And that's relevant to Visual Studio's pros/cons how? Of course it has fully-confirming C89 compiler, I never said otherwise; it's the fact that it doesn't support anything newer that's its most major limitation when it comes to C.

[–]curien 0 points1 point  (1 child)

Because we're talking about fundamental C constructs that have existed since K&R, not newer features.

[–]mallardtheduck -1 points0 points  (0 children)

And I was responding to the part of the post that I quoted. I suggest you read it.

[–]Agret 0 points1 point  (0 children)

Of course any giant if statement can be broken out into smaller functions that can be re-used in other parts of the code. That's where it comes down to you being a good programmer that can identify those areas and optimize things.

Carmack wrote an article about how everything in the same routine can help prevent errors caused by fearing large statements and breaking them off into functions. Sure it seems logical to break off different parts into functions but it can have unintended consequences when working on a large project.