The new System.Collections.Concurrent Namespace

July 20th, 2010 by jason No comments »

I just stumbled across the new System.Collections.Concurrent Namespace in .Net 4.0.  I needed a thread safe dictionary and a coworker suggested I check out ConcurrentDictionary.  Of course if you are attempting multiple operations against the dictionary you still need to lock or use some other type of mutex.  But if all you are doing is reading a writing from multiple threads in single, atomic statements then this is the critter for you.

Book Review: The Language of Life

June 1st, 2010 by jason No comments »

Last week I finished reading The Language of Life: DNA and the Revolution in Personalized Medicine by Francis S. Collins.  It has taken me a few days to digest the ideas in the book, such is the scope and depth of the materials presented.

Collins is an expert in genetics, holding a PhD in chemistry and an MD, and ran the Human Genome Project.  With this background, and knowledge from a number of professional relationships he has built, a vast tale of personal medicine based on genetics is told.   He manages to tie together large bodies of cited research with human stories.  The author brings real stories of real people impacted by real science: cutting-edge genetic testing and genetic treatments.  These are stories of cancer, Huntington’s disease, Alzheimer’s disease, and heart attacks.  They are stories of sorrow, of hope, and of the controversy and ethics of stem cells, cloning, and genetic testing of fetuses.

I was caught off guard with the advances being made in the various medical fields related to genetics.  This isn’t pie-in-the-sky stuff.  Collins documents a well-know (in medical circles) case of AIDS being cured with a genetically-modified stem cell implant.  He discusses how patients’ lives have been saved with genetic screening, and how patients have avoided painful and unnecessary procedures because of the same screening.  He also discusses a number of cures waiting in the wings, often delayed by an archaic FDA.

Most convincing to me was his line of predictions.  Collins illustrated 10 predictions he made in 2000 about the state of genetic medicine in 2010.  At the time he got laughs, yet all 10 predictions have come true.  He lays out further predictions for the future.  We are looking at a time when major diseases could be cured due to our increased understanding of DNA, and new techniques being developed almost weekly for the modification of our genetic code.

Beyond the stories and the medicine, this book provides a solid layman’s education in DNA and microbiology.  I would recommend it to anyone with a disease (especially cancer), to anyone concerned about their health, or anyone curious about genetics and the future of medicine.

Book Review: Proust Was a Neuroscientist

May 30th, 2010 by jason No comments »

I recently purchased this book based on some of positive reviews I had read on Amazon.com and elsewhere, and because I read Mr. Lehrer’s blog. I now wish that I had followed the negative reviews. Almost immediately it seemed that Mr. Lehrer was stretching various scientific evidence and theories very thin to match up to his thesis that some artists predicted scientific breakthroughs (such as Proust). I tried to dismiss these instances as artistic fancy, but when the author including information about DNA that is 10 to 15 years out-of-date and flat out wrong, I just could not continue. If Mr. Lehrer is going to compare hard science with art then he should have researched the fields about which he writes, or had better fact-checking of the book.

I ultimately quit this book because while I read a lot about science, and was able to cross-check that things in this book were wrong according to what experts in the field wrote, I am not a scientist nor am I a literary scholar. If Mr. Lehrer is misrepresenting, lying, or simply so bad at science writing that he is giving me bad information, how am I to know? Long story short: Mr. Lehrer lost my trust. I read books by good authors, that are often scientists, to learn more about the world. I *trust* that their professional credentials mean that they will provide me with accurate information. I don’t need to unintentionally poison my mind with outright incorrect information.

COM: Everytime I think I am out, it pulls me back in. (Silverlight + DLR)

May 24th, 2010 by jason No comments »

Silverlight 4 introduces some nice functionality on top of the Out Of Browser (OOB) capabilities introduced in Silverlight 3.  The application can now be granted a higher level of trust which allows it to operate outside the Silverlight sandbox file system, and to interact with COM.  To test the capabilities of this new functionality I immediately tried to take it file system access far beyond the sandbox; I wanted to enumerate all of the drives on the client machine.  I quickly ran into a wall.  Silverlight does not expose access to drives through its IO libraries.  Why?  I read several answers to this question, none of which satisfied me, especially given the fact that the app can simply access these drives through COM!

Luckily .Net 4.0 / Silverlight 4.0 / C# 4.0 comes with the Dynamic Language Runtime (DLR).  I had previous used the new dynamic pseudo-type that ties into the DLR to call Iron Python.  I figured I would see if I could use this same technique to call into COM. Back in ancient times (circa 1990s) I called into COM all the time from VB and ASP. I knew the libraries were all there to do what I needed to do.

I was not surprised to find I wasn’t the first person down this path, and quickly encountered multiple articles and postings about working with the file system via COM this exact way.  With the knowledge that it was possible I plowed forward.

To access COM from Silverlight one uses the AutomationFactory to instantiate a COM library.  I wanted to use the good ol’ Scripting.FileSystemObject.  In my test case I had a Silverlight app running locally OOB with elevated privileges.  This Silverlight app has a single list box which will display the drive letters once I can get access.  Via COM, the code looks like this:

dynamic fs = AutomationFactory.CreateObject("Scripting.FileSystemObject");

foreach (dynamic drive in fs.Drives)
{
  filesListBox.Items.Add(drive.DriveLetter);
}

Its really that simple. The dynamic keyword and COM do all the heavy lifting. The most work I had to do was lookup the object model to use in the FSO, as no intellisense is available. The runtime does late binding onto these properties via the DLR. This did a nice end-route around the missing Silverlight IO libraries and provided me with a nice list of drives.

Excellent C# Threading Memory Model Article

April 28th, 2010 by jason No comments »

