Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

question about declaring extraneous variables

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Often times I come across code as such...

boolean isValid = someObject.isValid();
if (isValid) { // isValid only being used in one place
....
}

other than the fact that the variable is declared outside of the block in which it is being used, is there a performance hit (no matter how small) to doing this or does the compiler figure it out and optimize the call

This question does not apply to those cases where readability is to be take into account such as...

double commissionAmount = someObject.someReallyScrewyMethodName();
if(commissionAmount > 15.43) { // used once - var for readability only
...
}

Thanks, in advance
 
New rule: no elephants at the chess tournament. Tiny ads are still okay.
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic