Comment On It Had Too Many Functions

As one of the more experienced C# coders in his group, Yakir is often asked programming questions. Recently, his colleague James asked him the best way to store hundreds of thousands of items in memory, to which Yakir replied "It depends on how you want to access your data. If you want to access your data by index, you should store it in an ArrayList. If its easier to store things as a key-value pair, then you should use a Hashtable." [expand full text]
« PrevPage 1 | Page 2 | Page 3 | Page 4 | Page 5Next »

Re: It Had Too Many Functions

2007-12-05 08:12 • by 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?

Re: It Had Too Many Functions

2007-12-05 08:14 • by Help (unregistered)
Uughh. I think I just died and went to hell

Re: It Had Too Many Functions

2007-12-05 08:15 • by 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.

Re: It Had Too Many Functions

2007-12-05 08:18 • by 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)

Re: It Had Too Many Functions

2007-12-05 08:19 • by snoofle
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!

Re: It Had Too Many Functions

2007-12-05 08:22 • by 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 -

Re: It Had Too Many Functions

2007-12-05 08:22 • by 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.

Re: It Had Too Many Functions

2007-12-05 08:22 • by Fiona (unregistered)
How... did... my god.. I don't understand what these people do to be landed in these jobs.

Re: It Had Too Many Functions

2007-12-05 08:28 • by 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...

Re: It Had Too Many Functions

2007-12-05 08:28 • by 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!!!

Re: It Had Too Many Functions

2007-12-05 08:29 • by J (unregistered)
I think James should get rid of at least one function. Three functions is not compact enough (five seconds).

Re: It Had Too Many Functions

2007-12-05 08:31 • by Ch0 (unregistered)
164142 in reply to 164138
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?

Re: It Had Too Many Functions

2007-12-05 08:31 • by Gamen (unregistered)
164143 in reply to 164139
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.

Re: It Had Too Many Functions

2007-12-05 08:34 • by 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.

Re: It Had Too Many Functions

2007-12-05 08:35 • by 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) {
..
}

Re: It Had Too Many Functions

2007-12-05 08:38 • by nwbrown
A HashTable with what, O(n^2) removal time? Briliant!

Re: It Had Too Many Functions

2007-12-05 08:39 • by Grovesy
I wait with a sense of trepidation for the first ’This is not a WTF’ WTF comment

Re: It Had Too Many Functions

2007-12-05 08:39 • by Welbog
164150 in reply to 164145
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.

Re: It Had Too Many Functions

2007-12-05 08:40 • by DOA
*THUMP* *THUMP* *THUMP*
What's that you ask? It's my head landing on my desk.

Re: It Had Too Many Functions

2007-12-05 08:46 • by Rene (unregistered)
164153 in reply to 164150
It's called sarcasm.

Re: It Had Too Many Functions

2007-12-05 08:46 • by Claxon (unregistered)
164154 in reply to 164137
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...

Re: It Had Too Many Functions

2007-12-05 08:50 • by vP (unregistered)
164155 in reply to 164148
Wait until you see his version of skiplist!

Re: It Had Too Many Functions

2007-12-05 08:57 • by Devek (unregistered)
164156 in reply to 164145
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.

Re: It Had Too Many Functions

2007-12-05 08:59 • by akatherder
I'm not saying you have to KNOW and USE hash tables to be a good programmer... but it sure seems that way.

Re: It Had Too Many Functions

2007-12-05 09:06 • by täheke (unregistered)
164158 in reply to 164146
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) {
..
}

Re: It Had Too Many Functions

2007-12-05 09:07 • by Thorsten (unregistered)
164159 in reply to 164156
What's wrong with Portage?

Re: It Had Too Many Functions

2007-12-05 09:08 • by jpaull
164161 in reply to 164142
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.

Re: It Had Too Many Functions

2007-12-05 09:08 • by krupa (unregistered)
164162 in reply to 164156
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.

Re: It Had Too Many Functions

2007-12-05 09:09 • by Derek (unregistered)
164163 in reply to 164157
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.)

Re: It Had Too Many Functions

2007-12-05 09:10 • by Devek (unregistered)
164165 in reply to 164159
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.

Re: It Had Too Many Functions

2007-12-05 09:11 • by raveman (unregistered)
he should use HashMap, Hashtable is slower because its synchronized :P

just messing with you

Re: It Had Too Many Functions

2007-12-05 09:16 • by Grovesy
164168 in reply to 164158
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?

Re: It Had Too Many Functions

2007-12-05 09:16 • by 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.

Re: It Had Too Many Functions

2007-12-05 09:20 • by Martin (unregistered)
164170 in reply to 164145
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.

Re: It Had Too Many Functions

2007-12-05 09:25 • by QuinnFazigu
164171 in reply to 164137
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.

Re: It Had Too Many Functions

2007-12-05 09:26 • by Ben Blok (unregistered)
164172 in reply to 164156
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.

Re: It Had Too Many Functions

2007-12-05 09:28 • by Karl von L. (unregistered)
164173 in reply to 164163
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.

Re: It Had Too Many Functions

2007-12-05 09:28 • by 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

Re: It Had Too Many Functions

2007-12-05 09:29 • by Anonymouse (unregistered)
164175 in reply to 164163
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

Re: It Had Too Many Functions

2007-12-05 09:30 • by Devek (unregistered)
164177 in reply to 164162
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.

Re: It Had Too Many Functions

2007-12-05 09:33 • by German B (unregistered)
164178 in reply to 164168
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.

Re: It Had Too Many Functions

2007-12-05 09:33 • by Nelle
164179 in reply to 164177
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.

Re: It Had Too Many Functions

2007-12-05 09:34 • by Fuji (unregistered)
164180 in reply to 164154
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

Re: It Had Too Many Functions

2007-12-05 09:40 • by Devek (unregistered)
164181 in reply to 164172
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.

Re: It Had Too Many Functions

2007-12-05 09:47 • by Jackal von ÖRF
164184 in reply to 164166
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.

Re: It Had Too Many Functions

2007-12-05 09:49 • by gabba
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.

Re: It Had Too Many Functions

2007-12-05 09:51 • by jimjim (unregistered)
164188 in reply to 164145

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

Re: It Had Too Many Functions

2007-12-05 09:51 • by anti-cynic (unregistered)
164189 in reply to 164178
Better yet, screw functions:

{ }

Re: It Had Too Many Functions

2007-12-05 09:53 • by Grovesy
164192 in reply to 164189
anti-cynic:
Better yet, screw functions:

{ }


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

Re: It Had Too Many Functions

2007-12-05 09:57 • by K (unregistered)
164195 in reply to 164178
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.)
« PrevPage 1 | Page 2 | Page 3 | Page 4 | Page 5Next »

Add Comment