News for hackers. Stuff that matters.
Re:I am a horse in the land of booleans by dmix on Saturday August 10, 2019 @01:39PM (#20663433)
> if does not have a return value in a language like Java. In other words, it is not an expression, but a statement. Because everything in Clojure is an expression, there is no equivalent construct to Java’s if in it.

Anyone know the language design rationale behind the way Java does it? It seems much easier to make everything an expression. Ive always disliked that part of Javascript and being forced to use ternary operators to do a single line return statement for a conditional. Same with case statements.

Re:I am a horse in the land of booleans by zwkrt on Saturday August 10, 2019 @01:49PM (#20663490)
If your control structures are expressions then they can lead to code that the maintainers of the language might not want to promote. Remember that language design is not just about being as flexible as possible. If it were we would have stopped with Lisp. Languages are also designed with readability, portability, and simplicity in mind.

Imagine if you could write this (nonsense) code in Java:

bool a = (while (b) { if (c) { b=d;} else { b=e; }});

While it is efficient, some may balk at how “implicit” it is.

Re:I am a horse in the land of booleans by ACow_Adonis on Saturday August 10, 2019 @08:59PM (#20665533)
Of course I'd say this as a lisper, but as long as the return values of everything is intuitive and well defined, I don't see an inherent problem with such form.

Indeed, if anything, if the intention is to communicate that the Boolean value is the result of some process that runs through a while loop, then explicitly saying that in the assignment seems to me to almost be the best way to do it :\

ymmv.

Now deeply nested while/assignment/ifs, that's a bad-pattern, but I'm not inherently convinced that's an expression/statement problem.

Re:I am a horse in the land of booleans by yogthos on Saturday August 10, 2019 @07:22PM (#20665144)
I've worked extensively with both Java and Clojure, and the latter is far easier to read in my experience.
Re:I am a horse in the land of booleans by sedachv on Saturday August 10, 2019 @03:34PM (#20664069)
> Anyone know the language design rationale behind the way Java does it?

Because C did it, because Algol did it, because Fortran did it, because that is how assembly code works. Expressions require code to be compiled to something that uses a temporary value stack (or equivalent, like what some continuation-passing style compilers do by allocating values from garbage-collected memory), which, along with subroutines, was an exotic technology well into the 1960s.

Re:I am a horse in the land of booleans by verandacoffee on Saturday August 10, 2019 @05:22PM (#20664582)
Algol (60) had if-expressions, as did Simula 67 (based on Algol): x := if (y = 0) then 0 else 4 / y
Re:I am a horse in the land of booleans by gumby on Saturday August 10, 2019 @04:46PM (#20664434)
In general the split between expressions and statements has been disastrous IMHO.

I remember the first time I saw 'constexpr' in C++ I was excited, until I realized it's really conststatement.

The elaborate syntactical decorations of most languages drive away from this, unfortunately.

Re:I am a horse in the land of booleans by Plaastix on Saturday August 10, 2019 @06:06PM (#20664749)
In Kotlin, if is an expression: https://kotlinlang.org/docs/reference/control-flow.html. This is why the language drops Java's ternary operator.