Interesting...

Working for some years on multiplatform / multi compiler big
performance sensitive projects( console games actually), I always find
that macro / conditional compilation WAS the consensus !
Using this for distinctions between platform specifics + version
specific + switching between several versions of the code is soooo
common  ( but, obviously, not the only used tool )
In no way I'm saying we're using this in all situations : we can have
distinct specific code in several libraries or different per platform
implementation files or using interfaces... But there are many cases
where I honestly think macro use is the very best situation...

Using interfaces adds unnecessary virtual that are really costy on
some processors.
Adding some classes make the project more complex to handle, read,
debug, maintain... Using too much macro also make the project more
complex to handle / read / debug / maintain, so you have to find a
balance between those two...
As much as we can, we try to maintain a good level on performance on
the debug versions too, in order to have them usable in the first
time, so counting on the optimiser is not a good idea !
We have a assert macro that makes use of the __line__ and __file__
special symbols
...

Beside that, I tried to open some files given with my compiler ( here
at home, so it's Visual C++ Express 2005 ) : stdlib.h, stl
implementations, etc...
They contain macro usage...
I looked into Android C++ code ( this is an android ML after
all :) )... And find macro usage...
Looked into linux sources... and find macro usage...

I'm quite suspicious thinking both My projects AND microsoft + google
+ linux developers all get it so wrong...

Emmanuel
http://androidblogger.blogspot.com/
http://www.alocaly.com/



On Apr 1, 6:28 pm, Bob Kerns <r...@acm.org> wrote:
> My first response was to say "OF COURSE YOU CAN!" -- but then I
> realized you must be talking about including or excluding data
> members, rather than the actual data.
>
> All I can say is, if you're doing that in C++, you're doing it wrong,
> and you should read up on object-oriented design patterns.
>
> C++ goes out of its way to make #ifdef unnecessary. But a lot of C++
> programmers come from a C background, or read a lot of C in the
> process of learning C++, that they never learn to properly use it. It
> doesn't help that the language is insanely complicated, and it takes a
> LOT of time and effort to become really proficient.
>
> Adding or not adding fields and methods to classes should be handled
> through subclassing and/or interfaces. And you should consider
> refactoring into collaborations of separate objects, rather than large
> flat classes.
>
> Guy Steele, the author of the Java standard, cowrote a popular book on
> C, and was a key member of Tartan Laboratories, which created
> optimizing C compilers for a wide range of platforms. James Gossling
> had a huge amount of C experience as well, implementing Gossling
> Emacs, and of course, Java. Hell, Guy used to write maintain a huge
> amount of ITS PDP-10 macro assembler, code that I also worked on as
> part of the same group at MIT, so I can say with absolute certainty --
> the designers of the Java language and its standard are VERY aware of
> conditional compilation, and the reasons it is not in the language are
> to make it a better language.
>
> I can also speak from my own personal experience. It's hard to
> quantify my C/C++ experience, but it goes back to the 1970's, long
> before there was even a dream of C++, and Java since relatively soon
> after it came out in 1995. I've mentored a lot of people both in C++
> and Java. I've also participated in language standardization efforts,
> maintained and written compilers and language runtimes.
>
> Now, all that constitutes "argument by authority", and proves nothing,
> of course.  But I'm not trying to get you to switch off your mind and
> just believe what I'm telling you. On the contrary -- when there's a
> consensus of experts, you should poke around, kick the tires, explore,
> try things, look for counter-examples, etc.
>
> One of the best type of counter-example is "X is a real gain of time",
> as you put it. My guess is that it's a gain of time for you because
> you're not familiar with other techniques, but if you'd like to post a
> more concrete example, we can discuss it and alternatives.
>
> I won't waste your time with examples of how conditional compilation
> can waste your time, as the solution is generally "don't use it that
> way".
>
> But I'm generally in favor of things that save you time. Sometimes,
> even things that save you time up front but cost you more time later.
>
> On Mar 31, 4:50 pm, Emmanuel <emmanuel.ast...@gmail.com> wrote:
>
>
>
> > Waooo...
>
> > I think you are a little bit expeditive on this one !
>
> > I really think #ifdef are a very important thing in C / C++, and I
> > missed so much in any other languages I am using !
>
> > Using static / constant data can't achieve the same thing : for
> > instance you can't have different data in a class without ifdef...
> > It makes programs more difficult to read, but you really can switch
> > from different versions of your programs much more easily, and it's a
> > real gain of time !
>
> > Emmanuelhttp://androidblogger.blogspot.com/http://www.alocaly.com/
>
> > On Mar 30, 12:36 pm, Bob Kerns <r...@acm.org> wrote:
>
> > > You do not do that in Java.
>
> > > I suggest you should not do that in C++, as there are better ways to
> > > do it.
>
> > > I suggest you do not use C.
>
> > > On Mar 30, 2:57 am, Dilip Dilip <dileep2m...@gmail.com> wrote:
>
> > > > Hi All,
> > > >  How to do conditional compilation in JAVA.
>
> > > > something like in C, C++ :
>
> > > > #ifdef TRUE_CONDITION
>
> > > > #else
>
> > > > #endif
>
> > > > Thanks and Regards,
> > > >   Dileep

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

To unsubscribe, reply using "remove me" as the subject.

Reply via email to