>That's a lot of commenting for (technically) one line of code. Let's look it over, because I think you went a little overboard:
Somewhat exaggerated, perhaps, but it the same argument for whitespace: "everyone else" always has too much or too little.
>Cute border, but does it really add anything?
For me, it does. I divvy things up into "hunks" and I find it easier to spot the beginning/end.
>There's no need to say that you're giving a description if the macro is commented well. But I'll get to that in a moment.
It follows a format used with functions for a consistent look and feel.
* Parameters:
* itype - an intgeral type
* for example, DECIMALS(int) or DECIMALS(unsigned char)
*
>The description clearly states that DECIMALS works with an integral type, and the parameter is called *type, so it's not only safe to assume that itype is an integral type, it's obvious to any competent reader.
Just hammering home that you don't feed it an object like most C and C++ functions receive.
>Technically it doesn't return anything, it evaluates to something. ;)
Yes, thus the finger quotes.
>There's no need to include this either as the description practically screams what the result is.
Again, consistency. At least I've started dropping these "section" headers in functions returning void or receiving no parameters.
* Comments:
* A blatant copy of the hard work of Peter Nilsson:
* http://groups.yahoo.com/group/cncppassist/message/13395
*
>This is only needed if the link adds anything important, or if there are copyright issues.
The important thing, I figured, was a better explanation of how it works as well as crediting the author.
>I would like to believe that readers would be able to figure out how to use the macro, and example code may limit creativity in how it's used.
Using it has already prompted questions on another forum we are familar with, so I don't know that the uncommented version or even a sparsely commented version is as good.
>DECIMALS isn't exactly the most intuitive name that could be used.
Since I was stealing it, I left it as is.
>Tell me, what does your comment (and code) do that this doesn't (aside from take up space):
/* Approximation of the number of digits in an integral type */
#define DIGITS(type) \
( sizeof(type) * (CHAR_BIT * 12655UL) / 42039 + ((type) -1 < 0) + 1 )
- It doesn't follow a consistant format (from which this example was taken). Though not a function, it is function-like and nontrivial, so I borrowed the function header format.
- It is not like sizeof that can be used with either an object or type. I found this most odd when I first toyed with it. So I figure the parts that messed with my head the most when I first saw something are the parts that may need special care for anyone who is not as familiar with such things. It is somewhat counterintuitive for C and C++ that the parameter must be an actual type.
- It doesn't provide a link to the explanation of the derivation of the magic numbers used, or any of the rest of Peter's more detailed explanation.
Sometimes redundancy is just redundant. But other times the rewording can help make the confusing clear. YMMV.
[EDIT]Also, the information is more detailed with the autocomplete whatever thingy.
[IMG]http://img148.exs.cx/img148/9608/decimals7pp.th.gif[/IMG] [IMG]http://img148.exs.cx/img148/8155/digits5gy.th.gif[/IMG]