Honey, I’ll be late, I forgot to nohup

March 11th, 2012
  • It’s been a long day at work and you are about to leave for home
  • There is final shell script you have to run and send the output to your boss
  • You run the script on your machine (which is in office) and waiting for it to complete.
  • You realize that the process is going to run for a little longer than you expected and you should have started it in the background.
  • You do not want to kill and restart it since it already has done some decent progress..
  • You do not want to wait for the process to complete, you can easily reach home and then send the email.
  • If you kill the terminal on your machine the process gets killed. You do know want that..

Here is what you should do.

  • Hit “CTRL+z” : This suspends the program execution. Note “suspends”, not stops.
  • type “bg” : This will send the process to background
  • type “disown -r” : This will  make your shell session “disown” the running processes. Hence when you kill the shell, your process would still be running.
  • Go home :)

Copy Paste – Productivity Tip

February 19th, 2012

I am sure you have heard about it – Ever copied text from 5 different sources into a target file ?

File 1 -> Copy -> Target File -> Paste

File 2 -> Copy -> Target File -> Paste

File 3 -> Copy -> Target File -> Paste

File 4 -> Copy -> Target File -> Paste

File 5 -> Copy -> Target File -> Paste

Can you visualize the amount of context switch that is happening and slowing you down ? ! Feeling infuriated yet ?

Would it not be nice to do the following ?

File 1 -> Copy

File 2 -> Copy

File 2 -> Copy

File 3 -> Copy

File 4 -> Copy

File 5 -> Copy

Target File -> Paste  -> Paste -> Paste -> Paste -> Paste

Or having pasted the 5 entries here and then realizing you need one of them in another file  ? what do you do – go back and search through the 5 files ?

If you are not using a clipboard tool, you are missing out. I would recommend using a tool like ClipX, which I personally use and find tremendously useful. It’s a small tool for windows that sits in your system tray and remembers your clipboard history – including screen-shots and images captured in your clipboard.

It provides some simple options that are beautiful and very useful

  1. Allows you to specify the number of clipboard entries to save
  2. Option to clear all clipboard history or only image history
  3. Options to go across sessions
  4. Key board shortcuts to pick any entry and make it the active clipboard entry so that CTRL +V would use that.
  5. Search through the clipboard.

Use ClipX or find one that suits your need – but do not depend on one clipboard entry in your history. Take it from me, you would love the flexibility !

xmllint windows – new version

February 16th, 2012

Posted a newer version of xmllint on my google code page.

 http://code.google.com/p/xmllint/ 

It now supports a console redirection as well

Usage :

xmllint <filename>

cat <filename> | xmllint

Unit testing and healthy living

February 7th, 2012

Unit testing is like staying healthy. Staying healthy requires best practices such as eating right and working out. Similarly, development teams need the right practices in order to innovate faster. Just as it’s hard to start working out, many find it’s hard to unit test and thus stop — despite its well-known benefits

http://drdobbs.com/testing/232500344

What’s in a name – The importance of naming convention

February 7th, 2012

“What’s in a name? That which we call a rose by any other name would smell as sweet.”  - Juliet

Well Romeo, try calling her by a different name and thy shalt see ! Anyway, let’s talk about contemporary programming  - and how polyglottic it has become. It is not uncommon for a developer to think in more than one language at the same time.

Just like you have a Mother Tongue, you have a programming language that you are more biased towards. It is but natural that your style of programming is heavily influenced by that language. Let’s call it “C”.

NO-SQL not withstanding, you are pretty good at oracle databases and a database scripting language called “PL/SQL” . You are currently working on a PL/SQL script that needs to update the user name in a table called “USER” with following columns

  • ID
  • USER_NAME
  • ADDRESS

The function you have written in PL/SQL to do this.


PROCEDURE prc_update_user_name(i_id IN NUMBER, user_name IN VARCHAR2) IS

BEGIN

UPDATE user
SET user_name = user_name
WHERE id = i_id;

COMMIT;

END prc_update_user_name;

Now like a good PL/SQL citizen, you have named your input variable for “id” as i_id , however being a better “C” citizen,  you have used a variable name called “user_name”

What’s in a name, right ?

Now, let’s take another look at the update statement you have come up with.


UPDATE user
SET user_name = user_name
WHERE id = i_id;

You had all the good intention of setting the user name in table to the value being sent to the procedure. But if you notice the set statement, it has “user_name = user_name” , which is essentially a “no-op” in SQL. You are setting a column to it’s own value.

You will not get any compiler warning while compiling this code but when the code is executed, the column user_name will never be updated.

The example is trivial and hence easy to spot the problem. However, if you are writing complex functions with multiple parameter and multiple statements, this error can easily go unnoticed until you really test your code for every column that is being updated.

Bottom line – Coding conventions are important and it is important to take some effort and learn coding style recommended for each language. Your code will look cleaner, professional and you will avoid problems like this.

Good to great

February 5th, 2012

