Always Get Better

Never stop looking for ways to improve

March 24th, 2011

Drizzle – a lightweight fork of MySQL – has reached general availability. Drizzle’s design goals are to create a highly performant and module database engine tailored for cloud computing.

Some of the interesting features this database has to offer are:

  • No Views, Triggers, or Stored Procedures – I consider this a huge advantage. Stored Procedures were once a good thing when query optimizers were all but non-existant, but modern database systems perform this task extremely efficiently. Using stored procedures adds a second level of APIs to your application for what I would consider to be a rather dubious potential security benefit.
  • Sharding – The client protocol is designed to decide which database server to target based upon a hashing key. This is similar to how memcached handles its linear horizontal scaling – leaving this calculation to the client is a huge advantage to systems hosting a high number of concurrent visitors
  • Gearman Support – This is a terrific tool for spreading workload across machines. Use Gearman to handle logging in Drizzle, keeping the actual DB server available for database work

How Does Drizzle Compare to Percona?
Percona is a high-performance build of MySQL which promises to offer better performance than “stock” MySQL. It is built from a branch of publicly-available MySQL source code and enhanced by the folks at Percona. Percona maintains the same functionality as “real” MySQL, but attempts to achieve faster speeds.

How Does Drizzle Compare to MariaDB?
MariaDB is a different database engine started by the original creator of MySQL intended to replace MySQL using non-Oracle licensing. Anyone concerned with Oracle’s development practices or plans for the future of MySQL should consider switching to MariaDB. MariaDB implements all of the existing MySQL functionality plus more and provides a drop-in replacement for MySQL.

March 4th, 2011

One of the things I miss most about C# is the expressive ways in which it handles variable defaults. The ‘double ?’ – ?? – operator is especially useful for checking whether a value is NULL and providing a default object:

December 28th, 2010

The MongoDB classes do not come with default generators for Rails applications. In order to use the rails generate commands, you can use the indirect rails3-generators project available at https://github.com/indirect/rails3-generators/#readme

Installation:
1. Download the generators into your application’s lib folder:
cd myapp
git clone git://github.com/indirect/rails3-generators.git lib/generators

2. Install the rails3-generators gem
gem install rails3-generators

3. Add this to your project’s Gemfile
gem 'rails3-generators'

Usage:
rails generate model ModelName --orm=mongo_mapper

October 18th, 2010

Here’s a thought: is it possible for a computer programmer to work part-time? It’s a serious question because programming is not like other trades – once you build a house, for example, it’s built; there is no going back and re-pouring the foundation and moving to make it a better, more efficient house. When a programmer is given a problem to solve, they can continue to improve, optimize and re-factor their solution nearly indefinitely.

In reality, software engineering is probably much more similar to writing than to engineering, despite what the academics may say. In theory the projects we build are finite, have measurable outcomes and test cases, and at the end of it the either “work properly” or they don’t. They can be planned to the most minute of details. But then you have to program them – a skilled programmer can make the pieces fit together like clockwork while a poor programmer can ruin the outcome.

Seeing a project through to fruition takes patience, time, communication and commitment. It’s nice to say the documentation is complete and the design is frozen but that ignores the human aspect of the business. As time passes, the client will think of new ways to integrate the software we write into their business – suggesting changes that might improve the quality and value of our code. If we are properly aware of our limits and open to suggestion this need not be scope creep.

So – can it be done part time?

March 28th, 2010

If you want to use anything more complex than a list of strings in a ListBox, you’re in luck because the control accepts all types of objects.

Custom Objects (Blog Posts) Displayed in a CheckListBox

Custom Objects (Blog Posts) Displayed in a CheckListBox

In this case, I want to display a list of posts found in a blog. Blog is a class which contains Posts, an array of Post classes. To start, I created the CheckedListBox in the form designer, and I add the posts to it like this:

clbPages.Items.AddRange(_blog.Posts);

If I do nothing else, the ListBox will call the Post’s ToString() method and will display as:

Post
Post
Post
Post

We have two options for displaying this correctly:

1. Override the ToString() method. I don’t recommend doing this because ToString() is much more appropriately used in a debugging context.

2. Add a string converter: This will automatically convert each post object to a usable string when called by an object like a ListBox. ListBox uses Convert.ToString() – this uses that converter more appropriately. ToString() should only be used as a fallback.

<pre>
// Use System for the Type object
using System;
// Use ComponentModel for the TypeConvert base class
using System.ComponentModel;

