|
|
I've gone both ways, and both points are valid. I find myself using this a lot in JavasScript for some reason, but in C# I seldom do. For me, my biggest peeve is inconstancy in a project. So, looks like one of y'all are going to have to give in, or you could have him off'ed.
Jeremy Falcon
|
|
|
|
|
I think it's tip 97 in the How to Make C# Look Like Java guide.
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
|
Errrm, this.
Alberto Brandolini: The amount of energy necessary to refute bullshit is an order of magnitude bigger than to produce it.
|
|
|
|
|
Only assignment, call, increment, decrement, and new object expressions can be used as a statement.
Your time will come, if you let it be right.
|
|
|
|
|
I do that. I prefer to type more up front and scratch my head less later.
That it honks off some members here is frosting on the cake.
|
|
|
|
|
My preference is to never use this unless there is a reason to do so (like conflicting names).
My methods are small enough that it is rarely a problem to see what is local and what is a property
and anyway, properties begin with a Capital and locals don't.
For static methods I use the classname. option, as there is no other obvious differentiator. That said, I don't work with many classes with static methods, so not something I have formed a habit out of.
When I see
this.SomeProperty = this.SomeMethod(this.SomeOtherProperty)
I cringe, and think "this? What else?)
PooperPig - Coming Soon
|
|
|
|
|
|
I do that sometimes....
And I don't really care either way...
And sometimes it's necessary when function parameter has the same name as class field!
|
|
|
|
|
I do not care about these redundancy but, personally, I do not prefer these type of redundant code.
___ ___ ___
|__ |_| |\ | | |_| \ /
__| | | | \| |__| | | /
|
|
|
|
|
By that same reasoning, stop using any "using" and reference only via fully qualified "System.Windows.Forms.ListCtrl.Item item" who needs any shortening of a line, just buy BLACK FRIDAY 50" MONITOR THATS IT?
|
|
|
|
|
Nareesh1 wrote: fully qualified "System.Windows.Forms.ListCtrl.Item item" Even when you say "fully qualified", there is no such thing as "System.Windows.Forms.ListCtrl.Item"..
Nareesh1 wrote: who needs any shortening of a line Oh the irony!
Your time will come, if you let it be right.
|
|
|
|
|
Yep, I know.
But I prefer not to include any Namespaces, only class names (the class name should be clear enough anyway).
I understand that in the new version of C# you can create a using for a class so you can use its static members without specifying the class. It's already my least favourite feature!
My blog[ ^]
public class SanderRossel : Lazy<Person>
{
public void DoWork()
{
throw new NotSupportedException();
}
}
|
|
|
|
|
Whenever there is the slightest chance of ambiguity, otherwise i prefer to keep it short.
Wrong is evil and must be defeated. - Jeff Ello
(√-sh*t) 2
|
|
|
|
|
Unless I have a construct like:
public class X{
private int number;
public X(int number){
this.number = number;
}
}
I rarely uses this .
|
|
|
|
|
I would say to use the property assignment 'this' in the following scenario:
void foo(int someValue)
{
this.someValue = someValue;
this.SomeMethod(AnotherClass.SomeMethod());
}
But not in the following scenario:
void foo()
{
someValue = 5;
SomeMethod(5);
}
With ThisClass.SomeStaticMethod() I'd always use is as you did unless of course you are using the static method of the class you are working in, then I'd just use SomeStaticMethod.
"Program testing can be used to show the presence of bugs, but never to show their absence."
<< please vote!! >>
|
|
|
|
|
this is good and I use it normally. The fact that it seems to annoy some pooples just encourages me to use it more.
|
|
|
|
|
such a trouble maker and non-conformist.
|
|
|
|
|
"this." triggers any auto-completion or Intellisense in the world. Yes I'm lazy - I wouldn't train machines to do men's work if I wasn't
|
|
|
|
|
If you just type one or two letters and then press Ctrl + Space, you would also get Intellisense and have to type even less.
The good thing about pessimism is, that you are always either right or pleasently surprised.
|
|
|
|
|
I don't think you have to type anything at all...
My blog[ ^]
public class SanderRossel : Lazy<Person>
{
public void DoWork()
{
throw new NotSupportedException();
}
}
|
|
|
|
|
It has become a habit for me to use 'this,' to type in access modifiers even when not required, and to never create duplicate names, but, over the last two years, I have transitioned to using 'var freely which I know causes some people to break out in a poison sweat.
I don't think these are particularly "bad" habits, but they are not any saving-grace of poor-quality design, or coding, either. At best, a syntactic sugar that may contribute to maintainability and future re-use ? But, I work alone, not in a team-setting.
If (gods forbid) I was managing a commercial software dev team, oh yeah, I'd plump for standards.
«OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. » Alan Kay's clarification on what he meant by the term "Object" in "Object-Oriented Programming."
|
|
|
|
|
Interesting that a lot of people do use this. I did not expect that.
I don't like it. It just clutters up with extra code that is unnecessary.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
BillWoodruff wrote: At best, a syntactic sugar Almost agreed.
The var keyword can actually be quite dangerous as I have witnessed a few times myself.
I work with Entity Framework a lot, which uses IQueryable to create queries that run on the database and return a result as IEnumerable that can be used in your application. Interface-wise there is little difference between IQueryable and IEnumerable , but the function of the two differs greatly! A few times I changed my IQueryable to IEnumerable and nothing broke, because the IQueryable was declared using var . The type of my variable just 'silently' changed to IEnumerable and all of a sudden my app wouldn't perform very well. Thing is, in order to create an IEnumerable the query was executed on the database. This was supposed to happen a few lines later, but because I put a ToList() function somewhere in between this was done to early. All my filter functions were done on the in-memory collection instead of the database.
Of course you'd also have this problem if you declared your IQueryable as IEnumerable (an IQueryable IS an IEnumerable ), but at least you'd explicitly choose to define it as such.
I haven't seen this problem with other .NET interfaces, probably because none of them are so common and so costly as IQueryable , but I could imagine it happening when working with Streams or some such base class which has a few subclasses that do different things.
My blog[ ^]
public class SanderRossel : Lazy<Person>
{
public void DoWork()
{
throw new NotSupportedException();
}
}
|
|
|
|