# How Carpal Tunnel improved my Code

“Waterfall”. M.C Escher.1961.

When I started waking up with annoying and persistent tingling every morning around one and a half years ago, I didn’t take it very seriously which probably was the wrong thing to do. By the middle of 2016 however, the pain had gotten annoying enough to affect my concentration which is when it was evident that I had carpal tunnel. With help from my father who is luckily a medical doctor and told me about wrist braces and various lifestyle changes, the pain became a little manageable however I was still left with an engineering constraint.

Here is what usually happens when I sit and type: After the first ten minutes the area between the thumb and index finger of my left hand begins tingling (I am left handed so it starts with the left hand). Around the seventeen minute mark, my right hand starts feeling similar tingling. After around half and hour, my hands are pretty much in pain and I also begin feeling pain around my shoulders. After forty minutes, I simply have to stand up and either walk around or lie down for a bit before resuming work. The pain subsides more or less completely after ten minutes of rest but my breaks typically last twenty minutes as I am lazy.

To summarize, every forty minutes of typing incurs a cost of 20 minutes. Initially, I was pretty depressed as I made the mistaken and naive assumption of time spent writing code was directly proportional to my productivity as a programmer. With that assumption, carpal tunnel meant a ~33.3% loss in productivity. I have been measuring my roughly productivity by assigning difficulty levels to tasks I store on Google Tasks. This includes research projects, course projects, assignments, reading textbooks/documentation etc. Surprisingly, after eight months of this, it seems my initial assumption of a ~33.3% loss in productivity could not have been more inaccurate. In fact, it seems to me that my productivity has actually  increased over this period.

Yes, I am aware that correlation does not imply causality. Understandably, there are a lot of factors involved in this increase in productivity from the fact that I gain more knowledge and experience with time to the fact that my caffeine consumption has also increased significantly. However, I am still convinced that carpal tunnel is playing a significant role in this trend. Here are a few reasons why I think that is the case.

1- The 20 minute “break” isn’t time wasted

In fact, during the 20 minute break I think about the code I have written and what I plan to do in my next 40 minute work session. In other words, this has turned into a kind of planning session that precedes every work session. The key advantage to this is that, earlier on if I had say ways to approach subproblem X, I would first mentally sort them in descending order with an order principle like: ($w_{1}$ * ease of implementation + $w_{2}$ * probability of working – $w_{3}$ * computational resources required) where the $w_{i}$s are weights. Then, I would mentally execute the following algorithm:


approach_list = []

while not tired:
new_approach = think_of_approach()
approach_list.push(new_approach)

sort(approach_list)

while not working_fine(current_approach):
current_approach = approach_list.pop()
implement(current_approach)
test(current_approach)



until I managed to come up with one that worked fine.

Now what the planning session allows me to do is prune the approach_list before the implementation and testing steps by simply thinking through all the approaches and removing the ones I can deduce (or when I’m really unsure, mathematically prove) will not work. In other words, now I execute the following in between the two while loops (after sorting, although it doesn’t matter):


approach_list.filter(approach =&gt; deduce_correct(approach))



Since the deduce_correct function takes less time in the average case than implementtest, this method of pruning the dataset more than offsets the 20 minutes “wasted” in the planning session.

2- Pain incentivizes cleaner code

When every key-press hurts your hands, it is not difficult to motivate yourself to write code that is more:

• Clear: as altering, say, variable values to figure out what a piece of code is doing later in case I forget will result in more agony.
• Concise: the less code I write to address every problem, the less it hurts.
• Reliant on the standard library and third party APIs: reinventing the wheel hurts too much.
• Better commented: The last thing I want to do is rewrite a routine because I’ve forgotten how it works. The clearer (and more concise) comments I write, the less painful my future.

3- Picking the right tool

This is in some ways a corollary of reason 2. I have now also become more inclined to begin projects using programming languages and technologies that will help me get them done with the least amount of boilerplate code etc. While admittedly this can add performance and scalability challenges as things get more complex, I realize I often over-complicated my life by thinking that far ahead resulting in even bare-bones functionality taking a long time to get implemented and in me often resorting to hacky solutions. For example, it is almost redundant to mention that a simple web-crawler written quickly and beautifully with python + urllib or node-js + https/http libs (or even bash + wget) can take over twice the time (and twice the code) if implemented in certain other languages (Captain obvious: “He means Java”).

Statistics: Writing this took me 1.575 writing sessions and 2 planning sessions. 🙂

# The Best Course I’ve Taken Yet

CS210 – Discrete Mathematics. Hands down the best course I have ever taken. I will argue my case from three different perspectives.

Discrete Mathematics as a Mathematics course

a.k.a Why Formal Math is good too, but Discrete Math is better.

I took both Discrete Mathematics and Introduction to Formal Mathematics in the same semester. I found Discrete Mathematics to be better. Why? It covers almost everything one learns in a formal mathematics course plus more exciting stuff! Formal mathematics covered proof-writing, set theory, cardinality, equivalence relations, functions and (very very) introductory group theory. Discrete Mathematics covered all of this except for the group theory part. However, it also covered introductory number theory, RSA Encryption (we missed that part, though. Due to cancellation of the last class), principles of counting and (the best and most exciting part) graph theory.

Discrete Mathematics as a Computer Science course

a.k.a Mathematics makes code fast and pretty.

Every Computer Scientist on the planet should take a course on discrete mathematics. It gives one the mathematical maturity needed for algorithm design, automata theory, data structures, computational complexity etc. On top of that, it helps one become a better programmer. It teaches one a way of thinking that enables one to write more efficient and, indeed, more beautiful code.

Discrete Mathematics as a Liberal Arts course

a.k.a One can’t argue with a sound mathematical proof

“Liberal arts and math? Lol, who is this nerd trying to kid.” I’m serious, though. To start with, Discrete Mathematics teaches logic. What’s better? It teaches quantified logic and proof writing. This helps one make better arguments and (more importantly) accept only claims backed with rational arguments, which helps one understand the world better.

# Contemplations on Algorithmic Earth-Keeping

Here’s an idea that came to me just I was about to sleep right now. Why not… computerize the earth? Create one huge planetary network?

*readers shouting* “Maybe you mean… the internet?”

I know. What I mean is something more centralized and more intelligent. I’ll give you an example. A very  simple one.

Stabilizing Climate Change

First, divide all of the land of the planet into (geographical, not political) regions and assign a node to each region in the global network. Now create a world-wide fund for forest-preservation and rehabilitation. Let’s create an algorithm like the following:

Input: Carbon contribution (= CO2 emmission – CO2 consumption) at each node

Output: Weight of each node which in this application is the percentage of the world-wide reforestation fund assigned to that node.

A smart algorithm designed for this kind of network will finally create the effective, highly organized and intelligently executed world-wide reforestation effort that is needed to save the planet right now. Regions with less fertile soil e.g the Persian Gulf will, of course, require more funds per tree than regions like Indus Plain but our theoretical algorithm is intelligent enough to consider all such factors.

Of course I have mention reforestation only just for the sake of simplicity. There is no reason not to extend this to automobile restrictions, industrial pollution regulations, mass transit funding, solar panel / wind farm subsidies etc.

World Humanitarian™ Algorithm

Input: “Disaster Reports” from every node. Quantified on a scale that is proportional to the number of people affected, land area affected, population density and demographics of the region. To be more general, the HDI of every node, the living standards, levels of oppression etc.

The algorithm analyses the urgency of the situation in case of any disaster or generally measures a quantified ‘prosperity’ property for the node. Then it does the following:

• Publicizes donation requests on the nodes with higher prosperity for the nodes with critically low prosperity. In case of a disaster, also publicizes relief and volunteer requests.
• Calculates amount of international development funding assigned by more prosperous nodes for less prosperous ones.
• Creates economic simulations for best possible bail-out strategies.

Estimates of the number of relief workers

Global Smart Grid

Same concept at play. This time with energy exchange.

Maybe something like this could help our civilization reach Type 1 status on the Kardeshiv scale. That’s my two cents, anyway.

# Four Stanzas Down, The Sonnet is Still Incomplete.

Hello there.

The stream will cease to flow;
The wind will cease to blow;
The clouds will cease to fleet;
The heart will cease to beat;
For all things must die.
All things must die.

“All Things will Die” Verses 9-14 – Alfred Lord Tennyson

On the other hand,

