Algorithms in the real world

Computer scientists that need to write code for a living, constantly straddle the line between the beautiful and neat little world of theory and the somewhat messy, “macgyverish” world of practical software engineering.

In the theory world, cute cuddly objects pass messages of peace and love between each other. They live on a beautiful planet, replete with natural resources.

In the practical world, objects sometimes try to set each other on fire. They drunk drive, and they live in a 100 sq ft apartment with their wive’s mother who moved in after they got married to that hot method from that other project.

But all the same, computer scientists are always trying to bring some of those cute objects back with them from Theory planet whenever they go on a visit.

One time, even I got lucky. A large company I worked for needed a directory system to help customers navigate their city-block-size building. You know those You-Are-Here maps they have in the malls with a red big dot that tells where you are. So like that, but on big digital screens.

Anyhow, long story short the project manager predicted this project will take many weeks to complete due to the perceived complexity involved in routing customers from any point A in the building to any point B.

In fact I thought so myself too. But then I remembered our networking guy saying something about a “shortest path algorithm” a while back. At the time he was trying to explain to me how network packets travel in an efficient manner given several possible paths.

A simple Google search brought back a complete implementation of an algorithm called the Dijkstra’s algorithm. The whole thing, top to bottom must have been 100 lines of code in Java. Very concise.

Since I didn’t know a thing about how it works or what it’s trying to solve I pulled up the Wikipedia article:

Dijkstra’s algorithm is an algorithm for finding the shortest paths between nodes in a graph.

For example, if the nodes of the graph represent cities and edge path costs represent driving distances between pairs of cities connected by a direct road, Dijkstra’s algorithm can be used to find the shortest route between one city and all other cities.

Oh, okay. So all I have to do is model all the points in the building as “nodes”, link them using “edges” and assign a distance to every edge. Then the algorithm can use this information to figure out the shortest path from any point A to any point B. Sounds easy.

I copy pasted the code to my project, fed it a few sample points and tested it on pair of endpoints. It worked.

I tried it on a few more endpoints, added alternative paths for the algorithm to choose from and it worked flawlessly every time.

I deployed the code to our dev environment and showed it to the project manager. He couldn’t believe it. I was showing him a working demo of the product within days of receiving the assignment.

He then proceeded to test it himself. Certain he could find edge cases which would break the algorithm. He even came to me a few times proudly announcing that he found one. But in each and every case we found out that his input was at fault and not the algorithm.

So what’s the moral of the story? Well, for me at least, it was the realization that Computer Science is a useful subject and that it is a distinct activity from software building.  Moreover, it taught me that there are powerful, fundamental principles to programming. And that it’s absolutely worth learning these fundamentals very well, because the time invested in learning them will pay itself back many times over.

Staying human in a digital era

This is not a technical post. But in light of the recent tragedies I decided to take a moment and reflect about us. Humans.

Without a doubt, the last few decades had given us many technological wonders. Personal computing gave us the ability to create incredible things. The Internet took down our artificial barriers and made it possible for us to freely exchange ideas regardless of our physical location. The web gave us access to the world’s information and open source leveled the software playing field.

Computers are also giving us self-driving cars, delivery drones, chess mates, better science and a million other great things.

But no matter how much faster, better and smarter our computers get, there’s one thing that computers will never be able to give us. A simple human touch.

As programmers we tend to get lost in the cyber world. We work there, we play there, we communicate there, we buy our groceries there and we have less and less opportunity to step out and take a break.

But we are still human. And we sometimes forget that the world is full of other humans. And most of these other humans are actually pretty awesome. Some of them are working hard to keep us healthy, others are keeping us safe from harm, still others are growing the food we eat and every one of them no matter who they are, or what they do, is waking up in the morning to make the world a little bit better than yesterday in their own unique way.

Maybe we need a Human Day. Something to remind us once a year that we’re all human.

So say hi to someone you don’t know today. Smile to another human being. Say hi to that pretty girl or handsome guy you like. Take a break from that computer. Turn off your phone. Go for a run. Meet a friend for coffee.

It’s okay to be human.

The self taught programmer’s journey

