Tricky Code

To what degree should your code be concise instead of comprehensive? Will there always be a trade-off? Find out in the lesson below.

As a general rule I prefer explicit code to using “tricks” to make code extremely short. There is a trade-off, of course. Short, tricky code is less code, but the tradeoff is that it may be more difficult to understand by others, and even by yourself, when you return to the code after some period of time. Finding the optimal tradeoff between concise and clear is something you should be thinking about, and something that will be different for everyone.

If you want to see some examples of ridiculously “tricky” code, there is a competition called The International Obfuscated C Code Contest. Here is an example, from the 2011 IOCCC Competition, the entry called eastman by Peter Eastman:

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy