Guaranteeing software behaviour

My foremost goal while building software is to build stable self-healing systems with deterministic behaviour. I want to ensure my code continues to work even when unexpected events occur. In the event of unknown unknowns, the expectation is a graceful degradation in the worst case. This requirement is even more important when implementing high-risk projects. … Continue reading Guaranteeing software behaviour

5 things I learnt from solving 100+ hackerrank algorithms

Sometime last year I started to solve hackerrank problems at my pace and here is my progress after about 108 days ago. Funnily, I used to think there was no need to practice interview questions unless you were looking for a job or interviewing job applicants. This earlier perception might be wrong; I now think engineers should … Continue reading 5 things I learnt from solving 100+ hackerrank algorithms

Adventures with XOR

I recently ran into a code puzzle; the question asked for the finding the unique element in a list of integers given that every integer appears twice except the single special element. My first solution You could use an array to hash elements to buckets (sort of like counting sort) and then flip their values … Continue reading Adventures with XOR

Working with Integers in JavaScript

One of the ways JavaScript differs from most programming languages is the absence of integer types. Every numeric value is a Number which is based off the IEEE754 floating point representation. You can still have 'integer' values and it is technically possible to approximate this behaviour using UInt*Array types but that's a discussion for another day. This … Continue reading Working with Integers in JavaScript

Why you should not use isNaN in JavaScript

I was on a video streaming site recently and moved the play point to the far right. It was amusing to see the hover details show NaN:NaN - ahah, some mathematical operation had NaN-ed and the code didn't cater for that. If you have read Why JavaScript ‘seems’ to get addition wrong; you would have seen … Continue reading Why you should not use isNaN in JavaScript

Why computer science matters for software developers

