Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Coding Standard - Time Cost Factor

 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



In class "A" I had declared an instance variable i and in
methodOne I am declaring a local variable i and initializing it to
some value. I need that value in methodThree but I have to go through
methodTwo(even if I am not doing any processing with that variable) and
I am calling methodThree from methodTwo.

Is it a good coding practice to do like this (or) to declare
the variable i as an instance variable and use it in the program.
I heard when we go for a instance variable, each time the instance
variable is used in the program it adds overhead to the object and
results in time cost.


Someone please help me with this doubt.
 
Alexandru Popescu
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by vishnu prakash:
[CODE]
[...]
I heard when we go for a instance variable, each time the instance
variable is used in the program it adds overhead to the object and
results in time cost.


From where???

--
:alex |.::the_mindstorm::.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In 99.99% of all cases, the time cost (if any) will be irrelevant. You should decide on this based on other reasons than performance, for example flexibility and maintainability of the design.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic