I prefer Whitesmith's and have always wondered why it's not more popular. It's the easiest to parse visually as the entire block is indented equally in relation to its control statement. Plus, if the goal is to indent logic blocks why treat the 'start of block' and 'end of block' tokens as external elements?
Mainly because having the } back on the previous indentation level helps 'reset' the eye, IMHO.
17 Jan, 2010, David Haley wrote in the 22nd comment:
Votes: 0
For me, if the brace is on the same level as the indented code, it might as well not be present because the indentation change is giving you the same effect. Having a brace on its own, with nothing directly above it, is far easier to spot IMO.
I just use gotos. No need for braces or indentation. So much easier to write, too.
I have a friend that has apoplexy when I use GOTO. Seriously, though, what's the difference between a goto and a function call? At least with a goto you usually don't have to go back to what you were reading before.
18 Jan, 2010, David Haley wrote in the 28th comment:
I have a friend that has apoplexy when I use GOTO. Seriously, though, what's the difference between a goto and a function call? At least with a goto you usually don't have to go back to what you were reading before.
Try recursion, for starters. There are things to be said about debuggers and logical units of code, as well.
The main advice I would give is to always use braces even if you have just one line, then there is no issue of remembering or forgetting them.
Seconded. Same story with using your blinkers, routine is your friend.
I use tabs for indentation, (hate it when people mix tabs and spaces), and for spacing I never use tabs, only spaces, so the code looks decent regardless of your tab size setting. There's an argument to be made against spacing, but in some cases it improved readability quite a bit.
I have a friend that has apoplexy when I use GOTO. Seriously, though, what's the difference between a goto and a function call? At least with a goto you usually don't have to go back to what you were reading before.
Try recursion, for starters.
You can do recursion without functions. I did it using BASIC for the TI TRS-80 Mo.... You just have to manage your own state variables, so you can rollback pervious values if need be. CGOTO is a beautiful thing.
You kids and your nerf toys.
18 Jan, 2010, David Haley wrote in the 35th comment:
Votes: 0
Of course you can do recursion with goto statements if you manage your own stack on the side. After all, the function call is doing just that. But the whole point of a proper function call is precisely that you don't have to do all that extra work that's always the same anyway. :wink:
Function calls have return. gotos do not. In fact, right down to the underlying machine codes, many architectures have two separate instructions for goto/branch and call, specifically because the later adds the caller location to the stack and the former does not.
In C/C++, goto also has issues dealing with variable initialization in a safe/easy way.
In general, the only things I would ever use a goto for in a C/C++ app are to break out of heavily nested loops or for error-handling in C (or C++ with exceptions disabled, on platforms like Xbox or PS3 where there is no usable exception support in the compiler toolchain). For general flow-control of logical units, functions are superior, not least of all because they are more readily reusable, and the compiler can do far more intelligent optimizations with functions. Gotos force the compiler into dumb mode because the compiler can't be sure how you're going to jump around the insides of a function, especially when you add support for things like computed gotos.
The only time I have ever used goto was when I thought of a new feature I could add to a piece of software I'd written and it was my last day on the job, so I didn't have the time for any semi-serious revision. (And no, it was nothing nefarious.)
Mainly because having the } back on the previous indentation level helps 'reset' the eye, IMHO.