• 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

Static without a cause

 
Ranch Hand
Posts: 974
11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am reading through some old code and the creator of the source is using static functions in a class everywhere he can. For example also private functions that are always called from a created object of the class. Is there some efficiency reason for doing this? Why should people prefer to make 'everything' static where they can?
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jan de Boer wrote:I am reading through some old code and the creator of the source is using static functions in a class everywhere he can. For example also private functions that are always called from a created object of the class. Is there some efficiency reason for doing this? Why should people prefer to make 'everything' static where they can?


Quite a bit there.

Let's deal with your questions:

1. Is there some efficiency reason for doing this?
Answer: theoretically yes, but in practise no; and even if there were, it's the sort of micro-optimization that Donald Knuth warned us all about a long, long time ago.

2. Why should people prefer to make 'everything' static where they can?
Answer: They shouldn't. And the only reason they would (and this is just my guess) is probably because they're beginners, and they discovered that you can't call an instance method from main(); which is where newbies usually start out doing all their work - a very bad habit, I might add.

So, congratulations: you're clearly developing a good sense of "code smell".

Winston
 
Jan de Boer
Ranch Hand
Posts: 974
11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank for confirming this is just bad coding. I thought I missed something here. :-)
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Possibly because he had a book teaching procedural programming and could only translate it into Java by making things into functions.
 
reply
    Bookmark Topic Watch Topic
  • New Topic