Ask HN: Are there any sites that help you practice reading obfuscated code?

2 points by TruthElixirX ↗ HN
I'm taking a java programming class this semester. Our quizzes and tests usually revolve around a chunk of code that is hard to understand, uses lots of nested loops, broken switch statements, etc.

The professor doesn't provide any material to prepare for the tests and the too easy to prepare for the test.

I'm looking for some sort of resource to practice reading hard to understand code, particularly java. Does HN have any suggestions?

Books/websites/videos/etc are all welcome.

EDIT:: The examples below are a little too hard. I'm looking for something that is entry level stuff.

4 comments

[ 19.0 ms ] story [ 15.2 ms ] thread
Use a pencil and paper. Make a column for each variable. As the values change, record the new value in a new row. That will get you through the test questions as long as you read the code correctly.

Think about what could cause loops to behave in unexpected ways. Consider off-by-one loop errors like >= where > was needed and vice versa, or a loop condition being assignment (x=y where y is nonzero, so it resolves to true) instead of testing for equality (x == y). Write code for long enough and you will make these errors yourself and debug them so you will become very good at recognizing them. Also be aware of the break, continue, return, and finally keywords.

It doesn't sound like you're looking for "obfuscated" code, which is what the links below show. But rather real code that's more complicated than slide examples.

I would look for random code people wrote, for example on github:

https://github.com/search?utf8=%E2%9C%93&q=sort&repo...

And then just look at the code and try to understand how it works. This result for example seems to implement basic functions and is well commented:

https://github.com/erlide/erlide/blob/6b836bcb0770d23c4471f4...

Hope this helps