Page 1 of 1

1960: "Code Golf"

Posted: Mon Feb 26, 2018 11:42 am UTC
by herbstschweigen
Image

Title text: "I also enjoy Reverse Regular Golf. I've been playing for years all across the country and I'm still on the first hole."

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.)

Re: 1960: "Code Golf"

Posted: Mon Feb 26, 2018 12:13 pm UTC
by cellocgw
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.

Re: 1960: "Code Golf"

Posted: Mon Feb 26, 2018 1:43 pm UTC
by roderik
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.


Actually that is one of those loopholes that are forbidden by default(creating a new language) and built-in functions are often disallowed in the specific challenge itself.

Re: 1960: "Code Golf"

Posted: Mon Feb 26, 2018 2:48 pm UTC
by karhell
Unless I severely misunderstood something, reverse-code-golf is usually called code bowling.

Re: 1960: "Code Golf"

Posted: Mon Feb 26, 2018 4:51 pm UTC
by rhhardin
Our code contest was the slowest sort.

Re: 1960: "Code Golf"

Posted: Mon Feb 26, 2018 6:06 pm UTC
by orthogon
Is "return 1+thing" another Yoda-style idiom like the stupid "if 1==x" nonsense?

Re: 1960: "Code Golf"

Posted: Mon Feb 26, 2018 6:58 pm UTC
by Justin Lardinois
Isn't "reverse code golf" just called Java?

Re: 1960: "Code Golf"

Posted: Mon Feb 26, 2018 7:10 pm UTC
by Draco18s
Justin Lardinois wrote:Isn't "reverse code golf" just called Java?


You can golf in Java. Your score is only going to be so good, though, but your score is only compared to other Java entries.
Heck, you can golf in Redstone too

In any case, the thing Randal is doing here isn't Code Golf, it's Code Bowling. The problem is there's no objective winning criteria.

For example I can "out-score" Randal trivially:

Code: Select all

define thisIsPointlesslyLong = 1 - 1
define callMeIshmaelSomeYearsAgoNeverMindHowLongPrecisely():
        return thisIsPointlesslyLong


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.

Re: 1960: "Code Golf"

Posted: Mon Feb 26, 2018 7:51 pm UTC
by ucim
orthogon wrote:Is "return 1+thing" another Yoda-style idiom like the stupid "if 1==x" nonsense?
What is the "if 1==x" nonsense?

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

Re: 1960: "Code Golf"

Posted: Mon Feb 26, 2018 9:34 pm UTC
by rmsgrey
ucim wrote:
orthogon wrote:Is "return 1+thing" another Yoda-style idiom like the stupid "if 1==x" nonsense?
What is the "if 1==x" nonsense?

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.

Re: 1960: "Code Golf"

Posted: Mon Feb 26, 2018 9:47 pm UTC
by ucim
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

Re: 1960: "Code Golf"

Posted: Mon Feb 26, 2018 10:58 pm UTC
by rmsgrey
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.

Re: 1960: "Code Golf"

Posted: Mon Feb 26, 2018 11:39 pm UTC
by Flumble
rmsgrey wrote:
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.

Re: 1960: "Code Golf"

Posted: Tue Feb 27, 2018 2:12 am UTC
by Bloopy
I wonder if Inverse Code Golf would work slightly better. Write a seemingly pointless program and see if anyone can come up with a problem that it solves.

Re: 1960: "Code Golf"

Posted: Tue Feb 27, 2018 3:17 am UTC
by ucim
Flumble wrote:The convention should've been "don't write a language where..."
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

Re: 1960: "Code Golf"

Posted: Tue Feb 27, 2018 6:09 am UTC
by herbstschweigen
cellocgw wrote:
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.

Re: 1960: "Code Golf"

Posted: Tue Feb 27, 2018 6:12 am UTC
by herbstschweigen
rmsgrey wrote:
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.

Re: 1960: "Code Golf"

Posted: Tue Feb 27, 2018 8:11 am UTC
by Tub
ucim wrote:
Flumble wrote:The convention should've been "don't write a language where..."
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.

This is not an issue that needs to be solved by yoda'ing your code.

Re: 1960: "Code Golf"

Posted: Tue Feb 27, 2018 12:41 pm UTC
by cellocgw
Bloopy wrote:I wonder if Inverse Code Golf would work slightly better. Write a seemingly pointless program and see if anyone can come up with a problem that it solves.


I believe the winner in that category is named "Facebook"

Re: 1960: "Code Golf"

Posted: Tue Feb 27, 2018 3:40 pm UTC
by ucim
Tub wrote:End users can choose to enable compiler flags that turn accidental assignments into warnings or errors.
How does it know which ones are accidental? Might as well let the compiler write my code.

Oh wait <koff>Haskell</koff>

Jose

Re: 1960: "Code Golf"

Posted: Tue Feb 27, 2018 6:32 pm UTC
by Solra Bizna
ucim wrote:
Tub wrote:End users can choose to enable compiler flags that turn accidental assignments into warnings or errors.
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.)

Re: 1960: "Code Golf"

Posted: Tue Feb 27, 2018 6:57 pm UTC
by speising
yeah, i don't know who ever came up with = as assignment anyway. couldn't have been a mathematician. something like <- would have been a lot more logical and unambigous.

Re: 1960: "Code Golf"

Posted: Tue Feb 27, 2018 10:30 pm UTC
by WanderingLinguist
The first language I wrote production code in used ⇐ for assignment.

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.

It was also used for loops:

Code: Select all

loop i ⇐ 1, 5

would loop over the indices 1,2,3,4,5 inclusive.

Re: 1960: "Code Golf"

Posted: Wed Feb 28, 2018 12:58 am UTC
by Soupspoon
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.)

Re: 1960: "Code Golf"

Posted: Wed Feb 28, 2018 9:04 am UTC
by chalkie
I write in VHDL, and that uses <= for signal assignment. Because that won't get anyone confused :)

Re: 1960: "Code Golf"

Posted: Wed Feb 28, 2018 10:17 am UTC
by orthogon
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.