6.20.2011

Offline repost #3: The wondrous wonders of macros

The wondrous wonders of macros

Macros are very useful tools to create something completely abstract and out-of-content: They don't require types, they don't requires prototypes. They just are and work in their own ruleset. Before I started using C that much, I believed that macros are completely evil in any possible circumstance. That's wrong. That's entirely, totally wrong. There's nothing evil except human fail and desire. The line that macros are evil is mostly used in combination with style guides, good practive write-ups for C++ and so on. It is true that C++ doesn't need macros as much as generic C does. But it's not that they screw up everything. Their are situations where macros are very, very useful - range collision, series of logical decisions to determine certain relationships between already calculated values and so on. Macros shouldn't be confused with functions and never written to do alghorithmic behaviour except you're planning a more complex system of code generation that should be cleanly seperated from normal code. I think that's also the reason why some people spread the word "evil" round the coder globe. Most C++ don't know how they are useful cause they don't program in C and have other problems to cope with. In general it's something bound to C code rather than to any other language. One can do simple and very efficient things with macros in C as well as with inline templates in C++.

It's sad to see how rarely it's explained what macros are useful for, that they are not evil but lost their purpose in contemporary C++ programming. Maybe that's because C++ programmers don't have enough C experiences to round it up or just because they like to plant nightmares in newbie programmer's heads. Let's say macros are a powerful but rarely to use element in C and a compatibility artifact in C++. They have their reasons to exist as well inline templates have. It's like always: C offers you awesome freedom while not taking responsibility for the results YOU programmed. It's a liberal language with some simple guidelines and a lot of syntactic sugar. Nowadays it requires more professionality than in other languages and a bit of perverted taste. Where others force to HOW your application is build up, C only forces you too keep a basic paradigm (and even that can be avoided if you need to). No classes, no framework entry points, no events, only simple functions. But almost everyone forgets how - theoretically - few facts one need to know about the C language itself to archieve almost anything other apps do nowadays. It's not a simply language but it's very, very small. BASIC languages on the other side demand you to browse through many, many API listings. C does have a standard library, yes, but you can also program in C without it. It's just not necessary cause it's also written in C or sometimes assembler. Java on the other side is imho quite strict and has more rules to force you coding in a specific layout. Is that easy to you? Well, if want to write like Java say you - it is. If not, it becomes a cruel and uselessly complex reign over programmers.

Oh, I'm tired of letting me force how and what to program. I see C as a free mind in that soup of programming languages and paradigms. It's the organic of informatics, no... but it's surely "the craft of an old age". Though not necessarily a more civilised one...

No comments: