Avoiding evil macros

  • Thread starter Cephalobus_alienus
  • Start date
N

noone

I'll never understand why people feel that macros are so bad that they
will work so hard at comming up with some convoluted template mess to
replace them just because they don't like them for some reason.

I agree with you that there persists an irrational fear of macros. I do
embedded robotics code on ARM, PPC, and Intel platforms and I NEEEEEED
macros to get my unified build procedures to work. My code has a lot of
platform specific stuff in it and I certainly consider that to be a good
reason to use them.

OTOH, using macros as shortcuts for code repetition in C++ is problematic
and I think a lot of the fear of macros came about because of that
particular misuse.
 
A

AzizMandar

Alf said:
* Howard:

Assuming any half-decent coding standard:

if(!)nl{nl nl} 9
||; 3



Yes. :)

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Oh come on compare it equally at least

if (!a) ::b; 12 (10 without required spaces)

a != 0 || ::b; 14 (10 without required spaces)

if you think the IF then statement needs the return and brackets for
readability then you are supporting the argument that yours is harder
to read. Personally I think the if is easier for everyone to read
(more common in text and classes) and flow nicely for those who read
the English language more than code. The second is more obscure.
Over all they look to evaluate to the exact same assembler so no foul
either way.

Most instructors and industry professionals say readability (for others
not just you) is more important than spiffy obscure (possibly space
saving) code.


as for the original macro issue check this out
http://www.research.att.com/~bs/bs_faq2.html#macro

as always no one can make you code in any specific way (though it could
cost you your job) but when you disagree with the creator of the
language you use on too many topics you have to wonder if you are
really using the right language.
 
N

Noah Roberts

Since my template skills are rather underdeveloped, it made sense to
me to join a newsgroup where people considerably more knowledgeable
and skilled than I am in these matters could give me advice. What is
irrational about wanting to learn? Now, it turns out that there just
isn't a template solution to the problem as I defined it, and I've
added something significant to my store of knowledge.

Well, that isn't how you brought this up. You didn't say you where
doing this to learn, you said you where doing this to avoid "evil".
 
C

Cephalobus_alienus

Noah said:
Well, that isn't how you brought this up. You didn't say you where
doing this to learn, you said you where doing this to avoid "evil".

A minor misunderstanding between us, then.
Hopefully no harm done. ;-)

Jerry
 
A

Alf P. Steinbach

* AzizMandar:
[quoting signatures]

Please don't quote signatures in postings in this group. Thank you.
Corrected.


* AzizMandar:
Oh come on compare it equally at least

if (!a) ::b; 12 (10 without required spaces)
a != 0 || ::b; 14 (10 without required spaces)

That kind of comparision would be

if(!a)::b; // 10
a||::b; // 7

So even without decent formatting the || wins hands down on number of
characters.

Not that number of characters is or ever was an issue: it was a joke,
that you didn't get.

if you think the IF then statement needs the return and brackets for
readability then you are supporting the argument that yours is harder
to read. Personally I think the if is easier for everyone to read
(more common in text and classes) and flow nicely for those who read
the English language more than code. The second is more obscure.
Over all they look to evaluate to the exact same assembler so no foul
either way.

Decent coding standards require the braces. It has to do not just with
readability but also with maintainability. As a general rule, always
put braces around your 'if' and 'while' bodies.

Most instructors and industry professionals say readability (for others
not just you) is more important than spiffy obscure (possibly space
saving) code.

Yes, correct.

as for the original macro issue check this out
http://www.research.att.com/~bs/bs_faq2.html#macro

as always no one can make you code in any specific way (though it could
cost you your job) but when you disagree with the creator of the
language you use on too many topics you have to wonder if you are
really using the right language.

I've never disagreed with Bjarne Stroustrup on that issue nor on "many
topics". The only public disagreement with Bjarne that I can remember
was a discussion of whether it's more practical to display C++ code in
monospaced font or not in books and articles. The above is an unfounded
insinuation for which you owe me an apology.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top