The stream flows,
The wind blows,
The cloud fleets,
The heart beats,
Nothing will die.

“Nothing will Die” Verses 9-13 – Alfred Lord Tennyson

Yesterday was the fourth anniversary of my blog. Looking back, a lot has happened. Four years… woah. When I began this blog, I was a sixteen-year old nerdy high-schooler who really didn’t get out much and had lots of tics which aggravated whenever he met people or was nervous. Look how things have changed. Now I’ve become so awesome. I am now a twenty-year old nerdy college-student who really doesn’t get out much and has lots of tics which aggravate whenever he meets people or is nervous. Okay fine, not much has changed. Sigh. -_-

But hey, I met two of my heros. Usman Naseer and Pervez Hoodbhoy. 🙂

I was tremendously obsessed with Computer Programming, I remember. Most of my first posts were about design patterns in Java, along with some SDL Tutorials and Programming humor.  I made video games, applications and whatnot. Then my interests slowly changed and I got increasingly interested in Physics. That was the only subject I got a good grade in, in my A Levels, but I got a distinction in it so luckily got into a reasonably good university. At around this time, my blog was filled with physics posts upon physics posts. Hilarious part is, it kind of burned out. Faded away, and back came Computer Programming but now in its more mature and mathematically rigorous form, Computer Science. In a way, perhaps Computer Science was a line and Physics was a squiggle:

How did this come about? Well, four years ago I thought Computer Science was Software Engineering. That was quite possibly one of the biggest misconceptions of my life. Computer Science is far more than Software Engineering. In fact, Computer Science is much more than just computers. As one of the greatest Computer Scientists of all time, Edsger W. Dijikstra said, “Computer science is no more about computers than astronomy is about telescopes.“. As I wrote in the Facebook group I created for my batch’s Computer Science majors, Computer Science is, among other things, about finding simplicity in complexity. It is about understanding abstract machines and the fundamental problems that can be solved with them. It is about understanding reality better using mathematical models. It is about solving problems that allow the creation of medicine and vaccines that save the lives of millions and cure cancer. It is about finding techniques that solve the most fundamental problems humanity has ever faced. Most importantly, it is about finding truth and beauty.

Why write a blog in the first place? Well, I have no idea. Initially it started out just because I was bored. The more I wrote, though, the more I felt empowered. I could express myself far better than I could ever do in person. I could share information, share my passions, my opinions, teach people stuff, complain about things. It was my voice. My corner in cyberspace. “Mistakes have been made”, though. I have written several posts I do not agree with anymore. I have written several things I’m downright embarrassed about. On the bright side, though, I’m kind of proud of some of the things I wrote. Such as this post.

The best part is, writing helps me fight one of the things I fear most… loneliness. There have been several times in part four years when I have been friendless. It is scary. Eats you up, one feels purposeless. In those dark times, I have written some of my best posts. Kind of reminds me of that amazing poem by Maya Angelou…

Leaving behind nights of terror and fear
I rise
Into a daybreak that’s wondrously clear
I rise
Bringing the gifts that my ancestors gave,
I am the dream and the hope of the slave.
I rise
I rise
I rise.

“Still I Rise” Stanza 9 – Maya Angelou

What do I think of life? Life is wonderful. I don’t mean that in the personal sense. Whether my life is wonderful or not, life in general is a wonderful thing. How amazing is it that we have been given this brief period in time to observe the beauty and mysteries of the Cosmos. One of Carl Sagan’s quotes especially appeals to me, “we make our world significant by the courage of our questions and the depth of our answers.” I also love how Richard Dawkins puts it (non-youtube link for people in oppressive regimes):

At the end of the day, even though one must never lose sight of the big picture. It is the little things in life that turn out to be the more important. Curiosity. Empathy. Love. Wonder. Kindness. Helping someone out, being kind, being sympathetic. This world has so much pain and suffering. Children starving, terminal diseases, people in pain, people in misery. I can never understand how anyone can ever have the audacity to kill another being. Life is precious, life is beautiful. Make the most of this life. Bertrand Russel’s words, I think, sum it all up the best in the prologue to his autobiography. Which is perhaps the most beautiful passage anyone has ever written:

What I Have Lived For

