Necessary unnecessary initializer

Hi,

I just stumbled over a quirk in R# 2.0. Consider these lines:

String line = sr.ReadLine(); //Ignore first header line
while((line = sr.ReadLine()) != null) {
...
}

(sr is, you may have guessed, a StreamReader)

R# says the first line contains an unnecessary initializer and provides
a quick fix to remove " = sr.ReadLine()";

This message should only be displayed if the variable is initialized
with a side-effect-free assignment. As this is probably not easy to
recognize, you might consider to only take constants into account and
miss some unnecessary initializations...

Regards,
Alexander

4 comments
Comment actions Permalink

The main idea of this warning is to show up that the assignment is not used.
It is up to you to decide wether the right part has side effects either not

--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Alexander Reifinger" <nospam@reifinger.de> wrote in message
news:e68lkm$vav$1@is.intellij.net...

Hi,

>

I just stumbled over a quirk in R# 2.0. Consider these lines:

>

String line = sr.ReadLine(); //Ignore first header line
while((line = sr.ReadLine()) != null) {
...
}

>

(sr is, you may have guessed, a StreamReader)

>

R

  1. says the first line contains an unnecessary initializer and provides a

quick fix to remove " = sr.ReadLine()";

>

This message should only be displayed if the variable is initialized with
a side-effect-free assignment. As this is probably not easy to recognize,
you might consider to only take constants into account and miss some
unnecessary initializations...

>

Regards,
Alexander



0
Comment actions Permalink

Hi Alexander

I agree with Eugene - the assignment is unnecessary and confusing. Your code
should be:

sr.ReadLine(); //Ignore first header line
while((line = sr.ReadLine()) != null) {
...
}

Cheers,

MikeS.
-


Original Message -



From: "Alexander Reifinger" <nospam@reifinger.de>
Newsgroups: jetbrains.resharper.community
Sent: Thursday, June 08, 2006 9:03 AM
Subject: Necessary unnecessary initializer

Hi,

>

I just stumbled over a quirk in R# 2.0. Consider these lines:

>

String line = sr.ReadLine(); //Ignore first header line
while((line = sr.ReadLine()) != null) {
...
}

>

(sr is, you may have guessed, a StreamReader)

>

R

  1. says the first line contains an unnecessary initializer and provides a

quick fix to remove " = sr.ReadLine()";

>

This message should only be displayed if the variable is initialized with
a side-effect-free assignment. As this is probably not easy to recognize,
you might consider to only take constants into account and miss some
unnecessary initializations...

>

Regards,
Alexander



0
Comment actions Permalink

I was thinking exactly the same; the warning is about the assignment to a
variable that is not accessed before the next assignment to the same
variable.

--
Gabriel Lozano-Morán
The .NET Aficionado
http://www.pointerx.net

"Mike Scott" <mike@mikescommunity.com> wrote in message
news:e6992s$oce$1@is.intellij.net...

Hi Alexander

>

I agree with Eugene - the assignment is unnecessary and confusing. Your
code
should be:

>

sr.ReadLine(); //Ignore first header line
while((line = sr.ReadLine()) != null) {
...
}

>

Cheers,

>

MikeS.
----- Original Message -----
From: "Alexander Reifinger" <nospam@reifinger.de>
Newsgroups: jetbrains.resharper.community
Sent: Thursday, June 08, 2006 9:03 AM
Subject: Necessary unnecessary initializer

>
>
>> Hi,
>>
>> I just stumbled over a quirk in R# 2.0. Consider these lines:
>>
>> String line = sr.ReadLine(); //Ignore first header line
>> while((line = sr.ReadLine()) != null) {
>> ...
>> }
>>
>> (sr is, you may have guessed, a StreamReader)
>>
>> R# says the first line contains an unnecessary initializer and provides a
>> quick fix to remove " = sr.ReadLine()";
>>
>> This message should only be displayed if the variable is initialized with
>> a side-effect-free assignment. As this is probably not easy to recognize,
>> you might consider to only take constants into account and miss some
>> unnecessary initializations...
>>
>> Regards,
>> Alexander
>



0
Comment actions Permalink

Gabriel Lozano-Morán schrieb:

I was thinking exactly the same; the warning is about the assignment to a
variable that is not accessed before the next assignment to the same
variable.


I agree, I will change the code. Should have figured that one out myself...

Thanks,
Alexander

0

Please sign in to leave a comment.