eyt*

Find your next scenic drive!

October 22, 2005

bBlog nextprev 0.4.2 Released...

The bBlog hide-from-homepage feature is something that I do not personally use, however, I have received a request to support it from Fredrik. As such, I am releasing nextprev 0.4.2 to resolve this issue.

All this version does is add the home variable to the nextprev call, similar to what you are currently doing for the posts.

If there are any other issues, please let me know. Enjoy.

August 24, 2005

Leonardo’s Laptop...

One of the books that I have recently read is Leonardo’s Laptop, by Ben Shneiderman.  In some regards, this book is similar to some of the other books that I have discussed on this site, such as The Inmates Are Running The Asylum, which basically state that today’s software is, in a word, unusable.  The amount of knowledge that people need to do to get a task done with a computer is still very substantial, and in some regards, this is a barrier between the user and their goals.

I have recently relocated, and with any joy of relocating comes the joy of opening new accounts.  The variety and disparity of the user interfaces to accomplish the simple task of getting statements and paying bills is unbelievable.  To single one out, my cell phone provider allows me to pay my bill automatically via credit card.  To enroll in this service, however, it takes “one or two billing cycles to take effect.”  Until this takes effect, you must pay your bill normally.  Now, I find this odd on many fronts.  First, why could they not add a little dialog box at the end to say, “Would you like me to charge the current amount due of $XX.XX to this card right now?”  Thus it would appear that this service would take effect immediately.  But because it is not this way, I must entire my information twice.  It just does not make any sense.

On the same token, I have recently had to change my credit card information on this site, and I could not change it for a week.  Why?  Because my bill was pending be charged to my credit card.  Yes, you read that correctly.  Because they were about to charge my credit card, I was unable to change my credit card information for a week.  Again, this does not make any sense.

We really need to take a step back, and look at the software we are writing and make sure that the underlying implementation details are not exposed.  The latter example is a wonderful example of this.  This is purely an implementation detail.  In reality, they could have taken my new information with the caveat that the information would not take effect until the next billing cycle.  Or at least, the error message would occur for at most one hour when they were actually processing my account, and not for the period of seven days.

This is the type of thing that Ben discusses in Chapter 2, “Unusable at any Bandwidth.”  Like his example of the Therac-25, a device that delivered radiation treatment for cancer patients.  While technologically advanced, its user interface was unusable, and caused many errors, including killing some patients.  According to the book, no one could imagine that it was the Therac-25 that was causing this, especially since the logs did not indicate the issue.  But many of these things were caused by incomplete documentation, poor user feedback, and error messages like “Malfunction 54”.  Ben goes on with other examples similar to this.

While the book discusses these matters a bit, the majority of the book is not directly related to this.  The author discusses Leonardo Da vinci’s multi-domain expertise, including technology, science, and arts, and how he was capable of using this expertise in all of his projects.  For example, his accuracy and attention to detail such as the angle of lighting, natural garments disposition, and facial expressions in his paintings.

He uses this as the introduction to the idea that we should rethink the way that we create software.  Instead of creating good-enough software or creating a portion of the software extremely well, really addressing every aspect of a software application, from the technology aspect, the user-interface aspect, the testing aspect, etc.  The goal in doing so is to make a great piece of software that can be used by every one, regarding of ability, disability, language, experience, etc., and to create software that you can collaborate with other people.  Ben spends a chapter discussing human activities and relationships and how they interact; collaboration and getting credit for things that you have done are takeaways from this chapter if you do not already believe that.  One of the great misfortunes is that Leonardo did not share many of his experiments with others, and some believe that this cost the world a number of years of advancement, not to fail to mention the number of pages of his work that have gone missing through the years.

The author then proceeds to provide some ideas to get us thinking in the areas of education, business, health care, and government.  I find that some of his ideas are not vastly different than what we have today; for example, he discusses the usability of Access Washington to encourage more usability like this.  Other ideas are just simply outrageous, such as the idea of placing a device on each tree, which would be able to tell you what kind of tree this was, the history of the tree, and even maintains a guest book.  I can only imagine the great expense of this type of project, not to fail to mention the number of these that would be vandalized in some form or another.

