Thursday, 30 June 2011

Golden Rules of Computer Security

The three golden rules to ensure computer security are: do not own a computer; do not power it on; and do not use it.

That's from computer security pioneer Robert Morris, who passed away recently.

 

Thursday, 23 June 2011

Improved Many-to-Many Relationships in Dubbiya

A class has many students. A student has many classes. In data modelling, this is a classic example of a many-to-many relationship. Type "Student = Class" into Dubbiya, my nascent browser-based, HTML5-dependent entity-relationship modelling tool, and until today, you got a Student entity, a Class entity, and a line between them.

The problem is, relational databases can't actually have real many-to-many relationships. You need to simulate them using an in-between table. Dubbiya now creates this for you:

Screen shot 2011 06 23 at 5 21 03 PM

This reflects my intention that Dubbiya be a tool for physical data modelling, not logical data modelling.

 

 

Wednesday, 22 June 2011

Why No Alternatives to JavaScript?

This is a question whose answer I can't find.

When you put some JavaScript in a web page, you use this syntax:

<script type="text/javascript">
    document.write("Hello World!")
</script>

You explicitly state that this is JavaScript.

It's been 16 years since JavaScript was invented. Why have no alternative languages been developed and added to HTML? Clearly HTML allows for the possibility. JavaScript is a language created in ten days, launched without time to go through a "are we really doing this a good way" phase. Hence there are several bad things in JavaScript. An more rigorously developed alternative would be valuable.

CoffeScript exists. But this must be compiled into JavaScript before adding to a web page.

 

Monday, 20 June 2011

JavaScript, Type-checking, and Preconditions

So JavaScript doesn't have type-checking. Which was the root source of a bug that took me a while to find.

I'm so much more comfortable with strong type-checking. In many languages, I can create a new type, including its allowable values. In Java, for example, here's a type I created:

public enum RelationshipType {
    ONE_TO_ONE,
    MANY_TO_MANY,
    ONE_TO_MANY,
    MANY_TO_ONE
}

Now I can specify that a function (method, actually) only accepts one of these four values wherever I need a relationship type.

In JavaScript, a function parameter can be ANYTHING - number, string, array, or object. You need to manually check the values. Which leads to template code like this:

function createRelationship(type) {
    if (!(type === 'one_to_one' ||
type === 'many_to_many' ||
type === 'one_to_many' ||
type === 'many_to_one')) {
throw 'IllegalArgumentException';
}

// now do the actual stuff for the function

}

In Java I like to use the Preconditions class from Google's guava-libraries. I wondered if I could do something similar in JavaScript to avoid this template code for simulated type-checking:

if (typeof dubbiya === 'undefined') {
    dubbiya = {};
}

if (typeof dubbiya.preconditions === 'undefined') {
    dubbiya.preconditions = {};
}

dubbiya.preconditions = {
    checkArgument : function(expression) {
        if (!expression) {
            throw "IllegalArgumentException";
        }
    }
};
I can use it as such:
function createRelationship(type) {
dubbiya.preconditions.checkArgument(
type === 'one_to_one' ||
type === 'many_to_many' ||
type === 'one_to_many' ||
type === 'many_to_one');
    // now do the actual stuff for the function

}
I like this because when I look at the code, I see immediately that this is type checking code, and not business logic.

Thursday, 9 June 2011

Dubbiya with better logging

Having the big window for Dubbiya log messages was ugly. So I took some inspiration from modern computer games and put the log right into the main canvas.

  • The last 20 log messages are shown
  • You can toggle the log on and off with Ctrl+L
  • The faded-out effect on the first message is intentional - a little experiment with HTML5 canvas gradients and rgba colours

Screen shot 2011 06 09 at 6 04 17 PM

Dubbiya now sorta working on iPhone

