Many concepts exist in life. You may have a business question of the form, “how do I determine what I need to do to be more profitable?” It may not be a business question. Perhaps you collect movie box office numbers out of curiosity and ask yourself, “how can I rank movies by box office returns?” You might ask such a question to help you decide which movies to buy that you haven’t seen yet. Plenty of questions exist that can be answered with the help of computer programming and armed with such a question, you now need to write code to answer questions.
How to Learn to Write Code
The most common way to learn code is the same process for piano lessons. That may sound odd, but it is true. With piano lessons, you are following the lead of your teacher at first. You are imitating your teacher who is your support until you are ready to work independently. Learning code is the same way. You are not writing code at the same time as your teacher but you do first learn by mimicry.
Unfortunately, most instructional guides on programming make one major mistake. They try to teach code in the wrong sequence. It throws most people off and unless you are persistent, you may never get on the right track. The wrong sequence teaches programming in the opposite order of how it should be understood. Maybe there is a reason for that, but this page will introduce actual requirements in the correct sequence.
What You Should Learn Before Code
The items that follow are not the only things you should learn but they are the minimum concepts you should understand before engaging with code. Each can be learned to various levels of detail but you may go for an overview at first. Even a cursory, general understanding is useful. The biggest roadblock in learning how to code is going from source code to program file. As I introduce these concepts remember, this is a compact guide and I leave the level of detail you decide to pursue up to you.
Item #1 – A Computer
The first thing you should know about is the computer itself. Simply put, a machine that executes code in order to meet the goals of those who operate that machine. The goals could be Netflix, Wikipedia, and Amazon otherwise known as entertainment, research, and shopping. The machine is there to help people do things.
The machine has rules, the machine has predictable behavior, and the machine runs code. The machine does not run programs, it runs code. Books and websites exist that discuss machine architecture. They are available if you decide to delve more into this topic. You write programs, but the machine runs code. You will be less confused as you proceed down this list.
Item #2 – Operating Systems
An operating system like Microsoft Windows or Apple OS X is a large body of code that a computer runs to define an environment for programs. You are creating a program that meets the standards of an operating system. Books and websites exist that discuss the details of these operating systems. Code and programs are not the same things. A program generally exists in the context of an operating system.
Item #3 – Programs
Source code that you write is not a live and actionable computer program by itself. The computer does not understand source code and such source has to be translated from what it is into a program file. A program, called a compiler, exists to convert source code into a program. You will often use a tool called an IDE that will do this conversion for you, but sometimes you need to do it yourself. Books and websites exist that cover command-line compilation. Regardless of tool or programming language used, the primary tangible output is a computer program that works.
Item #4 – Command-line and Inline Programs
A command-line program is a complete program file that encodes your logic and can be run on demand to operate according to the rules you have defined. They are represented as plain-text output and should run the same way every time you run them. I recommend command-line programs because they can be universally created in nearly all environments.
Item #5 – Source Code is Written in an Editor
You need a tool designed to accept source code input that you type and commit to a file. When you are on Microsoft Windows, I recommend Microsoft Visual Studio. XCode is available for Apple OS X. Both tools has a menu choice to create a command-line program (sometimes called a console program). These editors are not the only ones for creating programs, but are the ones designed for those operating systems and can be a quick and supported way to get started.
Build a Command-Line Program
After you have thought about the sequence above, the next thing to do is simply follow a tutorial for command-line programs in your chosen operating system. A web search of the form, “console program tutorial for Microsoft Visual Studio” would lead to a useful list of guides. You might substitute Microsoft Visual Studio with XCode. Try to engage with a tutorial on either Microsoft’s or Apple’s website. Follow those guides and you will have learned the mechanics of how to program in a very short time.
You may decide to understand the concepts mentioned in greater depth now or much later. The important thing is to put the concept of building a command-line program into practice. This is done by having questions or a goal and constructing a program around that goal. A poor way to learn programming is to rush through it and disregard areas that seem extra. Discipline and patient attention to the steps outlined here will strengthen your ability to create programs.
Programs exist to solve a problem or do something someone finds useful. The act of writing source code is to create inputs that are transformed into a program that an operating system runs. A computer and an operating system have rules that the program must observe before the purpose of the program can be enacted. Tools from Microsoft and Apple streamline the creation of programs that minimally meet the standards of the operating systems made by those organizations. You learn programming by first understanding the environment and tools in which these programs will run.
When you have the basic ability to create command-line programs to solve problems, the next thing to do is consolidate code so you minimize future rework. The next chapter concerns creating a code library. It is an important way to allow you to work faster and smarter when training the process of programming on a problem you want to solve.