Comment On I Think I'll Put It ... Here

In the .NET world there's quite often discussion on the most what the appropriate container is for a set of objects. That's probably because we've got so many to choose from: Stack, ArrayList, ListDictionary, HashTables, and so on. I'm sure there's just as many in Java to choose from, but since I'm not a Java guy like David Shay (who discovered today's example), I really couldn't enumerate them. [expand full text]
« PrevPage 1Next »

Re: I Think I'll Put It ... Here

2005-03-10 14:01 • by
Worst kind of OO is the clueless OO.

Re: I Think I'll Put It ... Here

2005-03-10 14:44 • by
I don't know about .Net 1.1, but in 1.0 the generic containers are
ArrayList, Hashtable and SortedList - practically nothing. Not even a
linked list. In comparison, Java has ArrayList, LinkedList, HashMap,
HashSet, TreeMap and TreeSet, LinkedHashMap and LinkedHashSet. And some
older containers with essentially the same functionality as some of the
new ones.



So yes, the programmer certainly had a lot to choose from.

Re: I Think I'll Put It ... Here

2005-03-10 15:40 • by
31042 in reply to 31037
System.Collections.Specialized Namespace



http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemcollectionsspecialized.asp



HybridDictionary

ListDictionary

NameValueCollection

StringCollection

StringDictionary

BitVector32

Re: I Think I'll Put It ... Here

2005-03-10 16:00 • by mugs
OK, usually the google ads make some sort of sense, but where do they come up with the idea that we'd want to order the "Entire Holy Zohor on Microfilm" or hire thousands of classical musicians?

Re: I Think I'll Put It ... Here

2005-03-10 16:19 • by

I used to see this kind of thing all the time in my college VB6 (don't ask) course.  People found out about the list objects in VB and started putting everything in there.  We had to have a special review class about arrays and introduce collections about three weeks early to stop people from doing this.

Re: I Think I'll Put It ... Here

2005-03-10 16:20 • by martinm1000
Ok, the example is in Java...



Some explanations for other people :



The JList is in the javax.swing package, which is the Swing GUI package for graphical components ;-)



Actually, I'm not even sure if this code would work, as some GUI
components would throw a HeadlessException exception if there is no
Display on the computer (think server). Maybee it would works because there is no
setVisible(true) called on the JList ;-)



In Java, the collections (Maps, Lists and Sets) are mostly in the
java.util package, and they have to implement the java.util.Collection
interface.

Re: I Think I'll Put It ... Here

2005-03-10 16:35 • by
31047 in reply to 31046
Actually,
java.util.Map doesn't implement java.util.Collection, as Collection is
really meant only for non-associative containers (though Set, which in
the C++/STL world would be considered an associative container does in
fact implement Collection).  If you look at Collection's methods,
it's pretty clear that implementing it for Map would be hard.  For
instance, how do you implement iterator() or add(Object) or
remove(Object) for a Map?



(Ooh, I think there are some more nits I can pick over here... :))

Re: I Think I'll Put It ... Here

2005-03-10 17:35 • by Rank Amateur

Am I seeing this right? The only reason to use the JList at all is to get a count of the number of ATMTrafficDescr’s? And then the first loop stuffs the JList elements back into an array of ATMTrafficDescr’s? And the only thing the count is needed for is to iterate through the ATMTrafficDescr array to select some strings? Even I would think there has to be a way to iterate through the ATMTrafficDescr list directly. And I’m one of those VB programmers the 4th anonymous poster is talking about who has used a list box control as a substitute linked list!


 


--RA


 


 

Re: I Think I'll Put It ... Here

2005-03-10 17:44 • by codeman38
31049 in reply to 31043
mugs:
OK, usually the google ads make some sort of sense,
but where do they come up with the idea that we'd want to order the
"Entire Holy Zohor on Microfilm" or hire thousands of classical
musicians?


Heh. I'm surprised the Google ads didn't include an ad for jlist.com--
it's a site that sells bizarre Japanese pop-culture goods, but you'd
think it would've come up considering the Java object being discussed.
:)

Re: I Think I'll Put It ... Here

2005-03-10 18:08 • by Sean Reilly

I'm also a java programmer, so for the record, here's how you do this when your head isn't shoved firmly between your own buttcheeks (I'm using Java 4 syntax, it would be slightly different in Java 5).

List atmTrafficDescrsList = DataStore.getObjectList("ATMTrafficDescr");

String[][] data = new String[atmTrafficDescrsList.length()][2];

int j = 0;
for (final Iterator i = atmTrafficDescrsList.iterator(); i.hasNext();)
{
final ATMTrafficDescr temp = (ATMTrafficDescr) i.next();
if (temp.getEnabled() && temp.getServiceClas().equals("CBR")) //I'm preserving a stupid bug here
{
data[j][0] = temp.getName();
data[j][1] = temp.getPcr();
}
}

The stupid bug I'm referring to in the comments has to do with how array initialization in Java.  Any time that the if statment fails and data isn't added to the data array, then the array elements at that index are left to null.  In other words, many nasty null pointer exceptions at runtime.  The best way to fix that would be to insert the following code before int j is declared:

for (final Iterator i = atmTrafficDescrsList.iterator(); i.hasNext();)

{
final ATMTrafficDescr temp = (ATMTrafficDescr) i.next();
if (temp.getEnabled() && temp.getServiceClas().equals("CBR"))
{
i.remove();
}
}

Once this is added the if statement in the original loop isn't neccessary any more.


All in all, this is one of the most criminal abuses of the java language I have seen, ever.

Re: I Think I'll Put It ... Here

2005-03-10 18:18 • by Jeremy Morton
31051 in reply to 31050
Sean Reilly:

All in all, this is one of the most criminal abuses of the java language I have seen, ever.



Agreed, but I wanted to point out that you missed incrementing j in your code.

Re: I Think I'll Put It ... Here

2005-03-10 21:16 • by
31052 in reply to 31051
Jeremy Morton:







 Sean Reilly wrote:





All in all, this is one of the most criminal abuses of the java language I have seen, ever.




Agreed, but I wanted to point out that you missed incrementing j in your code.



Dammit!  So I did.

Re: I Think I'll Put It ... Here

2005-03-10 22:23 • by cjs
31053 in reply to 31050
Hm. Cool. So let's see how you'd do it in Ruby.



cbr_descrs = DataStore::get_object_list("ATMTrafficDescr").select { |d|

    d.enabled? && d.service_class == "CBR" }

data = cbr_descrs.collect { |d| [ d.name, d.pcr ] }


Re: I Think I'll Put It ... Here

2005-03-11 02:51 • by V.
Although cheating by using GUI components where they're not needed is quite often used, this one does seems very, very strange to me.



And why would you use the DataStore object to copy to an array, when you already put the DataStore in a JList?

And why would you copy that array again in a string array?



Is there some info we need to know, why anyone would do it like that, else wtf. [:)]

Re: I Think I'll Put It ... Here

2005-03-11 03:24 • by
31058 in reply to 31053
This one actually made me cringe. Haven't seen this kind of abuse in a long time (fortunately).

Here's the Python way of doing it:

atmTrafficDescrsList = DataStore.getObjectList("ATMTrafficDescr")
data = [(d.getName(), d.getPcr()) for d in atmTrafficDescrsList if d.getEnabled() and d.getServiceClass() == 'CBR']

Re: I Think I'll Put It ... Here

2005-03-11 03:51 • by
In 16 bit VB a common way to sort a list of items was to use a hidden
list box with the Sorted property set to True.  Now there's a wtf.

Re: I Think I'll Put It ... Here

2005-03-11 05:25 • by
I get 2 google ads for G-Strings at the top of my page [:D]

Re: I Think I'll Put It ... Here

2005-03-11 05:40 • by nickelarse
31061 in reply to 31060
I get tactile metal domes.



Anyway, nobody has mentioned this yet, so is it my responsibility to
mention that surely the real WTF is that the opening braces are not on
the next line?  Actually, I couldn't care less, but I feel someone
had to mention it.



As for the abuse of JList.  Well, yep, seems pretty bad.  I
would have used a JTable myself, and a custom TableModel [;-)]. 
Though you could argue it shows imagination and creativity.

Re: I Think I'll Put It ... Here

2005-03-11 06:20 • by AndrewVos

hey i don get google ads, not that im complaining!!

Re: I Think I'll Put It ... Here

2005-03-11 09:51 • by
31064 in reply to 31061
nickelarse:
Anyway, nobody has mentioned this yet, so is it my responsibility to
mention that surely the real WTF is that the opening braces are not on
the next line?  Actually, I couldn't care less, but I feel someone
had to mention it.



Of course not, because that's the One
True Brace Style
, which all code should use.  The real WTF is actually the missing space between the ) and the { characters.


Re: I Think I'll Put It ... Here

2005-03-11 14:08 • by Romeo-Gresta
Seems like we're dealing another kind of Strings for Google:



Guitar strings

Low Prices on a Great Selection Free Delivery on orders over £15

Re: I Think I'll Put It ... Here

2009-05-18 03:56 • by wow gold (unregistered)
Out of runes of magic gold? Need it in urgent? Yes, I can understand you. As the most important currency, without rom gold, you ever can’t do anything. So you need to buy rom gold from those most professional and loyal game online shops with years’ experience and have a good reputation among players. Is there any difficult? No, when you need the rom gold, please feel free to contact us, we are promising to offer you the cheap runes of magic gold with fastest delivery. Moreover, we are online 24/7, you can contact us any time with any question about. So why are you still irresolute? Come here to grab your cheap runes of magic gold now. Crazy about running warhammer gold? Yup, it is so crucial indeed for us in Warhammer Online. Without it, we can even do nothing, without money to buy items, weapons and so on. So enough warhammer gold is substantial.
« PrevPage 1Next »

Add Comment