Re: Assigning void
On 13.10.2012 22:03, Lew wrote:
markspace wrote:
I'd consider post-increment there a side effect, yet it's legal. Yes, I
know there's an implied (required) assignment there, but it's still
side-effecty.
No true Scotsman.
It isn't an implied assignment, it's an explicit one.
http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.14.2
Since it's the purpose of the operator, it's not "side effecty", it's
"direct effecty".
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_effect_%28computer_science%29
Unless assignment through '=' is also "side effecty".
Yes, because variable assignment changes state. If you think about it,
statements in languages which have statements (additionally to
expressions) only make sense at all if there are side effects. A
statement (which doesn't have a result) in a language completely free of
side effects would do nothing - ever.
Kind regards
robert
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/