How Do You Program?
From codeTank
The first question I'm always asked is, "How do you actually program? What do you actually do?"
About 99% of programs have the same basic idea. (1) You create a new text file, (2) type instructions into that text file, and then (3) have some other program read that text file and do what you said. That is the basic idea.
Creating a text file is pretty easy - you can do that in Notepad if you wanted. Please note that you can't write a program using MS Word, or any other complicated text editor. It has to be something that can edit a raw, boring, normal, text file - which is what Notepad does.
Typing instructions is the interesting part. This is where the actual program is written. What you type depends on what language you're using, your overall goal, and the algorithms you've created.
Algo-what? Algorithms. Algorithms are very important in programming - it's basically a step-by-step plan of exactly what you want to happen. When you program, you'll soon realize that you need to be very very explicit. Computers are dumb - they can't read your mind. They only do exactly what you tell them to do.
The third step is to take your text file full of instructions (called source code), and give it to some other program to run it. The specifics of this last step depend on what language you're programming in, and your programming environment.
Examples
So what does actually programming look like? Well, it depends on what you're doing, and what language you've decided to use. Here are some examples of what programming might look like:
- Let's say I want to create a simple webpage. To do so, the language of choice is HTML. I would open up Notepad, create a new file, and type something like the following:
<html> <head> <title>Hello World!</title> </head> <body> <h1>Hello World!</h1> <p> Welcome to the Inter-web! </p> </body> </html>
- I would save this file with the extension HTML (for example, index.html), instead of the default TXT. Then, I could open the file in Firefox to see what results my code produces.
- Perhaps I want to access data in a MySQL database. The language would be SQL. I could open up Notepad, and type the following:
SELECT books.title, count(*) AS Authors FROM books JOIN book_authors ON books.isbn = book_authors.isbn GROUP BY books.title;
- I would save this file with an SQL extension (for example, query.sql), and execute it using the MySQL daemon program.
- Maybe I want to write a sweet 3d computer game. One popular language to do that is C++. I could open up Notepad, and start this large project with the following:
#include <windows.h> #include <d3d9.h> #include <d3dx9.h> #include <commctrl.h> // this is for XP-themed controls #pragma comment(lib, "d3d9.lib") // directx #pragma comment(lib, "d3dx9.lib") // directx helper functions #pragma comment(lib, "comctl32.lib") // this is for XP-themed controls #define MUTEX_NAME "SweetAssGame_790124819" int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow) { HANDLE hMutex = CreateMutex(NULL, TRUE, MUTEX_NAME); if (hMutex == NULL) return 0; if (GetLastError() == ERROR_ALREADY_EXISTS) return 0; InitCommonControls(); // this is for the XP-themed controls // code goes here return 0; }
- Now of course, that isn't an entire game. Games take thousands of lines of code. But it could all be written in Notepad. At that point, I would save my file with the extension CPP (for example, main.cpp). Then load it in Microsoft Visual C++ Express 2005, in order to compile and run it.
Example Summary
As you can see, all three examples have very different goals. Each example starts with Notepad, but each uses a different language (which means a different file extension), and a different program to run the source code.
To make webpages, the language is HTML, the extension is HTML, and the program is Firefox. To query a database, the language is SQL, the extension is SQL, and the program is a MySQL daemon. To make a sweet game, the language is C++, the extension is CPP, and the program is Microsoft Visual C++ Express 2005.
It's not written in stone though... for any goal, there could be a dozen languages to choose from, and another dozen of programs to run your source code in. Not everybody uses C++ to make 3d games... but it is the most popular choice.
So Now What?
You are probably deathly confused. Don't worry. Hopefully you have grasped the basic lesson: when you program, you type a bunch of instructions in some programming language, then feed those instructions through a program that executes them. You choose which language to use based on what your goals are.
The absolute best way to learn how to program is to just PROGRAM. So, without further ado, let's jump right into Your First Program.

