I often realize people make their code hard to maintain. It's a very good idea to raise your value in the company since nobody else can maintain it. Let's learn from their code. Often you can even get more efficient code since you don't need to write extra lines to make your code nicer. It doesn't cover basic skills like using magic numbers, not making a method name readable, give an object more than one name, delete all comments, etc (Do all of them!). Ideas are listed in order of importance.
(1) Store the same value in more than one places.
If you store the same parameter in more than one places, you need to synchronize them. When a maintainer write a code that changes the value, he will have a change to miss the fact and change only one of them. Every code that uses the other variable which wasn't changed will behave mistakenly. Hopefully the program will be in an inconsistent state.
(2) Store lots of data in an object and every method depends on them
If lots of methods are dependent on the state of the object, the user of the class will need to set all of them properly before using the method and he will be confused. A nice side effect is that it makes the program hard to debug and test cause the behavior of a method can have lots of right and wrong cases. Try packing lots of unnecessary parameters, make the state of objects complicated, and make it hard to maintain.
(3) Reference an object from lots of other objects.
People who look at it will be puzzled, "Is the object I can get from A is the same as what I can get through B?". This strategy is good with (1) above. Unnecessary references are good!
Dec. 24:
Just tried to tell what will happen if you do them. Don't do them of course :)
Saturday, December 4, 2010
Tips to obfuscate your code.
Subscribe to:
Post Comments (Atom)
1 comment:
Thanks for the post!
It would also be helpful to see examples of bad code as well as good code. Common misconceptions and incorrect usage of these techniques would also be useful.
Keep it up!
Post a Comment