[Interview question] What is the biggest difference between C++ and Python?

Interview questions can be tricky.

Coming up with a decent answer in a highly stressful environment of a technical interview might prove to be a real challenge. That’s why preparation is necessary to land that dream internship!

Today we will dive into an answer to a very common interview question.

In your opinion, what is the biggest difference between C++ and Python?

This article is not meant to be a complete list of all differences between the two. It’s simply a draft of an answer with enough details to satisfy an interviewer asking this question.

Arguably, the biggest difference between the two is the type system. C++ is a statistically typed language. This means that a type of a variable has to be defined when the variable is declared and cannot be changed later. On contrary, Python is dynamically typed, which means that you’re free to change the type of variable if you wish to do so. id = str(id) is perfectly valid Python. Convenient, huh?

(If you want to read more about the topic: some people believe that dynamically typing is useless…. Oh, and static typing is horrible too)

C++ is a compiled language. Python code is first compiled to byte code (those .pyc files you probably seen). This byte code is then executed by a Python virtual machine.

In contrary to C+, Python does not support pointers, nor pointer arithmetic. You can read more about pointers and references in C++/Python here.

In C++ it’s programmers responsibility to allocate and deallocate memory. Python completely abstracts memory management from the programmer.

For the interviewer, it’s probably going to be the least interesting part of the answer, but the syntax of both languages is very different as well.


Image histogram

Histogram of an image is a histogram of pixel intensity values. It sounds complicated, but in reality the concept is very simple.

For simplicity let’s assume our image is a grayscale image, so that each pixel has some brightness (or intensity) represented by an integer from 0 to 2^n-1.

Histogram of that image is just a bar graph showing us how many pixels of each intensity there are in that particular graph.

Histogram might be normalized, meaning that for each pixel intensity i the number of pixels with that intensity is divided by the total number of pixels in the image. This way height of each bar in the chart represents a probability of some pixel having that brightness.

But what about colours? One of the most common solutions is to use RGB model: represent red, green and blue components of the image separately. Those three basic colours are then added to reproduce a broad array of colours. Now we can create separate histogram for each channel (red, green, blue) or we can convert it to grayscale and compute the histogram normally.

But why should we care about histograms?

Histogram are be used for many image enhancement algorithms. For example, histogram equalisation is used to automatically improve image’s contrast by “stretching” the histogram.

Histogram can also be used to choose an appropriate threshold if we want to make convert our image to a binary image (consisting of black and white pixels only).

To summarise: image histogram is a graphical representation of a pixel brightness distribution. It’s very important in image processing as many image enhancement algorithms, such as histogram equalisation rely on it.

Next time: Histogram equalisation


Fear of publishing for the first time

I created my blog almost 6 months ago. It has been empty since then.

I wrote about 10 articles, but I couldn’t force myself to publish any of them. I knew I’ll eventually have to do it, but I was afraid to put my work in front of other people. And I still am.

I wanted my first article to be excellent. Or at least not terrible. I kept changing, rewriting and eventually throwing away everything I wrote. It was particularly difficult for me, as I’m not a native speaker. Finally, I decided to do something about my fear. I gave myself 15 minutes to write something and publish it immediately.

So here it is, my first blog post 🙂