- 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
I don't get it... what's its purpose? It's not just a List<String> equivalent hard coded to fourteen elements (in an incredibly retarded way) is it?
Admin
It is their business secret. While the competition is stuck at 10, you just turn it up to 14!
This must have been the result of statistics. Perhaps someone noticed that 10 whatevers weren't enough to do whatever they wanted to do, and did some calculations and realised that they wouldn't need more than 13 whatevers in the company's lifetime, give or take error margin X. To be on the safe side, the business reqs contained the line 'next version must have 14 whatevers' and the programmer duly implemented 14 whatevers.
Admin
public class PaulaBean {
public Brillant() { // stuff }
}
Admin
I now understand.. this is the other half of the brain that Paula has missing...
Admin
Admin
Ummm actually, since management rarely has a clue, if he was convincing on how brilliant it is then he probably got a raise and promotion for "thinking outside the box." That term is pseudo-code for "I'm a management asshole."
Admin
Obligatory Spinal Tap Quote: "But this one, goes to eleven!"
Admin
Nice analysis, but you misspelled "dully". HTH!
Admin
Admin
It's not just a FOR-CASE paradigm. This is an all-new extension - the FOR-CASE-IF paradigm. I'm not sure we're fully appreciating it here!
Admin
Admin
One thing is clear: the golden rule of premature optimization was not a factor here. The optimizing programmer didn't even try ArrayList before concluding that a more "memory efficient" version was needed.
Whenever I see an attempt to supplant a standard library class, I ask for justification in the form of reproducible benchmarks in the code review.
Admin
Source -> Generate Getters and Setters
Duh.
Admin
If that is the (for-) case, than they are just one-third there, since the answer to all questions is 42....
Admin
for (int a=1;a<=params.size();a++) switch (a)
Aaaaaaaah!
Admin
I don't see what the big deal is. This bean can easily be fixed by adding "sie" to the end of all the member variables. Then, nobody would recognize the counting words and it would be totally logical.
private String onesie = ""; ... private String elevensie = "";
See, pretty elegant, right?
Admin
Please kill me now.
Admin
package dailywtf.fixed; public class ListBean { private String list[]; public ListBean() { } public ListBean(String ... list) { if (list == null) this(""); for (int i = 0; i < list.length; i++) this.list[i] = list[i]; } public String getElement(int n) throws ArrayIndexOutOfBoundsException { if (n < 0 || n >= list.length) throw new ArrayIndexOutOfBoundsException(n); return list[n]; } public void setElement(String s, int n) throws ArrayIndexOutOfBoundsException { if (n < 0 || n >= list.length) throw new ArrayIndexOutOfBoundsException(n); list[n] = s; } } Furthermore, OP's coding style of foo { bar; } was an eyesore for me so my replacement has sane indentation and style. Also, why had the OP not used arrays? Strings are objects you dumb-ass! Clearly an array is better. Also I added range exception checking. Had he been my student and I was a teacher, I would've expelled {him | her} from the course.
Admin
I believe it, although I suspect that it was their lack of JSP skills that drove this design rather than them not knowing how to use collections. Otherwise I'd declare shenanigans as well.
Admin
com.initrodeglobal... I'll make sure to steer clear of that company.
Admin
HOW do these people ever get a job as a software engineer?
Admin
Fourteen whatevers should be enough for everyone. I'm pretty sure that within a few years a new design pattern will emerge out of this idea, saying that if you have more that 14 fields or methods in your class, you should refactor.
Admin
Or they could have used the slightly less known
ArrayList<String> a = new ArrayList<String>(Arrays.asList(new String[] {one, two, three, ...}));
Admin
I just read all the comments, and I'm surprised that everyone missed something that seemed obvious to me.
The purpose had nothing to do with memory or avoiding using objects. That was clearly just a throw away line to try to justify the monster they had created. The telling comment was the one about using this with JSP. They're probably using Struts but don't know how to access a list. So they (wrongly) think they need to get all their data in an object that has {get|set}Foo method pairs (the JavaBean naming convention) so as to be able to reference it as simply "foo" in the JSP. That's why simply using ArrayList wasn't acceptable to them.
I was going to add that the ArrayList ctor was broken because it confused 1-based and 0-based indexing, but I didn't notice that although they have the cases labeled 1, 2, 3, ..., 14 they have hardcoded calls to .get(0), .get(1), .get(2), ..., .get(13) in those cases.
Ugh.
Admin
That fourteen pronged fork is inefficient. Here, try this shovel!
Admin
Unfortunately that is only guaranteed to work for values of i up to 17 portably (according to ISO14882::2003(e) the minimal supported maximum of an implementation for template recursion is 17)
Admin
Aargh! Like many of these CodeSOD entries, this makes me want to yank the keyboard from the programmer's hands, type in "delete ListBean.java" and tell him to start over.
Admin
Admin
Why would you call an array a List? That is TF!
If you want efficient direct access a.k.a. subscription (but don't care much about efficiency of adding/removing elements) one uses a vector (a.k.a. array). In the opposite case one uses a list.
Admin
And when you need to set the value at an index provided at runtime, you can use reflection to find the right setter method. Brillant!
Admin
Just in case you're being serious, the main difference between Vector and ArrayList since Java 1.2 (so a real long time ago) is that Vector is synchronized. So any instance where only one thread will access your array, ArrayList would be quicker. If you need multithreaded access then you may want to use Vector so you don't need to do your own synchronization.
Of course there's this snippit in the API for creating a synchronized ArrayList:
No idea how that compares to Vector.Admin
Not only mixed with an OO paradigm, but without leveraging a single piece of inheritence! (subtext: I see your corporate 31337 speak, and raise you one!) ;)
Admin
I'm not that big a fan of C++'s STL, but their basic collection data types, and the associated complexity guarantees, is something they got right.
Admin
Why not a spoon cousin?
Admin
The Exorcisim of ListBean:
I am 1, 2, 3, 4, 5, 6, 7, 8, entry, 10, 11, 12 ,13, 14
Admin
Can't wait until the next CodeSOD, where we'll be shown how they went about iterating over the thing!
Admin
What would you call it?
Admin
Admin
Duff's device or Duff Beer?
Admin
I'm not the best programmer of the world, but I think that maybe, that code can be improved using an array.. xD.. WTF!!?? WHO IN THE NAME OF GOD WRITE THIS!!!!.. ¬¬ My grandma can write a better class than ListBeans..
Admin
It's an ArrayList because it's an implementation of the List interface that's backed by an array. On insertion, the array is resized (normally by a power of two) if the capacity has been reached. In comparison, LinkedList is an implementation of the List interface that's ... surprise, surprise, backed by a linked list. The choice of which implementation to use usually boils down to whether you're more concerned with random access or insertion into anywhere other than the end of the list.
As for C++ STL, that's just a WTF. It's predicated on copying, and ends up being a memory hog.
Admin
Nope, as I point out above, there are different implementations of the List interface because they exhibit different behaviour. Meanwhile in C++ land, and in keeping with Stroustrup's own obsessions, the STL designers were more concerned with interface elegance than performance. The end result is that I find I have to use my own hand crafted containers for C++ quite often because the STL ones are too generalised to perform adequately.
Admin
I laughed so hard I made a mess in my pants. Nurse get the medication...
Admin
Nice! This "solution" is really something that I'd expect from our internal ERP Support Team. I stopped getting upset on this...
Admin
A List which really is an Array, or the other way around, is the worst of both worlds, since you cannot count on the good properties of either.
I suppose this miserable situation stems from the fact that there is this base-Interface called List and they felt it necessary to keep the name in subclasses. They could have done something more correct in that area.
Admin
If you need high-performance from your containers, may I suggest storing pointers instead? Even with my trusty Knuth Vol II at my side, I doubt I can roll a significantly better container than Stepanov et al.
I suspect that all the copying is more a result of the functional programming background of the STL lot, but I could be wrong.
Admin
And you can eat a Brillant Paula Bean with it afterwards.
Admin
Keyword being presentation.
Wouldn't a -normal- programmer get lazy writing that whole mess and just use one of the millions of more efficient ways to do it? I know I would.
Admin
There's an array of witticisms tat I could make here....
Admin
Surely if you mix the OO paradigm with the FC paradigm your code is totally FOOC-ed ?