This vs. that
-
I have a question about your preferred programming style. Whenever I write code in C# I make extensive use of the 'this' keyword and I use class names when referencing statics. So:
this.SomeProperty = someValue;
this.SomeMethod();
ThisClass.SomeStaticMethod();Instead of:
SomeProperty = someValue;
SomeMethod();
SomeStaticMethod();My reasoning behind this is that I can tell something is an instance method or a static method. And to be completely honest it's also something I started doing in VB because VB has Modules and Modules don't make you specify the Module's name. So
Me.SomeMethod()
can be an instance method, a Shared/static method on the current class or a method in some Module! Now there's a new guy at work and he really hates this style of programming because he thinks it's redundant. I'm not asking for right or wrong (unless I'm the one who's right ;p), but I want to know personal preferences.public class SanderRossel : Lazy<Person>
{
public void DoWork()
{
throw new NotSupportedException();
}
}this.Redundant
-
I have a question about your preferred programming style. Whenever I write code in C# I make extensive use of the 'this' keyword and I use class names when referencing statics. So:
this.SomeProperty = someValue;
this.SomeMethod();
ThisClass.SomeStaticMethod();Instead of:
SomeProperty = someValue;
SomeMethod();
SomeStaticMethod();My reasoning behind this is that I can tell something is an instance method or a static method. And to be completely honest it's also something I started doing in VB because VB has Modules and Modules don't make you specify the Module's name. So
Me.SomeMethod()
can be an instance method, a Shared/static method on the current class or a method in some Module! Now there's a new guy at work and he really hates this style of programming because he thinks it's redundant. I'm not asking for right or wrong (unless I'm the one who's right ;p), but I want to know personal preferences.public class SanderRossel : Lazy<Person>
{
public void DoWork()
{
throw new NotSupportedException();
}
}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. :badger:
-
I have a question about your preferred programming style. Whenever I write code in C# I make extensive use of the 'this' keyword and I use class names when referencing statics. So:
this.SomeProperty = someValue;
this.SomeMethod();
ThisClass.SomeStaticMethod();Instead of:
SomeProperty = someValue;
SomeMethod();
SomeStaticMethod();My reasoning behind this is that I can tell something is an instance method or a static method. And to be completely honest it's also something I started doing in VB because VB has Modules and Modules don't make you specify the Module's name. So
Me.SomeMethod()
can be an instance method, a Shared/static method on the current class or a method in some Module! Now there's a new guy at work and he really hates this style of programming because he thinks it's redundant. I'm not asking for right or wrong (unless I'm the one who's right ;p), but I want to know personal preferences.public class SanderRossel : Lazy<Person>
{
public void DoWork()
{
throw new NotSupportedException();
}
}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 have a question about your preferred programming style. Whenever I write code in C# I make extensive use of the 'this' keyword and I use class names when referencing statics. So:
this.SomeProperty = someValue;
this.SomeMethod();
ThisClass.SomeStaticMethod();Instead of:
SomeProperty = someValue;
SomeMethod();
SomeStaticMethod();My reasoning behind this is that I can tell something is an instance method or a static method. And to be completely honest it's also something I started doing in VB because VB has Modules and Modules don't make you specify the Module's name. So
Me.SomeMethod()
can be an instance method, a Shared/static method on the current class or a method in some Module! Now there's a new guy at work and he really hates this style of programming because he thinks it's redundant. I'm not asking for right or wrong (unless I'm the one who's right ;p), but I want to know personal preferences.public class SanderRossel : Lazy<Person>
{
public void DoWork()
{
throw new NotSupportedException();
}
}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!
My programming get away... The Blog... DirectX for WinRT/C# since 2013! Taking over the world since 1371!
-
Prefixing
this.
for members is a Microsoft .NET programming style guideline. I've tried to use it as often as I can remember to.Regards, Nish
Blog: voidnish.wordpress.com
Got a link?
-
I have a question about your preferred programming style. Whenever I write code in C# I make extensive use of the 'this' keyword and I use class names when referencing statics. So:
this.SomeProperty = someValue;
this.SomeMethod();
ThisClass.SomeStaticMethod();Instead of:
SomeProperty = someValue;
SomeMethod();
SomeStaticMethod();My reasoning behind this is that I can tell something is an instance method or a static method. And to be completely honest it's also something I started doing in VB because VB has Modules and Modules don't make you specify the Module's name. So
Me.SomeMethod()
can be an instance method, a Shared/static method on the current class or a method in some Module! Now there's a new guy at work and he really hates this style of programming because he thinks it's redundant. I'm not asking for right or wrong (unless I'm the one who's right ;p), but I want to know personal preferences.public class SanderRossel : Lazy<Person>
{
public void DoWork()
{
throw new NotSupportedException();
}
}I do not care about these redundancy but, personally, I do not prefer these type of redundant code.
___ ___ ___
|__ |_| |\ | | |_| \ /
__| | | | \| |__| | | / -
I have a question about your preferred programming style. Whenever I write code in C# I make extensive use of the 'this' keyword and I use class names when referencing statics. So:
this.SomeProperty = someValue;
this.SomeMethod();
ThisClass.SomeStaticMethod();Instead of:
SomeProperty = someValue;
SomeMethod();
SomeStaticMethod();My reasoning behind this is that I can tell something is an instance method or a static method. And to be completely honest it's also something I started doing in VB because VB has Modules and Modules don't make you specify the Module's name. So
Me.SomeMethod()
can be an instance method, a Shared/static method on the current class or a method in some Module! Now there's a new guy at work and he really hates this style of programming because he thinks it's redundant. I'm not asking for right or wrong (unless I'm the one who's right ;p), but I want to know personal preferences.public class SanderRossel : Lazy<Person>
{
public void DoWork()
{
throw new NotSupportedException();
}
} -
I have a question about your preferred programming style. Whenever I write code in C# I make extensive use of the 'this' keyword and I use class names when referencing statics. So:
this.SomeProperty = someValue;
this.SomeMethod();
ThisClass.SomeStaticMethod();Instead of:
SomeProperty = someValue;
SomeMethod();
SomeStaticMethod();My reasoning behind this is that I can tell something is an instance method or a static method. And to be completely honest it's also something I started doing in VB because VB has Modules and Modules don't make you specify the Module's name. So
Me.SomeMethod()
can be an instance method, a Shared/static method on the current class or a method in some Module! Now there's a new guy at work and he really hates this style of programming because he thinks it's redundant. I'm not asking for right or wrong (unless I'm the one who's right ;p), but I want to know personal preferences.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 (√-shit)2
-
By that same reasoning, stop using any "using" and reference only via fully qualified "System.Windows.Forms.ListCtrl.Item item" :rolleyes: 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".. :laugh:
Your time will come, if you let it be right.
-
By that same reasoning, stop using any "using" and reference only via fully qualified "System.Windows.Forms.ListCtrl.Item item" :rolleyes: 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".. :laugh:
Nareesh1 wrote:
who needs any shortening of a line
Oh the irony! :laugh:
Your time will come, if you let it be right.
-
I have a question about your preferred programming style. Whenever I write code in C# I make extensive use of the 'this' keyword and I use class names when referencing statics. So:
this.SomeProperty = someValue;
this.SomeMethod();
ThisClass.SomeStaticMethod();Instead of:
SomeProperty = someValue;
SomeMethod();
SomeStaticMethod();My reasoning behind this is that I can tell something is an instance method or a static method. And to be completely honest it's also something I started doing in VB because VB has Modules and Modules don't make you specify the Module's name. So
Me.SomeMethod()
can be an instance method, a Shared/static method on the current class or a method in some Module! Now there's a new guy at work and he really hates this style of programming because he thinks it's redundant. I'm not asking for right or wrong (unless I'm the one who's right ;p), but I want to know personal preferences.public class SanderRossel : Lazy<Person>
{
public void DoWork()
{
throw new NotSupportedException();
}
} -
I have a question about your preferred programming style. Whenever I write code in C# I make extensive use of the 'this' keyword and I use class names when referencing statics. So:
this.SomeProperty = someValue;
this.SomeMethod();
ThisClass.SomeStaticMethod();Instead of:
SomeProperty = someValue;
SomeMethod();
SomeStaticMethod();My reasoning behind this is that I can tell something is an instance method or a static method. And to be completely honest it's also something I started doing in VB because VB has Modules and Modules don't make you specify the Module's name. So
Me.SomeMethod()
can be an instance method, a Shared/static method on the current class or a method in some Module! Now there's a new guy at work and he really hates this style of programming because he thinks it's redundant. I'm not asking for right or wrong (unless I'm the one who's right ;p), but I want to know personal preferences.public class SanderRossel : Lazy<Person>
{
public void DoWork()
{
throw new NotSupportedException();
}
}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.Redundant
Errrm, this.
Alberto Brandolini:
The amount of energy necessary to refute bullshit is an order of magnitude bigger than to produce it.
-
this.Redundant
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 have a question about your preferred programming style. Whenever I write code in C# I make extensive use of the 'this' keyword and I use class names when referencing statics. So:
this.SomeProperty = someValue;
this.SomeMethod();
ThisClass.SomeStaticMethod();Instead of:
SomeProperty = someValue;
SomeMethod();
SomeStaticMethod();My reasoning behind this is that I can tell something is an instance method or a static method. And to be completely honest it's also something I started doing in VB because VB has Modules and Modules don't make you specify the Module's name. So
Me.SomeMethod()
can be an instance method, a Shared/static method on the current class or a method in some Module! Now there's a new guy at work and he really hates this style of programming because he thinks it's redundant. I'm not asking for right or wrong (unless I'm the one who's right ;p), but I want to know personal preferences.public class SanderRossel : Lazy<Person>
{
public void DoWork()
{
throw new NotSupportedException();
}
}this
is good and I use it normally. The fact that it seems to annoy some pooples just encourages me to use it more. :-D -
I have a question about your preferred programming style. Whenever I write code in C# I make extensive use of the 'this' keyword and I use class names when referencing statics. So:
this.SomeProperty = someValue;
this.SomeMethod();
ThisClass.SomeStaticMethod();Instead of:
SomeProperty = someValue;
SomeMethod();
SomeStaticMethod();My reasoning behind this is that I can tell something is an instance method or a static method. And to be completely honest it's also something I started doing in VB because VB has Modules and Modules don't make you specify the Module's name. So
Me.SomeMethod()
can be an instance method, a Shared/static method on the current class or a method in some Module! Now there's a new guy at work and he really hates this style of programming because he thinks it's redundant. I'm not asking for right or wrong (unless I'm the one who's right ;p), but I want to know personal preferences.public class SanderRossel : Lazy<Person>
{
public void DoWork()
{
throw new NotSupportedException();
}
} -
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
_Maxxx_ wrote:
(like conflicting names)
:thumbsup::thumbsup::thumbsup:
-
this
is good and I use it normally. The fact that it seems to annoy some pooples just encourages me to use it more. :-Dsuch a trouble maker and non-conformist. :-D
-
"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 ;)
-
I have a question about your preferred programming style. Whenever I write code in C# I make extensive use of the 'this' keyword and I use class names when referencing statics. So:
this.SomeProperty = someValue;
this.SomeMethod();
ThisClass.SomeStaticMethod();Instead of:
SomeProperty = someValue;
SomeMethod();
SomeStaticMethod();My reasoning behind this is that I can tell something is an instance method or a static method. And to be completely honest it's also something I started doing in VB because VB has Modules and Modules don't make you specify the Module's name. So
Me.SomeMethod()
can be an instance method, a Shared/static method on the current class or a method in some Module! Now there's a new guy at work and he really hates this style of programming because he thinks it's redundant. I'm not asking for right or wrong (unless I'm the one who's right ;p), but I want to know personal preferences.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."