Taswar Bhatti
The synonyms of software simplicity

“Success is not final, failure is not fatal: it is the courage to continue that counts.”
― Winston Churchill

Here is an experience of a failure that I wish to share with everyone. Recently I had an interview with a company (large travel company), and the interview went well until the technical question came along.

Now don’t get me wrong I did prepare for the interview, and did lots of questions (since I was expecting a hard interview):

1. Find if a subtree exist in a million node of a Binary Tree
2. Finding circular links in link list
3. Least common ancestor in a tree
4. Path between 2 nodes in a trees
5. Sum up tree nodes
6. Anagram in text
7. Practice my quicksort and mergesort
8. Wrote my own LRUCache, hastable (hashing function) etc how it works
9. Sql joins etc etc

Basically did most of career cup stuff.

And here is the thing, when the technical question was asked it was in fact a very simple one, and due to the fact that I over-prepared myself and ego kicked in I though I could do better, but in the end I screwed it up. The question was a rather simple one, it could have been answered in a few lines of code. In the beginning of answering it I was heading the right direction (i.e using a hashtable NOTE: most interview questions can be answered with hashtable)
Then I started to over analyze things, and though hmm I can do this faster if I did a merge sort O(n log n), which was not the right thing to do. Not to mention my mergesort is still a bit rusty.

All in all, I felt like I just threw up on the interview, although I did verbally answer the right question at the end, when s/he asked me that “if I can have done this in a simple approach, maybe there is a simple solution ?”, and it just hit me at that moment. Yes, of course I could have used this data structure in this way, and get the right results in these 3-4 lines of code.

But that in my opinion is too late, I would not have hired myself if I was in their shoes. For most of the time overthinking is not the right approach to the problem. Even though I did write down all the requirements of the question I still critically missed something because maybe ego kicked in or maybe anxiety of it. My mind had an analysis paralysis moment also, if you wish to read more about it, Scott Hanselman has also an excellent article on Analysis Paralysis

A quote from the article

I see so many issues and possible bugs that I’ve learned over the years that could derail a feature that I end up derailing the feature.
— Scott Hanselman

The moral of the story is keep it simple and don’t try to over think in an interview or in your programming, because you will over complicate things in those circumstances (there is only a certain limit of time and most of the time interviewee like to keep it simple), don’t let the time pressure sink into you, because if you don’t focus on whats on hand, you will derail and lack the focus of the real solution which in most time is just a rather simple solution. Keep it simple stupid !!!!


In this post I will write about some tips on JavaScript Conversion from type to values etc.

Tip 1: Boolean values
In JavaScript one can use the double not (!!) to convert a variable to a Boolean. What the !! operator (poor man casting) does is, it first cast the data to a true Boolean and then it flips it, and the second operator flips it back to the correct Boolean value.

Tip 2: Convert to Number
In JavaScript one can use the + to convert a string to a number. I mean the plus can be obscure, one can also >> shift operator and also use parseInt but remember parseInt may give you different results than + like the example below. Also here is some jsperf on int casting.

Tip 3: Convert to String
This is the inverse of the + you saw above, you can covert a value into a string by concat with empty string “”. If you wish to know which one is the fastest way to cast as string one can check out this jsperf


Here is another quick tip on JavaScript, the default value. If you are coming from the C# world you may have seen something along the line of

The above code shows the ?? for null coalescing operator in C#, don’t confused it by the generic default value. In JavaScript, there is the double pipe operator ||, where the object is null or undefined.

In the above code we have create a function call add and we have defined default values inside of the function. Learn it, love it, use it :) It comes in handy to define default values.


In JavaScript there are two types of equality operator, the === and the !== , sorry I forgot to mention their evil twin == and != .

tsdr; (too short didn’t read) Use three equals unless you fully understand the conversions that take place for two-equals.

Basically what the triple equal (===) compares is if the value is equal and if the type is equal.

Lets look at an example below.

The reason for the === operator to return false is due to the fact that it does not do type coercion, but the double == does type coercion and implicitly tries to convert the value before comparing.

Some additional examples:

I hope the examples above give you the reason to stop using == and != since it convert things for you during comparison. So start using the triple === and !== .

Below are two tables that show the equality of == and === provide by http://dorey.github.io/JavaScript-Equality-Table/

javascript ==

x == y


x === y


Here is a quick tip for JavaScript developers, there is a debugger statement in JavaScript, which invokes any available debugging functionality. e.g setting a break point, and if there is no debugging functionality available the statement has no effect.

Let’s say you wish to debug a function

This will automatically launch the debugger in Chrome, Firefox, Opera, Safari and IE.

The debugger statement is part of EMCA script version 5.
For more information


Here is another quick tip on creating modular JavaScript, namely function wrappers, or more technically called Immediately-Invoked Function Expression (IIFE). A self-invoking anonymous function runs automatically/immediately when you are create it, but don’t confuse it with document.ready or window.onload.

