herbstschweigen wrote:Reverse Regular Golf, is that standing with your putter next to the hole and waiting for the ball to jump out? And, shouldn't he start at hole 18 then? (or 9, depending on the course.)

I suspect you're Golf-trolling, but for those who are mercifully ignorant of this horrible "game," [meaning actual club-and-tiny-ball golf] Reverse Golf is to attempt to get the highest possible score (number of strokes).

As to Code Golf -- it's sort of fun and a useful exercise when learning a new language, but seeing as Golfers regularly create a new language or new 'builtin' functions to reduce their score, it's kind of a lame competition.

cellocgw wrote:As to Code Golf -- it's sort of fun and a useful exercise when learning a new language, but seeing as Golfers regularly create a new language or new 'builtin' functions to reduce their score, it's kind of a lame competition.

Which is why the mousover is what it is: he's still on his first hole in golf, because the more strokes he takes before finishing makes him score higher. If he takes a stroke that doesn't cause him to land the ball in the hole, he's objectively incentivized to never land the ball in the hole.

How else would you compare x to one? Unless you mean it should be "if x==1", for which I'm agnostic (it's just what I'm used to, and I can see the benefit of the "1==x" thing).

Jose

Order of the Sillies, Honoris Causam - bestowed by charlie_grumbles on NP 859 * OTTscar winner: Wordsmith - bestowed by yappobiscuts and the OTT on NP 1832 * Ecclesiastical Calendar of the Order of the Holy Contradiction * Heartfelt thanks from addams and from me - you really made a difference.

How else would you compare x to one? Unless you mean it should be "if x==1", for which I'm agnostic (it's just what I'm used to, and I can see the benefit of the "1==x" thing).

Jose

There's a general default for comparisons to be variable==constant rather than the other way around (and when comparing two variables, for the more volatile to be compared to the less volatile) so, while "1==x" is functional as code, and may well get compiled to exactly the same operations as "x==1" does (depending on how optimising the compiler is, and whether there's any advantage to either order), it's not as readable, so less good under most circumstances.

