• 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

why is it said that too many static methods are not good for performance.

 
Ranch Hand
Posts: 2925
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have read that that too many static methods are not good for performance. Why should be avoid keeping to many static methods in code.

thanks..
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where did you read that? Was there no explanation? It is certainly bad OOP style.
 
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Monica. Shiralkar wrote:I have read that that too many static methods are not good for performance. Why should be avoid keeping to many static methods in code.

thanks..



Maybe what was meant was that if you have a large formula its not as efficient to break that formula's parts down into static methods as it is to just try and get it all done within one method. If you use several methods you'll have an extra cost of unnecessary references.

For static methods as opposed to instance methods, if anything it seems like static methods should be more efficient since they don't involve cost associated with the creation of an object.

Side question:
A program has 30 unused static methods and 1 used method, while another program only has the used method. Will the second program *run* faster than the first? My guess is no, the second program might compile some insignificant time faster, but its run time will be the same.



 
Monica Shiralkar
Ranch Hand
Posts: 2925
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Static methods have nothing to do with performance. They have to do with not using instance members.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Monica. Shiralkar wrote:I have read that that too many static methods are not good for performance. Why should be avoid keeping to many static methods in code.


The second question is much more important than the first because - especially at this stage - the last thing that should be on your mind is performance.

Basically, static methods are restrictive because they can only access other static methods and fields; and static fields - especially variables - are usually a BAD thing. Instance methods, OTOH, can access anything they can see.

This is just one of the reasons why MainIsAPain (←click).

Winston
 
Monica Shiralkar
Ranch Hand
Posts: 2925
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks
 
reply
    Bookmark Topic Watch Topic
  • New Topic