this is assuming that what i wrote is a 'premature optimization' which is incorrect. using if-else block is a language construct. the compiler will optimize it according to its (compiler's) discretion. the jvm will optimize it according to its (jvm's) discretion.
using try-catch block, by law, required to carry the whole stack in the object. advising not to use bulldozer to kill a fly, is not an example of the 'premature optimization'. 2009/9/9 ie_khing <ie_kh...@yahoo.com> > > > > > In DonaldKnuth's paper "StructuredProgrammingWithGoToStatements", he wrote: > "Programmers waste enormous amounts of time thinking about, or worrying > about, the speed of noncritical parts of their programs, and these attempts > at efficiency actually have a strong negative impact when debugging and > maintenance are considered. We should forget about small efficiencies, say > about 97% of the time: premature optimization is the root of all evil." > > semoga bermanfaat > > --- In jug-indonesia@yahoogroups.com <jug-indonesia%40yahoogroups.com>, > Daniel Baktiar <dbakt...@...> wrote: > > > > sebaiknya pakai if else, kalau tidak salah exception handling jauh > (beberapa > > puluh atau ratus kali) lebih lambat.dan exception dibuat benar2 untuk hal > > yang pengecualian, bukan yang diharapkan. > > > > kalau dalam hal ini definisi mapping hibernate membolehkan adanya null, > > berarti nilai null diharapkan dan bukan pengecualian. > > > > 2009/9/1 Harry Christian <harr...@...> > > > > > > > > > > > > Hi JUGers, > > > > > > Mau tanya nih. Saya mengalami masalah klasik yaitu Null Pointer. > > > > > > Nah jadi ceritanya saya ada POJO yang berelasi dengan object lain. > > > > > > Contohnya : > > > private Employee emp; > > > private String deptName; > > > > > > public void setDeptName (String deptName) > > > { > > > // Cara 1 > > > if(emp == null) this.deptName = deptName; > > > else if(emp.getDepartment == null) this.deptName = deptName; > > > else emp.getDepartment.setName(deptName); > > > > > > // Cara 2 > > > try > > > { > > > emp.getDepartment.setName(deptName); > > > } catch (Exception e) {return;} > > > } > > > > > > public String getDeptName () > > > { > > > // Cara 1 > > > if(emp == null) return deptName; > > > if(emp.getDepartment == null) return deptName; > > > else emp.getDepartment.getName(); > > > > > > // Cara 2 > > > try > > > { > > > emp.getDepartment.getName(); > > > } catch (Exception e) {return null;} > > > } > > > > > > Inti pertanyaan saya lebih efesien dan lebih cepat mana antara cara 1 > > > (if else) ataukah cara 2 (try catch) ? > > > > > > -- > > > ============================== > > > Thanks & Best Regards > > > > > > Harry Christian > > > > > > YM : callme_harry > > > Skype : harry_christian > > > Facebook : http://www.facebook.com/profile.php?id=696095562 > > > Blog : http://www.harry-christian.blogspot.com > > > =============================== > > > > > > > > > > > > > > -- > > Daniel Baktiar > > Senior JEE* Monkey -- willing to work hard in the Java beans brewery for > a > > big bunch of bananas (http://dbaktiar.wordpress.com) > > > > > -- Daniel Baktiar Senior JEE* Monkey -- willing to work hard in the Java beans brewery for a big bunch of bananas (http://dbaktiar.wordpress.com)