Aaaarg....use the namespace
-
No, you prefix the member if a class with
this
to prevent any ambiguity. The method or property on it's own only implies where it is. If I have this code:class Thingy {
private int majig = 27;void summit() { if (majig > 42) { // clever code } }
}
And I copy the test to another method, all bad things could happen:
void nuThang() { // lots of code int majig = 69; // lots more code // copied: if (majig > 42) { // clever code } }
oops.
Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
Copy/paste is often an invitation not to check what you just pasted. Your example might be a nice example on why we introduced the DRY principle, but being this abstract, one can't be sure. But no, I'd not be bloating my code for the sake of "easy copies". If it's that re-usable, I'll take the time to make it a snippet. --edit;
Nagy Vilmos wrote:
No, you prefix the member if a class with
this
to prevent any ambiguity..the same kind of ambiguity that you have if you don't use the full name against a type, including it's namespace. Do you have global variables that clash with the names of the property/method that you're calling from the current object that you need to specify explicitly that you need the property/method from "this" object?
Bastard Programmer from Hell :suss:
-
No, you prefix the member if a class with
this
to prevent any ambiguity. The method or property on it's own only implies where it is. If I have this code:class Thingy {
private int majig = 27;void summit() { if (majig > 42) { // clever code } }
}
And I copy the test to another method, all bad things could happen:
void nuThang() { // lots of code int majig = 69; // lots more code // copied: if (majig > 42) { // clever code } }
oops.
Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
Nagy Vilmos wrote:
you prefix the member if a class with
this
to prevent any ambiguityCorrect.
-
I don't see the shame on this, this guy just like to write long names :|
I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)
Sentenryu wrote:
I don't see the shame on this, this guy just like to write long names :|
:doh: Huh? I don't, read my message again. I don't want the repetitions so I just mentioned the namespace at the top & replaced things.
thatraja
FREE Code Conversion VB6 ASP VB.NET C# ASP.NET C++ JAVA PHP DELPHI ColdFusion
HTML Marquee & its alternativesNobody remains a virgin, Life screws everyone :sigh:
-
I disagree, it's just code, the compiler doesn't care* and it's better to give the next developer too much information rather than too little. But could they have all shared one static instance? How often are these methods called? Are there threading issues? How big do the StringBuilders become? Can you estimate how big? If large, then pre-allocating enough memory or re-using existing instances can eliminate a lot of needless re-allocation. * However, I suspect that when you use the using directive** the compiler must have to spend some additional time looking them up. ** Qualification added for clarification.
There I mentioned
StringBuilder
is just an example. I found many similar things like below.System.Diagnostics.Trace.Write
System.Diagnostics.Trace.WriteLine
System.Drawing.Color
System.Configuration.Configuration
System.IO.StreamWriter
System.IO.StreamReader
System.IO.FileInfo
System.IO.FileStream
System.IO.StringReader
System.IO.StringWriter
System.IO.TextReader
System.IO.TextWriter
System.Xml.XmlDocument
etc.,
....
...
..
.Why so much repetitions? After that some more 100s of replacements done. Namespace at top.
thatraja
FREE Code Conversion VB6 ASP VB.NET C# ASP.NET C++ JAVA PHP DELPHI ColdFusion
HTML Marquee & its alternativesNobody remains a virgin, Life screws everyone :sigh:
-
Sentenryu wrote:
I don't see the shame on this, this guy just like to write long names :|
:doh: Huh? I don't, read my message again. I don't want the repetitions so I just mentioned the namespace at the top & replaced things.
thatraja
FREE Code Conversion VB6 ASP VB.NET C# ASP.NET C++ JAVA PHP DELPHI ColdFusion
HTML Marquee & its alternativesNobody remains a virgin, Life screws everyone :sigh:
-
Sentenryu wrote:
But it's a matter of taste.
No, it's not. Bloating code is an offence. Three offences, you're out.
Bastard Programmer from Hell :suss:
-
But, some folk like to bloat their code. ;) ;) I agree, there is no good reason to do this, but it is not as bad as wacky, buggy code.
Just because the code works, it doesn't mean that it is good code.
CIDev wrote:
I agree, there is no good reason to do this, but it is not as bad as wacky, buggy code.
To quote one of the arguments why it is;
CIDev wrote:
Just because the code works, it doesn't mean that it is good code.
And that's easy to explain; the more symbols you need to convey an idea, the more chances that there's an error in the communication. The more symbols, the more fluff, the more bugs.
Bastard Programmer from Hell :suss:
-
I found 100+
StringBuilder
s in a module(see below).function string function1()
{
System.Text.StringBuilder sb1 = new System.Text.StringBuilder();
....
...
}
function void method1()
{
System.Text.StringBuilder sb2 = new System.Text.StringBuilder();
....
...
}
function string function3()
{
System.Text.StringBuilder sb3 = new System.Text.StringBuilder();
....
...
}
....
...X| Then I have Included the namespace at top of the module.
using System.Text;
And replaced
System.Text.StringBuilder
withStringBuilder
thatraja
FREE Code Conversion VB6 ASP VB.NET C# ASP.NET C++ JAVA PHP DELPHI ColdFusion
HTML Marquee & its alternativesNobody remains a virgin, Life screws everyone :sigh:
Not that it's a good excuse, but it makes copy/pasting the code easier :) If you'd import the
System.Text Namespace
and copy/pasted the entire thing to another file you'd get an error for everyStringBuilder
.StringBuilder
is a common class that should be known to all programmers, but for some of the more 'obscure' classes I prefer to use the entire namespace. Something like:SomeCompany.ThirdPartyTool.Library.PartINeed.SubPart.TheActualClass
. At least now everyone who reads the code knows where thisTheActualClass
comes from, even if they didn't know the third party component. What I find even more annoying than havingSystem.Text.StringBuilder
100+ times in your code is having lots of imports/using statements at the top of every code file. Especially when half of them aren't used. In C# you can right-click and remove unused imports. VB (unfortunately) doesn't have this option (and please save me the C# vs. VB discussion). I wouldn't call this a code horror, but in this case an import ofSystem.Text
does seem logical. The real horror might be that you use 100+StringBuilders
instead of re-use one... But I'll leave that to you :)It's an OO world.
public class Naerling : Lazy<Person>{
public void DoWork(){ throw new NotImplementedException(); }
} -
I was talking about the original programmer, is that you?
I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)
Sentenryu wrote:
I was talking about the original programmer, is that you?
No
thatraja
FREE Code Conversion VB6 ASP VB.NET C# ASP.NET C++ JAVA PHP DELPHI ColdFusion
HTML Marquee & its alternativesNobody remains a virgin, Life screws everyone :sigh:
-
Not that it's a good excuse, but it makes copy/pasting the code easier :) If you'd import the
System.Text Namespace
and copy/pasted the entire thing to another file you'd get an error for everyStringBuilder
.StringBuilder
is a common class that should be known to all programmers, but for some of the more 'obscure' classes I prefer to use the entire namespace. Something like:SomeCompany.ThirdPartyTool.Library.PartINeed.SubPart.TheActualClass
. At least now everyone who reads the code knows where thisTheActualClass
comes from, even if they didn't know the third party component. What I find even more annoying than havingSystem.Text.StringBuilder
100+ times in your code is having lots of imports/using statements at the top of every code file. Especially when half of them aren't used. In C# you can right-click and remove unused imports. VB (unfortunately) doesn't have this option (and please save me the C# vs. VB discussion). I wouldn't call this a code horror, but in this case an import ofSystem.Text
does seem logical. The real horror might be that you use 100+StringBuilders
instead of re-use one... But I'll leave that to you :)It's an OO world.
public class Naerling : Lazy<Person>{
public void DoWork(){ throw new NotImplementedException(); }
}"VB (unfortunately) doesn't have this option (and please save me the C# vs. VB discussion)." It does have that option, at least in the version I've used (VB2010)
-
"VB (unfortunately) doesn't have this option (and please save me the C# vs. VB discussion)." It does have that option, at least in the version I've used (VB2010)
Really? I was never able to find it. Just right click and...?
It's an OO world.
public class Naerling : Lazy<Person>{
public void DoWork(){ throw new NotImplementedException(); }
}