BACKGROUND: I am a CS lecturer (teaching C++) and I keep thinking how to incorporate coding challenges in teaching.

Many questions in this site are great; I have just used Do you want to code a snowman? as a warm-up homework assignment. The challenge of writing short programs fits my goal of encouraging my students to write short and succinct code. The problem is, when the code is made too short (e.g. by putting everything in a single line without spaces), it is not readable - which goes against another educational goal.

QUESTION: is there a way to design a challenge of the form "solve problem X using the shortest code possible, but the code must still be readable"?

I am not sure how to define "readable" in a consistent way; maybe "the code should pass a linter check"?

• The problem with "readable" is that it isn't objective, and we require all challenges to have objective specifications. You can encourage users to include an ungolfed version, but there's no real way to require that – caird coinheringaahing Mar 11 at 0:04
• You could do an atomic code golf sort of thing, where the actual formatting doesn't matter, if you chose an instruction set similar enough to C++ to be helpful to your students. The linter check could be a neat idea too. – Redwolf Programs Mar 11 at 0:27
• There's also [fastest-algorithm], which may (sometimes) result in shorter code. – user Mar 11 at 0:28
• @RedwolfPrograms You might want to turn that into an answer. – user Mar 11 at 0:42