- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Actually No, there is a hidden feature in Hashtable, in that when you grab something out of a Hashtable it uses the equals method on the existing key instead of the object you passed in. This leads to a more secure operation since you could encapsulate the hashtable with just a get and put method without worring about someone trying to steal hidden keys from the hashtable. HashMap uses equals on the key you pass in, which tends to be easier to optimize from the JIT point of view.
Admin
The again, you don't store 100s of 1000s items in memory. You use the file system, or perhaps something a little easier, a database.
100,000 jpegs x 100kb/ea = 10,240,000,000
10 Gigs means all you will do is swap. Better use the disk in a controled manner than let Windows swap memory.
Admin
I was just having that thought myself.
Although mine was "That's why I'm not a programmer - I'm overqualified."
Admin
Doing] a job well requires skill, experience, tenacity, (good grammar and spelling?).
I have a good job because I can spell tenacity and try to use it in a sentence quite often. <g>
Admin
I showed this to my wife who uses C # to make her living. I am glad that she married well because otherwise she would obviously starve to death! The only thing that she pointed out was that the class member variables should not be public.
I almost choked on my spit. I told her to take Algorithmization 101. Now I sleep on the couch. :(
I would recommend changing James' job description from "C-sharp programmer" to "C-blunt writer". That would be, I think, appropriate.
Poor Yakir.
Myself
Admin
Admin
Uh... VB anyone?
CAPTCHA: Tesla - gawd awful band
Admin
sure it does, it's just that every item (implicitly) hashes to the same value.
Admin
Personally I think teaching programming using a language that requires people to understand what's going on is a good thing.
When you've got people trying to learn, the less that's just "magic" the better. Anyone that's come out of a C course should know what an array really is... and how that impacts usage. Why? You've had to deal with it at a much lower level than you would in something like Java.
When I was a supplemental instructor for one of the C courses at my uni, a large portion of my lecture time was devoted to helping people understand what was going on with memory and why that was important. I really doubt that'd have been the case if I'd been teaching a high level language like Java. There's too much abstraction... makes it difficult to really understand what's going on... you've got to teach multiple layers of abstraction before you can even really attempt to. Try explaining the difference between a Java int and a Java Integer to someone with no programming background. Not explaining the difference is going to cause them all sorts of problems, but to explain it you'll have to explain not only all the memory stuff that you would with C, but also explain what an object is, how it affects things, get into mutability, etc, etc. It's a mess.
Admin
... Insert obligatory Spinal Tap quote ...
Admin
It's just poorly named, it is not a Hashtable at all (notice no use of hashes). If he'd named it DeadStupidMap he would have been fine.
Or maybe he was doing Hash when he wrote it.
Admin
I don't think there is any excuse for someone making a living in C# or Java to be unfamiliar or uncomfortable with the collections classes of those platforms.
I once had a boss who asked me to come up with some coding challenges for use in interviews. One of my questions basically tested whether the candidate was fluent with collections. If they used the built-in ArrayList, HashMap, etc., the exercise would be trivial. If they tried to roll their own list and map implementations, they'd probably not complete the assignment on time.
My boss said it was an unfair trick question, that you shouldn't expect a developer to know any particular API.
I wish I'd had this WTF to show him then.
Admin
This can't be real.
Admin
We've all had corruption and seg faults from bad use of free and delete. But think about what that means! It means you are still using stuff after you free it. And that means you don't understand how your code flows.
And you know what? If you don't understand how your code flows then the seg faulting should be the LEAST of your worries. You need to be in control of your code. Whether you have garbage collection or not.
So go ahead and write stuff in Java or C#. But if your flow is still out of control then you're still writing crap code. It just doesn't show up as seg faults.
/rant
Admin
Admin
Hey hey hey, just because you write horrible horrible algorithms and have no concept of search optimizations or hashes or built-in-classes does not mean that you can't follow OOP principals!
Admin
No, sometimes you just get tired and forget to delete, much like in Java I sometimes overlook doing a writer.flush because I got a lot on my mind. Eventually I track it down, but if it caused a memory leak vs bad output, could have been a bad problem.
If you do something like Writer.close() then Writer.write, then obviously you have no idea how your code flows.
Admin
Man you people are spoiled with your BINARY... 1s and 0s... back in my day we only had 0s!!!
Admin
Ummmm.... I my be misreading your comment - are you saying that there is no destructor in C-Pound?
There is:
public class MyClass { public MyClass() { // do some init }
~MyClass() { // Do some finit } }
You could also implement IDisposable and put your finalisation in the Dispose method
Admin
Maybe you should. I once managed an order-of-magnitude speedup in a program by changing to a different implementation of FTP. Both were O(n) with respect to the number of files being transferred, but one had far less overhead.
Admin
Admin
As long as it compiles, it is ready for production, right? ;-)
Admin
I have one thing to say to this: head desk
Admin
Admin
Sounds like this James guy should be flipping burgers, not writing software.
Admin
Admin
And then James got fired !!!
Admin
This is today's true WTF!?! C programmers must know much more about code is implemented. C leaves memory management & array-bound checking to the programmer, just to name two. Java & C# are interpreted, and the handle memory, arrays, and most things.
No one, in my opinion, should learn C as a first language. I learned BASIC & 6502 Assembly (i.e. Apple II) before I tackled C. I probably understood C much better having Assembly Language experience first. Pascal & Fortran are both better first procedural languages.
Neither Java nor C# are very "high" level langauges. They are Object-Oriented ones. Objects can be made to protect their data, with memory management & array-bound checking, etc. Also, they raise exceptions to show where things went wrong, without crashing!
Any good programmer can write a HashMap from scratch using C or Java. This one, however, doesn't know what a HashMap is, or how it works. No language can teach someone how to make a HashMap. Java, at least, has a written HashMap class to do it for that programmer.
Admin
I think he's referring to the fact that in C++ the destructor was guaranteed to be called when the object fell out of scope, was "freed", or when an exception unwound the stack. I'm not sure about C#, but in Python the del "destructor" is not guaranteed to be called EVER since it's called on object deletion which happens at the discretion of the garbage collector. This means that you can't rely on Python "destructors" to release resources like file handles in a timely manner. I suspect that C# (being a GC language) has similar problems with the destructor.
Admin
Yes, those languages do exist actually.
Perl or Haskell are completely useless if you don't know what you're doing. They scare away most novices.
On the other hand, they are not really that usefull, even in the hands of experts, for many classes of problems.
But don't say it isn't possible. Any language can be made to scare away the idiots. For example, making Monads' the only way to do IO.
CAPTCHA == tastey ... Yeah, don't make languages too tasty or too much like donuts or hamburgers. They attract the wrong crowd.
Admin
My boss coded the same thing yesterday. And the day before and every day for the last ten years.
Admin
Well, that may be the spirit of OOP, but when it comes down to it, you do care how Array.sort() is implemented. It could be a bubble sort, a quick sort, or whatever. Once you feed it a large amount of data, it matters.
I mean, if you call a taxi to take you to the mall 50 miles away, in theory all you want to do is get to the mall. In actuality, you really do care if they show up in a 1960 VW Beetle instead of new Crown Vic. Both will do the required task, but one of them has some definite advantages.
smile! (captcha)
Admin
VB, ASP, XML, SQL, EJB, PHP ... they're all good. And you can get a hand-wavy job with any of them but -- and here's the catch -- you basically have to lie through your teeth, and find a friend who owns a company to back you up.
Hell, apparently even Clipper would work for this.
Have I annoyed a sufficiently large cross-section yet? No? I'd better add Mumps to the list.
...
It depends upon what you think defines a "programmer," mate. If you think it's producing a "solution" as in the OP, and then offering a spurious and incorrect premature optimisation to a non-existent problem, then, yes, indeed, you are over-qualified.
My tea-lady is over-qualified on these grounds.
Oops, sorry. My Beverage-supply-solution Person is over-qualified. At least it can boil water. If it exists, which it doesn't. And I don't have one. I am therefore in possession of an imaginary tea-person who is unqualified to fulfill its role in life by writing a marginally less insane version of something that it fondly thinks is a "hash table."
Unlike my tea-dispensing neuter, however, I am worried on your behalf. Exactly how are you over-qualified? Would that be a PhD? (Tee hee.) Would that be a degree in math, which you suddenly realise is largely irrelevant to all but 0.001% of computer jobs?
Would it be a degree in linguistics? (In which case, you're just fooling yourself. You are eminently qualified.)
What, precisely, do you intend to use your over-qualification for?
I ask, because there sure is a lot of WTF crap out here where we'd be happy to accept a little more than we actually need.
Admin
There are just so many things wrong with that question I don't know where to start.
Admin
The most useful thing you can do with finalizers (the Java version of this) is something like:
public void finalize() { if(!closed) { System.out.println("Hey you forgot to close me!"); } }
Admin
I can see it now:
"I re-implemented the burger-flipping protocol so that it used no spatulas. Maintenance costs alone mean that using a single spatula to flip a burger is too slow. It's not my fault that the line manager insisted on pushing the burger out to the customer before the bottom of the burger warmed up. Also, it's not my fault that the top side of the burger turned to charcoal. They should turn the flame down on those things, y'know?
"Plus which, I don't understand this fetish about mayo. I mean, that's just inefficient. You gotta collect the egg, transport it, break it, mush it ... I mean, this stuff never ends.
"What's wrong with just snorting the contents of your nose over the burger? I mean, same mouth-feel, same consistency, same taste. It even has the same colour.
"What's the big deal?"
No. I think you want properly qualified Central American illegal immigrants to be flipping your burgers.
You want James to be President of the United States.
Well, he could hardly be more of a fuck-up, could he?
Admin
The guy who wrote the hashtable is actually correct, as can be found by analyzing the complexity orders of both hashtable implementations. The built-in hashtable has many functions, that is to say "n" functions , while his has only 3. Therefore, his implementation is O(3) = O(1) complexity order, while the built-in is O(n) complexity order. Brillant.
Admin
Correct. In C#, even if you implement IDisposable and slap something in Dispose(), you're still at the mercy of the GC as to when things get taken care of. While I don't have any C/++ experience, I do know that difference exists. If you wanted performance that requires proper disposal of objects, perhaps something like C# isn't what you should be using anyway...
Admin
I found something similar in the c++ code of a departed collegue. He'd optimized by inserting into a sorted array and doing a binary search for lookup. This code in this WTF has the advantage of being much easier to understand and replace.
Recruiting graduates will not help you. My UK Computer Science Degree didn't cover hash tables. In any case they can't teach you everything, if you don't have the capacity to learn important stuff for yourself I.T. is probably the wrong career.
Admin
too... stupid... to... live...
Admin
Actually, Dispose has to be called manually by the developer and is thus totally predictable. You're thinking of Finalize, which is called by the GC when it decides to run on a class instance.
Admin
Except in insane and unusual circumstances, you can probably assume with a fair degree of certainty that your favourite library for your favourite language on your favourite hardware is not, in fact, a bubble-sort.
In more unusual cases, I prefer to pick my own library. Which is why I prefer C++ to C# or Java.
(Yes, I can hear those screams in the background.)
The tiny problem with bundling libraries with a language is that those libraries tend to take on a life of their own. Much as I appreciate the C++ standard from a compiler point of view, I can't tell you how happy I was to be able to substitute STLport for either Rogue Wave or the defective Sun alternative. In that restrictive language space, I've made myself equally happy by replacing Microsofts' crappy STL implementation with something better (ie the real thing).
Strangely enough, that wasn't Microsoft's fault. Dinkumware just got caught up in the legal crap to do with an over-rated piece of browser crap that was challenging a useless heap of garbage (Netscape 4) at the time. You can argue browser wars all you want, but it's not clear to me why Microsoft were consequently forbidden to implement the STL properly.
BTW: I'm hoping to be back in northern California sometime in the new year. Got a Crown Vic you want to sell me? I love those. Particularly the ex-police ones (which are probably the only ones on the market right now).
Admin
is it like java where there is not guarantee that ~Class will ever be called?
Admin
who cares
Admin
pfff I use an ABACUS
Admin
(waiting for someone to claim to exist in -1 dimensional space or somesuch)
Admin
Right. Because self-taught programmers never, ever learn about data structures, and people with CS degrees never make stupid data structure choices.
I'd be willing to bet the idiot who wrote the code in this article had a CS degree.
Admin
However there are cases (especially when writing threadsafe libraries of certain types) where there is no way to know for sure if a given object is being used other than to use GC or reference counting. In those cases trying to tack on GC of some sort can be a PITA.
Admin
I defy you to find anything faster than a Bubble sort! *
Admin
I don't know why people always knock Bubble Sort. It works, it's easy to code, and most of the time it's fast enough. Of course you need to understand when NOT to use bubble sort too.
If you need thousands or millions of items in order (as I often do), use the power of SQL to get them in the right order in the first place. Hopefully the database system designer used a more efficient sort, and spent a LOT of time optimising it.
As to a hashtable class - once I'd taught myself Perl a few years ago, I found the lack of hash in other languages so annoying that I actually wrote a hash class in VBA! Which I use all the time now. On performance, it takes a few microseconds per add or lookup, so long as the hash size isn't too big. I found that VBA breaks with memory allocation problems if the hash has much more than about 7 million entries. (Yes I know about Collections but they don't do most of what hash should do.)
So now I come to the real WFT here. Not only is James not using a library far better written than he can do, he has no idea WHY a hashtable is called a hashtable. BECAUSE IT USES A HASH TO DO LOOKUPS. Linear search? WTF!!