Sunday, May 24, 2009

Ruin of the Roman Empire

I just read The Ruin of the Roman Empire by James J. O'Donnell. For a book by an academic it is fairly well written. However, I can't help but picture a 'snooty academic' lecturing away. The style often wanders from vignette to explication without a strong coherent flow. He also seems to go overboard bringing in all sorts of literary allusions. (I probably missed half of them.) He seemed to compare Theoderic to Othello over and over again, and even manged to tie in somebody listening to Wagner on an Ipod. The number of pages could probably be cut in half without any significant loss of content. As a bonus, it did include a fair number of maps. However, the placement was somewhat odd, with the areas discussed in the nearby pages not referenced in a map.

His central thesis appears to that Alexander blew the opportunity to create a great secular empire, and it was religion that really led to the final fall of Roman 'civilization'. However, the focus seems to be evolving over the course of the book. Early on, it seems to be more historical, with an attempt to more accurate assess the history of 'barbarian' rulers of Rome, without being blinded by the labels. (The barbarians were in fact often more 'civilized' than those that they replaced.) Early historical writers has colored the history with their worldview, and thus only be filtering out the view could an accurate history be obtained.

For the section on Justinian, however, he goes a step further, removing the ancient worldview and applying a modern "secular multicultural" filter. Justinian becomes a religious tyrant (perhaps part Bush, part bin Laden), who manged to destroy the harmony of a multicultural civilization by enforcing religious orthodoxy and going out on rampant wars of empire.) If only he wouldn't have let religious orthodoxy take over, there would be one great unified state of Romano-Persia. Unfortunately, this view assumes that humans would not find some way to disagree and cause conflict. In a small southern town, Baptists and Methodists could be at constant loggerheads. Move them to larger US city, and they are lumped as protestants vs. Catholics. Take all three to the middle east, and they are Christians vs. Islam. And perhaps even further all the groups could be together as "Abrahamic religions" vs. others. Remove religion and there are further avenues for tyranny. (Saddam Husein did manage to somewhat quell religious conflict with his hard hand.)

Overall, the book has an interesting look at the final destruction of Rome, with good stories of others that I have not seen covered in great detail. However, it could be significantly improved. It also spends a long time discussing the empowerment of Christianity as a state religion. However, it could use more focus. It would have been interesting to see more attention paid to the "evolution" of the Roman empire from Rome to Constantinople to the Ottoman Empire to World War I. (This was mentioned as an aside that the empire really didn't 'fall' until the first World Wat, as the Ottoman Empire did appear to be a legitimate successor.) The title implies the ruin of the Roman empire, though the book ends primarily with the Ruin of the city of Rome.

Wednesday, May 20, 2009

Changing html classes - poor IE performance

How do you change the display of multiple similar elements on an html page? The simple answer is to give the elements a class, and then use a CSS rule to modify the output. This works for a static display. But what if changes are needed? Changing the CSS rule seems to be the logical answer. However, this requires going through lots of hoops - and often is not worth it.

First you need to find the stylesheet:


var getStyleSheet = function() {
var ss = document.styleSheets;
for (i=0;i<ss.length;i++) {
var s = ss[i];
if ((s.href != null) && (s.href.indexOf('myStyleSheet.css') != -1)) {
return s;
}
}
return null;
}


The you need to find the appropriate rules. The only catch: Internet Explorer does things wrong. So you have to go through a few tricks to get to the right place:


var getCssRules = function () {
if (g.cssRules != null) {
return g.cssRules;
}
var s = getStyleSheet();
if (s.rules) {
s = s.rules;
}
else {
s = s.cssRules;
}
g.cssRules = s;
return g.cssRules;
}


Once you find the appropriate rule, you need to set the appropriate value. Again, syntax is different:


var changeStyle = function(selector,key,val) {

for (i=0;i<rules.length;i++) {
if (rules[i].selectorText == selector) {
if (rules[0].style.setProperty) {
rules[i].style.setProperty(key,val,null);
}
else {
// IE
rules[i].style[key] = val;
}
return;
}
}
}


All seems well and good. It works for IE, Safari and Firefox. In Safari, it runs at lightning speed. In Firefox, it is fast. But IE? Well, IE takes its time. If it is setting the rule to the same value, then it is zippy. However, setting to a new value can take nearly forever (from times in milliseconds to seconds).

The alternative is to simply find all the elements in the document and manually change them. I use Robert Nyman's getelementsbyclassname, though many other js libraries have similar functions (and the newest firefox has it natively, but that doesn't help much for IE issues.)
This method seems to slow down Safari in updates (but somewhat speed it up in creating new rules.) However, it does significantly speed up IE, and make it almost competitive with other browsers. Since elements and a container can be specified it is also easier to narrow it down to a specific section of the document, thereby improving performance.


var changeStyle = function(selector,val) {
selector = selector.substring(1);
var elements = getElementsByClassName(selector,'tr',document.getElementById('containerelement'));
for (el in elements) {
elements[el].style.display=val;
}
}