- 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
If you absolutely must use a function, how about
sub split_at_tabs { return (split('\t', $_[0])); }
Admin
The java.util.Vector class is a WTF itself. The Java designers wanted to implement a resizable array-based container but did it wrong, ending up with O(n) amortized time complexity for adding a single element at the end. When they realized this (or maybe the Java users were realizing it because things were so painfully slow), they saw that they couldn't change this behavior without altering Vector's interface. They decided against that and wrote a new class called ArrayList which does essentially the same thing, only in a remotely sane way, and so has O(1) time complexity for "add".
C++ and the STL are often cited as a bad example of "design by committee" but if design by committee is the alternative to "design by ad-hoc rectal extraction", then I, for one, welcome our new committee of overlords.
Admin
A pointer is an abstraction within the language as well. A C-style pointer hides stuff like segments, virtual memory and memory-mapped IO from you.
So if you're going to be precise, you need to speak of "C pointers" for what you mean and then you might as well also speak of "Java pointers", or just "pointers" if you're being sloppy anyway. The main reason not to do this is that "reference" is what the Java Language Specification calls it.
Admin
Vector CAN be O(n) for adding an element if you set a capacityIncrement because then the size of the underlying array is increased by a constant when said array is full. This is only "painfully slow" if you built a very large Vector without setting an appropriately large increment. However, the default behaviour is to double the array size, which is the same thing ArrayList does. It is possible that some ancient (pre 1.1) implementation of Vector did not have that default behaviour, but obviously the problem WAS fixed without having to change the interface.
ArrayList was created for two reasons: First, to implement the List interface as part of the Java 1.2 Collections framework without the legacy methods present in Vector and second, to offer an implementation without the speed penalty of Vector's inbuilt synchronization, which is usually uneeded or insufficient.
Admin
Both Vector's and ArrayList's add operations have an amortized complexity of O(N), where N is the number of elements being added. Unless you set vector.incrementCapacity to a fixed positive value, in which case it becomes O(N) with N being the number of elements in the array.
You're also ignoring the fact that in both cases "add" can be used to insert into the middle of the list as well as append to the list, which with both classes is a O(N) operation, with N being the size of the array.
I'm not a Java expert, but it looks to me like they got into trouble because they made Vector threadsafe. At some point they realized that 90% of coders didn't need the threadsafe behavior, but that they couldn't change it without breaking code for the other 10%, so they made a new class which wasn't threadsafe instead. So it wasn't really the interface that was the problem, it was the defined behavior.
edit:
Doh! Beaten...
Admin
Thanks for being pedantic^W precise. I was taking about the add(Object o) method, not the add(int index, Object element) method which almost every other container library calls insert.
Don't buy the fairy tales - java.util.Vector is synchronized, not thread-safe. There is no such thing as built-in thread safety. Anyway, I guess Sun had several reasons for writing ArrayList (i.e. several design flaws in Vector).
Admin
But I guess Sun considers the much-touted (and admittedly quite impressive) compatibility of Java code and even bytecode across platforms and versions too important to ever break it, even for things that are not only ugly or performance-degrading but outright dangerous like Thread.stop()
Admin
I'd rather program in Perl than VB. Both have ugly syntaxes, but Perl at least allows me to do quick and dirty things with a very concise syntax. VB's syntax is not only clumsy, but also more irregular. Also VB's libraries are so useless and inconsistent. Perl is much better and the documentation is much clearer.
As for GUI, there is Perl/Tk, which is quite nice. (I find TCL's syntax much more terrible than Perl.) When will VB have a widget library that does AUTOMATIC geometry management?
Admin
I can't decide if the fist or 2nd comment is a better example of comment WTFs on this site. Both excellent examples.
Admin
If you try hard you can may unreadable progrma in any language. With Perl, remove "hard". But you still need to work on it.
P.S. Too many Perl examples are still written like in Perl 4. I prefer 5.10.
Admin
Say rather you can program readably in any language. With Perl add hard, but you still need to work on it.
can't say I ever recall anyone complaining about any language about how hard it was to obfuscate.
Addendum (2007-05-07 05:05): Oh well, my reply was just about as grammatical as the original post, upon second reading. If you try you can write readably in any language. With me add hard ;}
Admin
Admin
Admin
I will note that there may be a good reason to not use strtok...
From the GNU C manpage:
And don't provide an equivalent that does the same thing. strtok is very useful, afterall...
If someone is reading that page and runs across that, well, they may just write their own. After all, the C library guys know what they're talking about, and if they say not to use it, well, why should we use it?
Admin
No, he's not using PERL. He's using Perl.
Admin
You shouldn't use StringTokenizer. If it is speed you are worried about use Pattern. It should out perform StringTokenizer unless you have put the compile part into the loop as well.