# What programming language should we consider for the code-golf solution ? [closed]

If we want to prevent having ridiculous answer for Code-Golf with esoteric language that are made up just for the challenge, we need to define what are the acceptable programming language.

The boundary I would think of are the following (note that those are just up there as an example):

• Does the programming language have at least 10 page of documentation about it ?
• Does the programming language can do anything else than the challenge for which it's made up.
• Can you find at least a project using that language on the web ?

## closed as off-topic by Mego♦, Cyoce, PhiNotPi, GamrCorps, RɪᴋᴇʀMar 4 '16 at 16:46

• This question does not appear to be about Programming Puzzles & Code Golf Stack Exchange or the software that powers the Stack Exchange network within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

• Where do languages like HQ9+ fall in? – Nathan Osman Feb 21 '11 at 0:26
• They fall out, I guess? – Rei Miyasaka May 1 '11 at 22:55
• How about something like "100 point penalty for the following languages: APL, J, K, golfscript, ..." – Braden Best Feb 11 '14 at 4:06
• I'm voting to close this question as off-topic because complaining about usage of languages designed for golfing never contributes positively towards the site. – Mego Mar 3 '16 at 0:57
• @Mego considering the most upvoted answer to this question has since became our main rule for code golf, I think this should remained at least for historical reasons. – plannapus Mar 4 '16 at 9:55
• @plannapus I would agree with a historical lock, but that is not mutually exclusive with closing this question. – Mego Mar 4 '16 at 9:57

I think that as long as a compiler was released before the question was asked, it is a valid language. This removes stupid answers such as "I created language X with this command Y that solves this in one character".

• I suppose GolfScript to be a language created to solve golf tasks with one command. I'm against it ) – Nakilon Jan 27 '11 at 22:10
• @Nakilon Then what about J, for example? It's difficult to draw the line. I prefer the idea of just not voting golfscript answers up unless they really are good. – marcog Jan 27 '11 at 22:14
• @marcog, 1) J wasn't invented to solve golf, so it's normal. Let it win where it is suitable. 2) I think questions will be voted up just like always at SO — in 99% cases by solution size. When you are pro in Perl or Ruby or C, made such a cool code without sleeping for 3 nights, and some kid spends 10 minutes to beat you using golfscript... it at least demoralizing and kinda trolling ) – Nakilon Jan 27 '11 at 22:32
• @Nakilon I understand your point, but I disagree. If golfscript does the job well, so why not let it win where it is suitable too? I personally avoid ever up-voting golfscript solutions on SO. It might be the case even more-so here as people get bored seeing illegible golfscript solutions with no explanation. – marcog Jan 27 '11 at 22:36
• @marcog, my position is that golfscript breaks two rules (recommendations) at once: 1) language can't be invented for just solution this task - it's invented just for golfing; 2) language must be used in world practice - golfscript invented and suitable only for golfing. – Nakilon Jan 27 '11 at 23:05
• @Nakilon: Being invented to be good at code golf is different from being invented to solve the problem at hand. Yes, some language golf better than others. Too bad. Either learn a good golfing language, or (what I do) resign yourself to not "winning". For me the win is in the process. – dmckee Jan 28 '11 at 19:39
• Either eat steroids, or loose to Arnold – Nakilon Jan 28 '11 at 19:48
• Either break windows with stone, like I do, or be a mommy's boy – Nakilon Jan 28 '11 at 19:50
• @Nakilon: It's a game. There isn't some pure Platonic, ideal to live up to here. Surveying the code-golf questions on Stack Overflow I estimate the GS wins about 1/2--2/3; J wins about 1/5; perl, python, ruby, dc and rebmu win from time to time. Mathmatica, c, c++, befunge, and rebol show well but rarely win. And I sometimes write my solutions in fortran 77---heavily golfed, to make the shortest fortran solution I can---but I know I'm not going to "win". Such is life. – dmckee Jan 28 '11 at 20:07
• @Nakilon: What makes it a cheat? The stack nature? How about forth? The powerful single character operators? What about APL? GS doesn't do anything new, it just collects the good golfing features in one place. – dmckee Jan 28 '11 at 20:23
• @Nakilon: We're debating rules. You don't get to assume the ones you want without defending them. – dmckee Jan 28 '11 at 20:37
• @Nakilon: GolfScript cannot solve golf problems "with one command"---it's actually a general-purpose programming language. You should learn GolfScript before you bitch further about it. GolfScript also has things it does not do well or with brevity. Floating point comes to mind. – Chris Jester-Young Jan 30 '11 at 4:12
• @Nakilon: Regarding your claim that GolfScript is useful only for golfing, I beg to disagree. On a couple of occasions, I've found myself using it to do a few practical non-golfing tasks. Could I have used another language? Sure. But GolfScript was the most convenient for the occasion. – KirarinSnow Jan 30 '11 at 19:36
• I disagree that golfscript is purely designed to win codegolf. Firstly it has some really long keywords such as "while" and "base" which should surely be abbreviated to single chars. Golfscript stands up as an interesting language to learn and in a few hours you can really stretch your brain. There has certainly been times when I have spent 3 days trying to beat a perl or J solution with golfscript. I think only people who have learned the language can appreciate the answers properly. Everyone else seems to think we bash the keyboard randomly for 10 mins and the program writes itself – gnibbler Feb 1 '11 at 13:49
• @gnibbler -- It says right on the GolfScript site: "GolfScript is a stack oriented esoteric programming language aimed at solving problems (holes) in as few keystrokes as possible." Just because it can be used for general purposes (any Turing-complete language can), and occasionally can be used effectively, doesn't mean it's been designed for anything other than to win golfs. – Rei Miyasaka May 1 '11 at 23:00

