Tricky Code
Learn about the trade-off between writing code that's concise and tricky versus code that's longer but more comprehensive.
We'll cover the following
Short vs explicit
As a general rule, explicit code should be preferred over 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 ourselves as code authors, when we return to the code after some period of time. Finding the optimal tradeoff between concise and clear is something we 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