I just read the article "Idiomatic Programming" and it tried to stress an important concept: that the language should not dictate how you solve the problem, rather you should dictate how the language ought to solve a problem.
As an example, the author chose the C/C++ Preprocessor to do two things:
Enforce Consistency
Add Syntax and Grammar to the existing language.
Now, I know this article dates back to at least 2003 and is using the C language, but I have seen other people use at least point 1. before (Ogre 3D for example).
The example given is:
#define property(name, type) : \
type m##name; \
public: \
type name() \
{ return m##name; } \
void name(type t__##name) \
{ m##name = t__##name; }
used like this:
class MyClass
{
protected property(age, unsigned short);
private property(gpa, float);
private: // Other stuff can go here
};
Aside from the fact that macros are evil and we should use modern C++ variants, to my knowledge there is no suitable alternate solution, and I believe this is the sort of thing Boost.Wave and Boost.Preprocessor was made to clarify and enhance.
I believe this has some merit, but I would like to know from people having used/seen this, what are your thoughts? Do the author's points and example still have merit, or is it something to be read, taken into quiet consideration and stashed away as a nice-to-know tidbit?
EDIT
Thank you for the answers!
I wish to quickly elaborate on the nature of the question. It is not a "Is this example good to use or not?" question, it is an example of the type of changes and extensions the author proposes to enrich or enhance the existing language. Therefore, the question is: is it admissable to abuse the preprocessor to add language extensions and enforce consistency based on the example of this and other macro snippets?