I was thinking about this a lot, since the esoteric languages like APL, GolfScript, J, ... always win and suck out the enjoyment out of CodeGolf.

• It's not fair because these languages were created just for the challenge.
• In many cases, they use non-ascii characters to "compress" source code (Sclipting, APL)
• For me it's fun is to see a surprisingly short code or a trick in language which I use for serious things, not a squeezed code of some esoteric language, even if it's shorter, because that's not surprise - you already expected it, the language was created for that.

So I think it makes perfect sense to make specific challenges for non-esoteric languages only. It could bring the enjoyment back!

Back to the definition. Basicly, esoteric language is a language that is not normally used for any real bussiness and was created just for challenges. More objective criteria for what esoteric language could be:

• It is listed in Esoteric language list - with the exception of PERL and perhaps other mistakes.
• It doesn't have a tag on StackOverflow with at least 2000 questions.
• Is not part of any standard OS release (meant as an exception for small standard tools like awk, sed, dc etc. even if they don't have enough questions at SO).
• Uses non-ASCII characters.
• Yours "Can you find at least a project using that language on the web?" is a very good idea, but there might be very alternative and very esoteric projects too...
• You can also name specific languages you are sure you want to exclude just to prevent finding a hole in the rules :-)

Other ideas to develop (just brainstorming):

• Is not used for teamwork programming of products that other people use.
• Is not used for products other people pay for.
• Majority of operations use postfix notation and take operands implicitly from a stack.
• APL, and its descendants J and K, were not created for the purpose of code-golf. They just happen to be pretty good at it for a certain set of problems. – Gareth Feb 1 '14 at 19:16
• @Gareth, thanks for the note. Not pure code-golf in all cases, but the briefness of the language could be one of the authors priority. But certainly we can say that these languages are not applied for real programming. – Tomas Feb 1 '14 at 19:25
• I disagree. I personally only use it for code-golf except on rare occasions, but the J website lists a number of companies and institutions that use J: Cognos · Bayesian Enhanced Strategic Trading · Fax Focus, Inc. · Hewlett Packard · Intel · Korea Telecom · Luen Thai · Maple Partners · Microsoft · Niagara Mohawk Power · Nikko Securities · Novell · Okada Denki Co. Ltd. · Pivotal Technologies · Syngenesis, Inc. for example. It seems unlikely that these are using it for golfing purposes. – Gareth Feb 1 '14 at 21:09
• They say. But what does this actually mean? Can you link actual project made using J? Seriously, if you look at github, there's no serious project written in J, only few golf-like examples. – Tomas Feb 1 '14 at 21:28
• This answer is almost exactly duplicated at meta.codegolf.stackexchange.com/a/938/194 – Peter Taylor Feb 1 '14 at 22:13
• @Tomas You aren't seriously arguing that if it doesn't have many projects on Github, it's not a serious language are you?? Instead of arguing that we shouldn't allow these languages, perhaps you might take the opportunity to learn them? I'd never even heard of J before I started using this site, but now I greatly enjoy the challenge of competing against myself as much as against someone else - always trying to express the solution in a better way. Maybe this is easier to do in J and GolfScript? – Gareth Feb 2 '14 at 20:46
• @Tomas Would you also argue that R should be excluded for similar 'not much on Github' reasons? Or does R not concern you because you can beat it with Perl? – Gareth Feb 2 '14 at 20:49
• @Gareth, R has literally thousands of statistical packages shared in a similar way github does. It is very much used in serious projects and in business. And I can beat Perl with R :) – Tomas Feb 2 '14 at 21:10
• @Tomas k/kdb/q is in use in pretty much every top financial institution in the world. I use it daily to create "real" programs. That you don't see many projects on Github for it might have something to do with its exorbitant licensing fees. – tmartin Feb 6 '14 at 18:37
• @tmartin I see only 15 questions tagged k on SO. Can you link any resource, something to support your claim? – Tomas Feb 6 '14 at 19:05
• @Tomas code.kx.com/wiki/Main_Page . For what it's worth, users of q/k generally wouldn't use SO. They'd use the k4 listbox which is dedicated to the language. It might be niche, but that doesn't make it any less of a programming language than C or Perl or R. Walk into any bank in Wall St and the chances are they'll be using kdb to capture and store their tick data. This obsession you have with online exposure is meaningless. You're barking up the wrong tree. – tmartin Feb 6 '14 at 21:32
• -1 for the snark about stack-based languages. The reason many golfing languages are stack based is because that obviates the need for grouping operators, shortening the code, but that in no way detracts from the golfing, and is a feature of a number of other languages, e.g. PostScript. – AJMansfield Oct 6 '15 at 0:07
• In fact, as far as golfing goes, Postscript is actually a really effective language because of its inclusion of binary token equivalents of most of the operators, but has about as much production usage as they come, as it was the standard digital format for printed documents for over 20 years, only dying out as PDF (a PostScript derivative) came to replace it. – AJMansfield Oct 6 '15 at 0:13

Why do you demand "the language is being used in the real world"? Golfing is not a real word problem. Reducing the size of your program may have been a real world application many years ago. Reducing the size of a program is still an issue for web applications using tons of JavaScript but that process is not golfing. Golfing is about finding the shortest program, not take an existing program and just squeeze (remove white-space, line breaks, only one char identifiers etc.) it.

Can you find at least a project using that language on the web

That one is trivial. I can write webpages in esoteric programming languages, in fact, I've already done things like that.

Does the programming language have at least 10 page of documentation about it

Why would the quantity of documentation matter? Extremely simple languages barely need one page of documentation.

My feeling is that it's best to implement "soft" site-wide policies like not using built-in features of languages that automatically solve the bulk of the problem.

Why not? Golfing is about finding the shortest program in a language. If the language has a function which nearly does the job than that is the shortest way to do it.

The absolute shortest answer is secondary to me, and certainly a very short answer in a tool language that was designed for the domain of the problem isn't that interesting at all.

Again, if that is the case you are not golfing. It's not golfing if you just want some decent looking solution.

Are there two or more web-frameworks for serious use for the language?

That's no way to measure anything. Haskell has many good web-frameworks but is still considered (at least from the java/oop mainstream) to be a silly language nobody would use in production.

To sum up: If you want language agnostic golfing than some esoteric looking languages or even plain esoteric languages will win in some challenges. That's just the way it is. If you look at anarchy golf J kicks ass. It wasn't invented for golfing (probably ;)) but it turns out to be very good at it. Look at it as a sport. You won't set a maximum height for a basket ball player just because some are bigger than others and that turns out to be an advantage in some situations.

Otherwise create code golf problems and judge each language separately.

If you are not interested in golfing but interested in comparing your pseudo-leet-skills then just don't do golfing. Invent something else.

My feeling is that it's best to implement "soft" site-wide policies like not using built-in features of languages that automatically solve the bulk of the problem. For example, we might disallow using h in GoRuby for a Hello World problem, or using the built-in Easter-calculation functions in PHP for an Easter problem.

