Wishful Coding

Didn't you ever wish your
computer understood you?

My Bookshelf 5/5: Making Ideas Happen

Great book, read it. And if you don’t, scan the index, it reads like a list of do’s and don’ts.

Making Ideas Happen

The book describes the Action Method, which resolves around persisting, following up, managing action steps(todo’s that start with a verb) and relentless execution. It’s not easy, but it makes sense.

I actually read this book during summer holiday. I’ve been, uh… practicing since then. On thing that stuck with me in particular is that connectivity is inverse productivity.

I found it much easier to focus on the action step at hand without all the distractions from email, IM, Twitter, etc. But when you are offline, you need to prepare yourself with all the docs and libs you need, put the whole internet on a floppy if you can1.

Internet on a Floppy

Behance developed a web application specifically for following the Action Method, but as you can imagine, having your task manager ‘in the cloud’ while working offline, is not ideal.

I need something that syncs between my laptop and my desktop, but works great offline. CouchDB seemed to fit the bill perfectly. After I started a homebrew solution and one based on the Backbone MVC framework, I found this.

Those who don’t understand UNIX are condemned to reinvent it, poorly. – Henry Spencer

Why not use mighty tools such as text files and rsync(or Dropbox)? Googling for todo.txt shows I’m not the first to have that idea. There is a more or less agreed upon format, and even a GUI.

Good luck with that, I’m going back to my task list, which features cleaning the kitchen.

  1. Half of my action steps at the time consisted of “Download X” 

Understand SQL, learn NoSQL

I learned SQL when I started PHP. I found a website named Tizag, where they had SQL tutorials. I installed PhpMyAdmin, created tables, ran queries like SELECT * FROM pages WHERE foo IS bar LEFT JOIN ON comments or whatever. It was magic.

No one ever explained to me how it stored the information, or how it was so fast (or slow). They did say that indexes made stuff faster, sometimes.

On the other hand, when you read the CouchDB guide, they do not primarily teach you their query language, but also a lot about how stuff works. A lot of this also applies to SQL databases.

Storage

CouchDB uses a B-tree to store documents. This provides O(log n) lookup, update, etc. rather than O(n) scanning of all documents. It seems most SQL databases use a B-tree as well, but not always.

Indexes

When you add a WHERE clause to your query, the database has to look at all documents for a match.

If you add an index to the field, you get a sorted representation of that field. This way you can get single items or ranges(time > 123456) in logarithmic time, using binary search.

CouchDB gives you a ‘view’ of the _id of a document, but other views will have to be created to create the equivalent of a WHERE clause. (What _id is in CouchDB, is your primary key in SQL)

Locking & Transactions

NoSQL databases are infamous for their lack of locking and transactions. Why? For the sake of scalability.

Let’s ignore for a moment that 90% of all apps can run on a single server. The idea is that creating a transaction synchronously on a whole cluster is nearly impossible, let alone fast. So you you just don’t to it at all, in NoSQL land.

The flip side is that not locking at all allows reads to be faster. More on that in the next section.

Interesting to note is that both CouchDB and PostgreSQL use MVCC, allowing for reads without locking. So this is not unique to NoSQL databases.

History & Recovery

CouchDB stores its data in append-only B-trees, meaning that data is never changed.

Because old data is still there and immutable, readers can access it without waiting for a write to complete. It is even possible to read old revisions of the data.

What is maybe even more interesting is that, if the server crashes in the middle of an update, the old data is still there.

InnoDB also applies a similar technique, unlike Mysam, which needs to scan and repair the whole database.

Joins

Basically the same thing as transactions, you don’t want to scavenge your whole cluster looking for all comments referencing a blogpost.

The high-performance way to do joins is to not do joins, instead unlearn everything your learned about normalization, and denormalize.

The other way to do it teaches us more about SQL joins though. Basically you create an index or view on the ‘foreign key’, and run a separate query to get the correct documents. Here is an elaborate example.

Conlusion

Neither SQL or NoSQL databases are magic, and they are even pretty similar in most ways. Don’t follow the hype, choose wisely.

Minecraft 1.8 (P)review

Like most Minecraft addicts1, I downloaded the prerelease this weekend and played it all day. There are some really cool things in there, but also a few crapy ones, and of course a few bugs and glitches.

My new home

I rally love the new biomes. I spawned in a desert biome, and if it wasn’t for the NPC village, I would have died for sure. Rivers are also great for exploring by boat.

I really like all the stuff that is specific to certain biomes. Without compasses and maps, it’s quite an adventure to get wood, animals and later vines and mushrooms from other biomes.

There are quite a few odd new items, like Ender pearls, rotten meat, and huge mushrooms, but they win on atmosphere, so I built my home in a shroom. Beat that, treehouse!

Mineshaft

The new map features all look really neat, but I found the abandoned mineshafts impossible to navigate. They cross right through strongholds, other caves and themselves.

The only thing I rally don’t like about the Adventure Update is the food and fighting mechanics. It’s like playing Quake 3 on peaceful2.

I’m not going to say anything about experience points, because I don’t know what they will be used for, but let me say that I don’t think Minecraft is a classic RPG.

The idea of food healing you indirectly is really nice, but having it replenish my life slowly makes me play as reckless as if I’m playing on peaceful. Maybe it could heal you while sleeping?

When you run, you are able to jump 4 blocks. Though, mid-air, you go faster than running, so the fastest way to move is to jump running. I pray that running diagonally isn’t even faster.

There is a new fighting mechanic that lets you deal critical hits by jumping down on a mob while hitting. This means the best way to fight is to jump up and down.

The last thing that adds to the Quake experience is hammering the mouse button. Previously, it was possible to place blocks and hit mobs by just holding the button, now you need to hammer the mouse like a real FPS. dislike

So, overall, I really enjoy 1.8, but can I say it’s having a bit of an identity crisis?

  1. Well, I played all Sunday, but except for that I don’t play much. 

  2. I Play on hard.