Wednesday, June 16, 2010

Temporary Death

Your roof, as you know very well, has been recently repaired, and has no aperture by which even a Woman could penetrate.
Flatland, pg 81
by Edwin A. Abbott
My group at work has three main clients: 1) customers who use our product in our tightly integrated ecosystem, 2) customers who use a variant in a more traditional environment, and 3) internal clients using us to build even more complex products for customers.

Sadly (1) is what we end up testing the most.

One part of our system is heavily used by (2) and (3) but not (1). So it is no wonder that we just now found out (internally) about a race condition with a delay loaded object in software that is about 7 years old and used in mission critical applications. I know what you might be thinking but this will not be a sordid tale about the woes of singletons.

We have a critical section around the delay loading. I recently got a bug report on a crash when we have two threads racing to use the object on process start. I sat back baffled for a bit not seeing the problem in our code so moving on to blaming the tools. I know, big mistake but at some point libraries do fail. It turns out the problem was with us and was fairly simple

A little background for non-C++ folk:
In C++ there is an idiom called RAII which allows for easy handling of resources. In this case when tScopedLock is created the lock is acquired. At the end of scope the lock is released. Whenever I see a garbage collected OOP language without an equivalent a little part of me dies having to see all of those "finally" clauses. I was very glad Python added the "with" statement and "from __future__ import with_statement" can be found in most of my python scripts.
void tClass::loadIfNeeded()
{
tScopedLock(lock);
if(!loaded)
{
load();
}
}
With a coding convention that is discouraging of spaces things tend to bleed together. So sadly it took me digging into the Windows Critical Sections data structure to realize when the count inside it was being modified. So I went and put the fix in

void tClass::loadIfNeeded()
{
tScopedLock scopedLock(lock);
if(!loaded)
{
load();
}
}

Oh the joys of accidental temporaries and their scope which lasts for the expression they appear in (usually).

Of course I was a (mostly) good citizen. I grepped through our code and fixed about 5 instances of this problem. I then added a check in our (very limited) static analysis to watch for people adding them. On an internal forum people came up with some pre-proc magic to try and help. Maybe later I'll investigate that.

"It's because people are stupid!"

It was reported that when Dr. Willard Richards ... first saw a copy of the Book of Mormon he opened it in the center and read a few pages. He closed the book with this statement: "That book was either written by God or the devil, and I am going to find out who wrote it."
A Marvelous Work And A Wonder, pg 81
By LeGrand Richards
I've occasionally played catch up with BYU's Tuesday Morning Devotionals. Recently I read "Scholarship and Faith" by Ross Spencer. I'd like to start off with his introduction to Dr Henry Eyring and Dr Eyring's comments:
Dr. Henry Eyring, the great LDS chemist and father of President Henry B. Eyring, was a great example of how to combine professional excellence with faith and humility. He was world-famous for his work on chemical reactions and was also known both to his scientific colleagues and to members of the Church as a man of faith and devotion. He said:
...
So this, then, is sort of the picture that I would give you and end on the note that I can’t see any difference between the kinds of arguments that you make to support religion and the arguments that you make to support science. I understand, of course, that there are contradictions of all kinds in science, and there are contradictions between science and religion, and there are contradictions between various parts of religion in every human mind (but not in God’s mind; in a billion years you’ll have your problems solved, if you can wait).
[Henry Eyring, “You Don’t Have to Make All the Mistakes There Are,” speech given at Brigham Young University, no date, Henry Eyring Papers, Manuscript Division, Special Collections, J. Willard Marriott Library, University of Utah, box 20, folder 23;quoted in Henry J. Eyring, Mormon Scientist, 302]
I know that there is a God. I do not feel the need to conform my religion to science or science to my religion. I feel confident in holding two views in my mind that some may feel are opposite. I've not always felt that confidence and sought to bring them together but I've come to understand that of the vast universe I have an insignificant knowledge of both and that it would be futile for me to take my limited and incorrect perception of God and His Laws (moral and physical, if they can even be divided like that) and conform it to my misunderstanding of a bunch of observations and mathematical predictions we've made about the world around us.

