On Tue, 23 Jan 2024 16:32:09 +0000, Malcolm McLean wrote:
On 22/01/2024 20:34, Lawrence D'Oliveiro wrote:
On Mon, 22 Jan 2024 09:30:21 +0100, David Brown wrote:It breaks the rule that, in C, variables and functions are alphnumeric,
... I don't use the matching names in C++ either ...
I do, if/when I do use C++ and C. Don’t you think it improves readability:
whilst operators are symbols. sizeof is an exception, but a justified
one. However it's harder to justify a symbol for "plus" but a word for "or".
Less importantly, it also violates the convention that C macros are named in upper case to distinguish them from keywords and "regular" identifiers.
[...]
On 23.01.2024 18:21, Lew Pitcher wrote:
On Tue, 23 Jan 2024 16:32:09 +0000, Malcolm McLean wrote:
On 22/01/2024 20:34, Lawrence D'Oliveiro wrote:
On Mon, 22 Jan 2024 09:30:21 +0100, David Brown wrote:It breaks the rule that, in C, variables and functions are alphnumeric,
... I don't use the matching names in C++ either ...
I do, if/when I do use C++ and C. Don’t you think it improves readability:
whilst operators are symbols. sizeof is an exception, but a justified
one. However it's harder to justify a symbol for "plus" but a word for "or".
Less importantly, it also violates the convention that C macros are named in >> upper case to distinguish them from keywords and "regular" identifiers.
Interestingly the convention had been (AFAICT) to uppercase *all* CPP
items, _mostly_. But in practice we've seen CPP function macros that
were lowercase even in system headers (ISTR some functions in stdio).
It certainly has advantages to uppercase macro functions to be sure
about possible side effects, like in FUNCT(a++). OTOH, for plain CPP constants literals it's probably unnecessary to capitalize them.
On 2024-01-24, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
On 23.01.2024 18:21, Lew Pitcher wrote:
On Tue, 23 Jan 2024 16:32:09 +0000, Malcolm McLean wrote:
On 22/01/2024 20:34, Lawrence D'Oliveiro wrote:
On Mon, 22 Jan 2024 09:30:21 +0100, David Brown wrote:It breaks the rule that, in C, variables and functions are alphnumeric, >>>> whilst operators are symbols. sizeof is an exception, but a justified
... I don't use the matching names in C++ either ...
I do, if/when I do use C++ and C. Don’t you think it improves readability:
one. However it's harder to justify a symbol for "plus" but a word for "or".
Less importantly, it also violates the convention that C macros are named in
upper case to distinguish them from keywords and "regular" identifiers.
Interestingly the convention had been (AFAICT) to uppercase *all* CPP
items, _mostly_. But in practice we've seen CPP function macros that
were lowercase even in system headers (ISTR some functions in stdio).
It certainly has advantages to uppercase macro functions to be sure
about possible side effects, like in FUNCT(a++). OTOH, for plain CPP
constants literals it's probably unnecessary to capitalize them.
You might think, but due to scoping, they can cause problems, unless
they are namespaced. If you define macro like
#define speed 42.0
anything which includes this cannot use the speed identifier
for any purpose. Not as a structure member name, enumerator, parameter
name, function name, typedef, goto label, nothing.
If we use SPEED instead, and never use such an identifier as a function, parameter, or any of those roles I mentioned, then we have a kind of namespace separation.
This is why simple constants are capitalized.
What we don't want to capitalize are function-like macros (those
that take parameters) which are well-behaved and blend nicely into the language. Making them SHOUT just reduces the nice blending.
A function-like macro is not invoked if it is not followed by an open parenthesis, which reduces the possibility of a clash.
Macros that do weird things, and/or have severe or bizarre contextual restrictions on their use probably ought to SHOUT.
On 2024-01-24, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
On 23.01.2024 18:21, Lew Pitcher wrote:
On Tue, 23 Jan 2024 16:32:09 +0000, Malcolm McLean wrote:
On 22/01/2024 20:34, Lawrence D'Oliveiro wrote:
On Mon, 22 Jan 2024 09:30:21 +0100, David Brown wrote:It breaks the rule that, in C, variables and functions are alphnumeric, >>>> whilst operators are symbols. sizeof is an exception, but a justified
... I don't use the matching names in C++ either ...
I do, if/when I do use C++ and C. Don’t you think it improves readability:
one. However it's harder to justify a symbol for "plus" but a word for "or".
Less importantly, it also violates the convention that C macros are named in
upper case to distinguish them from keywords and "regular" identifiers.
Interestingly the convention had been (AFAICT) to uppercase *all* CPP
items, _mostly_. But in practice we've seen CPP function macros that
were lowercase even in system headers (ISTR some functions in stdio).
It certainly has advantages to uppercase macro functions to be sure
about possible side effects, like in FUNCT(a++). OTOH, for plain CPP
constants literals it's probably unnecessary to capitalize them.
You might think, but due to scoping, they can cause problems, unless
they are namespaced. If you define macro like
#define speed 42.0
anything which includes this cannot use the speed identifier
for any purpose. Not as a structure member name, enumerator, parameter
name, function name, typedef, goto label, nothing.
If we use SPEED instead, and never use such an identifier as a function, parameter, or any of those roles I mentioned, then we have a kind of namespace separation.
This is why simple constants are capitalized.
What we don't want to capitalize are function-like macros (those
that take parameters) which are well-behaved and blend nicely into the language. Making them SHOUT just reduces the nice blending.
A function-like macro is not invoked if it is not followed by an open parenthesis, which reduces the possibility of a clash.
Macros that do weird things, and/or have severe or bizarre contextual restrictions on their use probably ought to SHOUT.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 546 |
Nodes: | 16 (2 / 14) |
Uptime: | 00:31:31 |
Calls: | 10,385 |
Calls today: | 2 |
Files: | 14,057 |
Messages: | 6,416,570 |