17 Jul 2006
•
Software Development
Alex Bunardzic has written an interesting article about namespaces. He calls into question the usefulness of the canonical approach of hierarchically structured namespaces. I think he’s onto something but his example are pretty weak. It is easy to pick on the Java package names because they are often over the top. Unfortunately, Java package names are the namespaces that are most familiar. Most of the weirdness of Java package names come the fact that they tend to be used as way to categorized entities1. Using namespaces as a categorization mechanism is misguided and generally results in package names that are both bad namespaces and bad categories.
The primary use of namespaces is name disambiguation. This is a vital feature of programming languages. Any language without integrated namespace support has a gaping hole. Name disambiguation is provided by allowing a name in particular namespace and that same name in another namespace to co-exist simultaneously and independently .
Name disambiguation is necessary when multiple implementations of the same logical class exist. Name disambiguation is rarely required within the application layer. Developers generally have enough visibility into their own code base to avoid implementing duplicate classes. When naming conflicts occur it is usually between two independent libraries or between the application and the libraries it uses.
Namespaces should be used exclusively to prevent name conflicts. Class names should always include enough information so that a reasonably information person will know the purpose of the class. This means if you have an accounts payable object it is called “AccountPayable” regardless of what namespace in which it lives.
Name conflicts are a real issue. Code that will be used in an unknown environment should be in a non-default namespace. That means if you are writing a reusable library it should should have it’s own namespace. Namespaces should usually match independently installable components. Any namespace that you can only get by installing some other package probably should not exist.2
Just to be clear, namespaces are pure overhead. They are necessary in many situations but namespaces add no value to the application. One way to minimize the overhead is to put your application classes in the default (or null or root or whatever your language calls it) namespace. That means that the classes that you spend most of your time using do not require any namespace overhead. You will be responsible for ensuring that your code base does not include multiple classes with the same name. That is a constraint you should embrace because having multiple classes with the same name is just confusing.
12 Jul 2006
•
Miscellaneous
I have been using Markdown to write my blog posts for quite some time now and I really like it. I was a little surprised how much I liked it when I first switched because before I had been writing in HTML which works well. But it really is easier to focus on the content when you don’t have to worry about all the minutiae involved with XML based formats.
The only real problem I had with Markdown (the syntax and PHP Markdown) was that it does not support footnotes. I really like footnotes so that was sad. Many months ago I noticed the footnote support in MultiMarkdown. It is really clean and the intent is obvious from the text. I liked it so much so I started using it in places that I never intended to convert to another format (readme files, comment blocks in code, etc). The whole time since I noticed the footnote syntax I have been waiting for someone to add that feature to PHP Markdown so that I can use it with WordPress.
Well, I finally got tired of waiting, so yesterday I implemented footnote support in PHP Markdown1. The result is a drop-in replacement for the original PHP Markdown2. You can download it here.
Feel free to use it to your hearts content but be aware that it is – how shall I put this – fairly minimally tested3.
A footnote is defined like this
[^my-footnote]: Explain the tangential thing that just occurred to me.
This will product the following at the end of the output (if it is referenced).
<ol class="footnotes">
<li id="footnote-my-footnote-(markdown document unique id)">
<p>Explain the tangential thing that just occurred to me.</p>
</li>
</ol>
The “markdown document unique id” is an md5 hash of the original Markdown text we are converting. This is needed to keep footnotes with the same name but in different articles separate from one another when they appear on the same HTML page, as they do in a blog.
The text content of the footnote is processed as a normal Markdown block so you can use all your favorite markdown syntax, both block and span elements, inside of it. A footnote is all the text from the [^footnote-name]:
bit until the first line with a non-space character in it’s first column following a blank line. For example
[^my-footnote]: Something tangential just
occurred to me.
This is a second paragraph in my footnote.
This is just another paragraph in the document, *not* part of the
footnote.
Code in is also supported in footnotes but it must be indented eight spaces, or two tabs, similar to having code in a list.
Footnotes that are never references are stripped so to get the above output you need to reference the footnote somewhere else in the document. This is done like
I have some stuff to say[^or-not].
If there is an ‘or-not’ footnote defined, the following output will result
<p>I have some stuff to say<a href="#footnote-or-not-(markdown document unique id)" class="footnote-ref">1</a>.</p>
References to undefined footnotes are ignored and the [^name]
text is left in the output.
The numbering of footnotes is based on the order of the references, not on the order of definition. So the first footnote you define may end up with a number other than 1 if it is not the first footnote referenced.
Happy Marking down.
06 Jul 2006
•
Miscellaneous
•
Software Development
I just completed my transition back to a Linux workstation1. My distro is Ubuntu, of course. I first tried Ubuntu about eight months ago, at my previous job, and was impressed so I stuck with it. On a side note, I am quite pleased to see how Ubuntu is getting noticed recently.
Every time I install Ubuntu it blows me away with it’s completeness and ease of use. The thing that impressed me the most this time is that it created a dual boot machine out of my laptop. No option twiddling, no questions even I don’t know the answer to, not even a “do you want a dual boot machine” question. It just detected the Windows installation on the NTFS partition and went about configuring grub appropriately. That is the it-just-works sort of behavior that really sets Ubuntu apart.
I am really glad to back on Linux. My job is a windows-on-the-desktop shop. I figured I would go with the flow and use windows for couple of months just to make sure Linux would work. That was just about as long as I could stand. I find Windows to be a significantly less productive, and more frustrating, environment in which to program.
I have been the lone Linux user in a Windows shop before so that did not worry me, but IE compatibility testing did concern me. Most of my development is on web based applications and web based applications have to support all the weirdness that is IE. So I went on a little search and I found IEs4Linux. This is a sweet program that downloads and sets up IE 6, 5.5 and 5 via Wine. That gives Linux even better browser support than Windows which only support one version of IE.
28 Jun 2006
•
Miscellaneous
I have started roller-blading again after a two plus year absence. I had forgotten how much fun it is. I managed to escape the office for a while today and go blading on the Boulder Creek Path. Blading is like biking in the sense that you don’t really forget how to do it. So even with not having done it in a couple of years I can still have fun on my blades. I did wipe-out once today, though. I was not even doing anything interesting, I just lost my balance for no particular reason. No real damage, thankfully, just a scraped knee.
Boulder Creek Path is really nice to blade on. The scenery is beautiful and the trail is fairly flat overall but has quite a few small hills. Highly recommended.
28 Jun 2006
•
Software Development
Mr. Davidson saying that “FastCGI is weak sauce” and HTTP is were it’s at. Damn right. I am glad to see the Rails community is coming realizing the power of HTTP.