Previous Slide
Next Slide
Introduction
Why do computers exist? The simple answer is that we want to eliminate the extra work involved in carrying out specific tasks, in order to give us more time to focus on more meaningful decisions. Computers are designated to perform that extra work automatically, but someone has to teach the computer how to do that work. This is where programming comes in.
Programming, coding, or scripting, all of which we will be using interchangeably today, refers to the process of creating computer programs through the manual implementation of one or more programming languages. Computers ultimately can only understand series of on or off circuits or "zeroes and ones." The type of code that a computer can understand directly is called machine code. Machine code is unreasonably difficult to write by hand, and that's why we have programming languages. Code written in these languages is called source code, which the computer subsequently boils down to machine code to process it directly.
There's a large diversity of programming languages that have been created, and an even larger set of systems and contexts for which these languages are implemented. However, virtually all languages share certain elements. Keywords and operators are examples of such shared elements. Let's take a look at them.
Keywords and Operators
In order to write code using a programming language, we have to know the rules of the language. The rules of a language are called the syntax of the language. The syntax must be strictly followed, or else the code may behave in an unintended way, or more likely fail to execute altogether. In this way, syntax is like grammar for a spoken language.
On top of grammar, spoken languages also have a lexicon or vocabulary. The equivalent to a vocabulary for programming languages are keywords. Keywords are special reserved words in a language that the programmer uses in order to create directives and logic within a program. We will be learning many examples of keywords throughout this course.
Anyone who has been through 1st grade is familiar with the idea of operators, but may be unaware of the word "operator." Operators are the built-in signs in a language that are used in arithmetic operations, comparisons, among other purposes. A simple example of an operator would be the '+' symbol.
This operator is used in the addition of two values. We will be seeing many more examples of operators in the coming pages. Now that we recognize that a programming language is similar to a spoken language in that it has its own rules of syntax and has its own vocabulary of built-in keywords and set of useful operators, let's learn about how to use these keywords and operators to create some basic code.
Variables
A critical component of our ability to function is the act of remembering information. We take it for granted because we do it effortlessly. We store long-term information, like our friends' names our home address, and so on. We also hold certain information for a very brief period of time, for instance when we calculate a tip at dinner.
In programming, remembering information is just as essential. The most basic form of storing values is utilizing variables.
In each of these languages, the process of storing a value to a variable requires an assignment operator, which each of these languages agrees should be the equal sign. When a variable is mentioned in the code the first time, this is called declaration. When a variable is assigned to a value for the first time, this is called instantiation. Declaration and instantiation can happen in the same statement. Lingo aside, what's going on here is that the variable x is storing the value 10, to be used later.
You may have also noticed that some of the languages in the example had a keyword like int or var while other languages did not use them. Some languages closed the statements with semi-colons, and others did not. This is just the syntax of the language. Most programming languages are case-sensitive with variable names too, so x and X are two different variables.