I remember my first programming gig. Being a self-taught programmer I figured it would be minutes before I would be exposed for the fraud that I was.

I pictured one of the other engineers take a glance at my code, frown their eyebrows, look at me and say: “wow, that is the worst piece of code I have ever seen in my life. Did you even pass your CS 101?”. About that time, someone from HR would then storm into the office with my resume and ask “where did you go to school? I can’t find it on your resume?!” And then I would wake up in a pool of my own sweat. Well, not really. But that’s how I would do it if I was in a movie.

If you’re a self taught programmer there’s no question that you had your fair share of self-conscious moments. Someone at work would start reminiscing about their college years and another would join and before you know it there’s a whole discussion going on while you’re trying to blend into the back wall before someone notices you and asks where you went to school. I know. Been there.

So I did a little bit of research and you’d be happy to hear that we’re not in a totally terrible company. Self taught programmers, scientists, artists and even philosophers have existed since time immemorial. Here’s an extremely incomplete list of some of them:

  • George Boole – The man who developed Boolean Algebra and without whom computers as we know them today could not have existed was a largely self-taught English mathematician, philosopher and logician, most of whose short career was spent as the first professor of mathematics at Queen’s College, Cork in Ireland.
  • Ada Lovelace – was the world’s first programmer. She is best known for creating the first program, designed to run on Charles Babbage’s proposed mechanical computer called the Analytical Engine.
  • Jimmy Hendrix – considered by some to be the greatest electric guitarist in music history. In 1957, while helping his father with a side-job, Hendrix found a ukulele amongst the garbage that they were removing from an older woman’s home. She told him that he could keep the instrument, which had only one string. Learning by ear, he played single notes, following along to Elvis Presley songs, particularly Presley’s cover of Leiber and Stoller’s “Hound Dog”.
  • Ernest Hemingway – considered as one of the greatest English-language writers. the American novelist and short story writer, was primarily self-educated after high school.
  • Herbert Spencer – the single most famous European intellectual in the closing decades of the nineteenth century was educated in empirical science by his father.

To be clear, this is not a rant against universities or against education. Quite the opposite. I’m a huge proponent of education. But I also happen to believe that there is more than one way to enlightenment and mastery. Some find formal education to be the preferred method of learning. Others, like myself, prefer to design their own curriculum and follow it at their own pace.

Whatever your approach is, make sure that you never stop learning. One of my favorites is the story attributed to Jigoro Kano, the founder of Judo. According to the legend, on his death bed, Kano summoned his students and asked them to bury him in his white belt. As the most senior Judo practitioner of his time, he wanted to be remembered as a life-long learner rather than a master.

No, you’re not bad at math

Sorry, but I’ll have to disagree with you about this one. Wholeheartedly. If you have the idea that you’re “bad at math” then you’re simply wrong. Dead wrong. How do I know this? Because no one was worse at Math than I was. I was at the bottom of my class throughout my teens and was convinced that Math is nothing but a torture device in the hands of my sadistic teachers.

Last week I published a post describing my personal Math journey. Several people have commented on the article on social media to the effect of: “I’m bad at Math”. the purpose of this post is to thoroughly disabuse them of this notion.

In his 2015 TED Talk, Mr. Sal Khan argues that the approach taken to teach math today in most public schools accounts for the high failure rate in the subject. Students are grouped together, typically by age and are shepherd together through the curriculum. Every few weeks the students will receive a test to asses their knowledge and regardless of how each individual student did on the test the class — as a whole — would move on to the next subject.

That, right there, is the heart of the problem. You see, mathematical concepts build on one another. You can’t understand Algebra without first understanding Arithmetic. Similarly, you can’t understand Calculus without understanding Algebra first. It’s just the way it is. But remember that time you got 85% or even 95% in your Math test when you were in middle school? Well, guess what? That gap was never corrected and later on when you tried to tackle the next subject you were missing 5%-15% of the required knowledge to understand it. So now you’re only getting 70% on your next test and soon enough you’ll be well on your way to hate Math and anyone and anything connected with it.

To really drive his point home, Mr. Khan used an analogy to Home Building:

