Friday, May 23, 2014

Once in a while technology makes your life easier

Once in a while you get a moment that you wish you could tell everyone, but a spouse and friends are not computer fans at all. So you need to tell someone. Now I just had my best GIT moment ever. Don't get me wrong, GIT saves my ass many times, even many times per day. I would never leave home without it, never ever do any work without it. I love Fossil also, the problem with fossil is that I don't use it at work, and if you don't use it you forget how it works. It is fantastic.

But here is my email to a friend of mine.

Hi friend,

As I have told you earlier, I made this site,, the cms, admin, booking, visa billing, voucher handling and email sending just to name a few items I had to do. I also don't use any frameworks besides Tornado and jQuery. Just bare metal, python and jquery, and the site is fast, ridiculously fast.

But I am not bragging here. I am telling you, if you use GIT, it will save your behind if you aren't already using it.

For me, the master branch is release branch. But I am lazy and small typos and small css editing happen on master. But like when I add a new template for email sending, I use a branch called f.ex. emails.

I start by checking out that branch, I merge master into it. Start coding, and once I am done, and that includes testing, I checkout master and merge emails into master, then run my script.

Lately I have been finding myself fighting my database, couchdb. It is a wonderful nosql database, but it is much more oriented towards documents and not really relational data. I was pretty happy with myself to have my own database layer, that is, everything that happens on the database is it's own class. If I want to get a list of products, I run a command called "self.db.get_products()", if I want to save a product, I do "self.db.save_product(product)". So I thought to myself, this will be easy as I only have to rewrite the database layer. Baahhh, wrong. The database layer is like 1000 lines. If I was changing from mySQL to PostgreSQL or even Oracle, this would have been a walk in the park, only connection part would have to be rewritten, and perhaps a small number of queries would need a little love. Having a nosql database, rewrite the whole stuff.

I am using tornado, a python system that is asynchronous, it pretty much means, it is fast and never hangs up. Like in php, the whole website stops loading while you fetch data from mysql, but it doesn't hurt since you have 30 copies of the web site running. But the hurt comes when you have over 100-200 users at the same time, you need to have loads and loads of threads, which eat memory and slows the whole system down. That is why NodeJS and Tornado are among these new types of servers gaining popularity. As long as you never ever write a blocking code, you can serve endless amounts of users on just 1-2 processes. If you use blocking code you might use 1 server per cpu core.

Anyway. There isn't any asynchronous driver for any SQL based database. You could take the chance that mysql is always very fast, and just use it anyway, the blocking is then only a few milliseconds. As for most sites, this is all very well and good.

But of course I can't take the wide and open street of common sense. I decided on another nosql database, MongoDB.

Now as I am rewriting everything, I figure out new cool stuff, I rewrite more and more because mongo is much better at querying data. But I am doing everything I am doing on a branch called mongodb.

While I am working on the code, the client (discover) calls and tells me he has hired SEO specialists and they have a lot of small things I need to fix on the site.

So, now, I don't loose any work. I just commit my changes. I checkout master. I make a new branch called seo. I do all the changes they ask for. And I actually found a bug, where I was showing search results inside a div, but the problem was the div wasn't there. So I fix that huge bug also. Test the code and voila. I checkout master, merge seo into it. I then distribute the code, restart the server and all is well.

Now I think to myself. If I checkout the mongo branch, and merge master into it, everything will turn to shit and I need to do a lot of fixes since I was fixing like hundreds of lines, and deleted probably more than a few.

But of course I knew the answer. If all hell breaks loose, I can always just revert. No problems. So I do the 'git merge master' and it starts churning, and there were 0 problems. All went great. I did not loose any work, and actually fixed a bug I didn't know of, and all changes are now in one place. I can't wait to merge the mongodb into master. It is just a few days off, but of course normal life and socialising has its toll on productivity.

I thought I should send this to you as a real life happy story about using git in no advanced way, just predictable way, and how it not only saved my day, it made my dev life easier. I don't recommend just using bare bones jQuery, it is a lot more work, you need to keep up with "on" and "off" events and a bunch of BS, which ember.js does for you.

Links :