Three passions, simple but overwhelmingly strong, have governed my life: the longing for love, the search for knowledge, and unbearable pity for the suffering of mankind. These passions, like great winds, have blown me hither and thither, in a wayward course, over a great ocean of anguish, reaching to the very verge of despair.

I have sought love, first, because it brings ecstasy – ecstasy so great that I would often have sacrificed all the rest of life for a few hours of this joy. I have sought it, next, because it relieves loneliness–that terrible loneliness in which one shivering consciousness looks over the rim of the world into the cold unfathomable lifeless abyss. I have sought it finally, because in the union of love I have seen, in a mystic miniature, the prefiguring vision of the heaven that saints and poets have imagined. This is what I sought, and though it might seem too good for human life, this is what–at last–I have found.

With equal passion I have sought knowledge. I have wished to understand the hearts of men. I have wished to know why the stars shine. And I have tried to apprehend the Pythagorean power by which number holds sway above the flux. A little of this, but not much, I have achieved.

Love and knowledge, so far as they were possible, led upward toward the heavens. But always pity brought me back to earth. Echoes of cries of pain reverberate in my heart. Children in famine, victims tortured by oppressors, helpless old people a burden to their sons, and the whole world of loneliness, poverty, and pain make a mockery of what human life should be. I long to alleviate this evil, but I cannot, and I too suffer.

This has been my life. I have found it worth living, and would gladly live it again if the chance were offered me.

– Prologue to Autobiography, Bertrand Russell.

I usually only reserve this phrase for very awesome people but…

Take care and don’t forget to be awesome.

# Thoughts on Nuclear Bombs

Moreover, the enemy has begun to employ a new and most cruel bomb, the power of which to do damage is, indeed, incalculable, taking the toll of many innocent lives.   Should we continue to fight, it would not only result in an ultimate collapse and obliteration of the Japanese nation, but also it would lead to the total extinction of human civilization.            ~ Emperor Hirohito

Note: Yes, this post and short and I’ve just shared stuff. You try writing original content a day before a Linear Algebra exam.

# So you decided to be a Scientist?

So you decided to ignore

And refute fables from the days of yore

So you decided instead, to soar

And sail out of the cosmic shore

So you decided to open the door

And let go of the delusions you bore

So you decided to let the pleasure roar

And fulfill your curiosity to the core

# Shoveling Away the Earth

Disclaimer: I’m brain-damaged.

Ridiculous question, but let’s say you took a shovel and tried to shovel away the entire planet. How long would it take to shovel it all away? Firstly, it doesn’t take an Einstein to figure out that doing this isn’t really that easy. You can’t actually shovel away all of Earth, with its hot plasma core and whatnot with a bloody shovel, but let’s oversimplify everything to an “assuming the chickens to be spherical and in a vacuum” level and assume we have a shovel that can essentially shovel away any possible substance, without breaking, disintegrating or melting. How long would it take one to shovel away all of the earth?

The capacity of an average bucket is about $8 m^3$, we’re already ridiculously oversimplifying everything, might as well assume the shovel we’re using to have the same capacity. Next, what about the Earth? The circumference of the earth is approximately $4.0075 \times 10^7 m$, and since the radius equals the circumference divided by $2\pi$. the radius of the Earth is about $6.38 \times 10^6 m$. Since the volume of a sphere is $\frac{4}{3} \pi r^3$, and we’re being super simplistic and assuming the Earth is a sphere, the volume of the Earth turns out to be a whopping $1.09 \times 10^{21} m^3$.

Now, not considering the fact that the Earth also has fluids etc. and different materials on Earth have vastly different densities, the number of shovel strokes we’ll need to shovel away all of Earth is $\frac{1.09 \times 10^{21} m^3}{8 m^3} = ~1.36 \times 10^{20} strokes$. Let’s say we’re working at a rate of 1 stroke every five seconds i.e $\frac{1}{5}$ strokes per second, then the time needed to shovel away all of Earth is about $6.8 \times 10^{20} s$ or about 22 thousand billion years! The current age of the universe is about 13.8 billion years so that is one heck of a lot of time.

