411 REFERENCE · Wikibooks
Scala Programming/Programming
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
To understand programming, we will first see the difference between normal machines and a computer.
Let's take a kettle for example.
It can do one thing - boil the water. It has just one thing, or process that can be done with it.
Other machines like a microwave may have some options that you can set, like temperature and time. Yet, they still have just one task they can do.
A computer on the other hand, can do anything you tell it to do. The thing is, that if you don't tell it what to do, it can do nothing.
And that's where programming comes in. Programming is the way we can tell the computer what to do, using a programming language.
A programming language is an artificial language that allows a human to tell the computer what to do, by writing a program, which is a set of instructions.
There are many programming languages, but all of them have the same purpose: allow people to give the computer instructions so it can do what they want.
Types of Languages
There are three main categories of languages: Machine code, Assembly and High-level programming language.
Machine code is written in binary, and is executed directly by the CPU.
Assembly is very similar to machine code, but is written using words to make it easier to read and write the programs.
In order to run assembly programs, the code is translated to machine code using an Assembler, and the result is run by the CPU.
High-level programming language is a language that is supposed to be much easier to manipulate and maintain in comparison to machine code or assembly.
It has two ways to be run, by an interpreter or a compiler.
The high-level languages are the most popular since their ease of use. Assembly is used mostly where a high-level language cannot be used an in real-time systems, where performance is crucial.
They are more high-level than assembly which is low-level. This means, that high-level languages have a higher level of abstraction and are written in terms of variables, functions, objects and high-level operations, while assembly programs are described in terms of the more low-level terms, such as registers, stack and very low-level operations (basically, those provided by the CPU). To demonstrate the difference, we will take the analogy of "disassembly the device" vs. "take the screw driver, unscrew the left screw, repeat for all screws until you unscrewed all of them".
In general, computers, hardware and software, are built with many level of abstractions on top of each other. From the quantum mechanics, through a transistor, going through gates, then memory unit, an instruction, a function, all the way up to a final program, that is described in very abstract terms such as files, variables and whole components. You can watch a video about the abstractions used in computing Youtube.
Interpreter
Interpreter is a program that runs another program. It reads your program, sentence at a time, and runs the corresponding instructions in machine code.
Compiler
Compiler is a program that translate another program to machine code. It take your program and turn it into a program in machine code which can be executed at any time.
Interpreter vs. Compiler
Compiler and interpreter, each has its own advantage. Interpreter is generally slower than the produced machine code of a compiler, because it does all the parsing, translating and executing on the spot. In contrast, the compiler produces a machine code that can be run later in native speed.
So what is the advantage of an interpreter? Mainly, it allows great interactivity, which is very good for testing something quick and getting immediate feedback.
Now that you understand programming, you can move on to The JVM, the platform on which Scala is built.