News for hackers. Stuff that matters.
Re:How high school students start thinking about code by joechung on Sunday July 05, 2009 @10:13PM (#688992)
"He hadn’t quite internalized left-hand side vs. right-hand side." This is noteworthy.

In mathematics, equality is symmetric (a=b is the same as b=a).

In programming, variable assignment is asymmetric (a=b is not the same as b=a).

Some programming languages recognize this but get the change wrong by changing the equality operator to == or === and always preferring assignment to be =. Some get it right, e.g., := as assignment.

Re:How high school students start thinking about code by patio11 on Sunday July 05, 2009 @10:52PM (#689048)
Some get it right, e.g., := as assignment.

This is a tradeoff of one hard day in your teens ("But but but equals should work both ways! head explodes") and thirty seconds every time you pick up a new language ("Assignment operator is equals? Got it.") versus typing more several dozen or hundred times a day every day for the rest of your professional life.

Re:How high school students start thinking about code by DannoHung on Monday July 06, 2009 @07:05AM (#689462)
How about just making assignment the colon character?
Re:How high school students start thinking about code by eru on Monday July 06, 2009 @12:20PM (#689883)
Or getting rid of assignment altogether?
Re:How high school students start thinking about code by bsaunder on Monday July 06, 2009 @09:40AM (#689610)
kinda like YAML? www.yaml.org
Re:How high school students start thinking about code by kragen on Tuesday July 07, 2009 @02:13AM (#691022)
The traditional solution is ←.
Re:How high school students start thinking about code by mattmcknight on Sunday July 05, 2009 @11:06PM (#689060)
Yes, but don't overlook the "Let x =" syntax of mathematics. Programming has just dropped the "let". So, really there is a choice to be made about how to resolve that ambiguity in a language parser. Visual Basic has the nice case of A = B = C setting A equal to the boolean expression B = C.
Re:How high school students start thinking about code by jules on Monday July 06, 2009 @07:31AM (#689484)
Let in mathematics doesn't really work that way. It's more general.

"Let <boolean expression>" means that the world gets set up so that the boolean expression is true.

Examples:

Let x=4

Let epsilon>0

Let a in A

There's very interesting work on providing an iteration construct like this in a programming language.

http://www.cs.cornell.edu/Projects/jmatch/

Re:How high school students start thinking about code by greggraham on Sunday July 05, 2009 @11:21PM (#689074)
Old versions of BASIC used LET for assignment, but Microsoft BASIC and other BASICs of that era dropped it as being unnecessary.
Re:How high school students start thinking about code by Hexstream on Monday July 06, 2009 @11:07AM (#689757)
Not completely, Lisp uses let for variable bindings...

  (let ((x 5)
        (y 10))
    (+ x y))

  => 15
Re:How high school students start thinking about code by dmnd on Sunday July 05, 2009 @10:38PM (#689030)
I don't know where I picked this up, but I use asymmetric whitespace around the assignment operator: a= b. It provides a subtle hint that assignment is not equality.
Re:How high school students start thinking about code by mahmud on Sunday July 05, 2009 @11:01PM (#689053)
You need to sit down with your text editor and see if you can teach it a few tricks.
Re:How high school students start thinking about code by lsb on Sunday July 05, 2009 @10:22PM (#689011)
Yup, in Haskell it's as explicit as a <- for assignment, and = for what amounts to pattern equality.
Re:How high school students start thinking about code by lanaer on Sunday July 05, 2009 @11:20PM (#689073)
Iirc, it isn’t even assignment, it’s a monad extraction.

e.g.

a <- [2] …

gives a the value of 2, unwrapping the List monad (only works if the return value of the function is a List of some kind).

The above could also be written:

[2] >> (\a -> …)

It’s been a while since I’ve done much with haskell, so forgive me if I’ve mis-remembered something.

Re:How high school students start thinking about code by llimllib on Monday July 06, 2009 @04:08PM (#690354)
I know that's what it does under the covers, but is there any reason not to think of it as assignment in your head? That's the mental construct I use in my extremely limited Haskell coding, anyway.
Re:How high school students start thinking about code by lanaer on Tuesday July 07, 2009 @10:41AM (#691536)
Because if you think of it as assignment, the fact that

a <- [2]

binds a to 2, rather than [2], makes no sense.

edit:

a better example (because it is more useful) would be:

a <- Just 2

which, again, binds a to 2, unwrapping the Maybe monad in the process. (I forget what happens if you try to do a <- Nothing)

Re:How high school students start thinking about code by sharkbrainguy on Sunday July 05, 2009 @11:22PM (#689075)
I accidentally downvoted this...
Re:How high school students start thinking about code by lanaer on Sunday July 05, 2009 @11:26PM (#689080)
Aw :(

I think I’ll live with 1 less karma ;)

Re:How high school students start thinking about code by wlievens on Monday July 06, 2009 @05:21AM (#689381)
Compensated. Now nobody vote this parent up or down lest we disturb the gods.
Re:How high school students start thinking about code by shachaf on Monday July 06, 2009 @01:17AM (#689196)
As lanaer said, "<-" is really syntax sugar for ">>=" (bind), and could mean a variety of things (including assignment). "=" is binding a variable, as in "let", and is not symmetric. One could argue that a better name for "=" would be "->", as in "case".

(Comparison, which is symmetric, is "==".)