Life

Toughest line of code

I was always fascinated with technology. I grew up watching Start Trek and imagined exploring distant places of universe. Closest thing to science fiction back in the days (late 80s, early 90s) were computers. So, you can imagine how happy and proud I was when my older sister decided to study computer science in college.

Of course, I was curious about computers and programming and she absolutely had to show me what’s it all about. She was learning BASIC back then and showed me some instructions and programs written in it.We did not have a computer, so we did it on paper. It was all very easy and clear to me, until we got to the problem of calculating a sum of integers from 1 to N.

I could solve it using the mathematical formula (N+1) * (N/2), but  in the book there was a solution with using the FOR loop and this line in the middle of it:

S = S + i

It was the toughest line of code for me. It bugged me for years. I memorized it, and knew that’s how things work, but couldn’t figure out why. How is it possible? How could S be equal to S + i? Wouldn’t that be true only if i is zero? I was thinking mathematically and S being equal to anything other then S was impossible for me to comprehend.

I can’t remember the exact moment in my life when I finally understood how this line of code really works. But I sure do remember it as my first ever programming challenge.

Recent Posts

Sonata Admin: modify validation groups in an admin extension

SonataAdminBundle has a powerful extensions feature which allows you to add or change features of…

4 years ago

Grandfather’s advices

I used to spend a lot of time with my grandparents in my childhood. My…

6 years ago

World. World never stops changing.

If anything is certain in this world, it is that things always change. And there…

6 years ago

How to be successful

This is the most important advice on how to be successful! Read it carefully!

8 years ago

I wanted to change WordPress URL, you won’t believe what happened afterwards

WordPress has a nasty habit of storing absolute URLs in the database. That means that…

9 years ago

Let’s Encrypt – providing free automated SSL certificates

In August 2014 Google announced that their search engine will value HTTPS as a ranking…

9 years ago