Programming
Programming
:max_bytes(150000):strip_icc()/warning--data-transfer-in-progress-507065943-59c6d2a70d327a001141794d.jpg)
What is programming?
Programming is the implementation of logic to facilitate specified computing operations and functionality. It occurs in one or more languages, which differ by application, domain and programming model.
Programming Language
A programming language is a vocabulary and set of grammatical rules for instructing a computer or computing device to perform specific tasks. The term programming language usually refers to high-level languages, such as BASIC, C, C++, COBOL, Java, FORTRAN, Ada, and Pascal.
Each programming language has a unique set of keywords (words that it understands) and a special syntax for organizing program instructions.
Types of Programming Language
Machine Code
Most computers work by executing stored programs in a fetch-execute cycle. Machine code generally features:
- Registers to store values and intermediate results
- Very low-level machine instructions (
add,sub,div,sqrt)
- Labels and conditional jumps to express control flow
- A lack of memory management support — programmers do that themselves
Machine code is usually written in hex. Here’s an example for the Intel 64 architecture:
89 F8 A9 01 00 00 00 75 06 6B C0 03 FF C0 C3 C1 E0 02 83 E8 03 C3
Assembly Language
An assembly language is an encoding of machine code into something more readable. It assigns human-readable labels (or names) to storage locations, jump targets, and subroutine starting addresses, but doesn’t really go too far beyond that. Here’s the function from above on the Intel 64 architecture using the GAS assembly language:
.globl f .text f: mov %edi, %eax # Put first parameter into eax register test $1, %eax # Examine least significant bit jnz odd # If it's not a zero, jump to odd imul $3, %eax # It's even, so multiply it by 3 inc %eax # and add 1 ret # and return it odd: shl $2, %eax # It's odd, so multiply by 4 sub $3, %eax # and subtract 3 ret # and return it
And here’s the same function, written for the SPARC:
.global f f: andcc %o0, 1, %g0 bne .L1 sll %o0, 2, %g2 sll %o0, 1, %g2 add %g2, %o0, %g2 b .L2 add %g2, 1, %o0 .L1: add %g2, -3, %o0 .L2: retl nop
High-Level Languages
A high-level language gets away from all the constraints of a particular machine. HLLs have features such as:
- Names for almost everything: variables, types, subroutines, constants, modules
- Complex expressions (e.g.
2 * (y^5) >= 88 && sqrt(4.8) / 2 % 3 == 9) - Control structures (conditionals, switches, loops)
- Composite types (arrays, structs)
- Type declarations
- Type checking
- Easy, often implicit, ways to manage global, local and heap storage
- Subroutines with their own private scope
- Abstract data types, modules, packages, classes
- Exceptions
The previous example looks like this in Fortran 77 (note how the code begins in column 7 or beyond):
INTEGER FUNCTION F(N) INTEGER N IF (MOD(N, 2) .EQ. 0) THEN F = 3 * N + 1 ELSE F = 4 * N - 3 END IF RETURN END
and like this in Fortran 90 (where the column requirements were finally removed):
integer function f (n) implicit none integer, intent(in) :: n if (mod(n, 2) == 0) then f = 3 * n + 1 else f = 4 * n - 3 end if end function f
and like this in Ada:
function F (N: Integer) return Integer is begin if N mod 2 = 0 then return 3 * N + 1; else return 4 * N - 3; end if; end F;
and like this in C and C++:
int f(const int n) { return (n % 2 == 0) ? 3 * n + 1 : 4 * n - 3; }
and like this in Java and C#:
class ThingThatHoldsTheFunctionUsedInTheExampleOnThisPage { public static int f(int n) { return (n % 2 == 0) ? 3 * n + 1 : 4 * n - 3; } }
System Languages
System programming languages differ from application programming languages in that they are more concerned with managing a computer system rather than solving general problems in health care, game playing, or finance. In a system langauge, the programmer, not the runtime system, is generally responsible for:
- Memory management
- Process management
- Data transfer
- Caches
- Device drivers
- Directly interfacing with the operating system
Scripting Languages
Scripting languages are used for wiring together systems and applications at a very high level. They are almost always extremely expressive (they do a lot with very little code) and usually dynamic (meaning the compiler does very little, while the run-time system does almost everything).
Esoteric Languages
An esoteric language is one not intended to be taken seriously. They can be jokes, near-minimalistic, or despotic (purposely obfuscated or non-deterministic).
Exercise: Implement the function above in False, Brainfuck, Befunge, Malbolge, Kipple, and reMorse.
Ousterhout’s Dichotomy
Java Programming Language
It enables programmers to write computer instructions using English-based commands instead of having to write in numeric codes. It’s known as a high-level language because it can be read and written easily by humans.
Like English, Java has a set of rules that determine how the instructions are written. These rules are known as its syntax. Once a program has been written, the high-level instructions are translated into numeric codes that computers can understand and execute.
Java was designed with a few key principles in mind:
- Ease of Use: The fundamentals of Java came from a programming language called C++. Although C++ is a powerful language, it is complex in its syntax and inadequate for some of Java's requirements. Java built on and improved the ideas of C++ to provide a programming language that was powerful and simple to use.
- Reliability: Java needed to reduce the likelihood of fatal errors from programmer mistakes. With this in mind, object-oriented programming was introduced. When data and its manipulation were packaged together in one place, Java was robust.
- Security: Because Java was originally targeting mobile devices that would be exchanging data over networks, it was built to include a high level of security. Java is probably the most secure programming language to date.
- Platform Independence: Programs need to work regardless of the machines they're being executed on. Java was written to be a portable and cross-platform language that doesn't care about the operating system, hardware, or devices that it's running on.
The team at Sun Microsystems was successful in combining these key principles, and Java's popularity can be traced to it being a robust, secure, easy to use, and portable programming language.
Paradigm language
- A paradigm is a way in which computer language looks at the problem to be solved.
Procedural
- simple and straight forward code writing.
- routines and subroutines.
- top down, step by step instruction.
Object-oriented Program (OOP)
- approach to problem solving where all computations are carried out using objects.
- object is component of a program that knows how to perform certain actions and how to interact with other elements of the program.
- object is Ben (people), Ben can walk (method)
Translator
- a program that translates from one programming language into another.
- reads a HL program and executes it.
- it processes the program a little at a time, alternately reading lines and performing computations.
- JAVA, Visual Basic programming purpose
Compiler
- reads the entire program (HLL) and translates it completely before the program starts running.
- HLL program is called source code, the translated program is called executable or object code.
- once compiled, it can execute repeatedly without further translation.
Assembler
- a translator that converts programs written in assembly language to machine code so that they can be executed.
Comments
Post a Comment