Anantha Kumaran random thoughts

SQL and Relational Theory

At work, I had to write a JQPL — Yet another poorly documented objected oriented query language — query which involved 3 tables. It was little frustrating because of the lack of proper documentation about JQPL and my poor mental model of the join operation. I almost forgot most of the SQL I had learned during my undergraduate years. I blame hibernate, active-record et al. for the decay of my SQL knowledge.

I finally decided to read the “SQL and Relational Theory” book by C.J. Date, which had been sitting on my bookshelf for more than 6 months. His writing style is a bit pedantic, but not dry. You will probably get used to it after one or two chapters.

In the initial chapters, he reiterates the fact that SQL is not a faithful implementation of Relational Model because SQL allows duplicates and null, which are not allowed in Relation Model, then goes on to explain all kind of problems introduced by this mistake — I wasn’t aware of Three-valued logic used by SQL.

Then he introduces the necessary vocabulary like relation, relvar, tuple etc. He uses a language called Tutorial D — seems like a well-thought language than SQL — alongside with SQL to explain most of the concepts.

Chapter 5 and 6 explain relational operators in a rigorous form, which in my opinion, is the real meat of the book. You might come across some new concepts — or old concepts described in new ways — like image relation and relation-valued attributes, also touches on recursion and cycle, which I hadn’t given much thought in the relational context before.

In later chapters, he explains constraints, views, the relation between logic and SQL, and how to map from logic to SQL. He also bashes SQL along the way for many bad design decisions and provides alternatives — Whether the alternatives are good or bad is difficult to judge, without hearing arguments from the other side.

Overall, I would say the book is rigorous, thought-provoking and worth a read.


I have been using Goodreads for about 3 years. Usually, I add a book to Goodreads reading list, once I am sure that I would finish the book. For some books, I can sense it right away. Either the writing would be outright bad, or I might not be interested in the subject, or it might be way over my current knowledge. For some cases, I would read about 30% and then realize it’s not worth to finish it. In cases where I successfully finish the book, I would rate it in Goodreads.

The above process eliminates “Rating book without reading” problem, but it introduces new kind of problems. I don’t rate very bad books, because who has time to finish it. I also abandon most of the mediocre books. The books I finish and rate mostly falls into either good or very good category. If I use 3 stars for good and 4 stars for very good, and 5 stars for outstanding, then I would never use 1 star or 2 stars. So my reading habit systematically prevents me from using lower ratings.

It seems like most of the Goodreads’ users suffer from this problem. Most of the books are rated between 3.5 - 4.25. I rarely see books rated below 3. So basically Goodreads rating is useless in most of the situation.


Human, the only species on the earth which is consciously aware of the fact that death is inevitable. Although everyone is aware of the fact, most of them act in such a way that they are going to live forever. The human race as whole lives, reproduces and goes on. Though it might make sense for the race as a whole — where it is marching towards is out of scope of this discussion — it never makes sense for an individual to take part in this.

It leads to the inevitable question, why does a human choose to live, when he can easily kill himself. Thus liberating himself and the yet to born descendants from the worldly misery. What makes human beings resilient against suicidal thoughts. I am sure everyone — at least those who have crossed their childhood — must have contemplated suicide at some point in their life. But almost all of them try to bury the thought deep inside their mind, afraid of it, even though they know nothing about what lies ahead.

We wouldn’t be here if all our ancestors had decided to kill themselves. But this doesn’t explain the fact nonetheless. What keeps them going forward. What keeps them from exploring the other end of the death.

jQuery documentation inside Emacs

Recently I found myself switching between Emacs and browser to refer the jQuery documentation. So I looked around and found XML dump of the jQuery documentation. Now I have the data and just have to figure out a way to display it inside emacs. Parsing the XML file every time to look-up a method documentation will be very slow. So I wrote a converter which will parse the XML dump and spit out elisp code. The generated elisp code will look as follows.

(push "$.grep" jquery-doc-methods)
 (quote (("name" . "$.grep")
          (("array" "The array to search through." nil nil)
           ("function(elementOfArray, index)" "..." nil nil)))
          (text . "The $.grep() method ...")
          (js . "$.grep( [0,1,2], function(n,i){
				             return n > 0;

Now all I have to do is configure auto complete to use this data and write some code to display the documentation in a buffer.

Emacs Tips

;; usage
;; (add-hook 'ruby-mode-hook
;;          (lambda ()
;;	    (local-set-key (kbd "C-x j") 'jump-to-view)))
;; keep the point anywhere inside a sinatra route and
;; press C-x j to open the haml file

(require 'thingatpt)
(defun jump-to-view ()
  "jumps to haml view"
  (let ((sentence (thing-at-point 'sentence)))
    (if (string-match ".*haml(?[[:blank:]]*:\\(?:'\\|\"\\)?\\([^\"\', \f\t\n\r\v]+\\).*" sentence)
	(let ((file (match-string-no-properties 1 sentence)))
	  (if (one-window-p)
	  (select-window (next-window))
	  (find-file (concat (project-root) (concat "app/views/" (concat file ".haml"))))))))