Today I wrote a piece of evil code.
Now, I’ve been known to write shoddy code, buggy code, broken code and naive code, but this was none of these. It was thought out, tested, worked as advertised and was reasonably complicated.
For the record:
//This is a block of evil code that ignores good programming style and design and will cause future programmers headaches.
//The code accesses the private member of a class, breaking encapsulation for the sake of convenience.
Class myClass = someoneElsesObject.getClass();
Field privateDoNotTouchField = myClass.getDeclaredField("doNotTouch");
privateDoNotTouchField.setAccessible(true);
Object myValue = privateDoNotTouchField.get(someoneElsesObject);
privateDoNotTouchField.setAccessible(false);
MyRealObject mro = (MyRealObject)myValue;
Evil code, yes… but not particularly unique. This code can be found without much difficulty, scattered all over the internet. In fact, after I had written it, the comment I received from a colleague was, “Did you use that reflexive technique for accessing private members that’s scattered all over the internet?”
Yes, yes I did. And so, I’ll wager, have many other people. This is why we must ban the internet. It is an example of a larger situation which itself is indicative of a greater problem.
If you throw “<programming language X> tutorial” into google, you will be inundated with millions of pages that have to do with learning language X. You will find many many tutorials that do indeed teach you how to program in language X. You may even read these tutorials and learn how to program language X.
And then you will go write evil code of the approximate quality above. Or worse. You can learn how to write C code without ever learning about a buffer overflow; you can learn to set up a website without ever learning about SQL Injection and XSS attacks.
Why? Because you learned from the internet. The internet is remarkably good at providing you with information, but remarkably poor at telling you which information is relevant, helpful, and worth knowing. The catch-22 here is that if you are learning something on the internet, you don’t know anything about it. That’s why you’re learning it.
You are floundering at the mercy of whatever google serves up, good or bad. If it’s bad, you won’t know, because you aren’t qualified to figure that out.
To put it another way,
THE INTERNET ALLOWS YOU TO BE FULLY INFORMED, ON A SUBJECT YOU KNOW NOTHING ABOUT.
Lets ban it. Ban it now, I say. This is why I hate computers.