R
Rui Maciel
When a C program grows, the odds that two identifier names will clash will
increase. So, unless the programmer has in place an effective policy to
name every identifier that is able to avoid any naming clash, including
thosed introduced by third-party code, the odds that this problem will
manifest itself will also become greater.
This problem isn't particularly hard to avoid. A simple policy based on
adding a descriptive prefix to the identifier name tends to be enough for
most cases. Even in corner cases, such as possible name clashes between
incompatible versions of the same library, it is possible to sidestep this
by adding a reference to the library version to the prefix being used.
Nonetheless, by relying on this method, identifier names tend to become a
bit verbose. This, in itself, isn't a major problem, but it isn't very
helpful either. After all, it tends to be preferable if it's possible to
call a function named do_stuff() instead of being forced to call another one
named package_name_version_library_task_do_stuff(), and long identifier
names tend to make some code constructs a bit hard to read.
A possible way to cut on verbose identifier names would be to implement a
system where these prefixes could be left implied by the programmer in such
a way that, in a given context, a call to do_stuff() could unambiguously be
interpreted as a call to package_name_version_library_task_do_stuff(). This
could, hypothetically, be accomplished by letting programmers specify
exactly, both in declarations and definitions, which group of identifiers
would share a specific naming prefix, and then also specify in which block
these naming prefixes could be left implied.
What I've described is, in essence, the concept of namespaces, which has
been a part of other programming languages, such as C++, for a long time
now.
So, with this in mind, what are your thoughts on the idea of introducing
namespaces to the C programming language? Would it be a bad idea?
Rui Maciel
increase. So, unless the programmer has in place an effective policy to
name every identifier that is able to avoid any naming clash, including
thosed introduced by third-party code, the odds that this problem will
manifest itself will also become greater.
This problem isn't particularly hard to avoid. A simple policy based on
adding a descriptive prefix to the identifier name tends to be enough for
most cases. Even in corner cases, such as possible name clashes between
incompatible versions of the same library, it is possible to sidestep this
by adding a reference to the library version to the prefix being used.
Nonetheless, by relying on this method, identifier names tend to become a
bit verbose. This, in itself, isn't a major problem, but it isn't very
helpful either. After all, it tends to be preferable if it's possible to
call a function named do_stuff() instead of being forced to call another one
named package_name_version_library_task_do_stuff(), and long identifier
names tend to make some code constructs a bit hard to read.
A possible way to cut on verbose identifier names would be to implement a
system where these prefixes could be left implied by the programmer in such
a way that, in a given context, a call to do_stuff() could unambiguously be
interpreted as a call to package_name_version_library_task_do_stuff(). This
could, hypothetically, be accomplished by letting programmers specify
exactly, both in declarations and definitions, which group of identifiers
would share a specific naming prefix, and then also specify in which block
these naming prefixes could be left implied.
What I've described is, in essence, the concept of namespaces, which has
been a part of other programming languages, such as C++, for a long time
now.
So, with this in mind, what are your thoughts on the idea of introducing
namespaces to the C programming language? Would it be a bad idea?
Rui Maciel