soegaard2
2022-5-8 17:55:09

> Critics, including language designers,https://en.wikipedia.org/wiki/Expression-oriented_programming_language#cite_note-1\|[1] blame expression-orientation for an entire class of <https://en.wikipedia.org/wiki/Software_bug|programming mistakes> wherein a programmer accidentally codes an https://en.wikipedia.org/wiki/Assignment_(computer_science)\|assignment expression, which replaces a variable with an expression rather than testing it for https://en.wikipedia.org/wiki/Equality_(relational_operator)\|equality with that expression. > The designers of https://en.wikipedia.org/wiki/Ada_(programming_language)\|Ada and https://en.wikipedia.org/wiki/Java_(programming_language)\|Java prevent this type of mistake by restricting <https://en.wikipedia.org/wiki/Conditional_(computer_programming)|control expressions> to those that evaluate strictly to the <https://en.wikipedia.org/wiki/Boolean_data_type|boolean data type>.https://en.wikipedia.org/wiki/Expression-oriented_programming_language#cite_note-2\|[2]https://en.wikipedia.org/wiki/Expression-oriented_programming_language#cite_note-3\|[3] From https://en.wikipedia.org/wiki/Expression-oriented_programming_language


soegaard2
2022-5-8 17:56:28

The first sentence doesn’t make sense. And the reference [1] is an advice for Java.

Anyone interested in writing repairing this?


ben.knoble
2022-5-8 18:36:13

Hm. Hilariously, since set! -> #&lt;void&gt; , and (not (not (void))) -> #t (i.e., #&lt;void&gt; is not #false)_,_ the following function always returns 1 regardless of its inputs (e.g., #t and #f) (define (f start end) (define a start) (if (set! a end) 1 2)) So while the criticised assignment-expression-as-conditional is possible in Racket, it’s behavior is not altogether surprising if you know what set! and if do. It’s also hard to confuse with equality comparisons given the completely different names (=, eq? , etc.)


soegaard2
2022-5-8 19:05:48

The phrase “replaces a variable with an expression” bothers me.


jcoo092
2022-5-8 20:47:23

Maybe somebody forgot the word “mutates”?


sw5355700
2022-5-8 22:52:10

actually, it’s more simple than that in schemes. anything that’s not #f is considered true.


sw5355700
2022-5-8 22:53:36

and it is weird that someone wrote that on wikipedia. obviously, the notation used for assignment and comparison isn’t a problem specific to expression oriented language.


sorawee
2022-5-8 22:55:24

yeah, I think it’s mostly about surface syntax confusion between = and ==. I think with := for assignment and == for comparison (and make = an error), the confusion would go away.


jcoo092
2022-5-8 22:59:32

In F# it is &lt;- for assignment and = for equality testing, which seems to work pretty well on the whole.


jcoo092
2022-5-8 22:59:51

But I mean, that’s a classic “six of one, half a dozen of the other” situation :slightly_smiling_face:


sorawee
2022-5-8 23:05:23

massung
2022-5-8 23:13:10

Or we can pull out R where assignment can be done with =, &lt;-, or -&gt;. Whoever thought that was a good idea should have their programming license revoked. :yum:


sw5355700
2022-5-8 23:38:35

&gt; (equal? 1 #t) #f


sw5355700
2022-5-8 23:38:39

:neutral_face:


ben.knoble
2022-5-9 01:40:32

Hilarious that Python is mentioned; I would definitely not call it expression-oriented.


ben.knoble
2022-5-9 01:40:51

Any way to see why it was removed and/or try to get it back?


sorawee
2022-5-9 01:54:40

It would start with finding a reference to back up the removed claim (see https://twitter.com/sorawee_p/status/1523481218070634496).


seanbunderwood
2022-5-9 02:08:26

I think it might even be less expression oriented than C