![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi. I'd like to know if there is any overhead in using static variables. I like to use them because the code is cleanner than when I'm using objects. But I don't know what are the negative aspects of doing that. I don't have a lot of static variables in my classes, but I have a lot of static methods. I think there is no problem with the methods. Can anyone help me? |
#3
| |||
| |||
|
|
Hi. I'd like to know if there is any overhead in using static variables. I like to use them because the code is cleanner than when I'm using objects. But I don't know what are the negative aspects of doing that. I don't have a lot of static variables in my classes, but I have a lot of static methods. I think there is no problem with the methods. Can anyone help me? Thanks |
#4
| |||
| |||
|
|
Ricardo <Ricardo (AT) discussions (DOT) microsoft.com> wrote: Hi. I'd like to know if there is any overhead in using static variables. I like to use them because the code is cleanner than when I'm using objects. But I don't know what are the negative aspects of doing that. I don't have a lot of static variables in my classes, but I have a lot of static methods. I think there is no problem with the methods. Can anyone help me? If a lot of your code is cleaner when using static methods, that's often (but not always) a sign that you don't have the right classes to start with. The negative aspects of static methods stem from the lack of a lot of the benefits of object oriented programming - most notably polymorphism. In fact, you may well find that static methods are very slightly faster than instance methods, but in either case the difference is very unlikely to be even slightly significant in any real application. Code for what is most readable - but if you find yourself writing a lot of static methods, consider changing your object model. -- Jon Skeet - <skeet (AT) pobox (DOT) com http://www.pobox.com/~skeet If replying to the group, please do not mail me too |
#5
| |||
| |||
|
|
It amazes how many developers love the "static" for ease of programming. ice |
#6
| |||
| |||
|
|
It amazes how many developers love the "static" for ease of programming. ice Ice, Can you elaborate on the point you were getting at? -Brock http://staff.develop.com/ballen |
#7
| |||
| |||
|
|
the point was that, my developers prefer doing things like: StaticClass.Method(parameters) verus InstanceClass class = new InstanceClass(instanceData) class.Method() Totally minimizing the ability to extend the classes i.e. let's avoid having state in the class, so i can call a static method and pass all the data I need in. The only classes that I really think should be designed for static use only, are "helper classes". |

#8
| |||
| |||
|
|
the point was that, my developers prefer doing things like: StaticClass.Method(parameters) verus InstanceClass class = new InstanceClass(instanceData) class.Method() Totally minimizing the ability to extend the classes i.e. let's avoid having state in the class, so i can call a static method and pass all the data I need in. The only classes that I really think should be designed for static use only, are "helper classes". I understand this is a limited example, but I think I'd tend to disagree with you here. Primarily because I can't tell what benefit InstanceClass is giving me in this scenario. Creating an object for the sake of doing "OO" programming isn't proper OO programing. OO programming is intended to model entities that hold state and to hide complexity. Also, it's silly to create a temporary heap based object to only call a single methid then give it back to the GC. statics are an excellent tool in the dev's toolbox (as are classes and objects). Each has its own purpose and utility. I know I'm probabaly starting a religious debate here (it wasn't my intent). ![]() -Brock http://staff.develop.com/ballen |
#9
| |||
| |||
|
|
I think we agree more than you think. |

#10
| |||
| |||
|
|
Hi. I'd like to know if there is any overhead in using static variables. I like to use them because the code is cleanner than when I'm using objects. But I don't know what are the negative aspects of doing that. I don't have a lot of static variables in my classes, but I have a lot of static methods. I think there is no problem with the methods. Can anyone help me? Thanks |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |