This answer used a built-in Python function to solve the question in a very short amount of code. Should we allow it and let people not up-vote, or should we police library abuse to some degree? If the latter, where do we draw the line?

Some languages have a big core with lots of functionality, others put it in the libs. Why should we discriminate against the latter in code golf? –  hallvabo Jan 27 '11 at 23:21
I think the title and tags are misleading. A python built in, is not what is commonly known as library. When I read the title and tags I thought of using an external library, which is different from the issue you bring up. –  Juan Jan 27 '11 at 23:40
@Juan Good point. Clarified it. –  marcog Jan 27 '11 at 23:43
add comment

5 Answers

up vote 10 down vote accepted

I'd suggest a certain amount of common sense here.

Using eval to implement a interpreter is an uninteresting solution to code golf, likewise the EasterSundayGreekOrthodox situation that Mark mentions, and Jon's joke language which is defined with a single character token for implementing the solution.

But taking advantage of any general purpose built-in or any general purpose (standard or non-standard) libraries seems fine to me. Why would you leave them out?

Probably this means I'll never "win", cause I pretty much use c, fortran 77 and awk for code golf. Cest la Vie.

Sometimes C rocks ,.) –  Nakilon Jan 28 '11 at 1:44
add comment

This has come up on a number of Code Golf questions on Stack Overflow, but the one I remember the most is Code Golf: Calculate Orthodox Easter date, where someone was lambasted for using Mathematica's built-in EasterSundayGreekOrthodox function. One should check out the discussions already had about this issue on Stack Overflow.

But certain languages derive their power from their large cores or standard libraries: PHP and Python are two notable examples. Let them be: Code Golf involves finding the most innovative solution with the shortest amount of code; if that involves using the standard library, why wouldn't you allow it?

David Sirlin wrote a series of essays entitled Playing to Win: in it, he has some helpful advice about competing using all tools available:

Mysteriously, some games do expect the player to divine the will of the designer, and expect him to adhere to a set of behavioral rules on top of the actual rules of the game. This is the fundamentally flawed concept embraced by most massively-multiplayer online games. Consider World of Warcraft as an example. In a town, you can go on rooftops and you can fight against other players, but you can’t fight other players while on rooftops, or you’ll receive a warning. [...] You can kill the same monster all day every day to “farm” in-game money for yourself (in fact you practically have to), but you can’t farm “too much” or you’re labeled as a gold-farmer and banned. [...] The complex web of made-up rules is not unlike the shackling self-imposed rulebook of the scrub.

I’m here to tell you that legitimate competitive games are not like this. Reasonable games have built-in rules and simply do not allow illegal moves to happen in the first place. Tournaments for reasonable games sometimes have to impose extra rules, but they keep this list as clear and as short as possible. [...]

So what lengths should a player go to in order to win? A player should use any tournament legal move available to him that maximizes his chances of winning the game. Whether certain moves or tactics should be legal in a tournament is a totally separate issue that we’ll get to later. For now, the issue at hand is that if it’s legal in a tournament, it’s part of the game, period. Players often fault other players for “cheating” or playing “dishonestly” when they use tactics that should not be allowed in a tournament, often because they are exploits of bugs. The player is never at fault. The player is merely trying to win with all tools available to him and should not be expected to pull his punches.

add comment

My take on it is, does the library do the interesting part of the puzzle, or is it just a general helper? For example, using map or reduce is perfectly okay, in my book.

Or, you know, print (which is a standard library function in most languages) or + (which is a standard library function in some). –  sepp2k Jan 27 '11 at 23:12
add comment

I guess for such trivial things a better answer would be a re-implementation which should be just as golfable as in any other language. Another such example would be to print out numbers in a readable format, where Lisp (iirc) has a built-in function to do so.

Upvoting an answer that actually does the implementation should probably take care of that. However, technically it still is a shorter solution. Meh.

How often does that happen, though, that there is a single function that essentially does all the golfing for you?

I once had a talk with LiraNuna and he generally had the opinion that trivial golf tasks are boring and a good golf task should be a challenge in any language you might throw at it – ofttimes with a straightforward and a clever solution where it's not immediately obviuos which one is better. So I guess the more successful golf challenges here will not be the ones that simply ask you to add two numbers or print out Hello World.

add comment

I really just think that you should have to code everything yourself. I mean the whole point of codegolf is to solve a challenge. Just calling a method is crap. What benefit or entertainment can you possibly gain from that? It almost seems like point-whoring for the shortest answer.

add comment

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .