StyleCop - How to prohibit usage of var keyword

View: New views
20 Messages — Rating Filter:   Alert me  
< Prev | 1 - 2 | Next >

StyleCop - How to prohibit usage of var keyword

by Tiago Soczek :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi guys,

How I can prohibit usage of var keyword? Or better, only allows for
anonymous type.

Thanks.

Tiago

Re: StyleCop - How to prohibit usage of var keyword

by Paul Cowan-7 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

That seems like a bit of a totalitarian approach.

Maybe you seek too much control?


Cheers

Paul Cowan

Cutting-Edge Solutions (Scotland)

http://thesoftwaresimpleton.blogspot.com/



2009/10/30 Tiago Soczek <tiagosoczek@...>

>
>
> Hi guys,
>
> How I can prohibit usage of var keyword? Or better, only allows for
> anonymous type.
>
> Thanks.
>
> Tiago
>
>  
>

Re: StyleCop - How to prohibit usage of var keyword

by alberto-40 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Use C#2.0 and VS2005, or earlier.

On Fri, Oct 30, 2009 at 12:51 PM, Tiago Soczek <tiagosoczek@...>wrote:

>
>
> Hi guys,
>
> How I can prohibit usage of var keyword? Or better, only allows for
> anonymous type.
>
> Thanks.
>
> Tiago
>
>
>

Re: StyleCop - How to prohibit usage of var keyword

by Hadi Hariri :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Now why would you want to prohibit someone from using the var keyword?

2009/10/30 Paul Cowan <dagda1@...>

>
>
> That seems like a bit of a totalitarian approach.
>
> Maybe you seek too much control?
>
>
> Cheers
>
> Paul Cowan
>
> Cutting-Edge Solutions (Scotland)
>
> http://thesoftwaresimpleton.blogspot.com/
>
>
>
> 2009/10/30 Tiago Soczek <tiagosoczek@...>
>
>>
>>
>> Hi guys,
>>
>> How I can prohibit usage of var keyword? Or better, only allows for
>> anonymous type.
>>
>> Thanks.
>>
>> Tiago
>>
>>
>  
>



--
Blog: http://hadihariri.com
Twitter: http://twitter.com/hhariri

Re: StyleCop - How to prohibit usage of var keyword

by Krzysztof Koźmic :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

how about prohibiting also internal, virtual class if and where keywords?
sounds fun to me.

alberto wrote:

>
>
> Use C#2.0 and VS2005, or earlier.
>
> On Fri, Oct 30, 2009 at 12:51 PM, Tiago Soczek <tiagosoczek@...
> <mailto:tiagosoczek@...>> wrote:
>
>
>
>     Hi guys,
>      
>     How I can prohibit usage of var keyword? Or better, only allows
>     for anonymous type.
>      
>     Thanks.
>      
>     Tiago
>
>
>
>
>
>


Re: StyleCop - How to prohibit usage of var keyword

by James Gregory-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Don't. Care less about how your code looks, more about what it actually
does.

On Fri, Oct 30, 2009 at 11:56 AM, alberto <alberto.email@...> wrote:

>
>
> Use C#2.0 and VS2005, or earlier.
>
>
> On Fri, Oct 30, 2009 at 12:51 PM, Tiago Soczek <tiagosoczek@...>wrote:
>
>>
>>
>> Hi guys,
>>
>> How I can prohibit usage of var keyword? Or better, only allows for
>> anonymous type.
>>
>> Thanks.
>>
>> Tiago
>>
>>
>>
>  
>

Re: StyleCop - How to prohibit usage of var keyword

by Tiago Soczek :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Calm down guys, I like the var keyword, but I only need to know how i can
create a rule in Style Cop to prohibit this.

On Fri, Oct 30, 2009 at 9:58 AM, James Gregory <jagregory.com@...>wrote:

>
>
> Don't. Care less about how your code looks, more about what it actually
> does.
>
>
> On Fri, Oct 30, 2009 at 11:56 AM, alberto <alberto.email@...> wrote:
>
>>
>>
>> Use C#2.0 and VS2005, or earlier.
>>
>>
>> On Fri, Oct 30, 2009 at 12:51 PM, Tiago Soczek <tiagosoczek@...>wrote:
>>
>>>
>>>
>>> Hi guys,
>>>
>>> How I can prohibit usage of var keyword? Or better, only allows for
>>> anonymous type.
>>>
>>> Thanks.
>>>
>>> Tiago
>>>
>>>
>>>
>>
>  
>

Re: StyleCop - How to prohibit usage of var keyword

by Krzysztof Koźmic :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ok, seriously, why on earth would you ever want to do this?

Krzysztof

Tiago Soczek wrote:

>
>
> Calm down guys, I like the var keyword, but I only need to know how i
> can create a rule in Style Cop to prohibit this.
>
> On Fri, Oct 30, 2009 at 9:58 AM, James Gregory <jagregory.com
> <http://jagregory.com>@gmail.com <http://gmail.com>> wrote:
>
>      
>
>     Don't. Care less about how your code looks, more about what it
>     actually does.
>
>
>
>     On Fri, Oct 30, 2009 at 11:56 AM, alberto <alberto.email@...
>     <mailto:alberto.email@...>> wrote:
>
>          
>
>         Use C#2.0 and VS2005, or earlier.
>
>
>
>         On Fri, Oct 30, 2009 at 12:51 PM, Tiago Soczek
>         <tiagosoczek@... <mailto:tiagosoczek@...>> wrote:
>
>
>
>             Hi guys,
>              
>             How I can prohibit usage of var keyword? Or better, only
>             allows for anonymous type.
>              
>             Thanks.
>              
>             Tiago
>
>
>
>
>
>
>
>


Re: StyleCop - How to prohibit usage of var keyword

by Paul Cowan-7 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>> Calm down guys, I like the var keyword, but I only need to know how i can
create a rule in Style Cop to prohibit this.

HA HA,

Fair point!!

Cheers

Paul Cowan

Cutting-Edge Solutions (Scotland)

http://thesoftwaresimpleton.blogspot.com/



2009/10/30 Tiago Soczek <tiagosoczek@...>

>
>
> Calm down guys, I like the var keyword, but I only need to know how i can
> create a rule in Style Cop to prohibit this.
>
>
> On Fri, Oct 30, 2009 at 9:58 AM, James Gregory <jagregory.com@...>wrote:
>
>>
>>
>> Don't. Care less about how your code looks, more about what it actually
>> does.
>>
>>
>> On Fri, Oct 30, 2009 at 11:56 AM, alberto <alberto.email@...>wrote:
>>
>>>
>>>
>>> Use C#2.0 and VS2005, or earlier.
>>>
>>>
>>> On Fri, Oct 30, 2009 at 12:51 PM, Tiago Soczek <tiagosoczek@...>wrote:
>>>
>>>>
>>>>
>>>> Hi guys,
>>>>
>>>> How I can prohibit usage of var keyword? Or better, only allows for
>>>> anonymous type.
>>>>
>>>> Thanks.
>>>>
>>>> Tiago
>>>>
>>>>
>>>>
>>>
>>
>  
>

Re: StyleCop - How to prohibit usage of var keyword

by Alex McMahon :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Over-using the var keyword can lead to code that is less readable in my
opinion... depending on how it is used. I'd say it's a bad idea to prohibit
it completely, but setting up a rule that caught cases where it was used in
particular ways could be useful. e.g. where the inferred type can't easily
be seen just by looking.

2009/10/30 Krzysztof Koźmic <krzysztof.kozmic@...>

>
>
> Ok, seriously, why on earth would you ever want to do this?
>
> Krzysztof
>
>
> Tiago Soczek wrote:
>
> Calm down guys, I like the var keyword, but I only need to know how i can
> create a rule in Style Cop to prohibit this.
>
> On Fri, Oct 30, 2009 at 9:58 AM, James Gregory <jagregory.com@...>wrote:
>
>>
>>
>> Don't. Care less about how your code looks, more about what it actually
>> does.
>>
>>
>> On Fri, Oct 30, 2009 at 11:56 AM, alberto <alberto.email@...>wrote:
>>
>>>
>>>
>>> Use C#2.0 and VS2005, or earlier.
>>>
>>>
>>> On Fri, Oct 30, 2009 at 12:51 PM, Tiago Soczek <tiagosoczek@...>wrote:
>>>
>>>>
>>>>
>>>> Hi guys,
>>>>
>>>> How I can prohibit usage of var keyword? Or better, only allows for
>>>> anonymous type.
>>>>
>>>> Thanks.
>>>>
>>>> Tiago
>>>>
>>>>
>>>>
>>>
>>
>
>
>
>
>

Re: StyleCop - How to prohibit usage of var keyword

by alberto-40 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I don't think you can, since fxcop analyzes assemblies, not source code, and
var is just syntatic sugar over the compiler.

On Fri, Oct 30, 2009 at 1:03 PM, Tiago Soczek <tiagosoczek@...> wrote:

>
>
> Calm down guys, I like the var keyword, but I only need to know how i can
> create a rule in Style Cop to prohibit this.
>
>
> On Fri, Oct 30, 2009 at 9:58 AM, James Gregory <jagregory.com@...>wrote:
>
>>
>>
>> Don't. Care less about how your code looks, more about what it actually
>> does.
>>
>>
>> On Fri, Oct 30, 2009 at 11:56 AM, alberto <alberto.email@...>wrote:
>>
>>>
>>>
>>> Use C#2.0 and VS2005, or earlier.
>>>
>>>
>>> On Fri, Oct 30, 2009 at 12:51 PM, Tiago Soczek <tiagosoczek@...>wrote:
>>>
>>>>
>>>>
>>>> Hi guys,
>>>>
>>>> How I can prohibit usage of var keyword? Or better, only allows for
>>>> anonymous type.
>>>>
>>>> Thanks.
>>>>
>>>> Tiago
>>>>
>>>>
>>>>
>>>
>>
>
>
>
>

Re: StyleCop - How to prohibit usage of var keyword

by Alex McMahon :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

fxcop can't but StyleCop should be able to in theory I think

2009/10/30 alberto <alberto.email@...>

>
>
> I don't think you can, since fxcop analyzes assemblies, not source code,
> and var is just syntatic sugar over the compiler.
>
>
> On Fri, Oct 30, 2009 at 1:03 PM, Tiago Soczek <tiagosoczek@...>wrote:
>
>>
>>
>> Calm down guys, I like the var keyword, but I only need to know how i can
>> create a rule in Style Cop to prohibit this.
>>
>>
>> On Fri, Oct 30, 2009 at 9:58 AM, James Gregory <jagregory.com@...>wrote:
>>
>>>
>>>
>>> Don't. Care less about how your code looks, more about what it actually
>>> does.
>>>
>>>
>>> On Fri, Oct 30, 2009 at 11:56 AM, alberto <alberto.email@...>wrote:
>>>
>>>>
>>>>
>>>> Use C#2.0 and VS2005, or earlier.
>>>>
>>>>
>>>> On Fri, Oct 30, 2009 at 12:51 PM, Tiago Soczek <tiagosoczek@...>wrote:
>>>>
>>>>>
>>>>>
>>>>> Hi guys,
>>>>>
>>>>> How I can prohibit usage of var keyword? Or better, only allows for
>>>>> anonymous type.
>>>>>
>>>>> Thanks.
>>>>>
>>>>> Tiago
>>>>>
>>>>>
>>>>>
>>>>
>>>
>>
>>
>>
>
>
>
>

Re: StyleCop - How to prohibit usage of var keyword

by Hadi Hariri :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Why would you think that? Why would it make it less readable?


2009/10/30 Alex McMahon <fluxmunki@...>

>
>
> Over-using the var keyword can lead to code that is less readable in my
> opinion... depending on how it is used. I'd say it's a bad idea to prohibit
> it completely, but setting up a rule that caught cases where it was used in
> particular ways could be useful. e.g. where the inferred type can't easily
> be seen just by looking.
>
> 2009/10/30 Krzysztof Koźmic <krzysztof.kozmic@...>
>
>
>>
>> Ok, seriously, why on earth would you ever want to do this?
>>
>> Krzysztof
>>
>>
>> Tiago Soczek wrote:
>>
>> Calm down guys, I like the var keyword, but I only need to know how i can
>> create a rule in Style Cop to prohibit this.
>>
>> On Fri, Oct 30, 2009 at 9:58 AM, James Gregory <jagregory.com@...>wrote:
>>
>>>
>>>
>>> Don't. Care less about how your code looks, more about what it actually
>>> does.
>>>
>>>
>>> On Fri, Oct 30, 2009 at 11:56 AM, alberto <alberto.email@...>wrote:
>>>
>>>>
>>>>
>>>> Use C#2.0 and VS2005, or earlier.
>>>>
>>>>
>>>> On Fri, Oct 30, 2009 at 12:51 PM, Tiago Soczek <tiagosoczek@...>wrote:
>>>>
>>>>>
>>>>>
>>>>> Hi guys,
>>>>>
>>>>> How I can prohibit usage of var keyword? Or better, only allows for
>>>>> anonymous type.
>>>>>
>>>>> Thanks.
>>>>>
>>>>> Tiago
>>>>>
>>>>>
>>>>>
>>>>
>>>
>>
>>
>>
>>
>  
>



--
Blog: http://hadihariri.com
Twitter: http://twitter.com/hhariri

Re: StyleCop - How to prohibit usage of var keyword

by James Gregory-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

If it's less readable when using var, you're naming your variables wrong.

On Fri, Oct 30, 2009 at 12:12 PM, Hadi Hariri <hadi.lists@...> wrote:

>
>
> Why would you think that? Why would it make it less readable?
>
>
> 2009/10/30 Alex McMahon <fluxmunki@...>
>
>
>>
>> Over-using the var keyword can lead to code that is less readable in my
>> opinion... depending on how it is used. I'd say it's a bad idea to prohibit
>> it completely, but setting up a rule that caught cases where it was used in
>> particular ways could be useful. e.g. where the inferred type can't easily
>> be seen just by looking.
>>
>> 2009/10/30 Krzysztof Koźmic <krzysztof.kozmic@...>
>>
>>
>>>
>>> Ok, seriously, why on earth would you ever want to do this?
>>>
>>> Krzysztof
>>>
>>>
>>> Tiago Soczek wrote:
>>>
>>> Calm down guys, I like the var keyword, but I only need to know how i can
>>> create a rule in Style Cop to prohibit this.
>>>
>>> On Fri, Oct 30, 2009 at 9:58 AM, James Gregory <jagregory.com@...>wrote:
>>>
>>>>
>>>>
>>>> Don't. Care less about how your code looks, more about what it actually
>>>> does.
>>>>
>>>>
>>>> On Fri, Oct 30, 2009 at 11:56 AM, alberto <alberto.email@...>wrote:
>>>>
>>>>>
>>>>>
>>>>> Use C#2.0 and VS2005, or earlier.
>>>>>
>>>>>
>>>>> On Fri, Oct 30, 2009 at 12:51 PM, Tiago Soczek <tiagosoczek@...>wrote:
>>>>>
>>>>>>
>>>>>>
>>>>>> Hi guys,
>>>>>>
>>>>>> How I can prohibit usage of var keyword? Or better, only allows for
>>>>>> anonymous type.
>>>>>>
>>>>>> Thanks.
>>>>>>
>>>>>> Tiago
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>>
>>>
>>>
>>
>
>
> --
> Blog: http://hadihariri.com
> Twitter: http://twitter.com/hhariri
>
>  
>

Re: StyleCop - How to prohibit usage of var keyword

by alberto-40 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Yeah, sorry I don't know why I was thinking he wanted to use fxcop.
Certainly Stylecop would allow that.

On Fri, Oct 30, 2009 at 1:09 PM, Alex McMahon <fluxmunki@...> wrote:

>
>
> fxcop can't but StyleCop should be able to in theory I think
>
> 2009/10/30 alberto <alberto.email@...>
>
>
>>
>> I don't think you can, since fxcop analyzes assemblies, not source code,
>> and var is just syntatic sugar over the compiler.
>>
>>
>> On Fri, Oct 30, 2009 at 1:03 PM, Tiago Soczek <tiagosoczek@...>wrote:
>>
>>>
>>>
>>> Calm down guys, I like the var keyword, but I only need to know how i can
>>> create a rule in Style Cop to prohibit this.
>>>
>>>
>>> On Fri, Oct 30, 2009 at 9:58 AM, James Gregory <jagregory.com@...>wrote:
>>>
>>>>
>>>>
>>>> Don't. Care less about how your code looks, more about what it actually
>>>> does.
>>>>
>>>>
>>>> On Fri, Oct 30, 2009 at 11:56 AM, alberto <alberto.email@...>wrote:
>>>>
>>>>>
>>>>>
>>>>> Use C#2.0 and VS2005, or earlier.
>>>>>
>>>>>
>>>>> On Fri, Oct 30, 2009 at 12:51 PM, Tiago Soczek <tiagosoczek@...>wrote:
>>>>>
>>>>>>
>>>>>>
>>>>>> Hi guys,
>>>>>>
>>>>>> How I can prohibit usage of var keyword? Or better, only allows for
>>>>>> anonymous type.
>>>>>>
>>>>>> Thanks.
>>>>>>
>>>>>> Tiago
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>>
>>>
>>
>>
>>
>
>
>
>

Re: StyleCop - How to prohibit usage of var keyword

by Alex McMahon :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

One example where I find it less readable is when you use it in a foreach
and the type isn't clear:

foreach(var p in IReturnACollectionOfSomething()){

}

now you could certainly argue that p is an appalling name for a variable,
but do you want to start hungarian notation when you could just use the type
instead of var? Also you can argue that a good IDE gives you the info easily
regarding the inferred type; but what about when you are using a diff tool
for a pending change checkin?

2009/10/30 James Gregory <jagregory.com@...>

>
>
> If it's less readable when using var, you're naming your variables wrong.
>
>
> On Fri, Oct 30, 2009 at 12:12 PM, Hadi Hariri <hadi.lists@...>wrote:
>
>>
>>
>> Why would you think that? Why would it make it less readable?
>>
>>
>> 2009/10/30 Alex McMahon <fluxmunki@...>
>>
>>
>>>
>>> Over-using the var keyword can lead to code that is less readable in my
>>> opinion... depending on how it is used. I'd say it's a bad idea to prohibit
>>> it completely, but setting up a rule that caught cases where it was used in
>>> particular ways could be useful. e.g. where the inferred type can't easily
>>> be seen just by looking.
>>>
>>> 2009/10/30 Krzysztof Koźmic <krzysztof.kozmic@...>
>>>
>>>
>>>>
>>>> Ok, seriously, why on earth would you ever want to do this?
>>>>
>>>> Krzysztof
>>>>
>>>>
>>>> Tiago Soczek wrote:
>>>>
>>>> Calm down guys, I like the var keyword, but I only need to know how i
>>>> can create a rule in Style Cop to prohibit this.
>>>>
>>>> On Fri, Oct 30, 2009 at 9:58 AM, James Gregory <jagregory.com@...
>>>> > wrote:
>>>>
>>>>>
>>>>>
>>>>> Don't. Care less about how your code looks, more about what it actually
>>>>> does.
>>>>>
>>>>>
>>>>> On Fri, Oct 30, 2009 at 11:56 AM, alberto <alberto.email@...>wrote:
>>>>>
>>>>>>
>>>>>>
>>>>>> Use C#2.0 and VS2005, or earlier.
>>>>>>
>>>>>>
>>>>>> On Fri, Oct 30, 2009 at 12:51 PM, Tiago Soczek <tiagosoczek@...
>>>>>> > wrote:
>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Hi guys,
>>>>>>>
>>>>>>> How I can prohibit usage of var keyword? Or better, only allows for
>>>>>>> anonymous type.
>>>>>>>
>>>>>>> Thanks.
>>>>>>>
>>>>>>> Tiago
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>
>>
>> --
>> Blog: http://hadihariri.com
>> Twitter: http://twitter.com/hhariri
>>
>>
>
>
>
>

Re: StyleCop - How to prohibit usage of var keyword

by Hadi Hariri :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

It's not about using hungarian notation or having an IDE. It's about naming
things for what they are. And by what they are I don't necessarily mean
their data type.




2009/10/30 Alex McMahon <fluxmunki@...>