That way, you can use an esoteric language if you like---as long as you're not using a built-in function to solve the problem in 1 character.

• Or people could just stop asking "Hello World" golfs. Just pick a different phrase - there are plenty of them – gnibbler Feb 1 '11 at 13:43
• @gnibbler His suicide note was in C. printf("Goodbye, World!"); – Mateen Ulhaq May 3 '11 at 0:13

I suppose I don't mind seeing answers in GolfScript or other similar "made-to-golf" languages -- but I admit that I don't consider them serious answers.

How 'bout this as a test: Are there two or more web-frameworks for serious use for the language?

Update:

Please understand: I wasn't proposing the test as a criteria for "serious language", but as a possible criteria that code-golf questions could use for the languages they'd like to score.

It feels to me like there are roughly four categories of languages in use when answering CodeGolf:

• Main stream general purpose languages: C, C++, Phython, Ruby, etc...
• Tool languages, that are generally aimed a certain domain: awk, bash, sed, MatLab
• Golf languages, aimed at winning code golf but which no one would use in production: GolfScript, etc...
• Obviously inappropriate languages for code golf, which people use for fun: Cobol, Visual Basic, LabView

Now, of course it is impossible to put hard and fast definitions on these categories. But I think that for a given problem, looking at the shortest solution in a main stream language is interesting, and has merit, separately from shortest overall (which is often in a tool or golf language).

I like code golf, because I like seeing the inventiveness of the answers, and the ways that people find to extract hidden power from a language's features and shortcomings. The absolute shortest answer is secondary to me, and certainly a very short answer in a tool language that was designed for the domain of the problem isn't that interesting at all. (Aside: I love good question design that manages to keep the solution from being solely in a single domain so that all languages have to stretch!)

In light of this, my proposed test (which was certainly cheeky) was for what would constitute a mainstream language. -- Though I have to admit, I've since found at least one web framework for bash on the web!

• I think my language of choice is both fairly suitable for golfing (being able to beat Python, sometimes Perl, rarely even Ruby), yet there is no web framework for the language. Not every language is created equal and you probably won't find a web framework for bash either. – Joey Mar 1 '11 at 0:52
• Are there any frameworks for the language at all? – MtnViewMark Mar 1 '11 at 3:22
• Not that I know of. By your line of reasoning you probably also don't consider awk a serious language or many esoteric ones (Befunge springs to mind which can be fairly short). – Joey Mar 4 '11 at 10:51
• So - I think you are all taking my comment in quite the wrong way... clearly I need to reword it. I wasn't proposing a hard filter - just a possible criteria people could choose use. – MtnViewMark Mar 4 '11 at 16:14

Edit: I removed the Bash version (it was buggy and I couldn't seem to fix it), and I updated the C/C++ version (now identical) due to a better implementation in the comments. I also added equivalents in several other languages.

I have a list of minified implementations of the greatest common divisor operation in several different languages. Maybe this can influence some of this discussion.

ANSI C/C++:
int a(int b,int c){return c?a(c,b%c):b;}

K&R C: (permits implicit int types)
a(b,c){return c?a(c,b%c):b;}

Common Lisp:
(defun a(b c)(if(zerop c)b(a c(mod b c))))

ECMAScript 5:
function a(b,c){return c?a(c,b%c):b}

ECMAScript 6: (uses implicit global)
a=(b,c)=>c?a(c,b%c):b

Forth:
: g begin ?dup while tuck mod repeat ;

GolfScript:
~{.@\%.}do;

Java:
int a(int b,int c){return c>0?a(c,b%c):b;}

g a b=if a > 0 then g(b rem a)a else b


So, here's the stats for each of those examples:

• Common Lisp: 42
• ANSI C/C++: 40
• K&R C: 28
• ES5: 36
• ES6: 21
• Forth: 38
• GolfScript: 11
• Java: 42
• The Java is buggy: the condition is back to front. It also includes unnecessary whitespace, and could use <1 or >0 to save another char. – Peter Taylor Jul 15 '14 at 8:34
• I suspect that Haskell can save a few by not using infix rem, but I don't know it well enough to easily test whether that compiles. – Peter Taylor Jul 15 '14 at 9:11