This is a cliché in IT and computer related blogs. You can find at least one topic on How to make a computer program in every blog written by a computer expert (scientist, engineer or experimental expert). So, I also decided to write about it. In this topic, I’m going to explain how your idea can be a program.
I’m not a startup or business person, and I hate when someone wants to teach other people how to have an idea so I consider you already have an idea, and you want to implement your idea as a computer program. Let’s start!
Choose your target hardware
Unfortunately, a lot of programmers ignore this important step, but if you consider a special hardware to develop and implement your ideas, you will have two points :
- You learn a new hardware architecture (and maybe organization)
- You help someone who wants a specific application on that hardware.
Sometimes, you realize that writing a calculator is pretty stupid. Of course it is when you write a calculator for Windows or macOS. But, when you write a calculator for Arduino, which can interact with a keypad and displays, it’s not.
Write Algorithm
Actually, algorithm is explaining the way we solve the problems. So, we need to write the steps of our solution and test it. Sometimes, when we write a simple algorithm, it’s not efficient at all, and needs a lot of improvements. Imagine this (This algorithm makes all even numbers lesser than 100:
while( a < 100){ if(a%2 == 0){ puts(a); } a++; }
This is a piece of larger code. But wait, how can we improve that? That if there can make this piece of code slower. But, if we consider a = 0, we can write something like this :
for(int a = 0; a < 100; a + 2){ puts(a); }
You know, I wrote a shorter code here. Also, this short code has a better structure of making all even numbers lesser than 100. But I think both of these codes have the same time complexity, so there is no difference. If we had two nested loops, and the inner loop’s condition had effects on the outer loop’s condition, we had to spend time on calculating time complexity and optimizing it.
Finally, you will realize there are some “classic” algorithms, which are already optimized, and you can just use them, and model your idea with them.
Choose the language
This step is also one of the most important ones. Imagine if you want to program an AVR chip, of course JavaScript is not the best choice. There are tools which allow you to write programs for those chips in JS, but the language is not made for communication with AVR! But, when you want to program a website, specially when you’re dealing with front-end stuff, C is not your best choice! But wait, if the program we want to make is a general purpose desktop program or a school/university project, we are actually free to choose the language!
Imagine we want to write a simple program, which does Addition with bitwise operations. We can write our program in C/C++ like this :
#include <stdio.h> int bitwiseAdd(int x, int y){ while(y != 0) { int carry = x & y; x = x ^ y; y = carry << 1; } return x; } int main(){ printf("%d\n", bitwiseAdd(10 , 5)); return 0; }
And you can write it in Ruby like this :
def bitwiseAdd(x, y) while y != 0 carry = x & y x = x ^ y y = carry << 1 end return x end puts bitwiseAdd(10, 15)
But, when you want to directly communicate with hardware, you’ll need a low-level language. C/C++ are actually mid-level languages. They can help you communicate with hardware (like this piece of AVR code) :
while(1){ PORTC.1 = 0; delay_ms(1000); PORTC.1 = 1; delay_ms(1000); }
or like that bitwiseAdd(x, y) function , they can help us write normal programs. But Assembly language is a really low-level language. We can use it when we need to talk to our hardware directly.
You see, all programming languages can help us, but depending on the conditions, we can use different languages.
And …?
And now, you probably know how a computer program is made. But, if you really want to become a developer, you have to study about paradigms, methodologies, etc. I tried to keep it simple in this article, but later, I’ll write about those topics more.