Re: This sort of thing might push me to Scala
Lorenzo Jorquera <lorenzo_jorquera-/[email protected]> Fri, 18 Dec 2009 04:42:50 -0800 (PST)
| Newsgroups | gmane.comp.programming.language-of-the-year |
|---|---|
| Message-ID | <[email protected]> |
Even with your code been punished by Java verbosity, I still think your new aproach is much better than the old one. In the old one you had to duplicate the code to disable the waiting cursor 4 times, with all the dangers associated with duplication. I also think then intent is clearer in the new aproach. Regards --- El jue 17-dic-09, Gordon Milne <[email protected]> escribió: De: Gordon Milne <[email protected]> Asunto: [pragprog] This sort of thing might push me to Scala A: [email protected] Fecha: jueves, 17 diciembre, 2009, 7:48 pm Hi! I have 4 methods that have code like this in them: final LsWaitingCursor waitingCursor = new LsWaitingCursor( frame); try { new MethodEditor( title, file); } finally { waitingCursor. disable() ; } The only thing difference between the 4 methods is the code in the try block. That piece of code is always a single statement. What I really want to write is this: runWithWaitCursor { new MethodEditor( title, file) } Since I work in Java, I settled for this: runWithWaitCursor( runnable) . The only problem is that this code is just as verbose and boiler-plated as before, since I end up writing: runWithWaitCursor( new Runnable() { public void run() { new MethodEditor( title, file); } }); How many lines of code did I just save? Zero and I now have another method (runWithWaitCursor) which also has 7 lines of code in it. So my neat idea hasn't reduced my verbosity. It has increased it! And now I have an extra 7 lines of code in runWithWaitCursor( ). The only benefit I did gain was that I separated out the execution of a task (e.g. new MethodEditor( )) from a change in the appearance of the cursor (i.e. waiting/normal) . It doesn't seem like a big enough benefit to me. So, I'm going to revert this change. And dig deeper into the Odersky/Spoon/ Venners book. regards, Gordon J Milne ------------ -- I struggle because it's good for me! ____________________________________________________________________________________ ¡Obtén la mejor experiencia en la web! Descarga gratis el nuevo Internet Explorer 8. http://downloads.yahoo.com/ieak8/?l=e1