The basic of IIFE is to use a wrapper so that it does not pollute the global namespace, all variables used inside the function will not be visible to the outside scope. You may have seen this kind of code, something along the line of:

For example the variable defined below bar will not be able to access it outside the scope.
IIFE provides a protection/encapsulation to your code.

If you wish to pass in data to your anonymous function, for example in our code below we are passing in the global window object to our function.

The last benefit of using the IIFE, is that it provides a way to create more modular Javascript.

The code below shows a module called counterModule and how we use it.

And if you have written any JQuery plugin you may have already seen the module pattern used for plugins. In the code below we are injection Jquery into our anonymous function.

This is the very basic of a module pattern, and if you wish to read more about the module pattern I suggest you Addy Osmani book on Javascript Design Patterns


Here is a quick tip for JavaScript programmers or for people who come from Java or C#.

In Java and C# when we thinks of using a compare conditions in a if statements, we tend to use something along the line of:

We tend to bring this baggage of knowledge to JavaScript also, but it is not necessary. In JavaScript one can simply use the conditionals as below.

Here is a table that will show you what could be the values of val that would translate to false.

Type Result
Undefined false
Null False
String if length == 0, false
Object true
Number if NAN or 0, false

Here is some sample code if you wish to test out falsy in JavaScript.

Learning these fundamental idioms in JavaScript allows one to write cleaner Javascript code.


Jade Node.js Template Engine, Include & Template Inheritance Part 6

In this post, I will write about using includes and template inheritance in Jade template engine.
You can also check out my previous 5 post on Jade.

  • Jade Node.js Template Engine Part 1
  • Jade Node.js Template Engine Basics Syntax Part 2
  • Jade Node.js Template Engine DataBinding Part 3
  • Jade Node.js Template Engine, Conditional Logic Statements Part 4
  • Jade Node.js Template Engine, Filters & Mixins Part 5
  • Includes (aka partial views for .net developers)

    To include css, javascript, html file, one can use the include directive in Jade. Lets say, you have a css that you wish to include in your jade file, you can then use the include like below, include can also import any html file that you may, or even markup text.

    One thing to note is the scope in the parent file and the include file is shared, so it allows one to use variables inside the include that are defined outside. Also one has to use the right extension for the file with the correct path. The example above shows the data/copyright.html is an html file located in the data folder.

    There are also some other ways to include, css and javascript code blocks in Jade.

    Template Inheritance

    Most sites have a generic look and feel, and if you are using includes (partials) it could soon become very ugly and hard to maintain all the includes. This is where Jade provides us with template inheritance, using the Block keyword as placeholders to inject other templates into the view.

    We may have already seen this if we have used express web engine the layout.jade file as show below

    In order to use this layout file, Jade provides us with the keyword extends, for example in our index.jade file we can extend the layout like.

    From the above example, we see that we are replacing content, but Jade also provides us with prepend and append to the blocks. For example, if we wish to add zepto.js to our layout we can use the append keyword.

    Or if we want to prepend a css file to the link tag, so that style2.css loads before style.css we can use the prepend keyword.

    Note: Conditional statements like if else do not work with blocks since they are evaluated during compile time. The code below does not work.


    This marks the end of the Jade, node.js template engine series, if you have any questions feel free to contact me, in the upcoming post I will write more about node and grunt/gulp (the Javascript task runner/ stream building system).

    Sign up and follow my mail list if you wish to be posted on upcoming blog post.


Jade Node.js Template Engine, Filters & Mixins

In my previous post I have talked about conditional statements inside of jade. In this post I will write about filters and mixins in jade template engine.


Filters in jade means something different from what you may know as filters like the ones in Angular.js. In Jade filters allow you to use different languages (text formatters) with jade template. (e.g CSS, CoffeeScript, markdown, etc), and all filters are compile time, thus they does not support dynamic content.

For example to use markdown we would first install markdown

Now if we wish to use markdown in our jade template, we can simply use the :markdown syntax, Note: all filters use the colon “:” syntax, eg. (:sass, :less, :coffee, etc)


Mixins allow one to use reusable code blocks in jade. The way to declare mixins is by the keyword mixins following the tags that you wish to display, example

In order to use the mixin we just need to append it with the “+” sign

Mixin can also take arguments like function

One can also use conditional statement and blocks of jade inside of mixins, the indent statement below the calling of the mixin is taken as the blocl

In my next and probably last blog post on jade, I will talk about includes in jade and template inheritance.


Jade Node.js Template Engine, Conditional Logic Statements

In my previous post I have talked about databinding with jade, i.e. feeding data to your template. In this post I will write about how one can use conditional and logical statements (for, if, while statements) in jade template engine.

Ternary Operation

The conditional ternary operator can be applied in Jade as follow ( ? : )

Conditional Statements

Jade has built in (if, else statements, and also provides the unless statement)

Case statements

The case statement is more of a shorthand for the switch statement in Jade.


Jade provides (for, each, while as loops)

In my next post I will write about mixins and filters for Jade.