Even if I interpret the written and spoken word to be contradictory to established theories of Science I still see value in learning from those theories for even if they happen to be incorrect they provide valuable insight into how God's creations work.
Sometimes it seems both "religious communities" and "intellectual communities" are far from learning the valuable lesson that Ross Spencer learned from Isaac Asimov:

I received a similar message from a rather unlikely source early in my career. When I was just out of graduate school, I attended my first meeting of the American Physical Society in New York City. It was a heady experience, and a highlight was a special event arranged by the conference organizers: the great science fiction writer Isaac Asimov had been invited to speak to us.

He began by telling us about something that had happened to him when he was a young student. He was hired to help a historian do research on social resistance to technological change. Hour after hour he wrote down the stories he found in books in the university library about people protesting the invention of things like machines to spin thread and to weave cloth, steam-powered trains, automobiles, airplanes, etc. All of these advances were perceived by the general public either to be physically dangerous or to be a threat to the livelihoods of workers in trades that were about to be destroyed by these advances.

He regaled us with these stories for a long time, and they were very funny, but it went on so long that I began to wonder where he was going. Finally he got to the point. He said that when he started to write science fiction, he remembered all of this work he had done. So while his fellow writers were all rhapsodizing about the thrill of rockets and space travel (long before such things were possible), he wrote a story about how the local populace showed up at the launch site with torches and pitchforks in opposition to space travel. Years later, when rockets and travel outside of the earth’s atmosphere became possible, there were protests, and many of Mr. Asimov’s colleagues were astounded that he had predicted so far in advance that this would occur.

“Why,” Mr. Asimov then asked us, “among all of these talented and visionary writers, was I the only one who was able to predict that this resistance to change would occur?” He let us think about the question for an uncomfortably silent minute, then leaned into the microphone and said in an intense voice that I still vividly remember: “It’s because people are stupid!” And he included himself. He said that if he hadn’t had this idea pounded into his head daily for several months, he was sure that he wouldn’t have been able to foresee it either.

Tuesday, June 15, 2010

Laws of the Land

He thought it proper however that the true nature of the existing confederacy should be investigated, and he was not anxious to strengthen the foundations on which it now stands.
The Anti-Federalist Papers, Opposition to the New Jersey Plan, pg 81
by James Madison
On social news sites I came across an interesting article "Do laws even matter today?".

Cushioning the consequences of people's bad decisions from hurting themselves makes me wonder sometimes why I bother to be careful. If everyone else is in debt and has no savings, why should I maintain self-discipline to not get into debt and save for retirement? The government will cushion the pain for people. If it can't then it is probably because it is buckling and breaking from its own paternal nature. At that point what good will my self-discipline have done me if money isn't even worth anything (fiat or otherwise)?

Another area I find interesting in this the effect of unavoidable law breaking has on the mores of a nation. I came across a quote from Bastiat (who I've now added every book of his to my reading list) that says

When law and morality contradict each other, the citizen has the cruel alternative of either losing his moral sense or losing his respect for the law. These two evils are of equal consequence, and it would be difficult for a person to choose between them.
The Law, by Bastiat

In college I took a course titled "History of Creativity" to fulfill my Civilization credit. One of the things we discussed was the affect of prohibition on the mores of the nation. Overnight the nation became a nation of criminals. When this happens people turn a blind eye to other crime. How can they condemn others in the court of law when they are criminals themselves?

This leads me to wonder about other things like the "War" on Drugs and Speed Limits. Are we making people tolerant of worst crimes by outlawing these? If we legalized these and other crimes become the new rage where do we draw the line on legalizing these verse taking a stand for what is right and what is wrong?

Sweet-and-Sour Bitter Melon

But to the hackers it was all part of the system. It made no human sense, but it had its logic. It was The Right Thing
Hackers, pg 81, by Steven Levy
I've been meaning to start a blog for a while (which can be interpreted as I'll be playing catch up on post ideas for a while). I plan to have this serve as way to collect my thoughts on things political, spiritual, electronic, and personal.

As a side benefit I will also get to explore what page 81 says in each of my books.