To appreciate how absurd that is, imagine if we did other things in our life that way. Say, home-building.

(Laughter)

So we bring in the contractor and say, “We were told we have two weeks to build a foundation. Do what you can.”

(Laughter)

So they do what they can. Maybe it rains. Maybe some of the supplies don’t show up. And two weeks later, the inspector comes, looks around, says, “OK, the concrete is still wet right over there, that part’s not quite up to code … I’ll give it an 80 percent.”

(Laughter)

You say, “Great! That’s a C. Let’s build the first floor.”

OK, so that’s all nice and good. But you might be asking yourself: “yea, but why do I need to learn Math? I got it that you’re excited about Math and all that. Why do I need to care?” Well, if you’re reading this post, chances are that you’re a programmer. While many programmers try — and to varying degrees succeed — at ignoring Math, they are painting themselves into a very tight corner. Computer Science has its roots firmly established in Mathematics and therefore ignoring Math means ignoring the very foundation upon which the entire subject rests on.

Eventually, automation will catch up to the more trivial tasks of programming and those with only superficial understanding of the subject will be at risk of being replaced — ironically — by their own tools.

OK, so hopefully by now I convinced you that you’re not “bad” at Math. That you’re not lacking some mysterious Math gene and that Math is not something that is reserved to the exceptionally smart.

Where do you start? Personally, I like the way Khan Academy is broken up by subjects and grades:

Khan

When I signed up I decided to swallow my pride and start at the very beginning. Yes, I was doing arithmetic and kindergarten level Math again. But since I was doing it at my own home, on my own time, no one was there to judge me or tease me. And by doing so I was making sure that I was covering every gap in my Math education. And you know what? I found gaps as early as the 1st or 2nd grade!

Next thing you know I was gaining ground and tackling more and more complex subjects. These same subjects I flunked throughout my high school years. So I know it can be done, because I’ve done it.

Cheers.

Math: from hate to love

Programmers don’t typically like to admit that they’re bad at Math. Also, it doesn’t help that most non-programmers have this idea that all programmers are some kind of Math geniuses. Unfortunately for me though, I wasn’t blessed with any Math superpowers. Not by a long shot. In fact, I used to hate Math more than anything else in the world. Just the thought of going to Math class at junior high brings back memories that look something out of a Pink Floyd video.

By the time I got to high school I was convinced that Math was totally beyond me, that I lack that mysterious Math gene and that only people blessed with a mind for numbers can approach the subject and get good at it. I am simply not smart enough, I figured.

Around the same time though, my high school began teaching us Computer Science. Quickly, I found out that I liked it and was even pretty good at it. I was solving the algorithmic problems relatively easy while other classmates were struggling and I seemed to have a knack for it.

After graduating from high school, I was drafted to the army where I managed to get myself into a position of writing computer database applications. As I got better and better at it I wanted to know more. I wanted to truly understand how computers work down to the atoms, learn these more advanced algorithms I keep hearing about, understand how cryptography work, how computer animations are generated and so on. I was enthralled with the possibilities.

So I signed myself up for a remote university course to study for a Computer Science degree. After exactly 4 study periods of introductory Math course, my head was spinning so hard from Set Theory that I dropped out like my life dependent on it and never looked back. I felt like a complete failure and was ashamed to be so incompetent in Math.

After I finished the army, I managed to get a job as a computer programmer. Through diligent self-study of mostly books, I was able to advance my understanding of programming and software and built myself a rather successful career by average standards.

But while this was fine, and my work was paying the bills, my understanding of the subject was on the surface. I lacked the in-depth understanding required to truly master the subject. And I knew it. But each time I tried to penetrate the subject matter on a deeper level, I would inevitably hit a wall. Math seemed to be everywhere.

One day, while minding my own business, I ran into a TED talk given by a man named Sal Khan. Sal, previously a hedge fund analyst, quit his job in 2009 to work on a website he’d created to teach Math — for free — to anyone who wishes to learn the subject. He talked about the trouble in the Public School system: kids are moved through the curriculum in bulk, accumulating gaps in their knowledge due to a one-size-fits-all approach. So by the time they get to the more advanced subjects, their foundation was so shaky that they hit a wall they couldn’t pass. He website, he said was solving this very problem.

