Re: [Boost-users] Why something like #ifndef BOOST_MPI_HPP is alwayscapitalized?
Hi,
I'm wondering how you would handle the following case.
Suppose I have a set of mathematical formulas that has both bigger case and
lower case variables (such as both 'X' and 'x'). This situation is pretty
common. In order to implement them in C++, I could either write bigger cases
as well as lower cases in C++, which is not in consistence with the
convention that you mention. Or I have to convert bigger cases to lower
cases, which is also not easy to read, as it is different from the original
mathematical form.
Which approach would you prefer? I would prefer the former one. Therefore,
the convention is not followed.
Thanks,
Peng
On Fri, Sep 19, 2008 at 3:06 PM, Peter McGill
It is a standard C++ convention to capitalize #defines and constants like that. There is no technical reason, it just makes them easy to identify. Following common practice makes boost more accessible to many people.
You should never have two header files which only differ in case. Some file systems (ie. dos/windows) do not allow files which only differ in case. Technical reasons aside, having two files which only differed in case would be potentially hard to understand. It is much clearer to give them different names.
In both cases it is important to write understandable code, it is easier to maintain.
Peter McGill IT Systems Analyst Gra Ham Energy Limited
-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Peng Yu Sent: September 19, 2008 3:47 PM To: boost-users@lists.boost.org Subject: [Boost-users] Why something like #ifndef BOOST_MPI_HPP is alwayscapitalized?
Hi,
In most of the C++ header files I've seem, a macro like the following is used to guard repetitive inclusion of the file. I'm wondering why it is always in upper case. Why not make it the same case as the file name?
What if there are two header files on is in lower case, the other is in upper case?
Thanks, Peng
#ifndef BOOST_MPI_HPP
On Fri, Sep 19, 2008 at 16:30, Peng Yu
I'm wondering how you would handle the following case.
Suppose I have a set of mathematical formulas that has both bigger case and lower case variables (such as both 'X' and 'x'). This situation is pretty common. In order to implement them in C++, I could either write bigger cases as well as lower cases in C++, which is not in consistence with the convention that you mention. Or I have to convert bigger cases to lower cases, which is also not easy to read, as it is different from the original mathematical form.
Which approach would you prefer? I would prefer the former one. Therefore, the convention is not followed.
It's generally a very bad idea for readability to have names that differ only in case. The situation you describe would one one of the few exceptions, but even then it'd be reasonable only for local variables in a very small scope. You always have the option of upper_x and lower_x or big_x and little_x, which are perfectly clear, if more verbose. For headers, though, you can't have 2 headers whose names differ only in case on windows (and quite plausibly other filesystems), so the situation will never arise in portable code. Thus, there's no issue with using all-uppercase for the include guard macro. ~ Scott
On Fri, 19 Sep 2008 15:30:18 -0500, "Peng Yu"
Hi,
I'm wondering how you would handle the following case.
Suppose I have a set of mathematical formulas that has both bigger case and lower case variables (such as both 'X' and 'x'). This situation is pretty common. In order to implement them in C++, I could either write bigger cases as well as lower cases in C++, which is not in consistence with the convention that you mention. Or I have to convert bigger cases to lower cases, which is also not easy to read, as it is different from the original mathematical form.
Which approach would you prefer? I would prefer the former one. Therefore, the convention is not followed.
Thanks, Peng
First, I would say that in general a variable name as short as "x" is not usually desirable unless it is of very small scope as you are so apt to have multiple equations using the same symbol x to represent different things in the larger scope. The fact that you have two "x"s needing to be represented this way is a sign of this. In your equations, since normally equations use single letter symbols (since multiple letter together tend to imply multiplication of several variables). Somewhere off to the side is probably a key defining small x to be one thing and big X to be another, so you can go with names from that, or small_x / big_x or even x / xx (I prefer the first more descriptive unless it is a very small scope with comments defining the mapping). Richard Damon
participants (3)
-
Peng Yu
-
Richard Damon
-
Scott McMurray