[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ProgSoc] Programming! Code!



On Fri, 2006-10-20 at 00:23 +1000, Myles Byrne wrote:

> urls = (page/'.listing a[@href]').map { |a| a['href'] }
...
> With newlines (required for some form of readabiliy) the code looks like:
> 
> ListType urls = page.select('.listing a[@href]').map(
>    class {
>      public ListType returnResult(ListType list) {
>        private returnList ListType = new ListType;
>        while(list.hasMore()) {
>          returnList.add(list.nextItem().getAttribute('href'));
>        }
>        return returnList;
>      }
>    }
> )

Yuck!

> common way to do implement this anyway. An experience Java programmer 
> would probably use a foreach or a while ( maybe first doing a 
> someCollection.getIterator() ) loop. No matter how you slice it though 
> I'd wager the java solution would be at _least_ 5x longer. I'd be happy 
> to be proven with a better example though ;)



List urls = new ArrayList();
for (Element anchor : page.select(".listing a[@href]"))
	urls.add(anchor.get("href"));



(Type safety can be improved by appending <String> to List and
ArrayList.)

- Raz


-
You are subscribed to the progsoc mailing list. To unsubscribe, send a
message containing "unsubscribe" to progsoc-request@xxxxxxxxxxxxxxxxxxx
If you are having trouble, ask owner-progsoc@xxxxxxxxxxxxxxxxxx for help.