>
>
> One example where I find it less readable is when you use it in a foreach
> and the type isn't clear:
>
> foreach(var p in IReturnACollectionOfSomething()){
>
> }
>
> now you could certainly argue that p is an appalling name for a variable,
> but do you want to start hungarian notation when you could just use the type
> instead of var? Also you can argue that a good IDE gives you the info easily
> regarding the inferred type; but what about when you are using a diff tool
> for a pending change checkin?
>
> 2009/10/30 James Gregory <jagregory.com@...>
>
>
>>
>> If it's less readable when using var, you're naming your variables wrong.
>>
>>
>> On Fri, Oct 30, 2009 at 12:12 PM, Hadi Hariri <hadi.lists@...>wrote:
>>
>>>
>>>
>>> Why would you think that? Why would it make it less readable?
>>>
>>>
>>> 2009/10/30 Alex McMahon <fluxmunki@...>
>>>
>>>
>>>>
>>>> Over-using the var keyword can lead to code that is less readable in my
>>>> opinion... depending on how it is used. I'd say it's a bad idea to prohibit
>>>> it completely, but setting up a rule that caught cases where it was used in
>>>> particular ways could be useful. e.g. where the inferred type can't easily
>>>> be seen just by looking.
>>>>
>>>> 2009/10/30 Krzysztof Koźmic <krzysztof.kozmic@...>
>>>>
>>>>
>>>>>
>>>>> Ok, seriously, why on earth would you ever want to do this?
>>>>>
>>>>> Krzysztof
>>>>>
>>>>>
>>>>> Tiago Soczek wrote:
>>>>>
>>>>> Calm down guys, I like the var keyword, but I only need to know how i
>>>>> can create a rule in Style Cop to prohibit this.
>>>>>
>>>>> On Fri, Oct 30, 2009 at 9:58 AM, James Gregory <jagregory.com@
>>>>> gmail.com> wrote:
>>>>>
>>>>>>
>>>>>>
>>>>>> Don't. Care less about how your code looks, more about what it
>>>>>> actually does.
>>>>>>
>>>>>>
>>>>>> On Fri, Oct 30, 2009 at 11:56 AM, alberto <alberto.email@...>wrote:
>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Use C#2.0 and VS2005, or earlier.
>>>>>>>
>>>>>>>
>>>>>>> On Fri, Oct 30, 2009 at 12:51 PM, Tiago Soczek <
>>>>>>> tiagosoczek@...> wrote:
>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> Hi guys,
>>>>>>>>
>>>>>>>> How I can prohibit usage of var keyword? Or better, only allows for
>>>>>>>> anonymous type.
>>>>>>>>
>>>>>>>> Thanks.
>>>>>>>>
>>>>>>>> Tiago
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>
>>>
>>> --
>>> Blog: http://hadihariri.com
>>> Twitter: http://twitter.com/hhariri
>>>
>>>
>>
>>
>>
>  
>



--
Blog: http://hadihariri.com
Twitter: http://twitter.com/hhariri

Re: StyleCop - How to prohibit usage of var keyword

by Krzysztof Koźmic :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm with Hadi,

if you find smell around code with var it's not var that stinks - its
your choice of names.

Amen

Hadi Hariri wrote:

>
>
> It's not about using hungarian notation or having an IDE. It's about
> naming things for what they are. And by what they are I don't
> necessarily mean their data type.
>
>
>
>
> 2009/10/30 Alex McMahon <fluxmunki@... <mailto:fluxmunki@...>>
>
>      
>
>     One example where I find it less readable is when you use it in a
>     foreach and the type isn't clear:
>
>     foreach(var p in IReturnACollectionOfSomething()){
>
>     }
>
>     now you could certainly argue that p is an appalling name for a
>     variable, but do you want to start hungarian notation when you
>     could just use the type instead of var? Also you can argue that a
>     good IDE gives you the info easily regarding the inferred type;
>     but what about when you are using a diff tool for a pending change
>     checkin?
>
>     2009/10/30 James Gregory <jagregory.com
>     <http://jagregory.com>@gmail.com <http://gmail.com>>
>
>
>
>         If it's less readable when using var, you're naming your
>         variables wrong.
>
>
>         On Fri, Oct 30, 2009 at 12:12 PM, Hadi Hariri
>         <hadi.lists@... <mailto:hadi.lists@...>> wrote:
>
>              
>
>             Why would you think that? Why would it make it less readable?
>
>
>             2009/10/30 Alex McMahon <fluxmunki@...
>             <mailto:fluxmunki@...>>
>
>                  
>
>                 Over-using the var keyword can lead to code that is
>                 less readable in my opinion... depending on how it is
>                 used. I'd say it's a bad idea to prohibit it
>                 completely, but setting up a rule that caught cases
>                 where it was used in particular ways could be useful.
>                 e.g. where the inferred type can't easily be seen just
>                 by looking.
>
>                 2009/10/30 Krzysztof Koźmic
>                 <krzysztof.kozmic@...
>                 <mailto:krzysztof.kozmic@...>>
>
>
>
>                     Ok, seriously, why on earth would you ever want to
>                     do this?
>
>                     Krzysztof
>
>
>                     Tiago Soczek wrote:
>>                     Calm down guys, I like the var keyword, but I
>>                     only need to know how i can create a rule in
>>                     Style Cop to prohibit this.
>>
>>                     On Fri, Oct 30, 2009 at 9:58 AM, James Gregory
>>                     <jagregory.com <http://jagregory.com>@gmail.com
>>                     <http://gmail.com>> wrote:
>>
>>                          
>>
>>                         Don't. Care less about how your code looks,
>>                         more about what it actually does.
>>
>>
>>
>>                         On Fri, Oct 30, 2009 at 11:56 AM, alberto
>>                         <alberto.email@...
>>                         <mailto:alberto.email@...>> wrote:
>>
>>                              
>>
>>                             Use C#2.0 and VS2005, or earlier.
>>
>>
>>
>>                             On Fri, Oct 30, 2009 at 12:51 PM, Tiago
>>                             Soczek <tiagosoczek@...
>>                             <mailto:tiagosoczek@...>> wrote:
>>
>>
>>
>>                                 Hi guys,
>>                                  
>>                                 How I can prohibit usage of var
>>                                 keyword? Or better, only allows for
>>                                 anonymous type.
>>                                  
>>                                 Thanks.
>>                                  
>>                                 Tiago
>>
>>
>>
>>
>>
>
>
>
>
>
>
>
>             --
>             Blog: http://hadihariri.com
>             Twitter: http://twitter.com/hhariri
>
>
>
>
>
>
>
>
> --
> Blog: http://hadihariri.com
> Twitter: http://twitter.com/hhariri
>
>
>
>


