?

Log in

No account? Create an account
March 24th, 2007 - Adventures in Engineering — LiveJournal
The wanderings of a modern ronin.

Ben Cantrick
  Date: 2007-03-24 00:52
  Subject:   Jabba the Hutt is not amused.
Public
  Mood:"I'm the Juggernaut, bitcch!!"
  Music:The Bastard Fairies - We're All Going To Hell
  Tags:  humor, metafilter



Huang Liqian, 58, first discovered a bizarre growth on the back of his neck in 1990, but chose to ignore it.

After finally approaching doctors with the growing problem, his medical diagnosis revealed that he had a neck tumour.


http://www.metro.co.uk/weird/article.html?in_article_id=41697&in_page_id=2
Post A Comment | | Link



Ben Cantrick
  Date: 2007-03-24 02:21
  Subject:   "Thou shalt always kill" - The American version.
Public
  Mood:randomer than j00
  Music:Dan Le Sac vs. Scroobius Pip - Thou Shalt Always Kill
  Tags:  humor
Read more...Collapse )
Post A Comment | | Link






Ben Cantrick
  Date: 2007-03-24 18:23
  Subject:   Java 1.5's foreach() loop.
Public
  Mood:der uber-nerd
  Tags:  java, programming

While I was researching mods to the JWS today, I found out something interesting about Java I didn't know before.

You know Perl's foreach() loop? Where you can say foreach (1 .. 100) { code; } and it'll automagically put each of the numbers from 1 to 100 into a loop variable, and then run the loop for each of them?

As of v1.5, Java has the same thing! Check out "2) Enhanced for loop" on this page. The example they give is:

int sum(int[] a)
{
  int result = 0;

  for (int i : a)    // Note our foreach usage here
  {
    result += i;
  }
  return result;
}


The "for (objName : Collection)" should be read as "for each item in the Collection, assign it to objName and do the statement(s) below on it. When all of the items in Collection have been processed, exit the loop". In addition to Collections, also note the enhanced for() works with arrays.


I've loved Perl's foreach() loop for a long time. It's cool to see it added to Java. However, some other web pages that I read said it can be slow sometimes. So use with caution. (Though I can't see why it would be slow, unless the underlying Collection is naturally slow. It's easy to see how the compiler can trivially re-phrase "for(i : collection) { stuff; }" into something like "myIter = collection.iterator(); while(myIter.hasNext()){ i = myIter.next(); stuff;1 }".)

-----
1 "Stuff" is a technical term that only extremely skilled software engineers are allowed to use. ;]
3 Comments | Post A Comment | | Link



browse
May 2015