[openbeos] Re: ifdef style

  • From: Steven Hoefel <stevenhoefel@xxxxxxxxxxx>
  • To: <openbeos@xxxxxxxxxxxxx>
  • Date: Mon, 26 Feb 2007 08:58:25 +1100

Something like this?
 
if (fDeviceIcon) {     #ifdef __HAIKU__         
Menu()->SetDrawingMode(B_OP_ALPHA);          if (!IsEnabled()) {            
Menu()->SetHighColor(0, 0, 0, 64);               
Menu()->SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_OVERLAY);  
        }         #else         if (IsEnabled())
            Menu()->SetDrawingMode(B_OP_OVER);          else 
            Menu()->SetDrawingMode(B_OP_BLEND);    #endif
    Menu()->DrawBitmapAsync(fDeviceIcon, where); 
}



> Date: Sun, 25 Feb 2007 22:48:03 +0100> From: bonefish@xxxxxxxxxxxxxxx> 
> Subject: [openbeos] Re: ifdef style> To: openbeos@xxxxxxxxxxxxx> > > On 
> 2007-02-25 at 22:19:57 [+0100], Jonas Sundström <jonas@xxxxxxxxxxx> > wrote:> 
> > Which ifdef:ing is the most desirable in this case?> > (OT's coding 
> guidelines don't mention defines.)> > > > This:> > > > if (fDeviceIcon) {> > 
> if (IsEnabled()) {> > #ifdef __HAIKU__ > > 
> Menu()->SetDrawingMode(B_OP_ALPHA);> > #else> > 
> Menu()->SetDrawingMode(B_OP_OVER);> > #endif> > }> > else {> > #ifdef 
> __HAIKU__> > Menu()->SetDrawingMode(B_OP_ALPHA); > > 
> Menu()->SetDrawingMode(B_OP_ALPHA);> > Menu()->SetHighColor(0, 0, 0, 64);> > 
> Menu()->SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_OVERLAY);> > #else> > 
> Menu()->SetDrawingMode(B_OP_BLEND);> > #endif> > } > > > > 
> Menu()->DrawBitmapAsync(fDeviceIcon, where);> > }> > > > > > Or this:> > > > 
> #ifdef __HAIKU__> > if (fDeviceIcon) {> > if (IsEnabled()) {> > 
> Menu()->SetDrawingMode(B_OP_ALPHA);> > }> > else {> > 
> Menu()->SetDrawingMode(B_OP_ALPHA); > > Menu()->SetDrawingMode(B_OP_ALPHA);> 
> > Menu()->SetHighColor(0, 0, 0, 64);> > 
> Menu()->SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_OVERLAY);> > } > > > > 
> Menu()->DrawBitmapAsync(fDeviceIcon, where);> > }> > #else> > if 
> (fDeviceIcon) {> > if (IsEnabled())> > Menu()->SetDrawingMode(B_OP_OVER);> > 
> else> > Menu()->SetDrawingMode(B_OP_BLEND); > > > > 
> Menu()->DrawBitmapAsync(fDeviceIcon, where);> > }> > #endif> >> > I think the 
> latter is a lot easier to read, but leaves up to the> > reader to understand 
> what the diff is between the two cases,> > (the actual drawing mode setting), 
> which of course in this case'> > is very easy to see. Is this okay?> > I 
> would probably choose the second version, but move the common first and > 
> last 3 lines out of the #ifdef. What you do is what you like best though. > 
> There is no real guideline, save the general one to prefer code that is > 
> better to read.> > > Also, is it really necessary to #endif // __HAIKU__ or 
> is that> > only used for multipage #ifdefs, such as header guards ?> > Again, 
> no real guideline. For multipage #ifdefs it is definitely a must, > for a few 
> lines it is acceptable to omit the comments, I think. The second > version is 
> already a borderline case, IMHO. The more interesting question > is actually 
> what the comments should say, though. Probably:> > ...> #else // # 
> !defined(__HAIKU__)> ...> #endif // # !defined(__HAIKU__)> > A simple 
> "!__HAIKU__", although not quite correct, would be OK, too, I > guess.> > CU, 
> Ingo> 
_________________________________________________________________
Explore the seven wonders of the world
http://search.msn.com/results.aspx?q=7+wonders+world&mkt=en-US&form=QBRE

Other related posts: