My code hell, part 1 of lots.



  • Hello!

     I used to work for a small web design company as one of the two programmers of clever dynamic stuff. When I started, I didn't really have much proper programming experience. I was pretty useless and I knew it, so I set about constantly finding new ways of coding and learning the hard way about the advantages of using functions and comments and all that stuff that you learn in Chapter 1 and then decide you don't need until you're half-way through your final year project. Anyway....

    The other programmer, lets call her X, in case she decides to
    Google herself, had been there a year longer than me and gave the
    impression of knowing what she was doing. Whenever one of the designers wanted something cool, like a user-updatable news page, or editable pages, they asked her to do it for them. As more and more people wanted new and dynamic Web 2.0 goodies they decided to get someone new in -  me.

     X decided instantly that I was stepping onto her hallowed turf and made it very hard to get any information from her. Unless I asked her a direct question to do with work, she would completely blank me. A question regarding which of the 50-or-so randomly named files  included the spaghetti code for a particular function would get an irritable "I've already told you" type response.

    Anyway, the fact that she was horrid wasn't really the WTF. That would be too easy to deal with - a swift chat with the boss would sort that out. No, the problem was worse than that.

    She'd inherited a lot of pretty  scruffy code from some bloke who used to freelance. And when I say scruffy, I mean horrible. It's a posting in itself. I assumed for a while that a lot of her code was pretty poor because it was essentially a lot of hacks into this already mad code; that's understandable when your boss doesn't understand programming and just wants stuff to work.But there were two points when looking at code that she had written that I realised she was absolutely useless

     The super-amazing e-commerce system that had evolved had a big behemoth of ASP pages that only she understood. At it's root was a big config file. Part of it had something like this:

     


     WebsiteTitle = "Super Shop"

    Question1 = "How did you hear about us?"

    Question1Option1 = "Friend"

    Question1Option2 =  "Search Engine"

    Question1Option3 = "Other"

    Question1Option4 = ""

    etc... up to Question 10

    The code to display these questions was a huge mass of if/then statements, which would not display if the string was set to empty string. I asked what happened if you needed more options, or more question. She told me that would never happen.

    The other thing was when I looked in her "utils.asp" which featured "really useful code" the centrepiece of which was something which took 5 parameters and returned them as one concatenated string.



  • @djmikeyc said:

    At it's root was a big config file. Part of it had something like this:

     


     WebsiteTitle = "Super Shop"

    Question1 = "How did you hear about us?"

    Question1Option1 = "Friend"

    Question1Option2 =  "Search Engine"

    Question1Option3 = "Other"

    Question1Option4 = ""

    etc... up to Question 10

    The code to display these questions was a huge mass of if/then statements, which would not display if the string was set to empty string. I asked what happened if you needed more options, or more question. She told me that would never happen.

    The other thing was when I looked in her "utils.asp" which featured "really useful code" the centrepiece of which was something which took 5 parameters and returned them as one concatenated string.

    I've seen that one done a few times, myself. It's one of the fun ways to actually prove to someone's superior they don't know what they're doing when necessary. "It took me 5 minutes to do what took them an hour, and here's a list of problems with theirs mine doesn't have. Oh, and mine runs 3 times as fast."

    As far as concatenated strings as a utility function ... So far the funniest one of those I've ever seen was someone trying to be "clever". Instead of having 9 functions to concatenate up to 10 strings, they had 1 variadic function.

    It was, of course, recursive.



  • @Wolftaur said:

    As far as concatenated strings as a utility function ... So far the funniest one of those I've ever seen was someone trying to be "clever". Instead of having 9 functions to concatenate up to 10 strings, they had 1 variadic function.

    It was, of course, recursive.

     

    (define (wtffunction . wtfstrings)
    (if (null? wtfstrings) "" (string-append (car wtfstrings) (apply wtffunction (cdr wtfstrings)))))

    Not that a big of a wtf, except that it's unlikely that he is using Scheme, and also that string-append does exactly this already.



  • @HypocriteWorld said:

    @Wolftaur said:

    As far as concatenated strings as a utility function ... So far the funniest one of those I've ever seen was someone trying to be "clever". Instead of having 9 functions to concatenate up to 10 strings, they had 1 variadic function.

    It was, of course, recursive.

     

    (define (wtffunction . wtfstrings)
    (if (null? wtfstrings) "" (string-append (car wtfstrings) (apply wtffunction (cdr wtfstrings)))))

    Not that a big of a wtf, except that it's unlikely that he is using Scheme, and also that string-append does exactly this already.

    He was using C, and rather than use strcat() or anything else from libc, he malloc()ed a region to hold the new string, and used a while loop to do the copying. And, yes. He forgot about free()ing all the intermediates you get when you pass in a 400 string array... So he was clever enough to not make a ton of functions, buuuuut...



  • @HypocriteWorld said:

    (define (wtffunction . wtfstrings)

    (if (null? wtfstrings) "" (string-append (car wtfstrings) (apply wtffunction (cdr wtfstrings)))))

    Not that a big of a wtf, except that it's unlikely that he is using Scheme, and also that string-append does exactly this already.

     

    (define (wtffunction2 . wtfstrings)
      (define (wtf-iter cs ns)
        (if (null? ns) cs
            (wtf-iter (string-append cs (car ns))
                        (cdr ns))))
      (wtf-iter "" wtfstrings))

    Fixed it for ya :)

     Only in LISP would that look natural.



  • @HypocriteWorld said:

    @Wolftaur said:

    As far as concatenated strings as a utility function ... So far the funniest one of those I've ever seen was someone trying to be "clever". Instead of having 9 functions to concatenate up to 10 strings, they had 1 variadic function.

    It was, of course, recursive.

     

    (define (wtffunction . wtfstrings)
    (if (null? wtfstrings) "" (string-append (car wtfstrings) (apply wtffunction (cdr wtfstrings)))))

    Not that a big of a wtf, except that it's unlikely that he is using Scheme, and also that string-append does exactly this already.

     

    Ahhhhh, now that takes me back... I really hated scheme while I was taking the functional class that they made me take.  Now, however, I think scheme/lisp are actually pretty cool.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.