Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2005

Tip: Looking for answers? Try searching our database.

if statement

Thread view: 
geletine - 16 Nov 2005 15:39 GMT
I am a bigginner java programmer, thats obvious from the post, anyway i
am trying out this experiment, the program asks the users name, there
sex and there age.

the name is nothing more than a name, there sex determines weather they
can get a senior travel discount at 60 for females and 65 for males,
the standard discount can also be given to anyone 16 or under, anyone
older than 16 and younger than 60 cannot get a discount, anyone older
than 150 is considered dead.

I think i should be using two diffrent if statements, instead i have
combinded them together.

I start of by asking what there name is then there sex, if they are
male it asks there age and should decided weather there are 65 and
older to give them a senior bus card or under 65 but older than 16 to
give them no discount, if there 16 and younger a travelcard discount
and if they are over 150 there should be dead.

If they are not male then it asks if they are 60 or over, if they are
they get a senior travelcard if there 16 and younger a travelcard , if
they older than 16 but younger than 60 no travelcard and lastly if
there over 150 they should be dead.

here is my first attempt, :

import java.io.*;

public class bus

{

    public static void main (String args [])throws IOException

{

      String name, input, male;

      int age;

BufferedReader info = new BufferedReader ( new InputStreamReader (
System.in ) );

    System.out.println ("Enter your name");

    input = info.readLine();

    name = input;

   System.out.println ("Are you male? ");

   input = info.readLine();

   male = input;

    System.out.println ("Enter your age");

    input = info.readLine();

       age = Integer.parseInt ( input );

  if ((male) || (age >= 65))

  {

      System.out.println ( name + " is entitled to a senior travelcard
");

  }

  else if ((male) || (age < 65))

  {

     System.out.println ( name + " is not entitled to a senior
travelcard ");

 }

else if           ((male) || ( age >= 150))

    {

        System.out.println ( name + " , you are kidding, what are you on?
");

    }

    else if (age >= 150)

    {

           System.out.println ( name + " , you are kidding, what are
you on ? ");

    }

else    if (age <= 16)

    {

        System.out.println ( name + " is entitled to a bus pass");

    }

else if (age >=  60)
       {
          System.out.println (name + " is entitled to a senior bus
pass ");
       }

else

    {

        System.out.println ( name + " is  not allowed a bus pass");

    }

   

    }

    }
Roedy Green - 16 Nov 2005 15:54 GMT
>if ((male) |

you declared male as a string, presumably to contain "Y" "y" "male"
"M" or the like.

And you tried to use it as a boolean.  You need to write some code to
convert from the string to the boolean.

You might do it with a switch

 switch ( input.charAt(0) )
 {
case  'y':
case  'm':
....
  male = true;
 break;
....

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

J. Verdrengh - 16 Nov 2005 16:02 GMT
Have a look at this:

import java.io.*;

public class Bus{
   public static void main (String args []) throws IOException{
       BufferedReader info = new BufferedReader ( new InputStreamReader
(System.in ) );

       System.out.println ("Enter your name");
       String name = info.readLine();

       System.out.println ("Are you male? ");
       String male= info.readLine();

       System.out.println ("Enter your age");
       int age = Integer.parseInt (info.readLine());

       bool isMale = male.equals("yes");
       int borderAge = -1;
       if (isMale){
                   borderAge = 65;
       } else {
                   borderAge = 60;
       }

       if (age <= 16) {System.out.println ( name + " is entitled to a bus
pass");}
      else if(age>=borderAge && age<150) System.out.println ( name + " is
entitled to a senior travelcard");
      else if(age<borderAge ) System.out.println ( name + " is not entitled
to a senior travelcard ");
      else System.out.println ( name + " , you are kidding, what are you
on?");
  }
}
J. Verdrengh - 16 Nov 2005 16:08 GMT
>        bool isMale = male.equals("yes");

bool should be boolean
Roedy Green - 16 Nov 2005 20:48 GMT
>int borderAge = -1;
>        if (isMale){
>                    borderAge = 65;
>        } else {
>                    borderAge = 60;
>        }

Most java programmers would write that with the ternary operator as:

   int borderAge = isMale ? 65 : 60;
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Monique Y. Mudama - 16 Nov 2005 21:24 GMT
>>int borderAge = -1;
>>        if (isMale){
[quoted text clipped - 6 lines]
>
>     int borderAge = isMale ? 65 : 60;

I guess I'm not most java programmers.  I find the if/else syntax much
clearer.  In fact, I just found a bug in someone else's code in which
the second and third arguments to the ternary operator were reversed;
I'd imagine the bug would have been more obvious if written using
if/else blocks instead.

Signature

monique

Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html

Oliver Wong - 16 Nov 2005 21:39 GMT
>>>int borderAge = -1;
>>>        if (isMale){
[quoted text clipped - 12 lines]
> I'd imagine the bug would have been more obvious if written using
> if/else blocks instead.

   Also, Java does some short circuiting with the ternary operator, so
that:

int borderAge = isMale ? getMaleBorderAge() : getFemaleBorderAge();

   will only result in one method call, which may or may not be the
intention of the programmer (this is important if the methods have some sort
of side effect). Rewriting this as an if-else-statement usually makes the
intent explicit.

   - Oliver
Thomas G. Marshall - 17 Nov 2005 02:31 GMT
Oliver Wong coughed up:

>>>> int borderAge = -1;
>>>>        if (isMale){
[quoted text clipped - 19 lines]
>
>    will only result in one method call,

*Same* as with the if/else.

> which may or may not be the
> intention of the programmer (this is important if the methods have some
> sort
> of side effect). Rewriting this as an if-else-statement usually makes the
> intent explicit.

Huh?  Explicit how?  The if/else *might* have been arranged differently, but
then, so might the code containing the ?: ternary.

Signature

I've seen this a few times--Don't make this mistake:

Dwight: "This thing is wildly available."
Smedly: "Did you mean wildly, or /widely/ ?"
Dwight: "Both!", said while nodding emphatically.

Dwight was exposed to have made a grammatical
error and tries to cover it up by thinking
fast.  This is so painfully obvious that he
only succeeds in looking worse.

Oliver Wong - 17 Nov 2005 15:59 GMT
> Oliver Wong coughed up:
[snip]
>>    Also, Java does some short circuiting with the ternary operator, so
>> that:
[quoted text clipped - 13 lines]
> Huh?  Explicit how?  The if/else *might* have been arranged differently,
> but then, so might the code containing the ?: ternary.

   What I was getting at is that short circuiting happens rarely (I believe
it only happens for the ?:, || and && operators), and so a beginning
programmer might (wrongly) assume that it does not happen for the ternary
operator.

   As such, the programmer might expect all three expressions to get
evaluated. If the intention truly was to ensure that everything gets
evaluated, it might have been clearer to write the code as:

<code>
int result1 = getMaleBorderAge();
int result2 = getFemaleBorderAge();
if (isMale) {
 int borderAge = result1;
} else {
 int borderAge = result1;
}
</code>

   In other words, I think a higher percentage of Java programmers will
correctly determine what this code does:

<code>
int borderAge;
if (isMale) {
 borderAge = getMaleBorderAge();
} else {
 borderAge = getFemaleBorderAge();
}
</code>

than this code:

<code>
int borderAge = isMale ? getMaleBorderAge() : getFemaleBorderAge();
</code>

   - Oliver
Gordon Beaton - 17 Nov 2005 15:49 GMT
> What I was getting at is that short circuiting happens rarely (I
> believe it only happens for the ?:, || and && operators), and so a
[quoted text clipped - 4 lines]
> evaluated. If the intention truly was to ensure that everything gets
> evaluated, it might have been clearer to write the code as:

The only time it's important to evaluate every component of a compound
expression is when those components are not side-effect free. And if
that's the case, your expression is more correctly called a statement,
in which case if-else (i.e. the conditional statement) is an
appropriate choice.

If your expressions have no side-effects (i.e. only their values are
important), then I see no reason not to choose the conditional
operator (aka ternary operator) to produce a compound expression.

I don't see what all the fuss is about.

/gordon

Signature

[  do not email me copies of your followups  ]
g o r d o n + n e w s @  b a l d e r 1 3 . s e

Roedy Green - 16 Nov 2005 21:41 GMT
On Wed, 16 Nov 2005 14:24:44 -0700, "Monique Y. Mudama"
<spam@bounceswoosh.org> wrote, quoted or indirectly quoted someone who
said :

>>     int borderAge = isMale ? 65 : 60;
>
[quoted text clipped - 3 lines]
>I'd imagine the bug would have been more obvious if written using
>if/else blocks instead.

Objectively, the ternary form is clearer. There is less distracting
bubblegum and redundancy.  What you really mean is the ternary form is
less familiar.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Monique Y. Mudama - 16 Nov 2005 22:14 GMT
> On Wed, 16 Nov 2005 14:24:44 -0700, "Monique Y. Mudama"
><spam@bounceswoosh.org> wrote, quoted or indirectly quoted someone
[quoted text clipped - 11 lines]
> bubblegum and redundancy.  What you really mean is the ternary form
> is less familiar.

Objectively, I think you're wrong.  I really mean that I think the
if/else syntax is clearer, just as I think that using curly braces and
parentheses even when they are not required by the compiler can make the
code clearer.

Signature

monique

Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html

Thomas G. Marshall - 17 Nov 2005 02:35 GMT
Monique Y. Mudama coughed up:
>> On Wed, 16 Nov 2005 14:24:44 -0700, "Monique Y. Mudama"
>> <spam@bounceswoosh.org> wrote, quoted or indirectly quoted someone
[quoted text clipped - 16 lines]
> parentheses even when they are not required by the compiler can make the
> code clearer.

Objectively, I think you're wrong.  There is far less clutter to express the
same thing.  The only reason I can see that someone might think that

       int borderAge = isMale ? 65 : 60;

is somehow less clear than

       int borderAge;
       if (isMale)
           borderAge = 65;
       else
           borderAge = 60;

is simply because they are less familiar with :? or otherwise somehow
spooked by it.

Signature

I've seen this a few times--Don't make this mistake:

Dwight: "This thing is wildly available."
Smedly: "Did you mean wildly, or /widely/ ?"
Dwight: "Both!", said while nodding emphatically.

Dwight was exposed to have made a grammatical
error and tries to cover it up by thinking
fast.  This is so painfully obvious that he
only succeeds in looking worse.

Roedy Green - 17 Nov 2005 02:47 GMT
On Thu, 17 Nov 2005 02:35:23 GMT, "Thomas G. Marshall"
<tgm2tothe10thpower@replacetextwithnumber.hotmail.com> wrote, quoted
or indirectly quoted someone who said :

>   int borderAge = isMale ? 65 : 60;

This is elegant. Every fact is specified only once with the absolute
minimum of clutter.

Perhaps having a way to speak it internally to yourself might help you
appreciate it.

I would say that to myself as

  int borderAge is  isMale  (question-inflection -- swoop up on word
male) 65 otherwise 60

The other form has redundancy:

 int borderAge;
       if (isMale)
           borderAge = 65;
       else
           borderAge = 60;

you specify the borderAge fact 3 times.  You must by eye notice that
all three are ABSOLUTELY IDENTICAL otherwise the idiom is misleading
e.g.

 int borderAge;
       if (isMale)
           borderAge = 65;
       else
           borderage = 60;

Try an even longer variable name and you see the problem more clearly

 int x_coordinate_top_left;
       if (isMale)
           x_coordinatetop_left= 65;
       else
           x_coordinatetop_left= 60;
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Thomas G. Marshall - 17 Nov 2005 14:20 GMT
Roedy Green coughed up:
> On Thu, 17 Nov 2005 02:35:23 GMT, "Thomas G. Marshall"
> <tgm2tothe10thpower@replacetextwithnumber.hotmail.com> wrote, quoted
[quoted text clipped - 7 lines]
> Perhaps having a way to speak it internally to yourself might help you
> appreciate it.

REREAD what I wrote.  I advocate the :? !!!

...[misdirected examples snipped]...

Signature

It's time for everyone to just step back, take a deep breath, relax, and
stop
throwing hissy fits over crossposting.

Roedy Green - 17 Nov 2005 15:58 GMT
On Thu, 17 Nov 2005 14:20:51 GMT, "Thomas G. Marshall"
<tgm2tothe10thpower@replacetextwithnumber.hotmail.com> wrote, quoted
or indirectly quoted someone who said :

>REREAD what I wrote.  I advocate the :? !!!
>
>...[misdirected examples snipped]...

You are not the only one here.  I am speaking to everyone.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Monique Y. Mudama - 17 Nov 2005 16:07 GMT
> Roedy Green coughed up:
>> On Thu, 17 Nov 2005 02:35:23 GMT, "Thomas G. Marshall"
[quoted text clipped - 12 lines]
>
> ...[misdirected examples snipped]...

Read Roedy's attribution line.

(Personally I think that attribution line is just an attempt to
justify laziness in proper snipping, but that's just me.)

Signature

monique

Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html

Roedy Green - 17 Nov 2005 02:48 GMT
On Thu, 17 Nov 2005 02:35:23 GMT, "Thomas G. Marshall"
<tgm2tothe10thpower@replacetextwithnumber.hotmail.com> wrote, quoted
or indirectly quoted someone who said :

>Objectively, I think you're wrong.  There is far less clutter to express the
>same thing.  The only reason I can see that someone might think that
>
>        int borderAge = isMale ? 65 : 60;

No matter which form you chose for your own code, you will run into
both in other people's code, so it is important to become comfortable
with both notations.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

iamfractal@hotmail.com - 17 Nov 2005 08:34 GMT
> Monique Y. Mudama coughed up:
> >> On Wed, 16 Nov 2005 14:24:44 -0700, "Monique Y. Mudama"
> >> <spam@bounceswoosh.org> wrote, quoted or indirectly quoted someone
> >> who said :

> Objectively, I think you're wrong.  There is far less clutter to express the
> same thing.  The only reason I can see that someone might think that
[quoted text clipped - 11 lines]
> is simply because they are less familiar with :? or otherwise somehow
> spooked by it.

FWIW, I think int borderAge = isMale ? 65 : 60; is more concise than
the if-statement, and less clear, precisely because the if-statement is
more like English, and so I would guess that all English speakers are
more familiar with if-statements than ternary operators.

I was in a nightclub last night: I went up to a girl and said, "Would
you like to come back to my place ? Sure, why not : not if you were the
last programmer on earth." She didn't reply. But she didn't throw an
exception, either.

.ed

--
www.EdmundKirwan.com - Home of The Fractal Class Composition.
Thomas G. Marshall - 17 Nov 2005 14:22 GMT
iamfractal@hotmail.com coughed up:
>> Monique Y. Mudama coughed up:
>>>> On Wed, 16 Nov 2005 14:24:44 -0700, "Monique Y. Mudama"
[quoted text clipped - 27 lines]
> last programmer on earth." She didn't reply. But she didn't throw an
> exception, either.

Point.  LOL.  But this just speaks to being familiar with it, though you are
correct in that if you are not familiar with it the english in your head
will not help you much.

Signature

It's time for everyone to just step back, take a deep breath, relax, and
stop
throwing hissy fits over crossposting.

Chris Uppal - 17 Nov 2005 15:07 GMT
> Objectively, I think you're wrong.  I really mean that I think the
> if/else syntax is clearer

You've got to be a bit careful here.  There are (at least) two aspects to
clarity.  One is how well does the programming construct capture the intent of
the programmer, the other is how clearly is that construct expressed in the
concrete syntax of the language.

In this case I think these two aspects work in different directions.

First off, if the concept is something like (for instance):

   if the person is female then the retirement age is 60, otherwise
   it's 65.

Note two things about that: (1) we are covering /all/ the possibilities (2) we
are using the two values (60 and 65) for the same purpose (as signified by the
fact that we don't -- and in normal English shouldn't -- repeat the phrase
"retirement age").

Now we can translate that concept into Java code using an if statement:

   if (person.isFemale())
       retirementAge = 60;
   else
       retirementAge = 65;

but that doesn't capture the concept particularly well.  There is nothing to
stop us missing off the else (either syntactically or logically); and there is
nothing to hint that the important thing is that the same variable,
retirementAge, is assigned on both branches.  So the notation is an /indirect/
expression of our intent.  It works, but it's not as clear as it should be.

Using an ?: operator, OTOH, is a very direct expression of our intention:

   retirementAge = person.isFemale()
                               ? 60
                               : 65;

The reader doesn't have to /notice/ that the same variable is assigned to in
each case -- there is only one assignment.  Similarly there is no possibility
of forgetting to cover the cases.

So, as far as that goes, the ?: operator (if used correctly) is significantly,
and objectively, clearer than an if statement.

But that's only half the story.  /Given/ that a conditional expression is to be
preferred over conditional execution of different statements, does Java's
concrete syntax convey the underlying semantics well ?  Now there, I agree, the
answer is an objective "no".  It's something that you just have to get used to.
It belongs in the long tradition of punctuation abuse, which has been a central
feature of programming language design, more-or-less from the very beginning.

The syntactic unclarity is something that you /can/ get used to (especially if
you use decent layout conventions), and with experience you find the syntax
more and more transparent.  But the unclarity in the other department is
inherent -- it's not something that goes away as you get used to it.  If
anything it's the other way around -- as your sensitivity develops you find it
more and more off-putting.

   -- chris
Stefan Ram - 17 Nov 2005 22:30 GMT
>    retirementAge = person.isFemale()
>                                ? 60
>                                : 65;

 Another possibility might be:

retirementAge = person.ifFemale( 60, 65 );

 The drawback is the evaluation of both arguments, which here
 is not so disturbing in the special case of "( 60, 65 )".

 This "ifFemale" solution follows the guideline "Don't ask
 objects for information and do it yourself, but ask the object
 that holds the information needed, to do it for you
 (delegate)." (in this case: to do the selection of a value.)

 Now, just for fun, how to avoid both arguments (i.e., "60" and
 "65") being evaluated?

retirementAge = person.ifFemale
( new java.util.concurrent.Callable<int>(){ public int call(){ return 60; }},
 new java.util.concurrent.Callable<int>(){ public int call(){ return 65; }});

 (not tested.)
Oliver Wong - 17 Nov 2005 23:03 GMT
>  Now, just for fun, how to avoid both arguments (i.e., "60" and
>  "65") being evaluated?
[quoted text clipped - 6 lines]
>
>  (not tested.)

   Objectively, I vote for this as the implemention which most closely
reflects the original intention, and hence the clearest.

   - Oliver
Monique Y. Mudama - 18 Nov 2005 00:25 GMT
>>  Now, just for fun, how to avoid both arguments (i.e., "60" and
>>  "65") being evaluated?
[quoted text clipped - 11 lines]
>
>     - Oliver

If I had liquid in my mouth, you'd owe me a new monitor right now!

Signature

monique

Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html

Chris Uppal - 18 Nov 2005 11:21 GMT
> retirementAge = person.ifFemale( 60, 65 );
>
>   The drawback is the evaluation of both arguments, which here
>   is not so disturbing in the special case of "( 60, 65 )".

What I don't like about it is the way it obscures the /meaning/ of the
arguments -- it is difficult to see which is the "if female" and which the "if
male".  That is -- of course -- more a deficiency in Java's concrete syntax
for "function" calls than a flaw in the idea.

> retirementAge = person.ifFemale
> ( new java.util.concurrent.Callable<int>(){ public int call(){ return 60;
>   }}, new java.util.concurrent.Callable<int>(){ public int call(){ return
> 65; }});

Some might argue that it's a little verbose ;-)  Again the idea is sound (and
in fact very powerful), but Java's concrete syntax isn't really up to the job.

BTW, if we're going to take the "tell, don't ask" mantra seriously then it
would probably be better to let the person decide if they are over retirement
age:

   public boolean isRetiredIn(int year);

Or, following your earlier suggestion:

   person.ifRetiredIn(
                       aYear,
                       ( new java.util.concurrent.Callable<int>(){
                               public int call()
                               {
                                       // do something
                               }},
                         new java.util.concurrent.Callable<int>(){
                               public int call()
                               {
                                       // do something else
                               }});

(not tested either ;-)

   -- chris
J. Verdrengh - 17 Nov 2005 10:46 GMT
Roedy says:
> Most java programmers would write that with the ternary operator as:
>
>    int borderAge = isMale ? 65 : 60;

ok, but you may have forgotten to read the very first line in geletine's
post: "I am a bigginner java programmer". I think your suggestion would have
been more confusing then mine.

The discussion about syntactic sugar is a discussion of tastes. I do believe
you find = ? : clearer then if-then-else and I also believe Monique thinks
the opposite. You cannot say in general which one is the clearest because
you cannot evaluate "A is more clear then B" without *choosing* a definition
for it. A definition could be "A is more clear then B iff A is more English
then B", another definition could be "A is more clear then B iff A is
shorter then B"

Jeroen
Roedy Green - 17 Nov 2005 11:20 GMT
>You cannot say in general which one is the clearest because
>you cannot evaluate "A is more clear then B" without *choosing* a definition
>for it. A definition could be "A is more clear then B iff A is more English
>then B", another definition could be "A is more clear then B iff A is
>shorter then B"

My definition is "After training, which form can I, in the least
amount of time, reliably determine what the code does."

I suggest that if textbooks taught the ternary form first, people
might decide the if form was more confusing. I think a fair bit of the
preference for if is a reluctance to learn something new.

You really have to become skilled in both before you can judge which
truly is clearer.

We have  here in miniature a situation similar to people coming to
Java from C who think every difference from C is a bug.

It is also similar to the situation where people write stuttering
boolean expressions with ==true.  They claim they are clearer, but
have not yet learned to write code without them.  How do they know
which is clearer (using my definition).

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

HalcyonWild - 17 Nov 2005 11:41 GMT
> >You cannot say in general which one is the clearest because
> >you cannot evaluate "A is more clear then B" without *choosing* a definition
[quoted text clipped - 11 lines]
> You really have to become skilled in both before you can judge which
> truly is clearer.

....  [something i deleted]....

There has to be a compromise. The ternary operator is good for single
statement if else blocks. But not when you have multiple statements,
within if and else. Ternary is just a shortcut for if-else.
For multi-statement blocks, if-else is a much better idea. Ternary
would look confusing. Imagine searching for a colon in many lines of
code, instead of a well indented if - else blocks.
charles_n_may@yahoo.com - 17 Nov 2005 14:38 GMT
One benefit the ternary operator offers over the if-else is the ability
to declare the result "final" in one line:

final int borderAge = isMale ? 65 : 60;

If you do it this way, you have compiler-checks to ensure your code
doesn't change the value of borderAge within the current scope. If you
want to achieve a final result using an if-then, you have to leave a
temporary variable dangling in order to do it, and the result is
messier:

int temp;
if (isMale) {
 temp=65;
} else {
 temp=60;
}
final int borderAge = temp;
Thomas Hawtin - 17 Nov 2005 15:38 GMT
> One benefit the ternary operator offers over the if-else is the ability
> to declare the result "final" in one line:
[quoted text clipped - 14 lines]
> }
> final int borderAge = temp;

Not true. Go read the chapter on definite assignment.

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

charles_n_may@yahoo.com - 17 Nov 2005 16:06 GMT
I stand corrected. I must have had this in my mind from a previous
experience where the else was omitted. Thanks for the reference.

For what it's worth, I prefer the ternary expression when it is not
overly verbose.

> > One benefit the ternary operator offers over the if-else is the ability
> > to declare the result "final" in one line:
[quoted text clipped - 21 lines]
> Unemployed English Java programmer
> http://jroller.com/page/tackline/
Monique Y. Mudama - 17 Nov 2005 16:14 GMT
> I stand corrected. I must have had this in my mind from a previous
> experience where the else was omitted. Thanks for the reference.
>
> For what it's worth, I prefer the ternary expression when it is not
> overly verbose.

I think the subjectiveness of your last sentence (overly verbose is in
the eye of the beholder) just goes to show that this entire argument
is about a matter of stylistic preference.

People can go on "objectively" about how ternary is better than if/else,
if/else is better than ternary, whatever.  I personally find if/else
clearer, but I find the elaborate justifications for each person's point
of view on the matter to be entertaining, in much the same way as I
prefer vi but still find vi/emacs debates amusing and bemusing.

Signature

monique

Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html

Gordon Beaton - 17 Nov 2005 15:52 GMT
> People can go on "objectively" about how ternary is better than if/else,
> if/else is better than ternary, whatever.  I personally find if/else
> clearer, but I find the elaborate justifications for each person's point
> of view on the matter to be entertaining, in much the same way as I
> prefer vi but still find vi/emacs debates amusing and bemusing.

Neither is "better" in the general case, however they are semantically
different. if-else is for creating conditional statements, while ?: is
for creating conditional expressions.

/gordon

Signature

[  do not email me copies of your followups  ]
g o r d o n + n e w s @  b a l d e r 1 3 . s e

Thomas G. Marshall - 18 Nov 2005 00:22 GMT
Monique Y. Mudama coughed up:
>> I stand corrected. I must have had this in my mind from a previous
>> experience where the else was omitted. Thanks for the reference.
[quoted text clipped - 11 lines]
> of view on the matter to be entertaining, in much the same way as I
> prefer vi but still find vi/emacs debates amusing and bemusing.

I prefer vi only because 1. I ran a small unix department where the machines
I had to port to often had nothing else, and 2. I was horrified by how just
plain /weird/ emaxs is.

Signature

"So I just, uh... I just cut them up like regular chickens?"
"Sure, just cut them up like regular chickens."

Oliver Wong - 17 Nov 2005 16:04 GMT
> One benefit the ternary operator offers over the if-else is the ability
> to declare the result "final" in one line:
[quoted text clipped - 14 lines]
> }
> final int borderAge = temp;

You can write this:

final int borderAge;
if (isMale) {
 borderAge = 65;
} else {
 borderAge = 60;
}

   - Oliver
J. Verdrengh - 17 Nov 2005 11:54 GMT
>My definition is "After training, which form can I, in the least
>amount of time, reliably determine what the code does."
Ok, but this definition is subjective: depending on the person using it, the
outcome may be different. Thus it can't be used for absolute decisions about
which form is clearer.
Oliver Wong - 17 Nov 2005 16:09 GMT
> >My definition is "After training, which form can I, in the least
>>amount of time, reliably determine what the code does."
> Ok, but this definition is subjective: depending on the person using it,
> the outcome may be different. Thus it can't be used for absolute decisions
> about which form is clearer.

   Agreed. I was surprised when Roedy opened his post with "Objectively,
this is clearer" (Less surprised when Monique and Thomas used it, as I
assume it was to point out the absurdity of describing the clarity as being
objective in the posts they were responding to).

   This is just my opinion, but I think people are allowed to form judges
about what is or isn't clear even if they haven't had training on the
subject matter. In fact, perhaps as a "true" test that a concept is a clear,
we can see if people who have NOT been trained are able to grasp the
concept. If so, then that concept must be extremely clear.

   If we agree to this definition (and I'm not saying we have, this is just
a theoretical situation here), then I think, objectively, most English
speakers will find the "if-else" form clearer than the ternary operator.

   That is, even non-programmers can guess what will happen with respect to
the "if-else" form; that's an indication of how clear it is.

   Of course, Chris Uppal made an extremely good argument (in my opinion)
for the clarity of the ternary operator; namely that it makes it clear that
the same variable is being assigned to in both branches of the condition.

   So, like so many things, it all depends on your definition of "clear"
(as Verdrengh pointed out).

   - Oliver.
Monique Y. Mudama - 17 Nov 2005 17:31 GMT
>> >My definition is "After training, which form can I, in the least
>>>amount of time, reliably determine what the code does."
[quoted text clipped - 7 lines]
>     describing the clarity as being objective in the posts they were
>     responding to).

That's certainly what I meant to convey =)

Signature

monique

Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html

Roedy Green - 17 Nov 2005 22:00 GMT
On Thu, 17 Nov 2005 10:31:04 -0700, "Monique Y. Mudama"
<spam@bounceswoosh.org> wrote, quoted or indirectly quoted someone who
said :

>>> >My definition is "After training, which form can I, in the least
>>>>amount of time, reliably determine what the code does."
>>> Ok, but this definition is subjective: depending on the person
>>> using it, the outcome may be different.

But I conjecture that it won't be.  The brevity will win out. The
problem is people are making up their minds before they are
comfortable with both syntaxes.

My definition allows an  objective experiment to settle the question.
You could conceivably find that in a population of 100 programmers not
all 100 will go the same way but you can objectively measure each
programmer's ability to accurately determine the meaning of code
presented either way.

It is not just a matter of which you like.

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Monique Y. Mudama - 17 Nov 2005 22:28 GMT
> On Thu, 17 Nov 2005 10:31:04 -0700, "Monique Y. Mudama"
><spam@bounceswoosh.org> wrote, quoted or indirectly quoted someone
[quoted text clipped - 16 lines]
>
> It is not just a matter of which you like.

Okay, you really need to stop with this business of snipping out all
attribution and then lamely "covering" yourself with an attribution
line that acknowledges as much.  It's completely impossible to figure
out who said what when replying to you.

Trimming is not that hard.

I am still trying to figure out how you can pull these kinds of
arguments about definitions when you killfiled someone (not to mention
a lot of verbal, er, typed, abuse) for supposedly being a language
lawyer.  Pot, kettle?

I have lost track of the discussion, but I am having trouble imagining
a situation in which a coder would understand a well-formatted example
of the ternary operator, then read the same thing in if/else format
and be uncertain.  I can certainly imagine the reverse situation.

Signature

monique

Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html

Chris Uppal - 18 Nov 2005 10:33 GMT
> I have lost track of the discussion, but I am having trouble imagining
> a situation in which a coder would understand a well-formatted example
> of the ternary operator, then read the same thing in if/else format
> and be uncertain.  I can certainly imagine the reverse situation.

Interesting (a little) consider the inverted situation -- what the language
would be like if we leave the semantics as-is, but invert the concrete syntax:

   // single expression
   retirementAge = if person.isFemale()
                               then 60
                               else 65;

   // statements
   (person.isFemale())
   ? {
           retirementAge = 60;
           // more statements possible here..
    }
   : {
           retirementAge = 65;
           // ... and here..
   }

   -- chris
Roedy Green - 18 Nov 2005 12:23 GMT
On Fri, 18 Nov 2005 10:33:51 -0000, "Chris Uppal"
<chris.uppal@metagnostic.REMOVE-THIS.org> wrote, quoted or indirectly
quoted someone who said :

>    retirementAge = if person.isFemale()
>                                then 60
>                                else 65;

that is Forthian. In Forth, you use the same syntax for statement if
as expression if.  It works because Forth's strict left to right
expression postfix evaluation.

In Forth you could say:

         isFemale IF 60 ELSE 65 THEN retirementAge !

Where ! is the store operator.

If you were feeling verbose, you could write that as

       isFemale IF 60 retirementAge ! ELSE 65 retirementAge ! THEN

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Thomas G. Marshall - 18 Nov 2005 14:24 GMT
Chris Uppal coughed up:

>> I have lost track of the discussion, but I am having trouble imagining
>> a situation in which a coder would understand a well-formatted example
[quoted text clipped - 10 lines]
>                                then 60
>                                else 65;

The above would not actually be so crazy, if all block closures were
/themselves/ expressions.  Then our usual if/then's would work as is, but
just throw away the return value.  Similar to how the comma operator in C
often results in throwing away the value of the expression (value of last
expression in sequence) in practice.

Signature

Forgetthesong,I'dratherhavethefrontallobotomy...

Roedy Green - 18 Nov 2005 12:17 GMT
On Thu, 17 Nov 2005 15:29:49 -0700, "Monique Y. Mudama"
<spam@bounceswoosh.org> wrote, quoted or indirectly quoted someone who
said :

>Okay, you really need to stop with this business of snipping out all
>attribution and then lamely "covering" yourself with an attribution
>line that acknowledges as much.  It's completely impossible to figure
>out who said what when replying to you.

To me the only thing that matters is WHAT is said. Who said it is
irrelevant unless taking time out to deal with personal frictions.

You are commenting what his said, not who said it.

If you want to know who said what, read the original posts.

Again from my point of view what I am saying is:

"my thoughts on this statement:  xxxxx are yyyyy "

Who said it is irrelevant.  When I quote it is an an sense now my
statement. That is why I attempt to  snip anything irrelevant to what
I am commenting on.

I don't attributions.  If I am concerned about the reputation of the
person giving the information, I look at the original post, not some
mangling of it.

Attributions can't be properly handled in ASCII.  It is hopeless,
especially when you have people me who have contempt for the busywork
of tracking them, and people maliciously forging them as they do all
the time in the political newsgroups.  Here is my proposal to rectify
that :

http://mindprod.com/projects/mailreadernewsreader.html

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Thomas G. Marshall - 18 Nov 2005 14:30 GMT
Roedy Green coughed up:
> On Thu, 17 Nov 2005 15:29:49 -0700, "Monique Y. Mudama"
> <spam@bounceswoosh.org> wrote, quoted or indirectly quoted someone who
[quoted text clipped - 7 lines]
> To me the only thing that matters is WHAT is said. Who said it is
> irrelevant unless taking time out to deal with personal frictions.

No.  If you are responding to my post and use phrases similar to

       you this
       you that
       you the other thing

without /explicit/ qualification that you are not referring to my post, then
you are using "you" to mean me.  I cannot speak for everyone, but I'd be
amazed if nearly everyone doesn't read it precisely that way.

*Everyone* has goofed up reply targetting once in a while.  Just try to
minimize such things with preambles like

       The OP might {...}

or

       It is important for people in general to {...}

*NOT*

       You {...}

all by itself.

Signature

Forgetthesong,I'dratherhavethefrontallobotomy...

Roedy Green - 18 Nov 2005 15:57 GMT
On Fri, 18 Nov 2005 14:30:03 GMT, "Thomas G. Marshall"
<tgm2tothe10thpower@replacetextwithnumber.hotmail.com> wrote, quoted
or indirectly quoted someone who said :

> you this

sorry. than is informal for "one this" but then "you" sound like Queen
Elizabeth.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Roedy Green - 18 Nov 2005 16:02 GMT
>Roedy Green coughed up:

>        you this
>        you that
>        you the other thing

You repeatedly insult me comparing my posts to coughed up phlegm.

I have repeatedly asked you not to do that. Why then do you think I
will give a rat's a.s whether every one of your precious utterances is
perfectly attributed to your majesty?

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Roedy Green - 18 Nov 2005 16:09 GMT
On Fri, 18 Nov 2005 16:02:03 GMT, Roedy Green
<my_email_is_posted_on_my_website@munged.invalid> wrote, quoted or
indirectly quoted someone who said :

>You repeatedly insult me comparing my posts to coughed up phlegm.

There is a scene in the movie Cabaret where Sally Bowles is tutoring a
German woman in English.  She goes on and on about ze Flegma in ze
tubes.  Sally is grossed out, but Fraulen Landaur is completely
oblivious to the cultural gap.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Thomas G. Marshall - 18 Nov 2005 17:42 GMT
Roedy Green coughed up:
>> Roedy Green coughed up:
>
[quoted text clipped - 5 lines]
>
> I have repeatedly asked you not to do that.

/Repeatedly/ ?  Give me a list of how "repeatedly" this is.

> Why then do you think I
> will give a rat's a.s whether every one of your precious utterances is
> perfectly attributed to your majesty?

So by the "you" you write here are you talking to everyone in the newsgroup?

See the problem yet?

Signature

Onedoctortoanother:"Ifthisismyrectalthermometer,wherethehell'smypen???"

Roedy Green - 18 Nov 2005 20:50 GMT
On Fri, 18 Nov 2005 17:42:04 GMT, "Thomas G. Marshall"
<tgm2tothe10thpower@replacetextwithnumber.hotmail.com> wrote, quoted
or indirectly quoted someone who said :

>/Repeatedly/ ?  Give me a list of how "repeatedly" this is.

Get serious.  You argued back and forth with me that I had no right to
take offense then repeated the insult on every one of my posts you
commented on since. How else is one to interpret that but a f.ck you?
I explained that I could not plonk you much as I was infuriated
because you posted so much valuable information.

I tried to get you to understand with my "tubercular" exaggeration of
what you were doing, but you pretended to be amused.

You figured that since YOU would not find your insult offensive nobody
else possibly could, even if they asserted vehemently that they did.
That in itself is  infuriating. Different things bother different
people. Normal people stop behaviours infuriating to others that have
no benefit to them, unless they are deliberately attempting to
infuriate.  

I figure you did it because you resented me asking you to stop. You
felt it an imposition on your autonomy to stop insulting me, on the
grounds you insulted everyone else. Why should I be so special?

One of my main contributions to my planet are my posts.  I get really
pissed when someone compares them to spit up mucus day after day no
matter what the content.

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Thomas G. Marshall - 19 Nov 2005 00:33 GMT
Roedy Green coughed up:
> On Fri, 18 Nov 2005 17:42:04 GMT, "Thomas G. Marshall"
> <tgm2tothe10thpower@replacetextwithnumber.hotmail.com> wrote, quoted
[quoted text clipped - 7 lines]
> I explained that I could not plonk you much as I was infuriated
> because you posted so much valuable information.

I think you may have lost your mind.  Are you confusing me with "benji" ?

It took a bit of googling to find out what you're talking about, but I think
you're talking about this thread here, 08-Nov-05, "Null Pointer Exception"
in c.l.j.help, where I *wasn't* *even* *a* *participant* !  Am I supposed to
search for all your posts now?  And I notice that your post was pulled from
google----is that an anomoly?  I had to pull it off of verizon's server to
see it.

Here is Benji's response to your post that isn't on google.  Google loses
posts all the time, so I am not accusing you of anything:

http://groups.google.com/group/comp.lang.java.help/msg/a7659574bafaa977

...[rip]...

> One of my main contributions to my planet are my posts.  I get really
> pissed when someone compares them to spit up mucus day after day no
> matter what the content.

When I first conjured up the preamble "coughed up" what I had in mind was
hardly a negative description of the quote that follows it.  The original
intention was a tongue-in-cheek attempt to descript something like a
hairball in a cat---something bothering the cat that the cat must cough
up---the problem tha is coughed up for us to help with.  I of course
realized nearly immediately that it could be taken to describe the quality
of the material, but it simply makes no sense to me that it would be taken
as some sort of serious insult.  It is much the same as "so and so spewed
forth:" etc.

So beats me why you're freaking out over this.

But in any case, though I certainly don't "get" what you're on about here,
you seem convinced of it, so I'll change it.  Too late for this post though,
because I already hit [send]...

Signature

"Gentlemen, you can't fight in here! This is the War Room!"

Roedy Green - 19 Nov 2005 12:11 GMT
On Sat, 19 Nov 2005 00:33:55 GMT, "Thomas G. Marshall"
<tgm2tothe10thpower@replacetextwithnumber.hotmail.com> wrote, quoted
or indirectly quoted someone who said :

>I think you may have lost your mind.  Are you confusing me with "benji" ?
I went through a similar thing with Benji. The very fact you know
about that gives you less excuse for pleading ignorance.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Thomas G. Marshall - 19 Nov 2005 19:34 GMT
Roedy Green said something like:
> On Sat, 19 Nov 2005 00:33:55 GMT, "Thomas G. Marshall"
> <tgm2tothe10thpower@replacetextwithnumber.hotmail.com> wrote, quoted
[quoted text clipped - 4 lines]
> I went through a similar thing with Benji. The very fact you know
> about that gives you less excuse for pleading ignorance.

Still off the deep end I see.  *Like I said* I had to google to find out
what the heck you were talking about.  Here shows what I did:

http://groups.google.com/groups?q=thomas+roedy+plonk&start=0&scoring=d&ie=UTF-8&

googling for "thomas roedy plonk"

2nd hit.

So please just take a breath, and relax.  I've already changed the
attribution like I said I would.

Signature

Sometimes life just sucks and then you live.

Roedy Green - 19 Nov 2005 21:37 GMT
On Sat, 19 Nov 2005 19:34:42 GMT, "Thomas G. Marshall"
<tgm2tothe10thpower@replacetextwithnumber.hotmail.com> wrote, quoted
or indirectly quoted someone who said :

>So please just take a breath, and relax.  I've already changed the
>attribution like I said I would.

Thank you.  I am very glad this is over.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Roedy Green - 19 Nov 2005 13:27 GMT
On Sat, 19 Nov 2005 00:33:55 GMT, "Thomas G. Marshall"
<tgm2tothe10thpower@replacetextwithnumber.hotmail.com> wrote, quoted
or indirectly quoted someone who said :

>Roedy Green coughed up:

>I think you may have lost your mind.  Are you confusing me with "benji" ?

If you are STILL using that phrase after all this time, and you still
want to claim ignorance of its effect, you are the one who his lost
touch with reality.

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Thomas G. Marshall - 19 Nov 2005 19:43 GMT
Roedy Green said something like:

> On Sat, 19 Nov 2005 00:33:55 GMT, "Thomas G. Marshall"
> <tgm2tothe10thpower@replacetextwithnumber.hotmail.com> wrote, quoted
[quoted text clipped - 7 lines]
> want to claim ignorance of its effect, you are the one who his lost
> touch with reality.

{yawn}.  I think we're done here, and I'm running out of patience with you
and this nonsense.  Start paying attention to what I've recently said about
changing my attribution.  Stop claiming about going back and forth with me
in a conversation I was never in.  Chill out and let's go back to helping
people.

Roedy, I think you're fundamentally a good guy.  So my attribution was
changed (right when I said it would).  If this one bothers you too, let me
know.

Signature

Sometimes life just sucks and then you live.

Roedy Green - 18 Nov 2005 16:18 GMT
On Fri, 18 Nov 2005 14:30:03 GMT, "Thomas G. Marshall"
<tgm2tothe10thpower@replacetextwithnumber.hotmail.com> wrote, quoted
or indirectly quoted someone who said :

>No.  If you are responding to my post and use phrases similar to
>
>        you this
>        you that
>        you the other thing

This not email. EVERYTHING is address to all people reading.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Roedy Green - 18 Nov 2005 16:36 GMT
On Fri, 18 Nov 2005 14:30:03 GMT, "Thomas G. Marshall"
<tgm2tothe10thpower@replacetextwithnumber.hotmail.com> poked his
finger up one nostril and sprayed these words in blood and snot out
the other:

Eventually I will find some words that push your limit. My words cease
to be a "joke" the instant you complain and I persist.

>No.  If you are responding to my post and use phrases similar to
>
>        you this
>        you that
>        you the other thing

It would be interesting to have an experimental newsgroup where all
posts were completely anonymous -- not even pseudonyms. People then
might then focus on the issues , rather than paying attention to who
said them, alliances, insult tracking etc.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Roedy Green - 18 Nov 2005 14:37 GMT
On Fri, 18 Nov 2005 12:17:50 GMT, Roedy Green
<my_email_is_posted_on_my_website@munged.invalid> wrote, quoted or
indirectly quoted someone who said :

>I don't attributions.
that should read
I don't trust attributions.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Scott Ellsworth - 17 Nov 2005 23:47 GMT
> On Thu, 17 Nov 2005 10:31:04 -0700, "Monique Y. Mudama"
> <spam@bounceswoosh.org> wrote, quoted or indirectly quoted someone who
[quoted text clipped - 8 lines]
> problem is people are making up their minds before they are
> comfortable with both syntaxes.

I disagree with your claim that disliking ternary operators is driven by
making up one's mind before getting comfortable with the syntax.

I am quite familiar with ternary operators; I first saw them back in
'86, 19 years ago.  I have been doing Java now for seven years, and did
C++ for eight years before that.  (Yep.  Cfront was my friend.)

I have gone back and forth over the years, but I find that I am settling
in a stable state of disliking ternary operators intensely, precisely
because the code I have written and maintained that used them seems
harder to maintain than code that uses plain old if statements.

I know quite a few others here with similar experience who feel much the
same.  (And counterexamples, of course.)  Thus, I suspect it really is a
preference based on how you chunk the data, and what you find
straightforward.

Scott

Signature

Scott Ellsworth
scott@alodar.nospam.com
Java and database consulting for the life sciences

Monique Y. Mudama - 18 Nov 2005 00:31 GMT
>> But I conjecture that it won't be.  The brevity will win out. The
>> problem is people are making up their minds before they are
[quoted text clipped - 3 lines]
> driven by making up one's mind before getting comfortable with the
> syntax.

Wait, you mean you object to the implication that anyone who dislikes
ternary operators must be a rank novice?  Crazy talk!

> I am quite familiar with ternary operators; I first saw them back in
> '86, 19 years ago.  I have been doing Java now for seven years, and
[quoted text clipped - 10 lines]
> really is a preference based on how you chunk the data, and what you
> find straightforward.

Individual preference?  People think differently?  More crazy talk!

Signature

monique

Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html

Roedy Green - 18 Nov 2005 12:28 GMT
On Thu, 17 Nov 2005 17:31:06 -0700, "Monique Y. Mudama"
<spam@bounceswoosh.org> wrote, quoted or indirectly quoted someone who
said :

>Wait, you mean you object to the implication that anyone who dislikes
>ternary operators must be a rank novice?  Crazy talk!

That is not what I said.  People are not logical in their preferences.
What I did say is that I suspect if you did an experiment to measure
which syntax let trained programmers accurately glean the meaning of
code faster, ternary would win.

I would further add that nested ternary operators would probably slow
down programmers over the equivalent IF, since programmers are skilled
at handling nested IF, but would never develop sufficient skill at
handling nested ternaries since they occur so rarely.

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Thomas G. Marshall - 18 Nov 2005 14:20 GMT
Roedy Green coughed up:
> On Thu, 17 Nov 2005 17:31:06 -0700, "Monique Y. Mudama"
> <spam@bounceswoosh.org> wrote, quoted or indirectly quoted someone who
[quoted text clipped - 12 lines]
> at handling nested IF, but would never develop sufficient skill at
> handling nested ternaries since they occur so rarely.

Well, part of why they occur so rarely is that they are just darn goofy
looking and hard to read, generally.  I *do* advocate (as explained already)
ternary so long as they are not compound and are simple looking.  One
exception to this would be (IMO) an example similar to those I've given
before: (/please/ go fixed point type):

   String carStr =
       (carEnum == Ford)   ? "Crap" :
       (carEnum == Chevy)  ? "Worse Crap" :
       (carEnum == Hummer) ? "Crap, but Cool" :
                             "Unknown Car";

Do *NOT* bore me with posts like "but that is bad design".  This is merely
an example of format.

Signature

Forgetthesong,I'dratherhavethefrontallobotomy...

Chris Uppal - 18 Nov 2005 14:26 GMT
>     String carStr =
>         (carEnum == Ford)   ? "Crap" :
[quoted text clipped - 3 lines]
>
> Do *NOT* bore me with posts like "but that is bad design".

OK.

Instead, I'll ask the question that /really/ interests me.  WTF is a "Hummer" ?

   -- chris
J. Verdrengh - 18 Nov 2005 14:29 GMT
You should use google, first hit
Thomas G. Marshall - 18 Nov 2005 01:24 GMT
Scott Ellsworth coughed up:

>> On Thu, 17 Nov 2005 10:31:04 -0700, "Monique Y. Mudama"
>> <spam@bounceswoosh.org> wrote, quoted or indirectly quoted someone who
[quoted text clipped - 20 lines]
> because the code I have written and maintained that used them seems
> harder to maintain than code that uses plain old if statements.

Whoa, hang on now.  Are you saying that you can measure a difference in
maintainability based on the ternary /alone/ ?  I have a hard time imagining
that someone can actually feel that something seems harder to maintain
because of that.  There must be other things making a difference in
maintainability noticeable.

> I know quite a few others here with similar experience who feel much the
> same.  (And counterexamples, of course.)  Thus, I suspect it really is a
> preference based on how you chunk the data, and what you find
> straightforward.
>
> Scott

Signature

"So I just, uh... I just cut them up like regular chickens?"
"Sure, just cut them up like regular chickens."

Scott Ellsworth - 18 Nov 2005 23:01 GMT
In article <73aff.13176$Rb.450@trndny04>,
"Thomas G. Marshall"
<tgm2tothe10thpower@replacetextwithnumber.hotmail.com> wrote:

> Scott Ellsworth coughed up:
> >
[quoted text clipped - 28 lines]
> because of that.  There must be other things making a difference in
> maintainability noticeable.

I believe I could, were I willing to troll the cvs archive.  I have
noted ternary operators seem to hide mystery functionality more often
than ifs.

Obviously, there could also just be sampling bias because I dislike
them, but it does appear that they tend to be misused a fair amount.

Scott

Signature

Scott Ellsworth
scott@alodar.nospam.com
Java and database consulting for the life sciences

Thomas G. Marshall - 18 Nov 2005 23:47 GMT
Scott Ellsworth coughed up:
> In article <73aff.13176$Rb.450@trndny04>,
> "Thomas G. Marshall"
> <tgm2tothe10thpower@replacetextwithnumber.hotmail.com> wrote:

...[rip]...

>> Whoa, hang on now.  Are you saying that you can measure a difference in
>> maintainability based on the ternary /alone/ ?  I have a hard time
[quoted text clipped - 9 lines]
> Obviously, there could also just be sampling bias because I dislike
> them, but it does appear that they tend to be misused a fair amount.

It *does* seem as if the ternary operator is in the group of things that
engineers do just for fun to prove they can, though just barely so, but I
still maintain that for simple cases like those shown it is clearer.
Sometimes /sometimes/ terse is clearer than verbose.  I suppose the people
stuck with only the original cobol "subtract" operator might agree.

Signature

"Gentlemen, you can't fight in here! This is the War Room!"

Thomas G. Marshall - 18 Nov 2005 00:25 GMT
Oliver Wong coughed up:
>>> My definition is "After training, which form can I, in the least
>>> amount of time, reliably determine what the code does."
[quoted text clipped - 8 lines]
> being
> objective in the posts they were responding to).

Yep.

...[rip]...

Signature

"So I just, uh... I just cut them up like regular chickens?"
"Sure, just cut them up like regular chickens."

Roedy Green - 18 Nov 2005 12:28 GMT
On Fri, 18 Nov 2005 00:25:23 GMT, "Thomas G. Marshall"
<tgm2tothe10thpower@replacetextwithnumber.hotmail.com> wrote, quoted
or indirectly quoted someone who said :

>>    Agreed. I was surprised when Roedy opened his post with "Objectively,
>> this is clearer" (Less surprised when Monique and Thomas used it, as I
[quoted text clipped - 3 lines]
>
>Yep.

It is objective when you use my definition of clarity.

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Thomas G. Marshall - 18 Nov 2005 13:48 GMT
Roedy Green coughed up:
> On Fri, 18 Nov 2005 00:25:23 GMT, "Thomas G. Marshall"
> <tgm2tothe10thpower@replacetextwithnumber.hotmail.com> wrote, quoted
[quoted text clipped - 9 lines]
>
> It is objective when you use my definition of clarity.

Now if this isn't one of most useless threads I've seen in a long time.....
;)

Signature

Forgetthesong,I'dratherhavethefrontallobotomy...



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.