473,394 Members | 1,696 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,394 software developers and data experts.

Initialize local vars to a known value...

FxCop seems to hate this:

Public Class Foo

Dim mPrivate count As Integer = 0

..
..
..

End Class

Why? It says that the code is inefficient and not needed because the runtime
will do it for me.

Well heck, I want to be SURE it will be done, not rely on some runtime to do
it.

Sheesh.

--
Raymond R Cassick
CEO / CSA
Enterprocity Inc.
www.enterprocity.com
3380 Sheridan Drive, #143
Amherst, NY 14227
V: 716-316-5973
Blog: http://spaces.msn.com/members/rcassick/
Nov 25 '05 #1
6 1088
>Well heck, I want to be SURE it will be done, not rely on some runtime to do
it.

It does not depend on the runtime. The language specification states
that also.

Nov 25 '05 #2
Ray Cassick (Home) wrote:
FxCop seems to hate this:

Public Class Foo

Dim mPrivate count As Integer = 0

.
.
.

End Class

Why? It says that the code is inefficient and not needed because the runtime
will do it for me.

Well heck, I want to be SURE it will be done, not rely on some runtime to do
it.

Sheesh.


So are you saying you don't trust the runtime to comply to its
specifications with respect to initialization?

Personally, I wouldn't use a runtime I didn't trust that far. Why are
you prepared to trust it in matters such as garbage collection if you
don't trust it to obey the specs in terms of initialization?

Jon

Nov 25 '05 #3
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Ray Cassick (Home) wrote:
FxCop seems to hate this:

Public Class Foo

Dim mPrivate count As Integer = 0

.
.
.

End Class

Why? It says that the code is inefficient and not needed because the
runtime
will do it for me.

Well heck, I want to be SURE it will be done, not rely on some runtime to
do
it.

Sheesh.


So are you saying you don't trust the runtime to comply to its
specifications with respect to initialization?

Personally, I wouldn't use a runtime I didn't trust that far. Why are
you prepared to trust it in matters such as garbage collection if you
don't trust it to obey the specs in terms of initialization?

And why trust FxCop over the runtime? :)

Heck, if you're really paranoid, run FxCop against the runtime and see what
you get...

Marc
http://nomagichere.blogspot.com
Nov 25 '05 #4
Marc Bernard <fi****************@agfa.com> wrote:
So are you saying you don't trust the runtime to comply to its
specifications with respect to initialization?

Personally, I wouldn't use a runtime I didn't trust that far. Why are
you prepared to trust it in matters such as garbage collection if you
don't trust it to obey the specs in terms of initialization?
And why trust FxCop over the runtime? :)


If FxCop and the runtime disagreed, I'd trust the runtime. In this
case, FxCop is telling you *to* trust the runtime.
Heck, if you're really paranoid, run FxCop against the runtime and see what
you get...


Indeed :)

FxCop is really meant to give guidance rather than absolute rules - but
it's always worth at least seeing what it says...

--
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
Nov 25 '05 #5
Ok, ok.. maybe this is just me showing my age.

My whole life (while programming) I have always gotten into the habit of
clearly initiaializting my vars when they are created.

I guess this just threw me for a loop.
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Marc Bernard <fi****************@agfa.com> wrote:
> So are you saying you don't trust the runtime to comply to its
> specifications with respect to initialization?
>
> Personally, I wouldn't use a runtime I didn't trust that far. Why are
> you prepared to trust it in matters such as garbage collection if you
> don't trust it to obey the specs in terms of initialization?


And why trust FxCop over the runtime? :)


If FxCop and the runtime disagreed, I'd trust the runtime. In this
case, FxCop is telling you *to* trust the runtime.
Heck, if you're really paranoid, run FxCop against the runtime and see
what
you get...


Indeed :)

FxCop is really meant to give guidance rather than absolute rules - but
it's always worth at least seeing what it says...

--
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

Nov 25 '05 #6
Ray Cassick (Home) <rc************@enterprocity.com> wrote:
Ok, ok.. maybe this is just me showing my age.

My whole life (while programming) I have always gotten into the habit of
clearly initiaializting my vars when they are created.


And that's very valuable in a situation where the value is otherwise
*not* guaranteed. When a guarantee has been made though, it's fine to
use it :)

It's a similar situation to long-time C programmers still writing:

if (5==x)

in C#, despite that being less readable than

if (x==5)

On C, there's a benefit to the former version - it prevents an
accidental assignment. In C#, there's no benefit, and there's the
readability downside.

--
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
Nov 25 '05 #7

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

Similar topics

4
by: Rigs | last post by:
Hi, Does anyone happen to have a debug script that will display the variable name and value for all of the local variables on an .asp page? (not session nor application, as I already have...
2
by: Oliver Corona | last post by:
I am wondering if anyone has any insights on the performance benefit (or detriment) of declaring local variables instead of referencing members. Is allocating memory for a new variable more...
74
by: Peter | last post by:
Hi, So many times, I have seen compile warning: "you used a char* without initilize it", probably on the code like this: ------------ char* ptr; func(..., ptr); ----------
5
by: wim delvaux | last post by:
Hi all, I want to initialize two structures with pointers to eachother static StructA VarA = { PtrToVarB }; static StructB VarB = { PtrToVarA }; A solution that WORKS in C (using gcc 3.3)...
3
by: jut_bit_zx | last post by:
class A { public: A(); virtual ~A(){} .... private: int m_iarray; }
2
by: adamcort | last post by:
I am trying to create a simple page for users to log printer issues on our PS4 Citrix farm. I have created a simple html form and published it on our intranet, the form only asks too questions,...
21
by: Sriram Rajagopalan | last post by:
Hi, Which of these two would be a better way of initializing the local variables? and why? 1) At the time of their declaration. Eg: void func()
6
by: student1976 | last post by:
All Beginner/Intermediate level question. I understand that returning ptr to local stack vars is bad. Is returning foo_p_B from fnB() reliable all the time, so that using foo_p_A does not...
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.