namespace SiteAssistant.Blog
{
    /// <summary>
    /// Converts a post into a list-friendly string, for checkbox lists
    /// </summary>
    class PostConverter : TypeConverter
    {
        /// <summary>
        /// Indicates whether the Post can be converted to a destination type
        /// </summary>
        /// <remarks>
        /// We only support conversions to STRING at present
        /// </remarks>
        /// <param name="context"></param>
        /// <param name="destinationType"></param>
        /// <returns></returns>
        public override bool CanConvertTo(ITypeDescriptorContext context,
            Type destinationType)
        {
            if (destinationType == typeof(string))
                return true;
            else
                return base.CanConvertTo(context, destinationType);
        }

        /// <summary>
        /// Converts the post to the destination type. If the destination
        /// type is not supported, the base Conversion is applied.
        /// </summary>
        /// <remarks>
        /// We only support converting posts to strings at present.
        /// </remarks>
        /// <param name="context"></param>
        /// <param name="culture"></param>
        /// <param name="value"></param>
        /// <param name="destinationType"></param>
        /// <returns></returns>
        public override object ConvertTo(ITypeDescriptorContext context,
            System.Globalization.CultureInfo culture, object value,
            Type destinationType)
        {
            if (destinationType == typeof(string))
            {
                string text = "";
                Post p = value as Post;
                // Ensure that the Post is not null, avoid errors
                if (null != p)
                {
                    text = p.Title;
                }
                return text;
            }
            else
            {
                return base.ConvertTo(context, culture, value, destinationType);
            }
        }
    }
}
</pre>

The code we write in .NET is like the meat inside a sandwich. The framework is the bread that wraps around our logic and keeps our application together. Our new Posts string converter will be called by the application without us needing to override the Convert function.

It doesn’t happen by magic of course. The final change we have to make is to add information about our conversion function to the posts class:

<pre>
    [System.ComponentModel.TypeConverter(typeof(PostConverter))]
    public class Post
    {
        // Rest of the code goes here
    }
</pre>

That’s all there is to it! Now we can pass a list of Posts to the CheckedListBox and manipulate each item directly. In this application, I will be using this technique to provide the Post object to the text editor with a double-click.

February 6th, 2010

Following iTunes’ development has been an interesting experience. We’re moving toward a world in which physical packages of music is a thing of a past; in the meantime we’re stuck with a middling service.

My complaint goes something like this:

My wife recorded Grey’s Anatomy; when she was watching her tape the next day, she was surprised to find advertisements telling her the story from her episode was being continued in a crossover Private Practice on a different channel. Oops.

So I went on iTunes and bought her the episode she missed. $3.50 is pretty steep for a 40 minute TV show but that’s the price you pay for the convenience. After enjoying the program, my wife decided she wanted to see the rest of the season – so I bought that for her too.

When you buy a season of TV, iTunes warns you that any previously purchased episode will be downloaded again – essentially you’d be paying for it again. I can handle that – it makes sense that an item would be sold individually and part as a collection.

Two problems (both stemming from me not digging deep enough into the literature, but also totally unreasonable):
1. When I was billed for the season, I was billed individually for every episode, at the full $3.50 rate. So there was no reason to double-bill me for the episode I’d already purchased since the billing wasn’t based on a ‘full season’ – why is the system unable to correlate previous purchases and prevent the double-purchase?

2. I thought I was buying a whole season of the show – in fact I only bought the episodes that had already been released. A “Season Pass” (pay for the season and new episodes download as they become available) is something completely different… it would have been nice to have been informed of the difference.

$42 is a lot of money to pay for 11 episodes of TV. I don’t think I’ll be dropping a lot of money into iTunes when I can pay half that amount for a full season on DVD – not to mention get the benefits of hard copy, physical media.

My verdict: iTunes is an interesting model and was a fun experiment for us, but not at all cost effective. Bandwidth can be expensive, but the cost of distributing digital media is essentially $0. I would have thought TV episodes could be sold for less than $1 and still make a healthy profit for the content creators (no manufacturing costs, no distribution, no retail partners — Apple takes a cut and the rest is pure profit). What can I say, I was the one who got suckered into paying double the price for half the product.

January 19th, 2010

Hey folks, it’s been awhile!

I’ve been playing with Google’s Go language, and will be sharing what I’ve learned over the coming weeks.

First off, which seems like the easier way to compile your source code? This:

6g fib.go
6l fib.6
mv 6.out fib

or this?


make

Personally, I prefer using a Makefile, even for a small project with one source file.

Without further adieu, a simple Makefile for the Go Language:


GC = 6g
LD = 6l
TARG = fib

O_FILES = fib.6

all:
make clean
make $(TARG)

$(TARG): $(O_FILES)
$(LD) -o $@ $(O_FILES)
@echo "Done. Executable is: $@"

$(O_FILES): %.6: %.go
$(GC) -c $<

clean:
rm -rf *.[$(OS)o] *.a [$(OS)].out _obj $(TARG) *.6