Computers and Internet
PC Woes
Optimizing Virtual PC
Constellation of Features
1. Like a star field, here are so many stars that you have trouble singling out anything interesting
2. Like the ‘bigger dipper’, ‘the archer’, etc it is supposed to show or signify something to one person but to others it is impossible (or very hard) to recognise
3. A group of related features
In the talk the phrase was in the context of applications like Word where there are so many things to choose from that the user is simply bewildered and will find it difficult to focus on the task they wish to complete, i.e. (1). But I rather like the other definitions too, especially (3) which conveys the opposite message.
Javascript, scope fun with the for loop
function A()
{
for (index = 0; index < 10; index++)
{
alert(index);
B();
alert(index);
}
alert(‘finish’);
}
function B()
{
for (index = 0; index < 10; index++)
{
// do nothing
}
}
I ran this on Firefox/Safari and got….
0,9, finish
I was surprised on two counts, 1. Why didn’t the for loop work? 2. Why the shared scope? Anyway assuming I had accidentally created a global I corrected it and it worked as expected…
for (var index = 0; index < 10; index++)
Xml and XPath on the client via JavaScript
client browser using JavaScript. Normally I wouldn’t entertain the
thought but with the recent push of AJAX and various cross-browser
script libraries I thought I’d take another look. NB. This doesn’t
consider JSON, I’ll post on that option later.
XmlDocument
The
core requirement to most XML processing (ignoring SAX style processing)
is the document. AJAX has helped here and it seems that the majority of
browsers implement some form of Dom but they do suffer from
inconsistencies.
HttpRequest
Probably the most
reliable object is HttpRequest, which is a necessity for AJAX. There
is a cross-browser issue but it’s fairly simple to solve…
if(window.XMLHttpRequest && !(window.ActiveXObject))…
httpRequest = new XMLHttpRequest();
…
if(window.ActiveXObject)
httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
after
that the objects seem to use the same API. There does seem to be some
drawbacks with this approach, you need a web site (or service) to get
the XML from and the lack of XPath support.
XmlDocument revisited
"But
I don’t want to fetch my XML from a site, I created it on the client",
I hear you cry. Well most browsers support the following…
if (document.implementation && document.implementation.createDocument)…
xmlDoc = document.implementation.createDocument("", "", null);
…
if (window.ActiveXObject)
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
similar
in nature to the previous cross-browser test. These have good DOM
support and you can create/append elements as you’d expect. The load
method seemed a bit flaky. Now this maybe my code so I’ll hold off
saying it doesn’t work…but it didn’t seem to! But creating the DOM
manually seemed fine so it is still useful, especially for sending data
back. However, the biggest issue seems to be XPath
XPath
XPath is a very useful API for searching XML but its support in
browsers is very patchy. Mozilla based browsers offer a good implementation…
var paragraphCount = document.evaluate( ‘count(//p)’, xmlDocument, null, XPathResult.ANY_TYPE, null );
and it includes NodeIterator for a selectNodes style enumerating.
Microsoft has the more usual (I’m an MS developer) SelectNodes, again
very easy to abstract out the difference in API. However…Safari. The
Konqueror based browser simply doesn’t like XPath. So what to do? I
considered writing my own query engine but I don’t really want to waste
my time re-inventing the wheel. So I had a look for a script library,
but it seems like XPath libraries and are still in their infancy. Of
the ones out there XML for SCRIPT
looked promising but still not 100%. At this point I realised that for
my specific needs I could get away with a bit of DOM walking so I left
it there.
Conclusion
My conclusion is that XML support in the browser is ok if you base your
work around HttpRequest. But if you want to do XPath then look for an
alternative.
OS User Perspective – money for old rope?
Exceptions or Error Codes (will it ever end?)
“According to the .NET Framework Class Library Design Guidelines
Exceptions are the
standard mechanism for reporting errors. Applications and libraries
should not use return codes to communicate errors. The use of exceptions
adds to a consistent framework design and allows error reporting from
members, such as constructors,that cannot have a return type.
Exceptions also allow programs to handle the error or terminate as
appropriate. The default behaviour is to terminate an application if it
does not handle a thrown exception.”
1. Does the client have access to account A?
2. Does the client have access to account B?
3. Are there enough funds in account A?
4. Is account A open?
…etc
The Microsoft recommended route seems to be to create an exception for every rules. So you’d end up with something like;
1. AccountFailedAccessException(arg)
3. AccountInsufficientFundsException
4. AccountClosedException
etc
To catch these exceptions you need to write a specific catch statement for every type of exception. This is fine if you actually want to respond to each exception in a specific way but lets say the client is only interested in, "did it fail an access check" or "some other non access problem". This is a depressingly annoying to implement since you have to catch each exception and repeat handling code, e.g.
catch(AccountFailedAccessException)
DisplayAccessNotification()
catch(AccountInsufficientFundsException)
DisplayTransferUnavailabeNotification()
catch(AccountClosedException)
DisplayTransferUnavailabeNotification()
…etc
If this was an old style error code then a switch statement would easily consume similar codes…
switch(errorCode)
case: AccountFailedAccess
DisplayAccessNotification()
case: AccountInsufficientFundsException
case:AccountClosedException
case: etc
DisplayTransferUnavailabeNotification()
Now I’ve now become convinced that exceptions are the way to go (for none performance critical) errors. The obvious solution to the above problem is to create a hierarchy of exceptions…
AccountException
AccountFailedAccessException
AccountNonAccessException
AccountInsufficientFundsExceptions
AccountClosedException
Therefore if you’re only interested in something going wrong with the Account component you’d catch nothing but the root exception of AccoundException. If you want any other exception apart from Access then you’d catch AccountNonAccessException, etc. Although this sounds good I do concede that it is still a pain to code all those exceptions.
What happens if performance is still and issue? If there is no getting away from performance then the answer is to return a state structure/class or an enum. However, the big problem with this approach is the client isn’t required to consume return code. The great thing about an exception is its in the hands of the OS, if you choose to ignore the exception then the program counter will be whipped away from you. So isn’t an easy choice for the performance freaks but I feel the tide of change is such that if you do go the error code route then fewer clients will like you for it, and in the world of SOA it is becoming harder to ignore that unknown client. I just hope I didn’t dream about the change to SEH (Structure Exception Handling) and that a new performance oriented version is around the corner.
Architect MVP Juval Lowy and Ron Jacobs address my question
Expression Design Training
One gripe I did have with the training is that it is using beta software and some of the sample files in the beta simply don’t exist in the released version, although the sample used are so simple it doesn’t really matter.
Overall it was good to go through, just don’t sit there and watch it second by second.