I used to think computer science never mattered because I rarely used algorithms and never saw the value of algorithm-based interviews (I still don't ;) ). The few folks I asked also concurred so I felt I was right. September 2016 My team got reorged and our goal was to build and deliver a brand … Continue reading Why computer science matters for software developers

What every programmer should know about types I

What is a type? Type: (noun) a category of people or things having common characteristics. A type represents the range of values of a particular type. Let's take an example from the mathematical concept of sets in number theory. The set of integers can be seen as a type - only values such as 1, 2, 3 are integers; … Continue reading What every programmer should know about types I

Why JavaScript has two zeros: -0 and +0

Do you know there are two valid zero representations in JavaScript? In pure mathematics, zero means nothing and its sign doesn't matter. +0 = -0 = 0. Computers can't represent value well enough and mostly use the IEEE 754 standard. Most languages have two zeros! The IEEE 754 standard for floating point numbers allows for … Continue reading Why JavaScript has two zeros: -0 and +0

Understanding Bit masks

Bit masks enable the simultaneous storage and retrieval of multiple values using one variable. This is done by using flags with special properties (numbers that are the powers of 2). It becomes trivial to symbolize membership by checking if the bit at a position is 1 or 0. How it works Masking employs the bitwise OR … Continue reading Understanding Bit masks

Understanding and using Streams in JavaScript

Introduction What do you think of the following code snippet? Isn't it beautifully succinct and neat? It reads just like English! That's the power of streams. Streams are just like lists but offer more capabilities because they simultaneously abstract data and computation. Streams vs Lists/Arrays? Let's take a scenario from Mathematics, how would you model the infinite set of … Continue reading Understanding and using Streams in JavaScript

Why JavaScript ‘seems’ to get addition wrong

Introduction JavaScript is a dynamic weakly-typed language so it's possible to have expressions like this: This post explains how JavaScript evaluates such complex 'mix-n-matches' and at the end of this, you should know why foo is NaN. First, a screenshot showing more funny behaviour: A brief Maths Refresher Associativity The result of the mathematical operation is always same regardless of … Continue reading Why JavaScript ‘seems’ to get addition wrong

How to implement the Y-combinator in JavaScript

This post provides a very simple step-by-step implementation of the Y-combinator in JavaScript. You should be able to implement the Y-combinator in your language of choice after reading this post; as you'll see - it's that easy. What is a combinator? According to wikipedia, A combinator is a particular type of higher-order function that may be used … Continue reading How to implement the Y-combinator in JavaScript

SICP Section 3.3 – 3.5 : Found a bug in memq

1. Is memq broken? memq is an in-built list search function; it finds the first occurrence of a key in a list and returns a new list starting from that key. Now that you know what memq does, lets look at some weird behaviour Building on that foundation leads to the following conundrum memq tests whether the key exists in the … Continue reading SICP Section 3.3 – 3.5 : Found a bug in memq

SICP Section 1.3 : Thoughts and Concepts

This section exposed me to the full power and beauty of functional programming. The expressiveness of using functions as values is awesome. For example, a sum of cubes function can use a sum function which itself relies on a reduce function. Think of higher order differentiation in mathematics and you do get the idea. An interesting concept involves … Continue reading SICP Section 1.3 : Thoughts and Concepts

Understanding Partial Application and Currying

Partial application and currying are two popular concepts from functional programming and help cut code replication in certain scenarios. This article assumes an understanding of the JavaScript bind function; binding is related to partial application in JavaScript. Partial Application In pure functional languages, functions are not 'invoked', rather a set of arguments is 'applied' to them. Now, if all … Continue reading Understanding Partial Application and Currying

Understanding Tail Recursion

A tail call is the last call executed in a function; if a tail call leads to the parent function being invoked again, then the function is tail recursive. In the first function - foo; the baz() function is a tail call while in foo2, the baz and biz are tail calls because both are the … Continue reading Understanding Tail Recursion

Programming Paradigms: An Introduction

A programming paradigm is a way of programming, a style of solving problems and thinking about the domain. Languages directly or indirectly influence programming style; for example, Haskell is purely functional while Python allows a blend of OOP, functional and imperative programming. Even though most new languages are multi-paradigm, they usually make it easiest to program in a single paradigm; C … Continue reading Programming Paradigms: An Introduction

Programming Language Type Systems II

Strong/weak typing describes the ease of mixing variables of different types in expressions. Strong typing does not imply static typing just as weak typing does not mean dynamic typing. To put it simply, if a programming language tries to interpret an expression containing variables of varying types at runtime (e.g. adding an int to a … Continue reading Programming Language Type Systems II

Programming Language Type Systems I

Static, dynamic, strongly-typed and/or weakly-typed; the terms we routinely use to describe typing in programming languages. However, these terms (especially the last two) have more to them than is generally assumed. There is actually no widely-agreed upon definition for strong and weak typing – there are way too many contradictory views. Good news is that everyone agrees … Continue reading Programming Language Type Systems I

MOOC Review : Machine Learning

So I completed the Machine learning course on Coursera recently; it's my umpteenth MOOC Course and I actually do not know how many I have taken or want to take. Despite this,  I have only gotten three certificates so far; all my attempts at integrating Coursera courses into my schedule have not been successful. I have … Continue reading MOOC Review : Machine Learning

Thesis Stories Ep 3: Research is Hard!

Alhamdulilah I completed my thesis about three weeks ago; if you're interested, you can check out my thesis and presentation. Looking back at the two years I spent at MASDAR, I have a couple of thoughts: Alhamdulilah I learnt a lot, met a couple of wonderful people and matured significantly. There were a couple of not-so-pleasant experiences too but I believe … Continue reading Thesis Stories Ep 3: Research is Hard!

MOOC Talk : And I thought I knew SQL

Massive Open Online Courses (MOOC) became popular early this year with offerings from Coursera, Udacity and EdX. These platforms were inspired by the phenomenal success of the three online courses (db-class, ai-class and ml-class) that ran in late 2011. It has never been so easy to get high-quality knowledge - for example, Coursera has renowned … Continue reading MOOC Talk : And I thought I knew SQL