There are a lot of challenges that get you to write programs and/or functions, but (almost) none that get you to write classes. I thought of a way to lay out class-writing challenges - it's quite specific (and might be a bit longer than a code-golf challenge of similar complexity), but does ensure that the challenge is unambiguous and fair for all users.
Questions would include:
- An interface section which describes what public variables/functions the class should have, including the name of the functions and any parameters and return values. The underlying mechanics of the class are up to the user.
- A demo section: an algorithm/some pseudocode that describes a program that will be used in order to test the class. The demo code is separate from the class implementation, so its length not included in the submission's character count. This section exists so that any other user can quickly test a submission using the same code.
- Specifying any disallowances that would make the challenge trivial (e.g. already existing implementations of the challenge, where the user's class just acts as a wrapper). These may be implicit as per the standard loopholes.
Answers would include:
- A class code section, which contains the implementation of the class as described. Essentially, this is the same as any other code golf challenge - the user posts their character length and tries to get the lowest score!
- A demo code section, which contains the code for a program that can be run in order to test the user's class. This should perform the tests that were mentioned in the question. This section's code is not included in the character count.
For example, a challenge to write an integer queue class may be laid out like this:
- The interface would include functions such as
- The demo pseudocode would contain things such as "push 12 to the queue, then pop an item from the queue and print it to the screen, then add all of the integers from [0-100) to the queue"...
- The disallowances would include barring any existing implementations of a queue or dynamic data structure (e.g.
std::list<T>... in C++).
Here's why I think these types of challenges are a good idea:
- It encourages usage of "less popular" languages, as none of the Big Three (Small Three?) - Pyth, CJam and GolfScript - are object-oriented.
- The usage of named functions ensures that everyone's code has the same interface. It would also expose cheating (e.g. reducing
- Class challenges could introduce some new and interesting simple questions (which I personally prefer to the more complex/mathematically demanding challenges), but there is scope to expand these to something more complex.
I'd like to know what you think. Feel free to make any suggestions or changes.