On 17/10/14 14:56, Philip Sturgeon wrote:
>
> Huh?
>
> It's extremely common in various languages to declare multiple variables
> inline. JavaScriipt, Go, and for me PHP too.
>
> PHP: $total = $count = $i = 0;
> JS: var total, count, i;
> GO: var total, count, i int
>
> It's perfectly normal and doesn't have semantic meaning about grouping
> or anything, its just trivially quicker and sometimes a bit more
> logical. "All these things are 0."
There is a world of difference between the php and JavaScript snippet.
(Don't _know_ go; but I suspect it's closer to JavaScript.)
In JavaScript the closest to the php code you can get is:
var total = 0, count = 0, i = 0;
Possibly:
total = count = i = 0;
but that doesn't do the same thing either.
But that's really beside the point; I disagree that it is "extremely"
common; and even if it was that does not make it "good". Many languages
don't even allow it.
Assignments _anywhere_ but once, on their own line, is generally frowned
upon. Sure, somtimes it is seductive to write a
while ($item = next($array))
and at least _somewhat_ expected. Not placing the assignments first on
the line will make scanning the code for them harder.
Whatever you write; someone will look at it and try to figure out what
you mean. _To me_ placing them on the same line like that makes them
associated, and I will have to spend extra effort parsing the code to
ensure they aren't.
---
When I become benevolent-overlord-of-the-world, however, anyone that
designs a language where assignmnent is an expression will be drawn and
quartered. :)