I just read an excellent article on the memory model in .Net and C# as it relates to threading, written my Microsoft’s Igor Ostrovsky.  I think I had gathered most of these details over the years from various MSDN articles and CLR Via C# (1 & 2) by Jeffrey Richter.  However, Ostrovsky provides a solid narration of how the model works.  I was unaware that the local thread cache (conceptually) is all or nothing on reads and writes.  There are a lot of misconceptions of how threads, locks, and volatile variables work and this article does a pretty good job of nailing it all down.  There are some pieces of information that I had previously found slightly contradictory that really make sense when reading the article.

The New SyFy Riverworld Review

April 26th, 2010 by jason No comments »

I just finished watching the “4 hour” Riverworld movie on SyFy.  I was not that impressed.  As a fan of the Riverworld books, and knowing that SyFy can put together a good movie or mini-series when they want to (Tin Man, Battlestar Galactica), I was hopefully that this time SyFy would get it right.  My optimism was further encouraged by some good looking trailers for the show.  My optimism was misplaced.

I understand that any television or movie adaptation must change some things from the book.  To me a faithful interpretation is one that keeps the main characters and themes of the book in place.  Neither was done with any integrity here.  The books revolve around a cast of characters that alternately act as the main character in any given book or section of a book.  However, the overarching protagonist for the novels is Sir Richard Burton.  In the novels Burton leads a complex existence.  He is not an easy man to like but we like him all the same.  It becomes easy to overlook his shortcomings when his strengths are so many.  The author, Phillip Jose Farmer, created a believable character in his version of Burton.

Farmer had an ingenious science fiction concept when he reincarnated all of humanity, everyone that had ever lived, along the shores of a giant, planet-sized river.  But the real plot, and underlying theme of the book is so much more interesting.  Riverworld is a story about redemption and control, about religion and science, and about love and loyalty.

In the SyFy Riverworld, Burton is a 2-dimensional villain, wasting the talents of Peter Wingfield in the role.  A new protagonist is invented, with a new cadre of travel companions.  The new characters are likable, if not a little flat.  We don’t see any real character growth over “4 hours” of television (I keep putting the running time in quotations because SyFy inserted a lot of commercials.  I would suspect the running time with normal commercial usage would have been closer to 3 hours).

In the SyFy Riverworld, the plot of the books is twisted into a silly civil war between the aliens controlling the Riverworld.  So many interesting things could have been done with the real conflict from the books, but instead SyFy turns to a vanilla conflict.  They do try to take a stab at something more interesting than a black and white, good versus evil plot, but they never quite get there.

Once I realized that SyFy was once again trashing the characters and underlying plot of a great science fiction story, I decided to try to give the show a chance on its own merits.  Even pretending that I had not read the books didn’t make the movie better.  Plot holes were not adequately explained.  The motivations of characters seemed too generic.   Decent performances were turned in by many of the actors, but they had very poor material to work with.  And the entire time the film suffers from what must have been a very low budget for extras.  For a river that is supposed to hold billions of people, we see very few individuals outside the small cast of 10 or 15 people.

I wouldn’t recommend the movie.  Go get the books and read them.  They really are fantastic.

Belief vs Truth: Sara Mayhew Video

April 21st, 2010 by jason No comments »

Sara Mayhew, TED Fellow and Manga artist asks us, do we have the courage to let go of our beliefs in order to grab on to what is true?

Where Capitalism and Climate Science Meet

April 19th, 2010 by jason No comments »

Wired has a great article about how businesses are actually listening to the scientists and changing their business practices based on the reality of global warming.  Some businesses, like global shipper Beluga, are using new Arctic Sea routes that weren’t open even a couple of years ago.  Other businesses like insurance companies are betting that global warming is real.  Corporations cannot afford to listen to science-denier politics.  A corporation has to, you know, actually exist in the real world of facts and make money in that world.  Here is a short quote from an unusually good article from Wired.  I would encourage you to read the whole thing.

Companies, of course, exist to make money. That’s often what makes them seem so rapacious. But their primal greed also plants them inevitably in the “reality-based community.” If a firm’s bottom line is going to be affected by a changing climate — say, when its supply chains dry up because of drought, or its real estate gets swamped by sea-level rise — then it doesn’t particularly matter whether or not the executives want to believe in climate change. Railing at scientists for massaging tree-ring statistics won’t stop the globe from warming if the globe is actually, you know, warming. The same applies in reverse, as the folks at Beluga Shipping adroitly realized: If there are serious bucks to be made from the changing climate, then the free market is almost certainly going to jump at it.

Four Chords

April 19th, 2010 by jason No comments »

.Net 4.0 and VS 2010 GA

April 12th, 2010 by jason No comments »

Microsoft has released the 4.0 version of the .Net Framework and Visual Studio 2010.  The release includes several framework enhancements.  The Dynamic Language Runtime has been added, which will act as a useful bridge to such languages as IronPython and IronRuby.  The DLR optimizes dynamic languages at runtime for better performance with .Net.  Also added is the dynamic pseudo-type, which allows run-time lookup of properties and methods on dynamic and compiled types.  This will assist in the usage of dynamic code from compiled code, and also fits into some polymorphism scenarios.  There are also a number of Base Core Library changes.

C# will be gaining some new language functionality with the .Net 4.0 release.  C# now supports option parameters, named parameters and default parameter values to assist with those situations where overloads are cumbersome.  C# 4.0 also supports a type of covariance and contravariance for collections.

The .Net 4.0 framework was delayed because of performance issues.  I am glad they waited to get it right.

Silverlight 4.0 is scheduled to be released later this week.  ASP.Net MVC 2.0 was released a couple of weeks ago, which takes advantages of a couple of new .Net 4.0 scenarios.