473,549 Members | 4,476 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1101
>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.co m> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.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.co m>
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.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
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.co m>
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.c om> 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.co m>
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
2018
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 scripts those.) I'm looking for something that can be included in an .asp to write out values for debugging. Does anyone know what scope those variables...
2
2129
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 efficient than repeatedly referencing the member in a loop? Maybe using a string isn't the best example, but hopefully you get the idea! * example...
74
42979
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
1442
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) is
3
5925
by: jut_bit_zx | last post by:
class A { public: A(); virtual ~A(){} .... private: int m_iarray; }
2
3923
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, Users Department and Problem description. I however, am collecting more pertinant information on the asp submission page. (time, date, username,...
21
8075
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
1776
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 break? Thanks Josh
55
6165
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 C# in some way? Or maybe no, because it is similar to a global variable (with its scope restricted) which C# is dead against? Zytan
0
7455
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7723
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7962
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7480
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7814
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6050
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5373
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
1063
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
769
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.