Ok – the blog title is inspired by the book Good to great, but this post is a lot simpler in what it wants to convey – How can you become really good at something.

Let’s say you want to be the master of Vim – my personal choice of text editor which I think I am fairly good at ( sigh marks for modesty).  My journey on how I kept getting better at Vim.

  1. I use it across every OS that I work on – Linux, Windows, Mac. You might not be lucky to have a tool that is available across every platform, but the idea is to always use the same tool wherever you can.
  2. I write articles in Vim – and then put it on the format it is required to be published in. Whether it is word, power point or even this post. Essentially use the tool whenever you can.
  3. Every time I see myself doing something repeatedly in Vim which is taking longer than few keystroke, it is time to hit a search engine and find out if there is a better way to do it.
  4. Even when I am not searching for something specific, I look out for “tips and tricks” for vim. Every tool/subject has limitless scope and this helps me learn things that I would not have thought to be possible.

The Zen of the post is that to become a master, you need to sleep, breathe, drink and eat  that <something>. Depending on how good you want to get, you can decide to “sleep” on something else.

Pair Programming – Redeux

February 3rd, 2012

Pair Programming – Two people programming on the same computer

The concept of pair programming can be so radical that it raises several questions : Will I be a developer short ? Will every task take double the time ? These questions can outweigh the potential benefits of pair programming. What I would like to propose is an alternative to pair programming, but with lesser “extremity”

Idea is as simple – A single feature will always have two developers.

To demonstrate the idea a little better – let’s say your feature is to develop a UI which takes inputs from users and persists it into the database. Simple, right ? The process will be as follows.

  1. This feature should be divided into two parts – The UI development and the API development for database persistence/business rules.
  2. Two developers sit together and design the interaction between UI and API
  3. The first developer starts with the UI development using the API interfaces, never having any actual interaction with the database or the actual API.
  4. The second developer, works with on the API – without any UI to work with
  5. On completion, the API developer Integrates it with the UI.
  6. Any bugs during the integration are reported as tickets and fixed by respective developers
  7. Re-integrate
  8. The code is complete only when both the developers say it is

Let’s look at what we just accomplished : #1 and #2 ensures that your code is well designed with atleast 2 developers knowing it intimately – hence setting the stage for better code reviews and more accurate understanding of requirements.

#3 and #4 – Not every developer is good on both side of the house. Trying to have a single developer do both, is like telling your heart doctor to take care of your bones while she is fixing your heart – It can only result in broken heart(s) … and bones.

#3 : UI development is a job requiring great focus and attention to detail – it helps a lot if the person working on it can forget about everything else. Further, clear separation from the API also helps them test the application faster through “dummy” implementation of interfaces.

#4 : This is my favorite – doing API without a UI ensures that there are test cases written in code – since there is no other way to test the API otherwise. This helps your code be “testable” and clearly documented in terms of test suites. Think “Test Driven Development”. Hence if you have struggled to make unit testing a part of your development process, this may be the answer !

#5 : API Implementor Integrates : Key goal here is to have another developer test the UI before it goes to QA , and who can be better than someone who completely understands the design and requirements.

#6, #7 : This is a key productivity gain for your organization. In absence of this technique, your QA team would be finding these bugs and the cost of fixing would be much more than what it needs to be.
The tickets are required to measure the benefit of this process and also to analyze the kind of issues that are most common.

#8 : Need I say anything else ? Will do it anyway – The code delivered to QA will have better design, closer to the specs, and of significantly greater quality.

Some Notes 

  • I am not saying we are devoid of rockstar developers who are good with both, front end and back-end work. Have them flip hats and alternate between UI and API(if you are lucky enough to have them)
  • I have used UI and API to define the process of including two developers for a feature. Even if your “feature” is sans the UI, you can divide work based on the key principle that the two developers must integrate their code to be able to call a feature code complete.

Retrospect

February 1st, 2012

Things are always clearer and more obvious in retrospect – what do you think is the oldest advice that you got which you always ignored, but makes so much sense now.

For me :

The advice I got every time I rejected something to eat while I was kid, my mom saying “how do you know it is not good until you have tried it !”

Algorithm

January 22nd, 2012

Quoting from the book Introduction to Algorithms

A good algorithm is like a sharp knife – it does exactly what it is supposed to do with a minimum amount of applied effort. Using the wrong algorithm to solve a problem is trying to cut a steak with a screwdriver: you may eventually get a digestible result, but you will expend considerable more effort than necessary, and the result is unlikely to be aesthetically pleasing.

Oracle Cascade Delete

January 14th, 2012

If you have not enabled cascade delete option on a table while creating it, you need to figure out the dependencies in order to delete a row from the table by ensuring that all children rows are deleted. This is a cumbersome process and the script can change over a period of time when new children are added.

This is a groovy project I have created to dynamically generate the delete statements in the order they need to be executed.

http://code.google.com/p/oracle-cascade-delete/