|
Indeed, that may act very similar. However, here are two problems I see with that code:
- What if, for whatever reason, a user has two consecutive spaces in their first name? Given the variety of cultures, I wouldn't discount this.
- This version creates several extra and unnecessary strings.
- Unnecessary CPU time spent scanning the name parts (first/middle/last) for space to replace.
Still, with how compact it is, I'd say those are fine trade offs.
This is not the age of reason, this is the age of flummery, and the day of the devious approach. Reason’s gone into the backrooms where it works to devise means by which people can be induced to emote in the desired direction.
|
|
|
|
|
You missed the condition, that the middle name should be omitted if first or last is missing...
|
|
|
|
|
Nope, if a middle name is all you have to call somebody, then you might as well call them that.
Fixign now. | But who's fixing the fixign? |
|
|
|
|
|
What I meant was:
GetFullName(null, "middle", "last") => "last"
GetFullName("first", "middle", null) => "first"
isn't accomplished by your expression... but as well doesn't justify the code of horror in the OP
|
|
|
|
|
Actually, I am the OP and I didn't catch that. Take some 5's.
Fixign now. | But who's fixing the fixign? |
|
|
|
|
|
wahaha this a "Hall of Shame" code indeed XD
|
|
|
|
|
Recently I encountered brand new look at standard boring indexable collections like arrays or lists in code I worked on. To be more precise, at ways we usually use to iterate them. We no longer need properties or functions like: Length, Size, Count. See how it goes (example demonstrating the idea):
int[] someArray = new int[] {};
for (int i = 0; ; i++)
{
try
{
int item = someArray[i];
}
catch(Exception e)
{
break;
}
}
Smell the power! Lenght, Count, Size, etc. They are obsolete now. We will iterate an indexable collection item by item until it crashes and that means our iteration is finished. That's what try/catch block was really intended for!
P.S. int[] was used for demonstration purposes. You can try it at home with any indexable collection you want (in .NET, for example, any collection implementing IList or IList<T> will do just fine).
|
|
|
|
|
VUnreal wrote: You can try it at home
Shouldn't that be 'don't try this at home, leave it to the trained professionals'?
The bearing of a child takes nine months, no matter
how many women are assigned.
|
|
|
|
|
Yes, that will work. However, I sincerely hope to not see it in any real code.
Just because the code works, it doesn't mean that it is good code.
|
|
|
|
|
Jesus H. Christ. That's so appalling, I thought I'd investigate, so I ran this testbed:
static int listSize = 10000000;
static int tests = 10;
static List<int> list = new List<int>();
static void LoopClassic()
{
DateTime start= DateTime.Now;
int f;
for(int i= 0; i< tests; i++)
{
for(int j = 0; j < list.Count; j++)
f = list[j];
}
TimeSpan elapsed = DateTime.Now.Subtract(start);
Console.WriteLine("Classic: {0}", elapsed.TotalMilliseconds );
}
static void LoopCrufty()
{
DateTime start = DateTime.Now;
int f;
for (int i = 0; i < tests; i++)
{
for(int j=0;true;j++)
try
{
f = list[j];
}
catch
{
break;
}
}
TimeSpan elapsed = DateTime.Now.Subtract(start);
Console.WriteLine("Crufty: {0}", elapsed.TotalMilliseconds);
}
static void Main(string[] args)
{
for (int i = 0; i < listSize; i++)
list.Add(i);
LoopClassic();
LoopCrufty();
Console.ReadKey();
}
The Crufty method was faster for the large list (over several runs in release mode)@ Classic~1000 ms, Crufty ~650ms. I changed the list size to 1,000,000 and the normal loop ran quicker (130ms vs 160). Still not justified though!
[Edit]
This is quicker for loops <= 10,000,000 or so!
static void LoopClassic2()
{
DateTime start = DateTime.Now;
int f;
for (int i = 0; i < tests; i++)
{
int count = list.Count;
for (int j = 0; j < count; j++)
f = list[j];
}
TimeSpan elapsed = DateTime.Now.Subtract(start);
Console.WriteLine("Classic2: {0}", elapsed.TotalMilliseconds);
}
|
|
|
|
|
You made me laugh. You even managed to test the stuff
Actually I can even say how this wonderful code has emerged. One "colleague" of mine (I don't consider him as a real colleague to be honest, 'cause he produces sh*t regularly) was too lame to read documentation. Every wise enough human being must have a thought in his/her mind that if a collection's element can be retrieved by index, there must be some kind of function/property like Size, Count, Length, etc. allowing us to know when to stop. So that "guru" had found function that retrieves an object by index, but had failed to scroll the documentation a little further to find number of elements. And little genius invented the construction you saw above. I had no words when I first saw the stuff.
|
|
|
|
|
VUnreal wrote: You made me laugh.
Glad to be of service
|
|
|
|
|
I wonder what will happen when
//do some stuff here
throws an exception???
|
|
|
|
|
...to remind myself of my thoughts when I quit last time, but this comment takes the cake:
; DO SOMETHING, I DON'T KNOW WHAT, BUT DO IT HERE..
|
|
|
|
|
I was recently told that REM stood for REMark and did the same as ' in VB or // in C#... I was very tempted to put something like REM - Losing My Religion above every Class I made
It's an OO world.
|
|
|
|
|
Few interesting comments :
int i=10; //Don't forget
//DO NOT REMOVE THIS COMMENT. REMOVING IT WILL AFFECT THE BUILD PROCESS
-
Bits and Bytes Rules!
10(jk)
|
|
|
|
|
I hate comments that are there just because 'code should be commented'...
I see stuff like
Public Sub GetInfoFromDataBase(connString As String)
conn.Open
If dataRow("someColumn").Value IsNot DBNull.Value AndAlso dataRow("someColumn").Value IsNot Nothing Then
End If
End Sub
And then when there really is a whole lot of unreadable code no one commented it...
It's an OO world.
|
|
|
|
|
Agreed. I really hate it when, in C#, someone just puts the method name where there is supposed to be a summary of what the method does.
public void MethodName()
{
}
Just because the code works, it doesn't mean that it is good code.
|
|
|
|
|
C# guidelines. Method names should be descriptive. Why would you need comments?
|
|
|
|
|
If you have a nice tool like EA, you can put the comments at the top of methods and have those propagate into an API document. Who doesn't like a good API doc?
|
|
|
|
|
It took me a bit longer than I'd like to admit to detect the sarchasm.
|
|
|
|
|
But in the end, you did detect it.
|
|
|
|
|
I am but a naive human being, and it's going to be my downfall.
|
|
|
|
|
Yes, the method names should be descriptive. In my experience the ones who don't use descriptive method names also don't bother to write good comments. Also, sometimes, even a good method name can use a little extra description now and then.
Just because the code works, it doesn't mean that it is good code.
|
|
|
|
|
Ah... Captain Obvious... finally we meet...
(yes|no|maybe)*
|
|
|
|