View Single Post
  #31  
Old 02-12-2010, 10:36 AM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004
Quote:
Originally Posted by WhiteDragon View Post
PHP Code:
temp.distance = function (x1y1x2y2) {
  return( ((
x2 x1)^+ (y2 y1)^2)^.5 );
};
echo(
temp.distance(2211)); 
Anonymous functions can unfortunately not be executed in the same statement they are declared in.
I may have been gone for a while (and not to nitpick or jump on the bandwagon...), but this is wrong. It is not as pretty as javascript to pull it off, but it can be done.

Quote:
Originally Posted by Douglas Crockford on switch Fall Through
Someone once wrote to me once suggesting that JSLint [his javascript "checker"] should give a warning when a case falls through into another case. He pointed out that this is a very common source of errors, and it is a difficult error to see in the code. I answered that that was all true, but that the benefit of compactness obtained by falling through more than compensated for the chance of error.

Then next day, he reported that there was an error in JSLint. It is misidentifying an error. I investigated and it turned out that I had a case that was falling through. In that monent, I achieved enlightenment. I no longer use intentional fall throughs. That discipline makes it much easier to find the unintentional fall throughs.
Just because Crockford messes up doesn't mean no one should be allowed to benefit from the usefulness of switch. S'all I'm sayin'.

A few more things: javascript is a language in which appending the bracket at the end of a function is highly recommended because it has a sort of auto-complete where it puts a semicolon at the end of any line that a parser thinks is a complete statement. Placing a bracket at the end of a line avoids any confusion. GraalScript does not have this issue. Go hog wild, throw that bracket anywhere you like (where syntax allows).

The argument that X language uses Y means that Y is right for Z language is absolute nonsense. R is a statistical programming language that is C-like and return is a function in R.
__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/
Reply With Quote