4 ms·
In my more nieve days I used to genuinely believe that macros were a cool language feature. Now after spending some time in C/C++ I think macros are the enemy o
by UnoriginalGuy 12y ago
In my more nieve days I used to genuinely believe that macros were a cool language feature. Now after spending some time in C/C++ I think macros are the enemy of code readability, and I think this article summarises WHY nicely.
I'm sure there is some political reason why ldbl_strong_alias was used to rename printf to __printf, but frankly I don't really care, there are macros like that all over the C/C++ libraries that make finding the source for anything pure hell.
The only acceptable macro to me now is a block which only runs in the DEBUG build and is skipped over by the compiler in RELEASE.
PS - Yes this is why I don't code in C/C++ very often. I'm currently playing with Go which has no concept of macros.
- zem 12y agothe very few times you want the source to something to debug it etc. you'll have a hard time. the 99% of the time when you want not the implementation details but some semantically meaningful mapping of one token to one concept, macros are wonderful. another huge benefit is that they take care of fiddly bookkeeping for you - if you have to remember some incantation that involves doing several steps in sequence and making sure that if you change place A you need to change B and C in certain ways, just write a macro and be happy.