• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Monica Shiralkar
Ranch Hand
Posts: 858
1
  • Mark post as helpful
  • send pies
  • 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..
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where did you read that? Was there no explanation? It is certainly bad OOP style.
 
Tyson Lindner
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
  • 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: 858
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks
 
Campbell Ritchie
Sheriff
Pie
Posts: 49813
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Static methods have nothing to do with performance. They have to do with not using instance members.
 
Winston Gutkowski
Bartender
Pie
Posts: 10508
64
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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: 858
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic