• Paddington Bear (unregistered)

    I find my car has a radio, cd player and air conditioning, so it's much slower.

    Walking is a much simpler operation and much more efficient.

    Can you help me walk at 70mph please?

  • Help (unregistered)

    Uughh. I think I just died and went to hell

  • Paddington Bear (unregistered)

    ...and the real WTF is that it still says: 1 comments.

    It is true, one does, but I don't think that's how it's intended.

  • TwelveBaud (unregistered)

    "Your brain has too many synapses. Mine just has three. It's more efficient."

    Fail.

    CAPTCHA: ewww (my first reaction to the vict-- I mean, featured employee)

  • (cs)

    O.M.G.

    Even assuming that he HAD to write his own version of something that was already available, that is the worst implementation I've ever seen, including the stuff my students used to turn in!

  • Unomi (unregistered)

    For those amount of values in an array, you can use Duff's device.

    But looking at some code and thinking it has too many functions, without understanding the code and know when it is loaded..... Yeah, WTF?

    I don't know that library myself, but I do look into code to see if it is overkill or not. Default implementations do not simply mean fast. Sometimes you don't need the whole library.

    • Unomi -
  • TheophileEscargot (unregistered)

    I've seen similar things before, like a programmer with years of experience not knowing that there's anything faster than Bubble Sort.

    I think this is a good counterexample to the people who say that CS degrees are pointless since most of the content is never used. Self-taught programmers can often have big gaps in their knowledge like this, since they've never had to learn boring stuff like data structures. And since it's an unknown unknown, they're not aware that they're missing anything.

  • Fiona (unregistered)

    How... did... my god.. I don't understand what these people do to be landed in these jobs.

  • Gamen (unregistered)

    Well, it's not even a hashtable, or even a map. It maps a key to multiple values, but the only way to access suceeding ones is to remove the previous ones... The guy obviously doesn't understand that array resizing involves creating a new array and copying the items (assumption about C#), and it looks like he didn't even look up what a hashtable is. ...I'm honestly surprised he could write working code with as little knowledge as this shows...

  • Brett (unregistered)

    To paraphrase an old Saturday Night Live sketch: "It's not what you know. It's what you think you know!"

    Captcha = "darwin" How appropriate!!!

  • J (unregistered)

    I think James should get rid of at least one function. Three functions is not compact enough (five seconds).

  • Ch0 (unregistered) in reply to Fiona
    Fiona:
    How... did... my god.. I don't understand what these people do to be landed in these jobs.

    That's the thing.

    How can an idiot get a job when I can't? Who do they apply to?

    But then, would I really want to work for the sort of person who'd happily employ an idiot alongside me?

  • Gamen (unregistered) in reply to Gamen
    Gamen:
    Well, it's not even a hashtable, or even a map. It maps a key to multiple values, but the only way to access suceeding ones is to remove the previous ones... The guy obviously doesn't understand that array resizing involves creating a new array and copying the items (assumption about C#), and it looks like he didn't even look up what a hashtable is. ...I'm honestly surprised he could write working code with as little knowledge as this shows...

    Whoops, sorry, you can't ever access the succeeding values. Missed the loop in the remove code. ...So he knows there can be multiple values mapped to a single key... Forget it.

  • (cs)

    I dont see the problem. As it stands his implementation of hashtable is faster, although not because it has just 3 functions, but because there are far fewer layers of inheritance involved.

  • Nick S (unregistered)

    Something like:

    /**

    • @param add if true, add the value with the specified key, otherwise remove the key
    • @param value if add = true, add this value to the specified key, may be null otherwise. */ public void addOrRemove(Object key, Object value, boolean add) { .. }
  • (cs)

    A HashTable with what, O(n^2) removal time? Briliant!

  • (cs)

    I wait with a sense of trepidation for the first ’This is not a WTF’ WTF comment

  • (cs) in reply to Cthulhu
    Cthulhu:
    I dont see the problem. As it stands his implementation of hashtable *is* faster, although not because it has just 3 functions, but because there are far fewer layers of inheritance involved.
    Hello, obvious troll. I wonder how many will take your bait.
  • (cs)

    THUMP THUMP THUMP What's that you ask? It's my head landing on my desk.

  • Rene (unregistered) in reply to Welbog

    It's called sarcasm.

  • Claxon (unregistered) in reply to TheophileEscargot
    TheophileEscargot:
    I've seen similar things before, like a programmer with years of experience not knowing that there's anything faster than Bubble Sort.

    Hey stop that! No dissing of Bubble sorting, without them we'd have to put some effort into optimizations when we need to show justification for a pay rise.

    CAPTCHA: muhahaha - Yes, just what I was thinking...

  • vP (unregistered) in reply to nwbrown

    Wait until you see his version of skiplist!

  • Devek (unregistered) in reply to Cthulhu

    I don't know C#.. but one of the things that has troubled me in the past about "high" level languages(like Java) is that it requires an immense amount of knowledge to be able to do anything correctly while attracting novice programmers left and right.

    Just normal C is easier to program in because you know what your C code is doing for the most part. Novice programmers should start there.

    To write good Java code you have to not only know what your code is doing, but how everything your code is doing is implemented.

    Perfect example of novices using a "high" level language when they don't know enough about coding is Gentoo's portage system. Python is the worst offender when it comes to luring in novices to do something they have no business doing.

  • (cs)

    I'm not saying you have to KNOW and USE hash tables to be a good programmer... but it sure seems that way.

  • täheke (unregistered) in reply to Nick S
    Nick S:
    Something like:

    /**

    • @param add if true, add the value with the specified key, otherwise remove the key
    • @param value if add = true, add this value to the specified key, may be null otherwise. */ public void addOrRemove(Object key, Object value, boolean add) { .. }
    Your function has too many parameters.

    It should be

    /**

    • Adding comments takes too much time */ public Object[] DoStuff(Object[] params) { .. }
  • Thorsten (unregistered) in reply to Devek

    What's wrong with Portage?

  • (cs) in reply to Ch0
    Ch0:
    Fiona:
    How... did... my god.. I don't understand what these people do to be landed in these jobs.

    That's the thing.

    How can an idiot get a job when I can't? Who do they apply to?

    But then, would I really want to work for the sort of person who'd happily employ an idiot alongside me?

    Wow! This comment struck a nerve with me. I apologize if I go into a lengthy speech about this.

    I have run into quite a few people that I graduated from College with who were MUCH better programmers than I was but none of them could find work, while I have had few problems finding development jobs from the day I got my diploma.

    While I wouldn't classify myself as an "idiot", there is something to be said for having the ability to market yourself that can make you more "hirable" than someone with a broader skillset.

    Now that I have had the opportunity to be involved in a few hiring decisions, I have seen one major trend in these highly-skilled newly graduated developers that make them undesirable. The biggest problem is ARROGANCE. No one wants to hire somebody into an entry-level position who thinks they already know everything. The personality of a new employee is just as important as their skill set.

    I think every seasoned programmer has experienced a junior developer with some bizarre misconceptions about basic concepts (My personal favorite is "The only difference between inner joins and outer joins is that inner joins are faster").

    The ones that turn into good developers are the ones that are open-minded and willing to learn.

  • krupa (unregistered) in reply to Devek
    Devek:
    To write good Java code you have to not only know what your code is doing, but how everything your code is doing is implemented.
    How do you figure that? The whole point of OOP is that you don't need to know or care how a class is implemented.
  • Derek (unregistered) in reply to akatherder

    But seriously, where's the WTF in this? Looks fine to me.

    (Just implemented a very similar hash table in Ruby, pretty damn efficient over the 3 items in my test case.)

  • Devek (unregistered) in reply to Thorsten
    Thorsten:
    What's wrong with Portage?

    Check the python source for it :P I'll submit a few WTFs based on it next week when I get time.

  • raveman (unregistered)

    he should use HashMap, Hashtable is slower because its synchronized :P

    just messing with you

  • (cs) in reply to täheke
    täheke:
    Nick S:
    Something like:

    /**

    • @param add if true, add the value with the specified key, otherwise remove the key
    • @param value if add = true, add this value to the specified key, may be null otherwise. */ public void addOrRemove(Object key, Object value, boolean add) { .. }
    Your function has too many parameters.

    It should be

    /**

    • Adding comments takes too much time */ public Object[] DoStuff(Object[] params) { .. }

    Wait, still to much

    public Object[] do(o[] p)

    Actually.. why not just

    public object do(o p)

    Since an array of objects is just an object anyway?

  • Anonymouse (unregistered)

    Wow. Even as just a makeshift quick-and-dirty indexed table class this is real bad. I find myself among the ranks of those who fail to fathom how people like this find jobs and keep them for more than a week or two.

  • Martin (unregistered) in reply to Cthulhu
    Cthulhu:
    I dont see the problem. As it stands his implementation of hashtable *is* faster, although not because it has just 3 functions, but because there are far fewer layers of inheritance involved.

    It's only faster at implementation time.

  • (cs) in reply to TheophileEscargot
    TheophileEscargot:
    I think this is a good counterexample to the people who say that CS degrees are pointless since most of the content is never used. Self-taught programmers can often have big gaps in their knowledge like this, since they've never had to learn boring stuff like data structures.

    Did the article say James was self-taught? If we're going by anecdotal evidence, every WTF I've seen perpetrated by a current employee has been from a college-educated person. The best programmers in our department are self-taught.

  • Ben Blok (unregistered) in reply to Devek
    Devek:
    I don't know C#.. but one of the things that has troubled me in the past about "high" level languages(like Java) is that it requires an immense amount of knowledge to be able to do anything correctly while attracting novice programmers left and right.

    Just normal C is easier to program in because you know what your C code is doing for the most part. Novice programmers should start there.

    To write good Java code you have to not only know what your code is doing, but how everything your code is doing is implemented.

    Perfect example of novices using a "high" level language when they don't know enough about coding is Gentoo's portage system. Python is the worst offender when it comes to luring in novices to do something they have no business doing.

    I do not really agree on this mainly because C has the huuge overhead of learning memory management. C makes shooting yourself in the foot really easy.

  • Karl von L. (unregistered) in reply to Derek
    Derek:
    But seriously, where's the WTF in this? Looks fine to me.

    God, I hope you're joking. This so-called "hash table" doesn't even use any, um, hashing.

  • Tp (unregistered)

    If this wtf is real, than that is simply amazing! The guy sort of knows what a hashtable is and how it works, yet he thinks that fastness has to to with numberofmethodness.. As we say in my country (Norway): IDIOT!

    Captcha: wigwam --> worst glam rock band ever http://youtube.com/watch?v=0XIyCKgA8z8

  • Anonymouse (unregistered) in reply to Derek

    Easy improvements:

    • Resize the array in larger steps so resizing happens less often (an array can have unused elements you know)
    • Resize in even larger steps or not at all when removing items from the array.
    • When removing an element from the Array, rather than copying the rest into place, move the trailing element to the position of the one you just took out. Order of elements is arbitrary anyway.
    • If the number of GetItem calls far outweighs calls to AddItem and RemoveItem (as is often the case), keep the array sorted and index by binary search.

    or even better,

    • Use the HashTable class the platform provides
  • Devek (unregistered) in reply to krupa
    krupa:
    Devek:
    To write good Java code you have to not only know what your code is doing, but how everything your code is doing is implemented.
    How do you figure that? The whole point of OOP is that you don't need to know or care how a class is implemented.

    At the end of the day.. your code is going to do things like access disk and memory which are resources that are more precious than cpu cycles on modern hardware.

    I was reviewing some code for an unnamed company that was writing a server in Java for their game. They wanted to be able to update parts of the logic quickly and on the fly so they decided to use Jython which was fine and all but it was SLOW. The threads would call Jython and tell it to run a script with certain parameters. They even tried a test where they just did basic exec() calls on Jython that did nothing but return and the speed was the same so it wasn't the scripts causing the slow down.

    To fix the speed problem I simply created worker threads that were implemented in Jython that looked into a queue to grab work to do. Even though it was much more complicated, had more threads, and had more code at the end, it was 1000x faster.

    If you don't know how the classes involved are implemented, you won't know why the code went from running 1,000 scripts a second to 100,000 a second on my core 2 desktop. :P If all you knew was Java and knew nothing about how it and its classes worked you would swear the previous implementation would of been faster.

  • German B (unregistered) in reply to Grovesy
    Grovesy:
    public object do(o p)

    Better yet:

    public void do()

    Passing stuff in and out is inefficient. Globals are the way to go. This should be a pattern.

  • (cs) in reply to Devek
    Devek:
    [...] I was reviewing some code for an unnamed company that was writing a server in Java for their game. They wanted to be able to update parts of the logic quickly and on the fly so they decided to use Jython which was fine and all but it was SLOW. The threads would call Jython and tell it to run a script with certain parameters. They even tried a test where they just did basic exec() calls on Jython that did nothing but return and the speed was the same so it wasn't the scripts causing the slow down.

    To fix the speed problem I simply created worker threads that were implemented in Jython that looked into a queue to grab work to do. Even though it was much more complicated, had more threads, and had more code at the end, it was 1000x faster. [...]

    Could you plz email me teh codes.

  • Fuji (unregistered) in reply to Claxon
    Claxon:
    TheophileEscargot:
    I've seen similar things before, like a programmer with years of experience not knowing that there's anything faster than Bubble Sort.
    Hey stop that! No dissing of Bubble sorting, without them we'd have to put some effort into optimizations when we need to show justification for a pay rise.

    Always implement a bubble sort first. Then you can be the hero for really speeding things up in version 2.0

  • Devek (unregistered) in reply to Ben Blok
    Ben Blok:
    I do not really agree on this mainly because C has the huuge overhead of learning memory management. C makes shooting yourself in the foot really easy.
    If you can't write C without shooting yourself in the foot over and over you will not be able to write good code in any language.

    There isn't a language that has built in stupidity protection.

  • (cs) in reply to raveman
    raveman:
    he should use HashMap, Hashtable is slower because its synchronized :P

    just messing with you

    At least in Java. The real WTF is that people still use and teach the use of java.util.Hashtable and java.util.Vector (or even worse, java.util.Stack) instead of the newer alternatives and interfaces. It would be better for Sun to deprecate those classes.

  • (cs)

    It's not a hash table, but I'll call it a hash table anyway. Then, when it's too slow, it must be because hash tables are too slow. Or something.

  • jimjim (unregistered) in reply to Cthulhu

    I don't see why hash-tables would have a lot of inheritance involved, its a basic container

    On the other hand, custom implementation will not have built-in/platforms optimizations

    As hash-tables is a structure used very, compilers often replace them with a very fast implementation

  • anti-cynic (unregistered) in reply to German B

    Better yet, screw functions:

    { }

  • (cs) in reply to anti-cynic
    anti-cynic:
    Better yet, screw functions:

    { }

    Screw code!, machine code all the way baby...

  • K (unregistered) in reply to German B

    Better yet, how about

    int main(){ //...code goes here }

    Anybody that's ever used JavaScript knows how costly function calls are, and every good technical manager knows that encapsulation just confuses new developers because then they have to look into the class to see what it's doing. Better to write everything in one function. That's why VBScript is better, because you don't have weird conventions like "int main()" - you can just write code in any old text file, put "<%@Page Language="VB"%>" (much easier to remember, and informative!) at the top and be done.

    (Sadly, this was the state of the code at my workplace when I came on a few years ago.)

Leave a comment on “It Had Too Many Functions”

Log In or post as a guest

Replying to comment #:

« Return to Article