I've used the form
char const * const name;
long enough to be used to it. But for me it is too evenly spaced out.
And when I first enountered this form, it did throw me a bit as I had gotten used to more common, basic form
const char*
. The rule that the const actually binds to the left, except when it's the left-most token in the declaration, does throw a lot of beginners.
It was even worse in the olden days when some compilers silently accepted
const char const * name;
(nowadays you should see a warning.)
I thought that the point of this thread was to see why people prefer their coding conventions. |
Yes, it was. And I
am
slowly learning a bit more about the subject!
Discussions about coding conventions invariably end up getting bogged down in detail (I plead guilty to this tendency!) And I have found that there is a surprisingly high emotional component to peoples preferences (I am thinking in particular about some "negotitions" we had about the matter at one place I worked...)
I have mentioned that I like to arrange tokens into conceptual groups, as have others. But we disagree about what these groups are. But we do hold the common view that there should be structure. Out different preferences must have something to do with the features that we use to identify the groups.
If
everything is crammed together, or things are
absolutely uniformly spaced, then there is no structure. In between are different variations on the theme of grouping. (though randomly scattered code is far worse!)
The simplest example that I (still) don't get -- from a type-ist point of view -- is the
char *name
form of a C string variable or parameter definition. To me,
char* name
reads as "name is a variable/parameter of type char*". When the tokens are laid out the other ways, it looks - to me - like it should be read as "name is a variable that when deferenced is of type char." Is that what K & R were thinking about when they came up with their pointer syntax?
I am happy enough reading other styles/layouts, and if editing someone else's code would always (try to) conform to their style. But some styles are harder for me to read. Esp. if I am trying to read them at speed, in the midst of firefighting a problem. (this is generally code with little spacing)
I studied physics at university, and had therefore done a lot of (applied) maths before I ended up becoming a programmer. I think that this just might have some bearing on my preference of
int function()
over
int function ()
. When I hand write mathematical functions, in basic notation, the bracket pretty much follows the function name
f(c) = 2x + 1
. Now I have seen pure maths which uses other sort of notation, but that kind of thing's beyond me!