How to Use Member Variables
-
He's right though. Although statics have their place, they are so frequently abused (a "lesser goto" seems a reasonable analogy) that instinctively associating their prescence in a codebase with a "smell" (particularly when said code was written by someone lacking experience) is perfectly natural. Beginner beware, as ever.
Anna :rose: Tech Blog | Visual Lint "Why would anyone prefer to wield a weapon that takes both hands at once, when they could use a lighter (and obviously superior) weapon that allows you to wield multiple ones at a time, and thus supports multi-paradigm carnage?"
Thank-you AJ! I take the view that static should be avoided, but there are times were expedience allows them.
Panic, Chaos, Destruction. My work here is done. or "Drink. Get drunk. Fall over." - P O'H
-
Thank-you AJ! I take the view that static should be avoided, but there are times were expedience allows them.
Panic, Chaos, Destruction. My work here is done. or "Drink. Get drunk. Fall over." - P O'H
Anytime. :)
Anna :rose: Tech Blog | Visual Lint "Why would anyone prefer to wield a weapon that takes both hands at once, when they could use a lighter (and obviously superior) weapon that allows you to wield multiple ones at a time, and thus supports multi-paradigm carnage?"
-
I've been looking at some code today written by a former slave. Now instead of using member variables in methods, dufus decided to pass them all around the shop as arguments to STATIC methods so we get crapola like this:
class DoofusCode {
private int first;
private String second;// more stuff [tm]
public void Method()
{
if (IsFirst(first))
UpdateSecond(out second);
}private static bool IsFirst(int first)
{
// more stuff [tm]
return answer;
}private static void IsFirst(out String second)
{
second = "Second";
}
}Go Optimisers! Go!
Panic, Chaos, Destruction. My work here is done. or "Drink. Get drunk. Fall over." - P O'H
I think the "Create New Method" refactoring tool provided by VS automatically makes a method static if the code you selected to be in the body of the method did not use any non-static member variables. I have occasionally used this "pattern" if IsFirst contains behavior that is generally useful.
Regards Senthil _____________________________ My Home Page |My Blog | My Articles | My Flickr | WinMacro