Re: StyleCop - How to prohibit usage of var keyword

by Tiago Soczek :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm using StyleCop not FxCop, but only to explain, I'm very addicted in var
usage, and how like Alex says: in some cases, the type cannot be identified
easily, and how I'm using StyleCop I like to know how create rules for this.

Thanks.
On Fri, Oct 30, 2009 at 10:23 AM, Hadi Hariri <hadi.lists@...> wrote:

>
>
> It's not about using hungarian notation or having an IDE. It's about naming
> things for what they are. And by what they are I don't necessarily mean
> their data type.
>
>
>
>
>
> 2009/10/30 Alex McMahon <fluxmunki@...>
>
>>
>>
>> One example where I find it less readable is when you use it in a foreach
>> and the type isn't clear:
>>
>> foreach(var p in IReturnACollectionOfSomething()){
>>
>> }
>>
>> now you could certainly argue that p is an appalling name for a variable,
>> but do you want to start hungarian notation when you could just use the type
>> instead of var? Also you can argue that a good IDE gives you the info easily
>> regarding the inferred type; but what about when you are using a diff tool
>> for a pending change checkin?
>>
>> 2009/10/30 James Gregory <jagregory.com@...>
>>
>>
>>>
>>> If it's less readable when using var, you're naming your variables wrong.
>>>
>>>
>>>
>>> On Fri, Oct 30, 2009 at 12:12 PM, Hadi Hariri <hadi.lists@...>wrote:
>>>
>>>>
>>>>
>>>> Why would you think that? Why would it make it less readable?
>>>>
>>>>
>>>> 2009/10/30 Alex McMahon <fluxmunki@...>
>>>>
>>>>
>>>>>
>>>>> Over-using the var keyword can lead to code that is less readable in my
>>>>> opinion... depending on how it is used. I'd say it's a bad idea to prohibit
>>>>> it completely, but setting up a rule that caught cases where it was used in
>>>>> particular ways could be useful. e.g. where the inferred type can't easily
>>>>> be seen just by looking.
>>>>>
>>>>> 2009/10/30 Krzysztof Koźmic <krzysztof.kozmic@...>
>>>>>
>>>>>
>>>>>>
>>>>>> Ok, seriously, why on earth would you ever want to do this?
>>>>>>
>>>>>> Krzysztof
>>>>>>
>>>>>>
>>>>>> Tiago Soczek wrote:
>>>>>>
>>>>>> Calm down guys, I like the var keyword, but I only need to know how i
>>>>>> can create a rule in Style Cop to prohibit this.
>>>>>>
>>>>>> On Fri, Oct 30, 2009 at 9:58 AM, James Gregory <jagregory.com@
>>>>>> gmail.com> wrote:
>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Don't. Care less about how your code looks, more about what it
>>>>>>> actually does.
>>>>>>>
>>>>>>>
>>>>>>> On Fri, Oct 30, 2009 at 11:56 AM, alberto <alberto.email@...>wrote:
>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> Use C#2.0 and VS2005, or earlier.
>>>>>>>>
>>>>>>>>
>>>>>>>> On Fri, Oct 30, 2009 at 12:51 PM, Tiago Soczek <
>>>>>>>> tiagosoczek@...> wrote:
>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Hi guys,
>>>>>>>>>
>>>>>>>>> How I can prohibit usage of var keyword? Or better, only allows for
>>>>>>>>> anonymous type.
>>>>>>>>>
>>>>>>>>> Thanks.
>>>>>>>>>
>>>>>>>>> Tiago
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> Blog: http://hadihariri.com
>>>> Twitter: http://twitter.com/hhariri
>>>>
>>>>
>>>
>>>
>>>
>>
>
>
> --
> Blog: http://hadihariri.com
> Twitter: http://twitter.com/hhariri
>
>  
>

