New commenting Scheme

Pages: 12
Where does this style of commenting come from?
}//End of main

I have been seeing this a lot more in the last few months than ever before. I think it makes the code look messy and doesn't enforce proper indentation. I also feel that the intention is to aide beginners in understanding their loops and scopes better, but I don't see it's helping them any more than by understanding what a comment is and forcing them to type more.

Anyone actually use this and find it's helpful?

Even with eliminating one line conditional curly braces, I rarely find I have any issues. Maybe it comes from how I learned about scopes, but I see no benefits to this "new" style.
My best guess would be that the comments act as a primitive "editor fold indicator" for the cavemen that still refuse to use a modern IDE and prefer to build their sources via command-line.
Last edited on
I feel the IDE makes me a lazy programmer, but no one writes code in notepad...do they? Even those that compile from the command line still use an editor of some sort (I used N++) so I still don't see this is necessary. And is there an editor that can read those comments as a "fold indicator"? Wouldn't the time implementing that (and requiring everyone to use the same format) be better spent on implementing an auto fold feature?
I meant "fold indicator" as in the text itself acting as an indicator to the programmer, not the editor.

P.S. Last I knew, being a lazy programmer was a good thing. There's no need to torture yourself :-\
Last edited on
for the cavemen that still refuse to use a modern IDE and prefer to build their sources via command-line.

True! And what about the cavemen who still refuse to use a modern programming language?
I'm a bit confused by that, Catfish2. Are you meaning to say that C++ hasn't seen an update in a while? How do you define "modern"? Here's what I am going by:

characteristic of present and recent time
I feel it is not for the people who refuse to use IDEs, but for people who refuse to admit that whenever they write a function longer than 20 lines of code (without counting comments and blank lines), a kitten cries. I don't want to think what happens when they write a 3000 loc long classes...
I suppose that they would put //main hasn't ended yet
closed account (1yR4jE8b)
I do those kinds of comments when I end namespaces, especially when using nested namespaces, but not functions.
I usually use those types of comments in longer source files where things are nested. Just because I can usually use an IDE doesn't mean I'll always have one on hand.

(note, I have my project files syncing with my google drive and often work on code when I'm far away from my computer (read: at my parents house, spending the night at a friends house, visiting extended relatives with my family and need alone time)
I still don't see the purpose of them. I had written over 10 pages of code by hand on a paper and never got confused as to which scope I was in. Granted, I was younger and knew less, but knowing more should make you understand your own code better.

If someone gives you a 1000 line program and askes you to debug, are you going to go through and comment each scope? Will you refuse to look at it if they didn't do that already?

Anyways, I still don't see how any of this makes up for lack of indentation. Indentation, if applied correctly, should be all of the instructions required.
I put those kinds of comments when there's an above average amount of nested indentation, and the function is a bit longer than normal. Basically if it help clarify, I'll put it in, but otherwise I won't.

Also +1 @ darkestfright, I also put them on namespaces always... probably because I don't indent namespaces.
My best guess would be that the comments act as a primitive "editor fold indicator" for the cavemen that still refuse to use a modern IDE and prefer to build their sources via command-line.

I'm not using an IDE because I found most of them to be rather slow, resource consuming, hard to navigate and often enforce a particular project structure (even if not, they tend to make it hard to use another one than intended by the IDE devs). I'm currently using sublime text 2 - it has everything I could ask from a text editor, and pretty much any feature that worked reliably in any IDE I've been using so far, while staying fast. I can run make (or any other build system) from it (which I am right now abusing to run the build targets as well) too, so there's really nothing in particular I feel I'm missing.
I've always wondered how people who don't use IDEs do their debugging. The debugger is hands down the most important part of an IDE.
closed account (1yR4jE8b)
probably because I don't indent namespaces.


Exactly why I use comments. I often have 3 level deep nested namespace...indenting all of them would look terrible.

I've always wondered how people who don't use IDEs do their debugging. The debugger is hands down the most important part of an IDE.


I used to debug assembly on the command line with gdb back in the day, it really isn't as bad as it sounds.
I've always wondered how people who don't use IDEs do their debugging. The debugger is hands down the most important part of an IDE.

dbx, truss, totalview, purify, quantify.. There are many programs used in debugging. Some are command line, some have their own GUI. I have a hard time seeing where an IDE could help, although I suppose when developing desktop applications, it would make sense. But there I probably wouldn't be using vi either.
Last edited on
That kind of commenting is always found on #endif s in the official librarys
in the official librarys

No such thing.
to prevent code formatters from combining lines you've carefully split to add clarity
If your code formatter combines lines and you don't want it to, change your formatter options or get a better one. I'm using Astyle and I love it. It is all but perfectly set up for my programming style now (I use the one integrated into the Code::Blocks IDE).

I still haven't quite heard about the reasons for it other than nested namespaces (which I personally indent each namespace as well). I only use an indentation of 3 which makes up to 3 namespaces reasonable.

Since I don't see it necessary to start a new thread, what is everyone's preference on indentation? Tabs/Spaces? Tab size/Number of Spaces?

What does a basic program look like? Where do you brackets go for loops/conditions/functions? I guess I'll go first and show you what a small example would be (I'd suggest just modifying my example to reflect how you prefer your code to be written.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>

int main() {
   int a;
   std::cout << "Please enter the first variable: ";
   std::cin >> a;

   int b;
   do {
      std::cout << "Please enter the second variable to match the first: ";
      std::cin >> b;
   } while (a != b);

   if (a > 0)
      std::cout << "\nThe variables are positive!\n\n";
   else if (a == 0)
      std::cout << "\nThe variables are zero!\n\n";
   else
      std::cout << "\nThe variables are negative!\n\n";

   int c;
   std::cout << "Please enter the third variable to multiply by: ";
   std::cin >> c;

   int d = 0;
   for (int i = 0; i < c; i ++)
      d += a;

   std::cout << a << " * " << c << " = " << d;

   return 0;
}


Edit: I tried to cover as much as possible. I really need to get a sample .cpp file that I can use to cover all the different options of my source formatter so you can see the options. I do use the OTB style, which I didn't get to really show here, but the way my main has the brace on the same line is the same way my other statements have them. I do not put my if/else if/else on the same line as the braces though (I know some people prefer it this way).
Last edited on
Pages: 12