His speech really resonated with me. But I was still skeptical. This sounds great in theory. But can I, me, personally, benefit from it? I didn’t know yet.

I signed up and began watching videos and doing the exercises in order from the very beginning. I was literally doing arithmetic. The concepts were explained with crystal clarity and I could watch them again and again. I could also use the built-in exercises to practice these subjects and really drive the concepts home.

Next thing you know, I began tackling more and more advanced subjects which were previously completely occluded from my understanding. And was doing so with success and even ease, now that my mathematical foundation was rock solid.

Today, according to the Khan Academy website, I have mastered over 700 distinct skills. It truly recovered my Math education, my self-esteem and even ignited a real appreciation to the beauty of Mathematics. But maybe even more important than that, it unlocked many doors to understanding my profession and my real passion in life: computer programming.

P.S.

The image you see at the top of this post is a so-called Fractal. Fractals are patterns that are self-similar across different scales (Notice how the flower pattern repeats itself over and over as you zoom in).

They are created by repeating a simple mathematical process over and over rather than describing and encoding every detail. Fractal patterns are extremely familiar, since nature is full of fractals. For instance: trees, rivers, coastlines, mountains, clouds, seashells, hurricanes, etc.

That time when programming saved my life

The year was 2000 and I had been a soldier in the Israeli Defense Force beginning my second year of my mandatory 3 year serving term.

My post in the army was nothing glamorous. By strange chance of events I found myself in charge of a small seamstress office, in a small army unit that had nothing to do with computers (I think it had about 5 computers between all its offices). Needless to say, my life was not fulfilling and I was actually quite miserable.

Prior to joining the army, at high-school, I discovered my passion to programming and even did pretty well at that. Unfortunately the Deputy Commanding Officer (who hated my guts) at the unit I was serving, wanted to hear none of that when I asked for a re-appointment as a computerization officer.

Additionally, my less than rudimentary high-school computer science training gave me no real-world skills when it comes to building any usable software.

One day I came across an army manual which was explaining how to use Microsoft Access to build applications. The manual was quite small and was only covering the basics but it made me realize that the army has approved Microsoft Access as a technology for building applications.

Since I didn’t know the first thing about Access, the next time I got an off day from the army I went to the nearest book store next to my home and bought the biggest book on the subject that I can get my hands on. I think it was this one (in Hebrew):

MS Access Book

Now I just needed a project.

So I walked around the various offices in the unit, sniffing around for a project. After a little bit of searching, I found out that the “Hamal” (a mix of receptionist and phone operator) had stacks of hand drawn phone books and other scraps of paper all over the place with phone numbers on it. So I decided to build a phone book database. Seems easy enough.

I started reading the book and got into it just enough to build the first few screens. Once I got stuck I opened the book again and resumed reading until I got my answer. Then I got back and continued writing some more code, fixed a couple more screens and hitting yet another wall. Opened the book again, continue enough to get my answer and then get back to the code. Rinse, repeat.

Bear in mind, the internet was not as ubiquitous, Stack Overflow didn’t even exist for the next 8 years and Google was not really a thing yet. So my only option was to continue on with my book.

After building a significant portion of the application I decided to give it a go with that phone operator guy. He seemed interested but somewhat skeptical. But was willing to give it a go.

The next day, when I came to visit him, he had already entered most of his phone books and scraps of paper into the application and had a big smile on his face. This made his life so much easier — he said — and gave me my first list of feature requests.

Feeling like I’m onto something, I decided to take a leap of faith and give that Deputy Commanding Officer a demo. Heck, I got nothing to lose. It’s not like I can get fired.

So I walked into his office and asked if I can show him something. Reluctantly, he agreed. I started up the application and I could tell that I got his attention. I continued to explain the problem with the hand written phone books, how phone numbers get lost to wear and tear, how hard it is for the operator to share the data with other offices in the unit and the positive feedback I got from the operator.

He was sold and within days I was re-appointed as a computerization officer which led to many more interesting projects (one of which was featured in the army’s magazine) and ultimately what started me on my career path.