Re: StyleCop - How to prohibit usage of var keyword

by James Gregory-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

foreach(var something in IReturnACollectionOfSomething())

There you go.

foreach (var car in GetCars()
foreach (var property in Properties)
foreach (var developer in DevelopersStillReadingThisList)

On Fri, Oct 30, 2009 at 12:23 PM, Hadi Hariri <hadi.lists@...> wrote:

>
>
> It's not about using hungarian notation or having an IDE. It's about naming
> things for what they are. And by what they are I don't necessarily mean
> their data type.
>
>
>
>
>
> 2009/10/30 Alex McMahon <fluxmunki@...>
>
>>
>>
>> One example where I find it less readable is when you use it in a foreach
>> and the type isn't clear:
>>
>> foreach(var p in IReturnACollectionOfSomething()){
>>
>> }
>>
>> now you could certainly argue that p is an appalling name for a variable,
>> but do you want to start hungarian notation when you could just use the type
>> instead of var? Also you can argue that a good IDE gives you the info easily
>> regarding the inferred type; but what about when you are using a diff tool
>> for a pending change checkin?
>>
>> 2009/10/30 James Gregory <jagregory.com@...>
>>
>>
>>>
>>> If it's less readable when using var, you're naming your variables wrong.
>>>
>>>
>>> On Fri, Oct 30, 2009 at 12:12 PM, Hadi Hariri <hadi.lists@...>wrote:
>>>
>>>>
>>>>
>>>> Why would you think that? Why would it make it less readable?
>>>>
>>>>
>>>> 2009/10/30 Alex McMahon <fluxmunki@...>
>>>>
>>>>
>>>>>
>>>>> Over-using the var keyword can lead to code that is less readable in my
>>>>> opinion... depending on how it is used. I'd say it's a bad idea to prohibit
>>>>> it completely, but setting up a rule that caught cases where it was used in
>>>>> particular ways could be useful. e.g. where the inferred type can't easily
>>>>> be seen just by looking.
>>>>>
>>>>> 2009/10/30 Krzysztof Koźmic <krzysztof.kozmic@...>
>>>>>
>>>>>
>>>>>>
>>>>>> Ok, seriously, why on earth would you ever want to do this?
>>>>>>
>>>>>> Krzysztof
>>>>>>
>>>>>>
>>>>>> Tiago Soczek wrote:
>>>>>>
>>>>>> Calm down guys, I like the var keyword, but I only need to know how i
>>>>>> can create a rule in Style Cop to prohibit this.
>>>>>>
>>>>>> On Fri, Oct 30, 2009 at 9:58 AM, James Gregory <jagregory.com@
>>>>>> gmail.com> wrote:
>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Don't. Care less about how your code looks, more about what it
>>>>>>> actually does.
>>>>>>>
>>>>>>>
>>>>>>> On Fri, Oct 30, 2009 at 11:56 AM, alberto <alberto.email@...>wrote:
>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> Use C#2.0 and VS2005, or earlier.
>>>>>>>>
>>>>>>>>
>>>>>>>> On Fri, Oct 30, 2009 at 12:51 PM, Tiago Soczek <
>>>>>>>> tiagosoczek@...> wrote:
>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Hi guys,
>>>>>>>>>
>>>>>>>>> How I can prohibit usage of var keyword? Or better, only allows for
>>>>>>>>> anonymous type.
>>>>>>>>>
>>>>>>>>> Thanks.
>>>>>>>>>
>>>>>>>>> Tiago
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> Blog: http://hadihariri.com
>>>> Twitter: http://twitter.com/hhariri
>>>>
>>>>
>>>
>>>
>>>
>>
>
>
> --
> Blog: http://hadihariri.com
> Twitter: http://twitter.com/hhariri
>
>  
>
< Prev | 1 - 2 | Next >