473,322 Members | 1,259 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

static functions variables

What could be the possible reasons (technical/non technical) of not using lots of static functions or variables in a program keeping in mind that Framework by itself has tons of static functions and variables?
Feb 8 '06 #1
9 2143
If a method does not refer to any state, then it should probably be static as your making it clear it is not and does not need to be an instance method. This can also be more convenient to program against as you can call the static from anywhere in your app domain and don't need an obj instance first. It can also be a bit ~safer as you can't mistakenly change instance data on the type (unless you get a ref to one and go out of your way to change a field). Instance methods kinda tell you they need to be instance methods when you need to refer to instance state,

--
William Stacey [MVP]

"Pohihihi" <no*****@hotmail.com> wrote in message news:eK*************@TK2MSFTNGP09.phx.gbl...
What could be the possible reasons (technical/non technical) of not using lots of static functions or variables in a program keeping in mind that Framework by itself has tons of static functions and variables?
Feb 8 '06 #2
There are no non-technical reasons. And the question is not exactly
well-put. Static functions and data are tools. Some tools are good for some
things, and others are good for other things. So, rather than asking why not
to use "lots of static functions," you should be asking when to use them,
and when not to. In other words, the real question is, "what are the
characteristics of static functions and data that affect my decision of when
to use them?"

Static data is not threadsafe straight out of the box, if you need to modify
it. It can be modified in a threadsafe way, but it requires a bit more work
to do. Static data is global to your application, which means if you change
it in one place, it changes for everything. This can be either good or bad,
depending upon whether or not you want this to happen. Remember that
encapsulation, one of the pillars of OOP, is there for a purpose. Static
functions are fine, as long as they don't need to work with instance data.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
We got a sick zebra a hat,
you ultimate tuna.
"Pohihihi" <no*****@hotmail.com> wrote in message
news:eK*************@TK2MSFTNGP09.phx.gbl...
What could be the possible reasons (technical/non technical) of not using
lots of static functions or variables in a program keeping in mind that
Framework by itself has tons of static functions and variables?

Feb 8 '06 #3
I guess you are right that question was not explained properly. I understand
the desig part of its use and when to and when not to use. What actually I
should have asked is that if I have lots of static functions/variables then
do thay create any memory problem (eating it all) or any performance issues?
What I understand is that because they are static they are in memory all the
time to server its users thus live all the time in memory.
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:eE*************@TK2MSFTNGP09.phx.gbl...
There are no non-technical reasons. And the question is not exactly
well-put. Static functions and data are tools. Some tools are good for
some things, and others are good for other things. So, rather than asking
why not to use "lots of static functions," you should be asking when to
use them, and when not to. In other words, the real question is, "what are
the characteristics of static functions and data that affect my decision
of when to use them?"

Static data is not threadsafe straight out of the box, if you need to
modify it. It can be modified in a threadsafe way, but it requires a bit
more work to do. Static data is global to your application, which means if
you change it in one place, it changes for everything. This can be either
good or bad, depending upon whether or not you want this to happen.
Remember that encapsulation, one of the pillars of OOP, is there for a
purpose. Static functions are fine, as long as they don't need to work
with instance data.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
We got a sick zebra a hat,
you ultimate tuna.
"Pohihihi" <no*****@hotmail.com> wrote in message
news:eK*************@TK2MSFTNGP09.phx.gbl...
What could be the possible reasons (technical/non technical) of not using
lots of static functions or variables in a program keeping in mind that
Framework by itself has tons of static functions and variables?

Feb 9 '06 #4
| Static data is not threadsafe straight out of the box, if you need to
modify

I would add that no var is thread safe - instance or static does not really
matter. If a var is "read-write" by 2 or more threads, it needs some kind
of syncronization.
--wjs
Feb 9 '06 #5
William Stacey [MVP] <wi************@gmail.com> wrote:
| Static data is not threadsafe straight out of the box, if you need to
modify

I would add that no var is thread safe - instance or static does not really
matter. If a var is "read-write" by 2 or more threads, it needs some kind
of syncronization.


Unless it's got a ThreadStaticAttribute :)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 9 '06 #6


Jon Skeet [C# MVP] wrote:
William Stacey [MVP] <wi************@gmail.com> wrote:
| Static data is not threadsafe straight out of the box, if you need to
modify

I would add that no var is thread safe - instance or static does not really
matter. If a var is "read-write" by 2 or more threads, it needs some kind
of syncronization.

Unless it's got a ThreadStaticAttribute :)

To be fair he did say "straight out of the box". Though I didn't get my
box. I downloaded VS... How can it be thread safe if there's no box?

Scott

too early in the morning.
Feb 9 '06 #7
If you got the blue box on a Monday, then I think it is. :)

--
William Stacey [MVP]
Feb 9 '06 #8
Hi Pohihihi,

