• hung weh low (unregistered)

    I want to add another exception for my name!

  • [email protected] (Hassan Voyeau) (unregistered)

    Why is there even a need for such a ridiculous function?

  • [email protected] (Hassan Voyeau) (unregistered)

    Also, Du Maurier is a popular brand of cigarettes here in Trinidad and Tobago.

  • Barry Etter (unregistered)

    Split() returns a zero-based array and the for loop starts at 1, right? Isn't that the WTF?

    :)

  • RJ (unregistered)

    My WTF:
    *The special caseing is really not sufficient
    *The for loop is not needed (split can limit the max returned array length)
    *UBound, in general, always makes me think WTF
    *Undeclared/uninitialized strTmp used as a string, what does that do? Gives "" or "0"?

    And finally, isn't it better to move the last token to be first, instead of the other way around? But then, I'm not the bitch with the spec.

  • non_dev (unregistered)

    I see!
    The specs said: "make <em>exceptions</em> for strings <em>like</em>..." so the developer should use a regexp class and test for a match using patterns ".Not Applicable." and ".Daphne Du Maurier.".
    On a success he must throw an user-defined exception. Am i right?

  • Tim Cartwright (unregistered)

    Barry, the line below the for loop adds position 0 on to the resulting string, so looping from 1 should be good, but that is an <i>interesting</i> way to do it....

    I think the real WTF, is the fact that the FOR loop does not go back-wards, so if you name had multiple spaces in it, this function would return a jacked result.

    "John Jacob Jingleheimer Schmidt" would return
    "Jacob Jingleheimer Schmidt John" when you would think it would supposedly return
    "Schmidt Jingleheimer Jacob John"

  • xenophobe (unregistered)

    Well, obviously the wtf here is that this code implies non-Americans are programmers (note the spelling of "dramatisation") and as we all know only Americans use computers.
    </sarcasm>
    Goes off to eat a big mac

  • Reader (unregistered)

    Tim: I don't agree. The purpose of the routine, given the special case for Daphne as an example, is to convert a string from "LastName FirstName" to "FirstName LastName", assuming that there are multiple first name parts, and only a single last name part. That's why Daphne, with multiple last name parts, is a special case.

    The WTF in my view is that it assumes a single name convention and one special case, and doesn't account for the myriad variations of first name and last name, but otherwise the routine seems to work as advertized.

  • Matt K (unregistered)

    And surprise, surprise! It's in VB! sigh

  • Omer van Kloeten (unregistered)

    There's no WTF here, I'm sure. It's just a case of misunderstanding.

    The developer who wrote this code must have been SQLian. In SQL-Land the word 'LIKE' means the same as '=' for those two values.

    The fault lies with the person who designed this method. Some people are so inconsiderate!

  • Reader (unregistered)

    Alex: one problem with posting these snippets as screen shots is that the code can't be copied out and tested. Not that I normally would want too, but this one is (ahem) a special case...

    Sure I could retype it (and will), but what if, with my expert coding skills, I inadvertantly correct the WTF I can't see?

  • Tim Cartwright (unregistered)

    Reader, not so sure about that. For one thing the EXCEPTION "Daphne Du Maurier" has two spaces in it. Then there is the fact that a for loop was used. Then there is the fact that ubound was checked to be greater than 0. If only one space was in the spec, then it most likely would have checked for ubound = 1, AND not used a for loop. But then this bitch doesn't have the spec..... LMAO... All other special cases would have been ruled out by checking for ubound = 1.

  • RJ (unregistered)

    xenophobe: Parsing names is hard. Period. The best you can do is an elaborately engineered system like .Net has for dates/numbers/currency. No need to get anti-american about it.

  • Manni (unregistered)

    I have to agree with Reader that it appears the format is supposed to take the last name (possibly multi-part) and puts it after the first name. My opinion is that the WTF is the overblown code used to perform this action, and the hardcoding of special cases like "Daphne Du Maurier". You don't need Split(), you don't need a For loop. My idea for the code to fix this (and the uninitialized variable):

    Function strReverse_Name(strName)

    Dim strTmp
    strTmp = ""

    If StrComp(strName, "Not Applicable", vbTextCompare) = 0 Or InStr(strName, " ") <> 0 Then
    strReverse_Name = strName
    Exit Function
    End If

    strTmp = Trim(Mid(strName, InStrRev(strName, " ") + 1)) & " " & Trim(Mid(strName, 1, InStrRev(strName, " ") - 1))

    strReverse_Name = strTmp

    End Function

    The obvious flaw in this code is that it assumes the last "word" is the first name. The truth is there is no way to do this without someone double-checking the results or having a LOT of hardcoded stuff.

  • Manni (unregistered)

    Of course I screwed up that last post. Replace


    If StrComp(strName, "Not Applicable", vbTextCompare) = 0 Or InStr(strName, " ") <> 0 Then

    ...with...

    If StrComp(strName, "Not Applicable", vbTextCompare) = 0 Or InStr(strName, " ") = 0 Then

  • Reader (unregistered)

    Tim: The exception input is "Du Maurier Daphne", which seems to be "multiple last name parts, single first name part". (Note that the thread name is the output string, not the input.)

    I think the routine is intended to handle things like "Schmidt John Jacob Jingleheimer", ie, single last name part, 1-or-more first name parts in normal order.

    If UBound is 0, there's only a single part, no need for swapping things around. If greater, then move the first item to the end.

    Being a spec-less bitch myself <g>, I can't say they were only anticipating one space. It seems they were expecting more, and coded thusly.

  • Mario Goebbels (unregistered)

    Actually, I can understand the motivation for the special case for some "special" employee. Each company has this really annoying retard of an employee, and if you're in a position where you can apply changes, they'll bug the shit out of you. I think that act was done out of resignation, means to make that woman shut up.

    (I had a similar case as sysadmin)

  • [email protected] (Hassan Voyeau) (unregistered)

    This function is uncalled for. I can't imagine a system where you cannot get the first name and last name separately and display how you want it. Why is this function even needed?

  • Reader (unregistered)

    Really Hassan, now that's just silly. How can you claim it is so unnecessary without knowing what kind of data the guy has to work with? Maybe it's a one-time cleanup function.

    The only WTF in this code is that it's a short sighted way to deal with names in general. BUT maybe it worked exactly as intended on his input data and therefore was entirely appropriate for the situation at hand.

    How do we know? We don't, so we can't say otherwise.

  • Jeff (unregistered)

    Hassan: The last system I rewrote had the employee's full name (Last, First Middle) stored in one field in the database and a display name (Nickname Lastname) in another field. You should have seen some of the code (both SQL and C#) I had to write to import existing employees into the new system which separated First Name, Middle Name, Last Name and Nickname.

  • HAVEWORLD (unregistered)

    Points taken.

  • fogelman (unregistered)

    How well does this behave with famous people like Sting and Prince (which is now actually a single non existent ascii char)?

  • Foreigner (unregistered)

    Hmm... strTmp is a global var that is not cleared before use? So in the first time it works okay but after that it screws out?

  • Caleb (unregistered)

    I can understand the need to put in a special case when massaging some data at the last minute.

    The funniest part to me is that it says "make exceptions for string like 'Daphne Du Maurier' in the comments.

  • Reader (unregistered)

    fogelman: single-word input results in UBound = 0, so it just returns it as is. But maybe there should be another special case returning "Gordon Sumner".

    Also, the Artist Formerly Known As Prince is now the Artist Once Again Known As Prince: he is legally allowed to use his own name again.

    Foreigner: it's not clear whether strTmp is local or global, but it seems reasonable to assume it's local; as such, it goes out of scope once the function is done, and the next time it is called it is brand new again.

    BTW, which is your favorite tune, "Feels Like The First Time", or "Star Rider"? My pick is the latter.

  • John Le Carre (unregistered)

    Dear Tech Support: My name is showing up as Carre John Le on the godd*mn intranet. It's working fine on Daphne's computer. WTF?!!

  • Daphne Du Maurier (unregistered)

    Why are you making fun of me?!?!

  • icelava (unregistered)

    The way I see it, the comments author is probably not the method author. The class designer/architect must have left the comments with an empty method body for the programmer to do the rest.

  • Brad Corbin (unregistered)

    I think icelava has the key:
    The person who wrote the comment wanted the programmer to account for multiple-part last names LIKE "Du Marier", not program JUST for one specific possible name.

  • Matthew W. Jackson (unregistered)

    That could be true. But if it were, how could a programmer meet that spec? Perhaps the spec meant for all multiple-part last-names to be accounted for, and the programmer, knowing it could never work completely, and even attempting a high accuracy would require a lot of code, he/she decided to simply check for the case specified in the spec.

    Otherwise, a complicated list of rules would need to be written, and then to every rule there'd be an exception.

    In general, storing names suck. There's no good way to do it. Just look at how complicated HR-XML's name schema is. Addresses suck too. (http://www.hr-xml.org/)

  • Ovidiu (unregistered)

    Icelava definitely got it right - the person who wrote the spec wanted the programmer to switch between last name + first name and first name + last name and keep an eye on out-of-pattern inputs. And Mr. Jackson is right as well - it's impossible to do it in any language of the world.

    I've seen composite family names and composite first names of various kinds, in various languages, and given a single string, it's impossible to solve the problem and meet the requirements.

    However, I think the programmer missed that point - he just thought the two given strings were supposed to receive special treatment. Anyway, who's Daphne?

  • Frederik Carlier (unregistered)

    What's the thing with the unitianilized variable? If you declare one in VB, it gets initialized rightaway:
    Dim str As String equals Dim str As String = ""

    Next, what's wrong with UBound? It's quite common in VB and I honestly don't see what's wrong with it.

    Those who commented that the loop starts at 1 and only adds the item at index 0 after it has finished obviously don't get the code -- this is the essence of the code :). It just puts the first word at the back.
    Of course this could be done better, but still...

    The only real WTF I see is the "exception" for "special cases" ;)

  • Sean Lynch (unregistered)

    Frederik, do you see a "Dim strTmp As String" anywhere in this function? Sure it will work the first time its run, but there is nothing that says it is being cleared before each call to the function (it really shouldnt be the job of the caller anyways). Sure they might be doing it now, but wait till the new guy uses the function, and only runs one name through as a test without clearing strTemp.

  • Brad Corbin (unregistered)

    Sean- Assuming this is VB6, which it appears to be, not declaring the strTemp variable is bad form, but not really a problem, and certainly not all that uncommon.

    Unless "Option Explicit" is on, simply starting to use a variable will implicitly declare it as a variant in the local scope.

    When the function ends, it goes out of scope, and its value will not carry across to other calls to the function.

    Unless, of course, strTemp is declared on the module level somewhere else that we can't see. Then it would be a big problem, because this function simply concatenates to the end, instead of clearing it first.

  • Bil Simser (unregistered)

    I have to agree on one part that this function may not be needed. However given the fact that maybe the person needs to take a single field and split it into multiples (as someone said for a one-time load) there are three types of data one can expect:

    1. No string. Just return blank or throw and exception.
    2. One string. Just return the string as-is.
    3. Two strings. Reverse them after a call to split.
    4. More than two strings.

    The last issue is where it gets tricky. While I understand they want to handle dual last names in a special way there are a couple of other "special" names that need to be handled:
    - full names like "last middle first"
    - dual last names like the one above
    - dual first names like "John Jr. Kennedy"

    The problem is what determines the rules of the split? Hard coding a name isn't the most elegant way but in a sea of 10,000 rows of data who knows how many names are there. Hard to say but there's no easy way to handle exceptions except to maybe ignore them and deal with them by hand later (assuming that the number of them is pretty low).

    In any case, I would use the Split method to get the values into an array and work with it from there. As for WTF code, I would use a while loop going backwards through the array since for doesn't allow this.

  • HAVEWORLD (unregistered)

    Of course you can go backwards in a for loop, just use a negative increment (is that called a decrement?)

    For counter = startValue To stopValue Step -N
    Next

  • Jennifer Daniel of St Thomas (unregistered)

    I'm afraid I got bored half-way through the commentary, so maybe someone said something sensible. It's obvious that the intent of the code is to take names in "Last First Middle Middle" format and convert them to "First Middle Middle Last". I'd assume the other cases mentioned above, like "Last Middle First" are simply irrelevant. I wouldn't expect the function to be perfect-which means I wouldn't accept it in a spec-and I certainly don't expect it to do better than I would by hand.

    The wtf example handles the usual case poorly: why not split at the first space and swap?

    The code also needs to handle the case where the first word is one of the well known adjuncts, like "du", "de", "bes", "de la", "von", etc.

    However, the code can't just guess when there is a short word followed by more than one word, because of "Ho Charles Viet" etc.

    Which reminds us that there is a distinction between "First-name Last-name" presentation and "standard presentation", since asian names, Magyar names, etc. are presented last name first. Which was intended?

    Mostly the WTF for me is, "WHY did we lose the information about which part of the name was surname?" Of course there could be legitimate reasons, but are there?

    I also whether we expect to see "Ruiz y Picasso Pablo" or "Picasso Pablo Ruiz y".

  • Jennifer Daniel of St Thomas (unregistered)

    I meant to add (like it wasn't long enough):

    I get that "handle class of special cases by explicitly testing for the examples given in the assignment" a lot in the answers to interview questions. That's not a WTF for me, it's a pure "goodbye".

  • Jennifer Daniel of St Thomas (unregistered)

    One more WTF: no one seemed to have spotted that according to the specification, the name "Doe Jane" should be transformed to "JaneDoe".

  • Dexter (unregistered) in reply to [email protected] (Hassan Voyeau)
    Anonymous:
    Also, Du Maurier is a popular brand of cigarettes here in Trinidad and Tobago.
  • me (unregistered) in reply to Reader

    What is wrong with a NBSP marker, like is used in TeX to signify that two words (in the TeX sense) should not be split across lines, to signify that the words are all part of the surname, and which can be stripped out when the name is displayed. This would be trivial enough to code for, and those with multi-part surnames can be told how to enter thier names.

  • (cs)

    I'm doing the same thing right now: One of our sopranos has an exceptionally long name. Instead of simply truncating the name, I decided to use the (much) shorter "Mea".

  • jeff (unregistered)

    I think the WTF is located in the chaps exception code. He is supposed to accept two strings unchanged. The first one he does but the second one he hard codes in the required response and look at it it's reversed.

Leave a comment on “Daphne Du Maurier”

Log In or post as a guest

Replying to comment #:

« Return to Article