Austin Danger Powers
-
G-Tek wrote:
implicit conversion is not really the worst part of the function, is it?
That would get my vote for worst part. What part of the function would you vote worst part? Maybe we should suggest a Code Project survey. :rolleyes:
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.
-
It can be useful to split names. That way, companies can send you emails and address you by your first name (or given name, or whatever name part it is common to address people by in a given region). So, they can say "Dear Joe" rather than "Dear Joe Blo III". It is also useful to let the user know that all portions of the name must be entered. For example, if entering credit card details, it is a handy reminder to users to have first/last name so they know they must enter their whole name. While unfair to those with different naming conventions, first/middle/last is the standard for English websites (some add title and others, but the main thing is first/middle/last). It might be best if they allowed for a toggle, so you could switch between first/middle/last or just "full name".
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.
AspDotNetDev wrote:
companies can send you emails and address you by your first name
someString.Split(' ')[0];
AspDotNetDev wrote:
let the user know that all portions of the name must be entered
lblName.Text = "Full Name:"
I know that name splitting has it's usefulness, like displaying in formats like "Last, First Name" the way the user wants, but I believe single field names benefits outweighs by far the benefits of multiple field names. Not only on the functional perspective, but also on development. It's much simpler to have only one column on the database to hold a name. A better solution would indeed be a toggle, but then, that adds overhead to development.
-
G-Tek wrote:
implicit conversion is not really the worst part of the function, is it?
That would get my vote for worst part. What part of the function would you vote worst part? Maybe we should suggest a Code Project survey. :rolleyes:
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.
Dim firstEmpty As String = String.IsNullOrEmpty(firstName)
...
If firstEmpty Then
What's really horrible is that it's not only doing an unnecessary implicit conversion, it's converting it back implicitly with each "If" statement. That may not be a big performance hit here, but put this in an iteration for a few thousand/million loop cycles and I'm sure it would add up (unless maybe the compiler corrects for this mistake, I'm not certain). That gets *my* vote...
-
AspDotNetDev wrote:
I wasn't sure if I should put this in "Clever Code" or "Hall of Shame".
Hall of shame, definitely, specially considering that this line would do the same job:
Return String.Format("{0} {1} {2}", firstName, middleName, lastName).Replace(" ", " ").Trim()
Yes, it works even if firstName, middleName and/or lastName are null. Edit: Forgot the Replace
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.
-
AspDotNetDev wrote:
companies can send you emails and address you by your first name
someString.Split(' ')[0];
AspDotNetDev wrote:
let the user know that all portions of the name must be entered
lblName.Text = "Full Name:"
I know that name splitting has it's usefulness, like displaying in formats like "Last, First Name" the way the user wants, but I believe single field names benefits outweighs by far the benefits of multiple field names. Not only on the functional perspective, but also on development. It's much simpler to have only one column on the database to hold a name. A better solution would indeed be a toggle, but then, that adds overhead to development.
How would your code handle a user who enters: "Mr. Fabio Franco, Ph.D."? :) Or how about these:
- "Mr Fabio Franco, Phd"
- "Mr Fabio Franco the first, phd cna"
- "Mrs. Fabio Franco"
- "Fabio Franco, Mr"
- "Fabio Franco III"
- "Fabio"
There is quite a bit of variation out there, and I'm sure more variation I don't know about in other cultures. Users do funny things when you let them (try to) think for themselves.
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.
-
How would your code handle a user who enters: "Mr. Fabio Franco, Ph.D."? :) Or how about these:
- "Mr Fabio Franco, Phd"
- "Mr Fabio Franco the first, phd cna"
- "Mrs. Fabio Franco"
- "Fabio Franco, Mr"
- "Fabio Franco III"
- "Fabio"
There is quite a bit of variation out there, and I'm sure more variation I don't know about in other cultures. Users do funny things when you let them (try to) think for themselves.
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.
I get what you mean, users thinking by themselves are not good :~, but I think design can solve those issues :) : Title: Full Name: Again, it works so well here that I'm still to find a place in .com.br domain that asks for a multi field name. I don't there's magic bullet for anything, but I still believe that my argument stands, that single field names benefits outweighs multi-field names. I think in US is more of a culture of "most do this way, so we're not changing", although I've seen several single field name cases already.
-
AspDotNetDev wrote:
I wasn't sure if I should put this in "Clever Code" or "Hall of Shame".
Hall of shame, definitely, specially considering that this line would do the same job:
Return String.Format("{0} {1} {2}", firstName, middleName, lastName).Replace(" ", " ").Trim()
Yes, it works even if firstName, middleName and/or lastName are null. Edit: Forgot the Replace
You missed the condition, that the middle name should be omitted if first or last is missing... :cool:
-
There is a small change in the specs, we now have two more optional (middle?) initials. Please adapt your code... :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
Private Function GetFullName(firstName As String, middleName As String, lastName As String) As String
' Variables. Dim fullName As String Dim firstEmpty As String = String.IsNullOrEmpty(firstName) Dim middleEmpty As String = String.IsNullOrEmpty(middleName) Dim lastEmpty As String = String.IsNullOrEmpty(lastName) ' Combine name parts into full name. If firstEmpty Then If middleEmpty Then ' Powers. fullName = lastName Else If lastEmpty Then ' Danger. fullName = middleName Else ' Powers (ignore middle name). fullName = lastName End If End If Else If lastEmpty Then ' Austin (ignore middle name). fullName = firstName Else If middleEmpty Then ' Austin Powers. fullName = String.Format("{0} {1}", firstName, lastName) Else ' Austin Danger Powers. fullName = String.Format("{0} {1} {2}", firstName, middleName, lastName) End If End If End If ' Return full name. Return fullName
End Function
I wasn't sure if I should put this in "Clever Code" or "Hall of Shame". :)
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.
wahaha this a "Hall of Shame" code indeed XD
-
There is a small change in the specs, we now have two more optional (middle?) initials. Please adapt your code... :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
You missed the condition, that the middle name should be omitted if first or last is missing... :cool:
Nope, if a middle name is all you have to call somebody, then you might as well call them that.
Chris Maunder wrote:
Fixign now.
But who's fixing the fixign?
-
Nope, if a middle name is all you have to call somebody, then you might as well call them that.
Chris Maunder wrote:
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 -
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 OPActually, I am the OP and I didn't catch that. Take some 5's. :thumbsup:
Chris Maunder wrote:
Fixign now.
But who's fixing the fixign?
-
AspDotNetDev wrote:
Dim firstEmpty As String = String.IsNullOrEmpty(firstName)
String.IsNullOrEmpty returns "bool"... How are you assigning it to a string variable..? :confused:
Timothy CIAN wrote:
String.IsNullOrEmpty returns "bool"... How are you assigning it to a string variable..? :confused:
I was wondering the same thing - the line shouldn't compile (and doesn't, when I test it)!
-
Here it is pretty normal to have several "first names", in Dutch we actually call them firstnames (plural), although first, second, third, etc. would be more logical. I have four. So we don't really have a middle name or middle initial, when you ask me for a middle initial you'd get three of them. And all that is without double or composite names. How about the code? :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
The multiple names is not SOOO uncommon here in the U.S.A. anymore either. The nanas were arguing about the middle name for our second daugher, so we just gave her "Amber Ann" as the middle name!