Actually, static members use *less* memory than instance members, because
they exist at the time the assembly is loaded, and there is only one copy.
There's a bit more mumbo jumbo involved because of the framework, but bottom
line is, they are single instances of data. Still, keep in mind the other
characteristics of static members when making your determination. Sometimes
they are exactly the right tool to use. Sometimes they are exactly the wrong
tool.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
We got a sick zebra a hat,
you ultimate tuna.
"Pohihihi" <no*****@hotmail.com> wrote in message
news:e0*************@TK2MSFTNGP11.phx.gbl...
I guess you are right that question was not explained properly. I
understand the desig part of its use and when to and when not to use. What
actually I should have asked is that if I have lots of static
functions/variables then do thay create any memory problem (eating it all)
or any performance issues? What I understand is that because they are
static they are in memory all the time to server its users thus live all
the time in memory.
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:eE*************@TK2MSFTNGP09.phx.gbl...
There are no non-technical reasons. And the question is not exactly
well-put. Static functions and data are tools. Some tools are good for
some things, and others are good for other things. So, rather than asking
why not to use "lots of static functions," you should be asking when to
use them, and when not to. In other words, the real question is, "what
are the characteristics of static functions and data that affect my
decision of when to use them?"

Static data is not threadsafe straight out of the box, if you need to
modify it. It can be modified in a threadsafe way, but it requires a bit
more work to do. Static data is global to your application, which means
if you change it in one place, it changes for everything. This can be
either good or bad, depending upon whether or not you want this to
happen. Remember that encapsulation, one of the pillars of OOP, is there
for a purpose. Static functions are fine, as long as they don't need to
work with instance data.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
We got a sick zebra a hat,
you ultimate tuna.
"Pohihihi" <no*****@hotmail.com> wrote in message
news:eK*************@TK2MSFTNGP09.phx.gbl...
What could be the possible reasons (technical/non technical) of not using
lots of static functions or variables in a program keeping in mind that
Framework by itself has tons of static functions and variables?


Feb 9 '06 #9
thanks Kevin, that gives me the right thing I was looking for.
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:ub**************@TK2MSFTNGP10.phx.gbl...
Hi Pohihihi,

Actually, static members use *less* memory than instance members, because
they exist at the time the assembly is loaded, and there is only one copy.
There's a bit more mumbo jumbo involved because of the framework, but
bottom line is, they are single instances of data. Still, keep in mind the
other characteristics of static members when making your determination.
Sometimes they are exactly the right tool to use. Sometimes they are
exactly the wrong tool.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
We got a sick zebra a hat,
you ultimate tuna.
"Pohihihi" <no*****@hotmail.com> wrote in message
news:e0*************@TK2MSFTNGP11.phx.gbl...
I guess you are right that question was not explained properly. I
understand the desig part of its use and when to and when not to use. What
actually I should have asked is that if I have lots of static
functions/variables then do thay create any memory problem (eating it all)
or any performance issues? What I understand is that because they are
static they are in memory all the time to server its users thus live all
the time in memory.
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:eE*************@TK2MSFTNGP09.phx.gbl...
There are no non-technical reasons. And the question is not exactly
well-put. Static functions and data are tools. Some tools are good for
some things, and others are good for other things. So, rather than
asking why not to use "lots of static functions," you should be asking
when to use them, and when not to. In other words, the real question is,
"what are the characteristics of static functions and data that affect
my decision of when to use them?"

Static data is not threadsafe straight out of the box, if you need to
modify it. It can be modified in a threadsafe way, but it requires a bit
more work to do. Static data is global to your application, which means
if you change it in one place, it changes for everything. This can be
either good or bad, depending upon whether or not you want this to
happen. Remember that encapsulation, one of the pillars of OOP, is there
for a purpose. Static functions are fine, as long as they don't need to
work with instance data.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
We got a sick zebra a hat,
you ultimate tuna.
"Pohihihi" <no*****@hotmail.com> wrote in message
news:eK*************@TK2MSFTNGP09.phx.gbl...
What could be the possible reasons (technical/non technical) of not
using lots of static functions or variables in a program keeping in mind
that Framework by itself has tons of static functions and variables?



Feb 9 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Bryan Parkoff | last post by:
I have noticed that C programmers put static keyword beside global variable and global functions in C source codes. I believe that it is not necessary and it is not the practice in C++. Static...
12
by: dual0 | last post by:
Hello, I found some function like void static foo(...){ .... } what does the static keyword stand for? what is a static function?
11
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you...
18
by: Jack | last post by:
Thanks.
9
by: CDMAPoster | last post by:
About a year ago there was a thread about the use of global variables in A97: http://groups.google.com/group/comp.databases.ms-access/browse_frm/thread/fedc837a5aeb6157 Best Practices by Kang...
55
by: Zytan | last post by:
I see that static is more restricted in C# than in C++. It appears usable only on classes and methods, and data members, but cannot be created within a method itself. Surely this is possible in...
3
by: Steve Folly | last post by:
Hi, I had a problem in my code recently which turned out to be the 'the "static initialization order fiasco"' problem (<http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.12>) The FAQ...
2
by: Nagrik | last post by:
Dear Group, The book of Bjarne Stroustrup in chapter 5.4.4 says the following "The word static is one of the most overused words in C and C++. For static data members it has both of the...
6
KevinADC
by: KevinADC | last post by:
This snippet of code provides several examples of programming techniques that can be applied to most programs. using hashes to create unique results static variable recursive function...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.