• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Whats the best approach?

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have one method which does some operations depending on a flag.I have to call this method from another method.But I already know the value of flag before calling the method.So I want to know which is the best way?should i call the method if the flag is true? or i should put the flag condition inside the method and call that method anyway?
the code may be like this?
1.Approach1.
boolean flag=false;
public void manage()
{
flag=true//some operatins
doSome();
}
public void doSome()
{
if(flag)
{
//do some thing...
}
}
2.Second approach
1.Approach1.
boolean flag=false;
public void manage()
{
if(flag)
{
doSome();
}
}
public void doSome()
{
//do some thing...
}
can u tell me the performance issues with both the approch...Question may seem silly..but I am eager to know..
Thanks..
A.Umar
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Theoretically, putting the check before the method call will be faster.
Practically, you probably wouldn't notice the difference. A modern Hotspot engine might even decide to inline the method call, so there wouldn't be any difference at all!
So, you shouldn't care about performance, but about maintainability!
 
reply
    Bookmark Topic Watch Topic
  • New Topic