6 ms·
> While the above pattern has become standardized, it feels somewhat unnatural as we read most of the spoken languages from left to right. Is this true (the 'u
by iandev 6y ago
> While the above pattern has become standardized, it feels somewhat unnatural as we read most of the spoken languages from left to right.
Is this true (the 'unnatural' part)? Reading left to right, `age = 42` can be read as "age is 42" which feels perfectly natural in English. `42 => age` would be read as "assign 42 to age"? This feels more awkward to me. I'm not sure I understand why anyone would want Rightward assignment.
- ianmobbs 6y agoExactly how I feel. This is one of the reasons I'm not a huge fan of R, either
- kevinmgranger 6y agoIf you visualize variables as "boxes" with values in them, "put 42 in age" makes sense.
- qbonnard 6y agoA math tutor of mine was actually pretty angry at computer science for writing things like `a=1; a=2; //so 1=2 ?` I guess he'd rather have the "assign 42 to age"... Except he'd probably read `42 => age` as "42 implies age", which would probably cause him more sleepless nights ;)
- toxik 6y agoHe’d probably like a := 42 which is in a lot of languages actually! Also Erlang and other fp’s do consider = equivalence.
- Izkata 6y agoI noticed a year or two ago when I'm pseudocoding I seem to default to "age <- 42" which I kinda like more...
- choward 6y agoI'm a big fan of immutability and using constantly so I agree with your tutor.
- danellis 6y ago> math tutor ... angry It's not the same language, so why should he expect the semantics to be the same?
- JadeNB 6y ago> It's not the same language, so why should he expect the semantics to be the same? It's a bit like discovering that inline C in your favourite non-C language isn't actually semantically correct C. If you're a mathematician, then you know, intimately and fluently, how math is spoken and written, so seeing something that looks exactly like "inline math", but isn't, is jarring. (I don't get angry over it, but it is exactly counter to the extremely delicate and precise way mathematicians train ourselves to think about '='.)
- __ryan__ 6y agoI had the same issue. This is why I always comment my assignments. x = x + 1 // assign x to x+1
- xthestreams 6y agoI can't tell if this is a multiple joke or not
- deleted 6y ago[deleted]
- mcphage 6y ago`42 => age` would probably be "42 is age", or if it was `42 => person.age` you'd read it "42 is person's age".
- syspec 6y agoAgreed, when I read that line I found myself saying it out loud wondering if it was a typo. `favorite_color = red' == "Favorite Color is Red" Which feels more natural than: "Red is Favorite Color"
- swiley 6y ago42 is the age
- Someone 6y agoBut “age is 42” is a statement/Boolean, not a mutation. “Let age be 42” is more natural, but doesn’t sound well on reassignments (“let age now be 42”?)
- Willamin 6y agoI read it as "42 is stored in age". The works particularly well for a long chain of methods that should end in storing the resulting value in a variable. I know this might seem to be the most conventional way that Ruby is written; it makes a single statement take 8 lines instead of 1, it transforms a value over the course of the statement instead of sending messages to tell an object to transform itself, and it ignores the concept of encapsulation by moving the interesting actions into the foreground rather than being hidden within an object. Below is an _incredibly_ contrived example. Take note how the `=> final_value` syntax is useful. The alternative is to place a `final_value = ` at the _top_ of the statement. I'll admit: placing the assignment at the top of the method chain helps point out to the reader of the code that an assignment is happening. However, more useful I think is quickly recognizing the flow of data. "hello" .chars .size .*(10980643.4) .to_i .to_s(36) .upcase => final_value puts(final_value) # => WORLD
- Freaky 6y ago... and it's useful how? It obscures the assignment at the end of an arbitrarily long statement instead of giving the value a name right up front. It feels a bit like a new method definition syntax that allows you to put the name after the `end` for... reasons.
- keeganpoppen 6y agowait i feel like that's actually kind of gorgeous. syntax highlighting as it exists today might not be good enough to really make that form stand out, though...
- coliveira 6y agoThat's why tcl uses: set age 42
- Igelau 6y ago"42 gets crammed into age"