UTF-16 & wchar_t: the 2nd worst thing about C++

  • Thread starter Steven T. Hatton
  • Start date
S

Steven T. Hatton

Phlip wrote:

Anyone who learns only part of a language, and its styles and idioms, will
have the potential to abuse some feature. You could say the same thing
about 'if' statements. They have a great potential for abuse. Yet you
don't often read posts here bragging "I know better than to abuse 'if'
statements!!"

Have you ever inadvertently defined a header guard to be the same value as
one used by a 3rd party library? Ever had a macro collision between two
libraries? And then there are, of course, the more straight forward
problems such as changing the name of a source file, answering the phone,
and creating a new source file with the same name as the original.

There are places where I've seen the CPP used effectively to do things in a
better way than any I can come up with. For example:

http://websvn.kde.org/trunk/KDE/kdevelop/languages/cpp/parser/ast.h?rev=467420&view=markup
 
P

Phlip

Steven said:
Ever had a macro collision between two
libraries?

Yes, and I have also written the wrong stuff inside an 'if' statement!

All languages have trade-offs between elegant things and icky things.

Now imagine if you wrote that on the job, and solved a tricky problem.
However, your supervisor once wrote a book that advised against many kinds
of code abuse - common in his industry - and then had to review your work.
Maybe he can't see past the macros to the elegant results. Maybe your
staying power at that company goes way down. Just because others abused some
language feature and he wrote a book about it.

Here's an even better example of macro elegance:

http://www.codeproject.com/macro/metamacros.asp
 
S

Steven T. Hatton

Phlip said:
Yes, and I have also written the wrong stuff inside an 'if' statement!

If you are experiencing macro-like problems when using them, I will suggest
avoiding global variables, and to use the scoping facilities of the
language. Something which is not an option with the CPP.
All languages have trade-offs between elegant things and icky things.
http://websvn.kde.org/trunk/KDE/kdevelop/languages/cpp/parser/ast.h?rev=467420&view=markup

Now imagine if you wrote that on the job, and solved a tricky problem.
However, your supervisor once wrote a book that advised against many kinds
of code abuse - common in his industry - and then had to review your work.
Maybe he can't see past the macros to the elegant results. Maybe your
staying power at that company goes way down. Just because others abused
some language feature and he wrote a book about it.

Not really a major problem in the case of the r++ code. I've already done a
regexp replacement on all the macros with the resulting code working just
fine.
Here's an even better example of macro elegance:

http://www.codeproject.com/macro/metamacros.asp

Perhaps I've failed to appreciate something, but I don't find the example
overly compelling. I've been working on someting similar using templates.
One big difference is that with templates I can use type information to
form hierarchies of "typelets". The biggest shortcoming of themplates
verses macros is that macros can use one string for both code generation
and string literal creation. But a bit of `C-M-%' deals with that. To get
hard strings into templates use char[], and wrap them in an anonymous
namespace to avoid ODR indictments. If I really need high-powered string
manipulation, I have tools that make sawdust out of the CPP. In addition
to stringification, another advantage of the CPP, one that other approaches
don't offer, is the ability to distribute the unexpanded macros to anybody
with a standard C++ implementation and know they will be expanded
predictably - barring the possibility of macro collisions. But the avian
flue also has the ability to have it's code understood and expanded by most
hosts.
 
P

Phlip

Steven said:
If you are experiencing macro-like problems when using them, I will
suggest
avoiding global variables, and to use the scoping facilities of the
language. Something which is not an option with the CPP.

You are having fun arguing with things I'm not saying.
 

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

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,113
Latest member
KetoBurn
Top