Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Assigning void

Reply
Thread Tools

Assigning void

 
 
Jeff Higgins
Guest
Posts: n/a
 
      10-14-2012
On 10/13/2012 01:54 AM, Wojtek wrote:
> I can legally do the following:
>
> if (server.getConnectionType() == ConnectionType.ACTIVE)
> ftp.enterLocalActiveMode();
> else
> ftp.enterLocalPassiveMode();
>
> but I want to do:
>
> (server.getConnectionType() == ConnectionType.ACTIVE) ?
> ftp.enterLocalActiveMode() : ftp.enterLocalPassiveMode();
>
> However the compiler insists that I must have an assignment even though
> both ftp methods return void. I would think that the compiler would be
> smart enough to realize that nothing CAN be returned.
>
> Oh yes, I am using Eclipse with Java 7
>
> Thoughts? I mean other than stylistic comments...
>

Summing up.
The kitty tickled is now resting content and secure in her favored JLS.
The poor maligned compiler is only performing as her implementers
have been allowed by the language specifiers.
Stylistically, some would accept the put forth construct; others not.

 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      10-14-2012
On Sunday, October 14, 2012 5:09:31 AM UTC-7, Robert Klemme wrote:
> My memory might be a bit rusty but the definition of "side effect" that
> I learned was that it is a state change not reflected in the result.
> That includes IO for example, even if one could argue that the main
> effect of System.out.println("foo") is to print "foo\n" on the console.
> The definition of "side effect" I have in mind solely deals with a
> distinction important in the context of functional languages. A side
> effect free expression has some properties which go away when side
> effects are introduced (thread safety, stability which has effects on
> analysis of behavior etc.). The introductory paragraph on the Wikipedia
> page nicely sums this:
>
> http://en.wikipedia.org/wiki/Side_ef...ter_science%29


As a term of art, its definition as you state it I cannot dispute.

As a term of common English, a "side" effect is something different from the
stated, explicit purpose.

In medicine they say, "There are no side effects, only effects."

I should have used the term of art, but I was actually saying "side effecty",
not "side effect", even to including the quotes, so I explicitly avoided the
term of art.

I admit I should have used a clearer term, but I was using the term introduced
in the post to which I responded.

My point is that assignment isn't a "side effect" (ordinary English) of
auto-increment, but the intended effect. In the context of why assignment and
its siblings can constitute a statement, but not '?:' or '+', it makes sense.

Thank you for distinguishing this from the term of art.

--
Lew
 
Reply With Quote
 
 
 
 
Gene Wirchenko
Guest
Posts: n/a
 
      10-15-2012
On Sat, 13 Oct 2012 21:01:34 -0400, Jeff Higgins
<(E-Mail Removed)> wrote:

>>> On 10/13/2012 03:38 PM, Lew wrote:

>
>>>> Whether it could have been, the history of the ternary ?: operator has
>>>> been solely as an expression,

> From what I gather from this thread so far
>there is no technical reason for not being able
>to share the ?: syntax between the conditional
>operator and an if-then-else statement.
>If Larry Ellison walked into the shop Monday
>morning and announced "I would like a
>'boolean expression ? block : block' syntax
>in the Java language" he would not be met with
>a chorus of "It cannot be done".


So what?

If he walked into the shop and announced that he was going to
hang himself, the same would apply.

Sincerely,

Gene Wirchenko
 
Reply With Quote
 
Gene Wirchenko
Guest
Posts: n/a
 
      10-15-2012
On Sat, 13 Oct 2012 14:16:43 -0700, Wojtek <(E-Mail Removed)> wrote:

>Lew wrote :
>> First of all, asking unanswerable
>> questions is not /per se/ trolling.

>
>I have always considered "trolling" to be making an obnoxious post
>which is designed to inflame someone into making a contradictory post.
>Hopefully many someones.
>
>Asking a "quiet" question which may/may not be answerable is hardly
>trolling.


No. It is not whether the question is quiet or not that
determines whether the post is trolling; it is the desired effect that
determines.

>Or, I am not trying to kick the cat, just tickle it a little.


Fluffy says, "Scratch behind my right ear, please."

Sincerely,

Gene Wirchenko
 
Reply With Quote
 
Jukka Lahtinen
Guest
Posts: n/a
 
      10-15-2012
Lew <(E-Mail Removed)> writes:

> 'if' is two keys plus 'then' is four for six keys. '?' is two keys.
> 'else' is four keys, ':' is two.


But 'then' is not Java.

> Advantage: '?:' ten to four.
> But for clarity, most ternary expressions require a pair of parentheses,
> adding four keys. Now the advantage is ten to eight.
> And '?:' loses its place as an operator.


--
Jukka Lahtinen
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      10-15-2012
Jukka Lahtinen wrote:
> Lew writes:
>
> > 'if' is two keys plus 'then' is four for six keys. '?' is two keys.


Right - '{' and '}' are four keys. Sorry.

>> 'else' is four keys, ':' is two.

>
> But 'then' is not Java.