Note: Since I gave the answer in years, I’m assuming we’re using a definition for a year based on the speed of light and not the orbital period of the Earth around the Sun since the mass of the Earth will be decreasing because of our stupid shoveling endeavor. But then again, since the equation for orbital period only takes into account the mass of the more massive body (i.e the Sun), I don’t think decreasing the mass of the earth will change its orbital period assuming the semi-major axis of its orbit remains constant.

However, as we shovel out the mass, because momentum is always conserved, Earth will gain a very tiny velocity in the opposite direction to the direction we’re shoveling out the mass. We can sum up all these tiny gains in velocity (probably by integration) to figure out the semi-major axis of orbit and hence the orbital period every year. I have a hunch that if one begins shoveling on the equator and throws the mass shoveled directly upward, since the earth is rotating all the tiny gains in velocity will cancel out and the orbital period will not change and hence the answer will still turn out to be the one I stated above.

# There is no Formula

Shortly before I got mercilessly rejected from MIT last year, I read an article on the MIT Admissions blogs titled “There is No Formula” which highlighted how there wasn’t an easy set of checkpoints you could complete to ensure your ticket to MIT. Being but an MIT reject, I am focusing on other goals like becoming a scientist.

Most people think you have to be super smart to be a scientist. Popular culture depicts the scientist as possessing a higher IQ level and level of intelligence than an average person. I used to think that too. I believed that only smart people became good scientists. I also believed I was smart. Both of these beliefs have been shaken completely now that I’ve actually embarked on the journey.

As the great Carl Sagan said in his book Pale Blue Dot: A Vision of the Human Future in Space,

“Modern science has been a voyage into the unknown, with a lesson in humility waiting at every stop.”.
Something I’ve realized us that you don’t need to be smart to be a good scientist. The biggest requirement for becoming a scientist is to be passionate and endlessly curious. There is no formula to become a scientist. Science is a risky profession and a risky tool. It brings with it lots of responsibilities. It isn’t always used correctly. Science has been used to create horrifying weapons they harness the energy stored in the nucleus of an atom. At the trinity test, the first successful test of an atomic bomb, the physicist Robert Oppenheimer quoted the following verse from the Bhagavad Gita:
“kālo’smi lokakṣayakṛtpravṛddho lokānsamāhartumiha pravṛttaḥ”
The English translation of which is
I am become Death, the destroyer of worlds.
And yet, even though I don’t support nuclear weapons at all, is there any way us puny humans can ever wield that kind of power if not for science? We must remember that we weren’t the first to harness nuclear energy. There is a nuclear reactor in our cosmic neighborhood that has been using this technology long before we emerged as a species. In fact it is the reason we emerged as a species. The Sun.

Our ancestors lived a life of bleak prospects. Their average life expectancy was about 20-30 years. In between all the hunting, gathering and foraging, there was little time to wonder about the reason behind our existence and our goals as a species. And yet, those are the very questions that drove our ancestors to accomplish their most mythic achievements. Science is what has been driving our species forward. It is what drives our economies and what grows our industries. But most importantly, it is the one thing that can vanquish the darkness that surrounds us.

We may be tiny ape-like germs on a speck of dust, but we have developed  a tool that can predict the motions of galaxies and determine the origin and fate of the cosmos. Merely thinking about this gives one a sense of euphoria. Whether they are accepted as such or not, scientists have always been the real heros of our species. They are the equivalent of brave wanderers who, in olden times, set off to discover lands unseen and bounties unimagined.

Yes. Science is flawed. I never said it wasn’t. It can take lives at a mind blowing scale. But hasn’t it also saved lives at an even larger scale? There are more people alive today  than there ever were in history. This has all been possible due to science. Science increases agricultural productivity and survival chances. It is the reason the planet can sustain more than seven billion people.

The British poet W. H. Auden wrote, in the final stanza of his poem, “After Reading a Child’s Guide to Modern Physics” (click here to read the full poem. It’s amazing),
It has chosen once, it seems,
And whether our concern
For magnitude’s extremes
Really become a creature
Who comes in a median size,
Or politicizing Nature
Be altogether wise,
Is something we shall learn.
And indeed, we do not yet know whether it is wise for ‘median sized’ creatures like us to concern ourselves with the knowledge of ‘magnitude’s extremes’ from the infinitesimal quarks and leptons to the humongous galaxies and nebulae, but we can’t help it. We crave to understand where we came from and why we are here.