Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #3224

Re: Coding style for conditionals

From Victor Bazarov <v.bazarov@comcast.invalid>
Newsgroups comp.lang.c++
Subject Re: Coding style for conditionals
Date 2011-04-06 15:21 -0400
Organization A noiseless patient Spider
Message-ID <iniegf$esb$1@dont-email.me> (permalink)
References <b8402511-f313-4b06-90da-6ccbcc9cb817@a17g2000yqn.googlegroups.com>

Show all headers | View raw


On 4/6/2011 3:05 PM, mzdude wrote:
> I have no interest in starting a religious war on the subject, but
> I've
> been doing some code reviews and running across code like
>
> Method 1:
> int x;
> if(  0 == ( x = MyFunct() ) )
>      //  do something
>
> I personally don't like the style. I seem to remember there were
> reasons not to do this but
> today google is not my friend. I can't find any reasons against this.
> Are there valid reasons
> not to do this style?

Doesn't "pronounce" well.  I can't come up with a good "spelling" of 
this when I, say, talk to somebody on the phone.

> I would prefer
>
> Method 2:
> const int x = MyFunct();
> if( 0 == x )
> 	// do something
>
> reasons for method 2
> 1) declare and initialize
> 2) allows variable to be const
>
> Are they any valid reasons to not do method 1?

They are valid.

I would prefer

    ... if (x == 0)

but I read/heard all arguments for your way (no need to repeat those, 
thank you).

Aside from satisfying someone's whim about writing in C style, I don't 
see any reason to define a variable without initializing it (in a case 
like yours).

V
-- 
I do not respond to top-posted replies, please don't ask

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Coding style for conditionals mzdude <jsanga@cox.net> - 2011-04-06 12:05 -0700
  Re: Coding style for conditionals Victor Bazarov <v.bazarov@comcast.invalid> - 2011-04-06 15:21 -0400
  Re: Coding style for conditionals Joshua Maurice <joshuamaurice@gmail.com> - 2011-04-06 15:24 -0700
    Re: Coding style for conditionals Michael Doubez <michael.doubez@free.fr> - 2011-04-07 05:28 -0700
  Re: Coding style for conditionals "MikeWhy" <boat042-nospam@yahoo.com> - 2011-04-06 19:58 -0500
  Re: Coding style for conditionals gwowen <gwowen@gmail.com> - 2011-04-07 00:10 -0700
    Re: Coding style for conditionals mzdude <jsanga@cox.net> - 2011-04-07 04:57 -0700
    Re: Coding style for conditionals gwowen <gwowen@gmail.com> - 2011-04-07 06:06 -0700
      Re: Coding style for conditionals gwowen <gwowen@gmail.com> - 2011-04-07 07:02 -0700
        Re: Coding style for conditionals gwowen <gwowen@gmail.com> - 2011-04-07 08:31 -0700
          Re: Coding style for conditionals Puppet_Sock <puppet_sock@hotmail.com> - 2011-04-07 13:26 -0700
          Re: Coding style for conditionals gwowen <gwowen@gmail.com> - 2011-04-07 23:07 -0700
            Re: Coding style for conditionals gwowen <gwowen@gmail.com> - 2011-04-08 01:44 -0700
              Re: Coding style for conditionals "io_x" <a@b.c.invalid> - 2011-06-05 09:04 +0200
            Re: Coding style for conditionals Michael Tsang <miklcct@gmail.com> - 2011-04-09 22:23 +0800
        Re: Coding style for conditionals Marek Borowski <marek_remove_@borowski.com> - 2011-04-08 13:23 +0200
          Re: Coding style for conditionals gwowen <gwowen@gmail.com> - 2011-04-08 05:33 -0700
        Re: Coding style for conditionals "robertwessel2@yahoo.com" <robertwessel2@yahoo.com> - 2011-04-08 16:07 -0700
          Re: Coding style for conditionals Leigh Johnston <leigh@i42.co.uk> - 2011-04-09 00:36 +0100
          Re: Coding style for conditionals "robertwessel2@yahoo.com" <robertwessel2@yahoo.com> - 2011-04-09 06:25 -0700
            Re: Coding style for conditionals Öö Tiib <ootiib@hot.ee> - 2011-04-09 07:28 -0700
  Re: Coding style for conditionals Juha Nieminen <nospam@thanks.invalid> - 2011-04-09 07:32 +0000

csiph-web