It turns out that Dubbiya, my entity-relationship diagram maker in-the-browser tool, works somewhat on iPhone and Android. But you couldn't move entities around. On a desktop computer in JavaScript you use mousedown, mousemove, and mouseup events to track what the user does with the mouse. Using these I've implemented the moving around of entities. On the iPhone, you don't have a mouse, and therefore these events don't work. However there are touchstart, touchmove, and touchend events. They are similar to the mouse events, but not quite the same. Now you can whip out your iPhone or (hopefully) Android device, or even (again hopefully because I ain't got a) iPad, open Safari, go to Dubbiya, and move the entities around by dragging them. While testing this, I dropped my iPhone YET AGAIN. Another crack opened in the case, another small piece of plastic flew off. I wonder how many more drops my iPhone can survive. The iPhone is roughly two years old, so maybe these drops will give me the excuse to buy a new one.

Wednesday, 8 June 2011

Dubbiya Layout with Animation

Dubbiya, my fledgling browser-based ER diagram app, now animates the auto-layout. This is less jarring that the sudden jumping around of entities. Watch a demo (best in HD or full-screen):

Try it here.

Saturday, 4 June 2011

Animation in HTML5 Canvas

A friend pointed me toward an excellent one-hour presentation on creating games in HTML5. I applied the animation techniques I learnt from the presentation to Dubbiya, my experimental browser-based database entity-relationship project. Click the "Animation" button and the background text follows a trigonometric path across the canvas.

Clearly this is not so useful yet. It is just a small test to understand the issues with animation in HTML5. I intend to use the technique to animate automatic changes to the diagram layout.

 

 

Friday, 3 June 2011

What is Dubbiya? Rethinking Entity-Relationship Diagrams

Dubbiya is the code name. I hope a better name comes to me soon. Suggestions welcome.

My vision for Dubbiya:

  • database design in the browser;
  • that works WITH you;
  • that doesn't involve fiddling around with lines and layout;
  • that is as easy to use as drawing on a white board;
  • yet looks damn attractive

A month ago, Dubbiya was nothing more than an itch to try out HTML5's new Canvas feature. Now it has become an embryonic project.

I've been creating entity-relationship diagrams for years. First I used ERwin, which was powerful software with a clumsy user interface. It did the job, but you had to fight somewhat to get it done. Then came Visio, which I started using before Microsoft acquired it. This was a big step forward from ERwin for usability. Another product I've used and loved is SQLEditor for Mac OS X. It wins on simplicity and prettiness. The Mac world also has OmniGraffle, which makes pretty diagrams but doesn't have smarts about what an entity-relationship diagram really is - it treats like just a pretty picture.

What do all these have in common? They are more awkward to use than a white board. It is click-click-click-type-click-drag-type, etc. I do my database design on a whiteboard, then switch to software to make it look good. Dubbiya eliminates the whiteboard step. It eliminates the click-click-click-type-click-drag-type step.

  • Creating a database diagram in Dubbiya is as simple as typing the names of the entities, and indicating the relationships with simple key presses.
  • Sharing a diagram is copying the URL and sending it via email to a colleague.
  • Diagrams are saved "in the cloud" so you can continue editing and viewing from any Internet-connected computer.
  • SQL is generated automatically as you go.
  • Surrogate primary keys are auto-added.
  • Foreign keys are auto-added.
  • Many-many relationships are magically turned into junction tables.
  • It's a tool meant for knocking up a small entity-relationship diagram for a new project, or to be added to a larger design.
  • It's a tool for use by those doing the implementation, as opposed to the analyst. Therefore it always creates physical models instead of logical models.

It solves pains I've often had when I did IT consulting:

  • the computer I was given to use didn't have the database software I needed. I had to beg, work through bureaucracy, use gratis but less able software, or work on my private computer. Hence Dubbiya is in-the-browser install-nothing software.
  • because I wasn't using the ER diagram software every day, there was a learning curve each time I used the software again. Hence ease of use is a heavily-weighted criterium for Dubbiya.

Yes, this is a big undertaking. Yes, there is a long way to go. Like I did with Poker Copilot, I'll develop Dubbiya iteratively, based on feedback.

 

 

Dubbiya now with auto-layout

I integrated my JavaScript graph layout code with Dubbiya. Now when you add an entity, the diagram is automatically laid out. At the moment it is a bit annoying because each time you add an entity the whole diagram changes. I think I'll experiment with anchoring some entities or introducing some animation that makes the jumping around less visually distracting.