Fancy Code
I find that in the past couple of years, I've been writing code that is fancier. When I think about it, it's pretty dubious whether this fancier code is actually better. For instance, I've done something like the following Java several times recently:
If you do a lot of Swing and you're used to creating a lot of anonymous objects which implement interfaces, this might be acceptable, but I personally find it pretty unreadable. Well why write it then? It is the least amount of code for the purpose, and it does provide good encapsulation. It's possible there's a performance benefit because it's an anonymous object, but I'm not sure if there is, and that benefit seems pretty negligible in the greater scheme of things. I think I better go back to creating it the way I used to do it, before I got fancy.
public void method() {
//run code in another thread with
Thread t = new Thread(new Runnable() {
public void run() {
System.out.println("Hello World");
}
})
}
If you do a lot of Swing and you're used to creating a lot of anonymous objects which implement interfaces, this might be acceptable, but I personally find it pretty unreadable. Well why write it then? It is the least amount of code for the purpose, and it does provide good encapsulation. It's possible there's a performance benefit because it's an anonymous object, but I'm not sure if there is, and that benefit seems pretty negligible in the greater scheme of things. I think I better go back to creating it the way I used to do it, before I got fancy.



0 Comments: Post a Comment
<< Home