Some of the other ideas though simply require a lot of work in order to accomplish, and it would require a lot of people fully behind these endeavors.  One of these examples is a world-wide medical database, in which the idea is that no matter where you are, no matter what language a doctor speaks or what time it is, a doctor could review your medical history, your allergies and current medicine, and from this information, be able to treat you.  Furthermore, by placing all this information into a database, the information could be analyzed to find out if other doctors have successfully treated patients with a particular disease.  In this case, doctors could communicate to each other to find out how this doctor was successful and what they would recommend doing.  And as doctors apparently do not have a grading system, this could double as a reputation, similar to ebay’s feedback system.  And this system could also give doctors instance even access to current medical outbreaks, since they currently get updates via periodicals.  As you can see, such a system could easily grow out of control.

But at the heart of this is enriching our lives with technology, no matter who we are or where we are.  This attention to detail is really important for a user experience.  In essence, users should be oblivious to the fact that they are even using computers to accomplish their tasks.  In this vein, I close with two quotes from the book:

Technical excellence must be in harmony with user needs.

Great works of art and science are for everyone.

August 18, 2005

protected in Java...

Here is an interesting question for Java developers. Consider the following classes, where class A is an abstract class that defines a protected method getInfo(), class B is a class that derives from A, and class C uses class A. In Java, is class C allowed to access the method getInfo()?

Classes defined above.

The answer may surprise some, but the actual answer is that it depends, because I have omitted one important piece of information that is required to answer this question, and that is piece of information, as surprising as it may be, is what package do these classes belong to.

If you refer to section 6.6.1 of the Java Language Specification, you will note that the definition indicates that:

Otherwise, if the member or constructor is declared protected, then access is permitted only when one of the following is true:

  • Access to the member or constructor occurs from within the package containing the class in which the protected member or constructor is declared.
  • Access is correct as described in 6.6.2.

Of important note here is that classes within the same package as class A from the above example can access the method getInfo().

To drive this point home a bit more, consider the following cases:

Classes discussed below.

Here, we illustrate a Package A, which contains our abstract class A with the protected method getInfo(), class B which derives from class A, and class C and D which use class A and B, respectively. With this in mind, if class C instantiates an A and acquires information from it, it is OK.

  • // From Package A, class C
  • A a = new A();
  • a.getInfo();
    // OK

If class D does the same call via an object B, this is not valid:

  • // From Package A, class D
  • B b = new B();
  • b.getInfo();
    // OK

Now, if we do the above two calls in a separate package, this will not work. For example, in Package B, we have a class E, and should you attempt either of the above, this will result in a compilation error because now the two classes are not in the same package, and therefore, it is not accessible.

  • // From Package B, class E
  • A obj = new E();
  • obj.getInfo();
    // ERROR: We're not in the same package now!

In Package C, I show a new class F that is derived class from class A (from Package A); it does not, however, overload getInfo(). If class H instantiates an F via an A as follows, this will also result in an error since the compiler does not know that you are actually manipulating an F and thus treats this as an error.

  • // From Package C, class H
  • A obj = new F();
  • obj.getInfo();
    // ERROR: Maybe he compiler does not know A is really an F? Keep reading

But is that really the reason the compilation fails? Let's see. If we have another class G that accesses the F directly, you will still have a compilation error.

  • // From Package C, class G
  • F obj = new F();
  • obj.getInfo();
    // ERROR: F is not involved in getInfo()'s implementation

Interestingly enough, this is covered in the example in section 6.6.7, in which it states that this cannot be permitted since class G is not involved in the implementation of A.getInfo().

So that brings us to Package D, which defines a class I that derives from class A and overrides the getInfo() method. Now in this package, if we try what we tried in the previous example in class J, we will note that it will now work. This is because class J is involved in the implementation of getInfo.

  • // From Package D, class J
  • J obj = new H();
  • obj.getInfo();
    // Works!

This is extremely interesting, especially if you come from a C++ background where packages do not exist. It is definitely an eye opener and will change my approach to class design!