I have no excuse. The only reason I can imagine for this is that I have
been doing a lot of bash coding lately. But still.

>> Advantage: '?:' ten to four.

>
>> But for clarity, most ternary expressions require a pair of parentheses,
>> adding four keys. Now the advantage is ten to eight.

>
>> And '?:' loses its place as an operator.


Another point I should clarify - "operator" is not a sufficient distinction.

I should have said "simple operator" or some such phrase to distinguish
operators like the ternary one here, the arithmetic operators, comparison
operators and the like, whose purpose is not to cause a state change but to
produce a value.

It's pretty clear that the Java designers viewed these categories of operators
differently, as that difference is codified in the language.

--
Lew
 
Reply With Quote
 
Joerg Meier
Guest
Posts: n/a
 
      10-20-2012
On Sat, 13 Oct 2012 13:31:58 -0700, Wojtek wrote:

> int compare = (a > b) ? 1 : (a < b) ? -1 : 0;


I know it's been a few days, but I just read this and wanted to add that I
find the above expression pretty horrible, as I could not without
experimentation or study of the JLS tell how that would turn out - could be
either

int compare = ((a > b) ? 1 : (a < b)) ? -1 : 0;

or

int compare = (a > b) ? 1 : ((a < b) ? -1 : 0);

maybe that's just me, though.

Liebe Gruesse,
Joerg

--
Ich lese meine Emails nicht, replies to Email bleiben also leider
ungelesen.
 
Reply With Quote
 
Sven Köhler
Guest
Posts: n/a
 
      10-20-2012
Am 13.10.2012 07:54, schrieb Wojtek:
> but I want to do:
>
> (server.getConnectionType() == ConnectionType.ACTIVE) ?
> ftp.enterLocalActiveMode() : ftp.enterLocalPassiveMode();


That's not correct Java syntax. Live with it.
 
Reply With Quote
 
Peter J. Holzer
Guest
Posts: n/a
 
      10-21-2012
On 2012-10-20 16:56, Peter Duniho <(E-Mail Removed)> wrote:
> On Sat, 20 Oct 2012 18:00:23 +0200, Joerg Meier wrote:
>> On Sat, 13 Oct 2012 13:31:58 -0700, Wojtek wrote:
>>> int compare = (a > b) ? 1 : (a < b) ? -1 : 0;

>>
>> I know it's been a few days, but I just read this and wanted to add that I
>> find the above expression pretty horrible, as I could not without
>> experimentation or study of the JLS tell how that would turn out - could be
>> either
>>
>> int compare = ((a > b) ? 1 : (a < b)) ? -1 : 0;

>
> It can't be that one. That expression doesn't compile, because the literal
> "1" is not a boolean value, nor is "(a < b)" an integer value, and so "1 :
> (a < b)" is not a valid portion of a ?: operator expression (i.e. the two
> possible results don't match in type, nor are convertible to each other's
> type).


True. However, in C there is (was) no boolean type so the precedence
could still be the wrong way around (requiring extra parentheses in
Java).

However, the inventors in C did spend some time contemplating typical
uses before deciding on the precedence of the operators, and they
expected that nesting ?: like this:

cond1 ? value1 :
cond2 ? value2 :
cond3 ? value3 :
value4

would be a typical use and chose the precedence and associativity to
allow this without extra parentheses.

hp


--
_ | Peter J. Holzer | Deprecating human carelessness and
|_|_) | Sysadmin WSR | ignorance has no successful track record.
| | | http://www.velocityreviews.com/forums/(E-Mail Removed) |
__/ | http://www.hjp.at/ | -- Bill Code on (E-Mail Removed)
 
Reply With Quote
 
glen herrmannsfeldt
Guest
Posts: n/a
 
      10-21-2012
Peter J. Holzer <(E-Mail Removed)> wrote:

(snip)
> However, the inventors in C did spend some time contemplating typical
> uses before deciding on the precedence of the operators, and they
> expected that nesting ?: like this:


> cond1 ? value1 :
> cond2 ? value2 :
> cond3 ? value3 :
> value4


> would be a typical use and chose the precedence and associativity to
> allow this without extra parentheses.


I suppose, but some of the C precedence rules are the result of
the late addition of the logical operators && and ||.

Previously, the & and | operators were used, and they kept their
precedence even after && and || were added.

-- glen
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the difference between void proba(); and void proba(void); ??? PencoOdStip@gmail.com C++ 1 05-23-2007 07:12 PM
Assigning methods to objects, and assigning onreadystatechange to an XMLHttpRequest -- an inconsistency? weston Javascript 1 09-22-2006 09:33 AM
what is the difference, void func(void) and void fucn() noblesantosh@yahoo.com C Programming 5 07-22-2005 04:38 PM
"void Method()" vs "void Method(void)" Ollej Reemt C++ 7 04-22-2005 03:47 AM
`void **' revisited: void *pop(void **root) Stig Brautaset C Programming 15 10-28-2003 09:03 AM



Advertisments