dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 22 of 22

Thread: C++ (boolean)? do if true : do if false;

  1. #16
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,554

    Re: C++ (boolean)? do if true : do if false;

    Quote Originally Posted by nuzzle View Post

    So you're dead wrong. Your're confusing your personal taste with good programming style. Your preferrance is not law to everybody else. I say drop this pompous attitude not to make a fool out of yourself.

    (*) C++ Coding Standards by Sutter & Alexandrescu.
    I really don't think there's any reason to get personal here.

  2. #17
    Join Date
    May 2009
    Posts
    2,413

    Re: C++ (boolean)? do if true : do if false;

    Quote Originally Posted by GCDEF View Post
    I really don't think there's any reason to get personal here.
    So your opinion is not personal? Then who are you representing at this forum?

    You got personal before I did. Crawl back to where you come from before accusing me of ad hominem.
    Last edited by nuzzle; January 31st, 2012 at 11:13 PM.

  3. #18
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,513

    Re: C++ (boolean)? do if true : do if false;

    Stop me if I'm wrong, but that document is mostly rules about the content of code, and has very little on about style per say...

    At best, it says:
    *1 variable declaration per line.
    *1 statement per line.
    * the "&" and "*" symbols when declariung variables should be attached to the type (and not the variables)

    Doesn't really say where to put brackets and how to indent.

    ----
    Over the years, I've found that the best coding standard is simply to code with exactly the same standard being used in the current document you are in:
    *If it is a brand new file, knock yourself out
    *When editing an existing file, and not following the current style, then you are making a mess of things.
    Is your question related to IO?
    Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
    It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.

  4. #19
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,762

    Re: C++ (boolean)? do if true : do if false;

    Quote Originally Posted by monarch_dodra
    Stop me if I'm wrong, but that document is mostly rules about the content of code, and has very little on about style per say...
    (...)
    Doesn't really say where to put brackets and how to indent.
    The message may have been lost in translation because of nuzzle's rather fierce response, but if we refer to the source, Stroustrup states that "the main point of a C++ coding standard is to provide a set of rules for using C++ for a particular purpose in a particular environment." He goes on to say that "design issues (...) are far more important than the choice of layout style". So, you were apparently mainly looking out for layout style with respect to indentation and brace placement and hence missed the stuff on naming conventions and various other aspects of style.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  5. #20
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,513

    Re: C++ (boolean)? do if true : do if false;

    Quote Originally Posted by laserlight View Post
    So, you were apparently mainly looking out for layout style with respect to indentation and brace placement and hence missed the stuff on naming conventions and various other aspects of style.
    Don't get me wrong, I've read that document end-to-end many times before, and even made some of my colleagues read it

    I'm just saying it appeared to me as if this argument started out on a minor style argument, and then this document came up...

    That said, I don't usually completely read arguments, so I may have been off topic, sorry.

    ----
    As for the "return in the middle of the function issue", I've always thought it is more of a matter of context and what the reader expects. I've always proffered the "bullet list of check, else return", then the monolithic "if-if-if-if-if-if-if-do-something-giant-diagonal-line-of-closing-brackets" (link)
    Is your question related to IO?
    Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
    It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.

  6. #21
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,554

    Re: C++ (boolean)? do if true : do if false;

    Quote Originally Posted by nuzzle View Post
    So your opinion is not personal? Then who are you representing at this forum?

    You got personal before I did. Crawl back to where you come from before accusing me of ad hominem.
    I pointed out some problems I see with that style. I didn't and wouldn't attack you personally.

    It's not an opinion that if you write
    Code:
    if(a == b) b = c;
    then run that in the debugger, you can't tell how the if condition evaluates by stepping. That's a fact.

  7. #22
    Join Date
    Aug 2005
    Location
    San Diego, CA
    Posts
    1,054

    Thumbs up Re: C++ (boolean)? do if true : do if false;

    Quote Originally Posted by sankou View Post
    I'm having an issue in one of my functions. I'm trying to format my if statement using the ? and : because I thinks it looks nicer and makes things more readable. But I keep getting an error.

    This is the code:
    Code:
    if(m_search != m_first->prev)
         m_search = m_search->next;
    else
         return;
    I want it to look like this:
    Code:
    (m_search != m_first->prev) ? m_search = m_search->next : return;
    However I get the following error.
    1>c:...\projects\program1\linklist.h(155): error C2059: syntax error : 'return'

    Are you not allowed to return when using that format? Or am I just writing it wrong?

    Oh, and it's a void function by the way.
    Even if what you wrote compiled, I fail to see how that would be easier to read. I find the ternary / conditional operator to be a weird syntax for someone to read. I've recently noticed that this was observed by those who worked on the python project and they specifically avoided that kind of syntax due to it being hard to read. The python way of doing the equivalent is far more intuitive. That being said, I would personally avoid the C++ conditional operator in that example for the same reasons as others have indicated. In other words, I'd only use it for very simple kinds of expressions. There is really nothing wrong with writing out the if..else blocks and that is much clearer, even if it is more verbose. That's just my two cents, and that is only my opinion.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)