if statement

T

Thomas G. Marshall

Oliver Wong coughed up:
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).

Yep.

....[rip]...
 
M

Monique Y. Mudama

I disagree with your claim that disliking ternary operators is
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
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.

Individual preference? People think differently? More crazy talk!
 
T

Thomas G. Marshall

Scott Ellsworth coughed up:
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.

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.
 
C

Chris Uppal

Monique said:
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
 
C

Chris Uppal

Stefan said:
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
 
R

Roedy Green

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
 
R

Roedy Green

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
 
R

Roedy Green

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.
 
T

Thomas G. Marshall

Roedy Green coughed up:
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.....
;)
 
T

Thomas G. Marshall

Roedy Green coughed up:
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.

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.
 
T

Thomas G. Marshall

Chris Uppal coughed up:
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;

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.
 
T

Thomas G. Marshall

Roedy Green coughed up:
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.
 
C

Chris Uppal

Thomas said:
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".

OK.

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

-- chris
 
R

Roedy Green

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 ass whether every one of your precious utterances is
perfectly attributed to your majesty?
 
R

Roedy Green

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.
 
R

Roedy Green

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top