July 26, 2005

bBlog Trackbacks for Moderation...

Unfortunately my site was down for the last couple of months during my move to Seattle, and I was getting used to not having any blog spam. While there are some preventive measures in bBlog for spam, with more coming in the newer releases, one of the parts that I find most annoying is the fact that trackbacks are posted directly on your site, regardless of your setting for posting comments.

Since the comments and trackbacks are stored in the same database, you can easy have trackbacks wait for moderations like other comments by simply adding onhold='1', in your trackback.php file where it generates the query into the SQL database. A snapshot of my 0.7.6 release of this file is http://www.eyt.ca/Software/trackback.php.

When you receive a trackback, you will receive your e-mail as normal, however, your visitors will see that a comment is pending moderation. In order for the trackback to be displayed, you will have to log in to your admin interface and approve the comment under Comments by clicking Approve. Or, Delete :-).

While it precludes the entire concept of trackbacks, this does prevent your visitors (and particularly your search-engine visitors) from seeing links to these sites.

Needless to say, this is not linked into your user interface, and thus if you change your mind, it will require another code change.

Enjoy!

March 10, 2005

Adding Stack Traces to C++ Exceptions...

One of the features that I love about Exceptions in Java, Python, and other languages is the stack trace that it provides you, detailing precisely where the exception was raised. This stack trace is invaluable when placed in log files or when you do not have a debugger available, since you can now know how your application got to the exception, which should give you some great context for starting to approach the issue.

In this weeks InformIT C++ Guide, Danny mentioned C++ exception-handling tricks for Linux from IBM. One of the tricks mentioned in the article is how to get a stack trace where the exception is thrown; the technique used is well documented in the GNU C Library Documentation.

The example code in the article demonstrates the concept well, however, displaying the stack trace in the constructor is not ideal, since this information should be made available to the code that catches the exception.  At that point, a decision can be made to log a summary of the exception, the full exception, or handle it in some other fashion based on the context.

When I went to run the first application with it, I was expecting a stack trace similar to Java. The actual output, though, was:

  • Something went dreadfully wrong.
  • at ./TestException [0x804aaaa]
  • at /lib/tls/libc.so.6(__libc_start_main+0xe0) [0x4012cb10]
  • at ./TestException(__gxx_personality_v0+0x119) [0x8048f01]

Using a GDB, you can use list *address or something similar (such as objdump) on that same executable, and with this, you can get the same information as what a Java or Python stack trace gives you, albeit with more work for you. Furthermore, this approach only works on non-Linux or HURD systems; hopefully the other operating systems you support have some mechanism similar to it.

In general, however, the most important piece of information in the stack trace is the first entry, viz. where the exception was thrown, and in many cases, you do not need to dig any further than it.  Because of this, we can reuse the C/C++ defines for __FILE__ and __LINE__, and have these passed into our constructor.  By using a quick and dirty macro, we can then do something like this:

  • MY_THROW( "Something went dreadfully wrong." );

Using this mechanism, it can now provide us with the following information:

  • Something went dreadfully wrong.
  • at TestException.cpp:13
  • at /lib/tls/libc.so.6(__libc_start_main+0xe0) [0x4012cb10]
  • at ./TestException(__gxx_personality_v0+0x119) [0x8048f01]

And now I have all the stack information if I need it, but I also have the filename and line number where the exception is raised. Furthermore, the filename and line number are available for all standard C or C++ compilers, and thus provide a portable mechanism to provide at least the most important information.

As such, I leave you with my refactoring of this exception class: ExceptionWithStack.h and ExceptionWithStack.cpp, and an example program, TestException.cpp.  I have only provided a printStackTrace() method similar to Java, however, a true environment would require other methods.  My class derives from std::exception simply to allow existing code to be updated to this mechanism where I am planning to use this class.  The code compiles on both g++ and Visual C++ 2003. This is a great extension; it is just too bad that it is not part of every exception.

Earlier Entries

<  2  3  4  5  6  7  8  9  10  11  12  >

Navigation

Recent Posts

eyt*