There are situations where "1==x" is defensible - if the 1 is a placeholder that will be replaced by an expression later, or the code has been modified from an earlier version where there was an expression present (though optimising the expression down to 1 is a questionable decision - most code-level optimisation is premature). Similarly, return 1 + stupidly_long_multi_line_variable_name_that_goes_on_and_on_and_on_for_far_too_long is more readable than return stupidly_long_multi_line_variable_name_that_goes_on_and_on_and_on_for_far_too_long + 1 because the important stuff (that you're returning a value 1 more than something) is all in one place, rather than having the "return" on one line and the "one more than" on another.

The point of 1==x rather than x==1 is to avoid bugs of the "oops, I typed = rather than ==" variety.x=1 will compile (it's an assignment).1=x will not. (You can't assign to an immutable).

So, it catches a particular kind of common bug.

Jose

Order of the Sillies, Honoris Causam - bestowed by charlie_grumbles on NP 859 * OTTscar winner: Wordsmith - bestowed by yappobiscuts and the OTT on NP 1832 * Ecclesiastical Calendar of the Order of the Holy Contradiction * Heartfelt thanks from addams and from me - you really made a difference.

ucim wrote:The point of 1==x rather than x==1 is to avoid bugs of the "oops, I typed = rather than ==" variety.x=1 will compile (it's an assignment).1=x will not. (You can't assign to an immutable).

So, it catches a particular kind of common bug.

Jose

Ah. I'd not encountered that reason before.

Yeah, that checks out, and should probably have been the convention from the start.

Nononononnonoo! The convention should've been "don't write a language where you can perform an assignment within an expression area" from the start. Allowing it makes code less readable and more error-prone in nearly all cases, if not literally all, if not factually all.Anyway, we got a topic for this specifically. Weird it's not in Religious Wars.

cellocgw wrote:but seeing as Golfers regularly create a new language or new 'builtin' functions to reduce their score, it's kind of a lame competition.

I wonder if there's a language that consistently gets top scores and whether it (well, its programming concepts; of course it needs some syntax changes to be useful) would perform well as general-purpose language.

Unfortunately, end-user-programmers don't get to design their own language - they use the languages that are already developed. You go to war with the army you have.

Jose

Order of the Sillies, Honoris Causam - bestowed by charlie_grumbles on NP 859 * OTTscar winner: Wordsmith - bestowed by yappobiscuts and the OTT on NP 1832 * Ecclesiastical Calendar of the Order of the Holy Contradiction * Heartfelt thanks from addams and from me - you really made a difference.

herbstschweigen wrote:Reverse Regular Golf, is that standing with your putter next to the hole and waiting for the ball to jump out? And, shouldn't he start at hole 18 then? (or 9, depending on the course.)

I suspect you're Golf-trolling, but for those who are mercifully ignorant of this horrible "game," [meaning actual club-and-tiny-ball golf] Reverse Golf is to attempt to get the highest possible score (number of strokes).

No, I'm just ignorant enough of golf to have never heard of this. What I wrote was my first association with "reverse golf". There could be a macro quantum phenomenon that allows a ball in the hole to tunnel through the gravity barrier after all (and thus jump out).

Myself I have only played miniature golf, and Wii Sports golf (which I liked), but never tried the real thing, even though I'm a bit curious and quite regularly travel to Scotland.

ucim wrote:The point of 1==x rather than x==1 is to avoid bugs of the "oops, I typed = rather than ==" variety.x=1 will compile (it's an assignment).1=x will not. (You can't assign to an immutable).

So, it catches a particular kind of common bug.

Jose

Ah. I'd not encountered that reason before.

Really? Being a C veteran, I'd not encountered any other reason before, and even though I've been programming Java for 10+ years now, "if (x==1)" still looks dangerous to me. And even though I really agree with:

Flumble wrote:Nononononnonoo! The convention should've been "don't write a language where you can perform an assignment within an expression area" from the start. Allowing it makes code less readable and more error-prone in nearly all cases, if not literally all, if not factually all.

Unfortunately, end-user-programmers don't get to design their own language[...]

End users can choose to enable compiler flags that turn accidental assignments into warnings or errors. For scripting languages, the same can be done with a linter, which can be integrated in your IDE, your bundling/publishing scripts, a pre-commit hook, your CI or whereever.

How does it know which ones are accidental? Might as well let the compiler write my code.

Oh wait <koff>Haskell</koff>

Jose

Order of the Sillies, Honoris Causam - bestowed by charlie_grumbles on NP 859 * OTTscar winner: Wordsmith - bestowed by yappobiscuts and the OTT on NP 1832 * Ecclesiastical Calendar of the Order of the Holy Contradiction * Heartfelt thanks from addams and from me - you really made a difference.

How does it know which ones are accidental? Might as well let the compiler write my code.

GCC asks you to wrap the assignment in an additional set of parentheses if you really meant to do it. This also makes someone reading your code more likely to look a little closer. Which, of course, still leaves us with:

Flumble wrote:Nononononnonoo! The convention should've been "don't write a language where you can perform an assignment within an expression area" from the start. Allowing it makes code less readable and more error-prone in nearly all cases, if not literally all, if not factually all.

(Though I personally think the slightly-orthogonal "don't write a language where assignment can be confused with comparison" is more important.)

That was back before the days of Unicode; the editor (dare I call it an IDE?) used a special code page.

Other special characters used in the language were ≤ ≥ ≠ (rather than <= >= and !=) and the tricolon ⁝ as a delimiter (to allows ; , and : to be used in strings without quoting), and something I can't find in Unicode but that looked something like 【 this 】 for substituting variable into string literals.

While ⇐ could be used in an expression in some cases, it was different enough to type on the keyboard from a = (which was used for comparison) that no problems ever came up.

WanderingLinguist wrote:The first language I wrote production code in used ⇐ for assignment.

Pascal uses := for assignment. Also, I think, was never loosely-powerful enough to allow a straight if a:=b then /* assigned */ else /* not assigned */ endif construct to actually attempt this kind of thing.

Which is what is being asked for, above, but (if your version of Pascal or Delphi or Lazarus allows overloading of assignment, to attempt cross-type reassignment) makes for a loss of handy functionality that you have to replace with a wrapper-function to use as if MakdeEqual(x,y) (MadeEqual(A, B) being."Is A equal to B, already? If so, return True (might as well, uness there's a good reason why not). If not, try making A equal to B. Is A now equal to B? If so, then return True. If not, return False". Remember you may need to explicitly pass references. Been decades since I Pascalled, though, and at least five years even since I last used Delphi/Lazarus.)

Yes, Pascal's ":=" is my favourite. "<=" is nice visually but it already means something else, and "<-" looks rubbish in Courier-like fonts because the minus is too small and doesn't line up with the middle of the "<". And again, the minus sign could be misconstrued. I always thought that if I wrote a language it would be ":=" for assignment and "==" for comparison; "=" would be a syntax error.

Also, having started in Sinclair BASIC, I always think of "x=1" as being shorthand for "LET x=1"; i.e. the "LET" is implicit. Including the "LET" makes statements like "x=x+1" a little less mathematically jarring.

The C assignment-in-conditional thing is possible because of C's "everything is an expression" principle. It has made me view with extreme suspicion any language where the textbook says "everything is an X!" as if that's a good thing.