Sei sulla pagina 1di 6

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.

High-Level Programming Languages


High-level programming languages, while simple compared to human languages, are
more complex than the languages the computer actually understands, called machine
languages. Each different type of CPU has its own unique machine language.
Lying between machine languages and high-level languages are languages
called assembly languages. Assembly languages are similar to machine languages, but
they are much easier to program in because they allow a programmer to
substitute names for numbers. Machine languages consist of numbers only.
Lying above high-level languages are languages called fourth-generation
languages (usually abbreviated 4GL). 4GLs are far removed from machine languages
and represent the class of computer languages closest to human languages.
Converting to Machine Language
Regardless of what language you use, you eventually need to convert your program into
machine language so that the computer can understand it. There are two ways to do this:
1) Compile the program.
2) Interpret the program.
The question of which language is best is one that consumes a lot of time and energy
among computer professionals. Every language has its strengths and weaknesses. For
example, FORTRAN is a particularly good language for processing numerical data, but it
does not lend itself very well to organizing large programs. Pascal is very good for writing
well-structured and readable programs, but it is not as flexible as the C programming
language. C++ embodies powerful object-oriented features, but it is complex and difficult
to learn.
C (programming language)
C (/ si ː/, as in the letter c) is a general-purpose, procedural computer programming
language supporting structured programming, lexical variable scope, and recursion,
while a static type system prevents unintended operations. By design, C provides
constructs that map efficiently to typical machine instructions, and has found lasting use
in applications previously coded in assembly language. Such applications
include operating systems, as well as various application software for computers
ranging from supercomputers to embedded systems.
C was originally developed at Bell Labs by Dennis Ritchie between 1972 and 1973 to
make utilities running on Unix. Later, it was applied to re-implementing the kernel of the
Unix operating system.[6] During the 1980s, C gradually gained popularity. Nowadays, it
is one of the most widely used programming languages,[7][8] with C compilers from
various vendors available for the majority of existing computer architectures and
operating systems. C has been standardized by the ANSI since 1989 (see ANSI C) and
subsequently by the International Organization for Standardization.
C is an imperative procedural language. It was designed to be compiled using a
relatively straightforward compiler, to provide low-level access to memory, to provide
language constructs that map efficiently to machine instructions, and to require
minimal runtime support. Despite its low-level capabilities, the language was designed
to encourage cross-platform programming. A standards-compliant C program that is
written with portability in mind can be compiled for a wide variety of computer platforms
and operating systems with few changes to its source code; the language has become
available on various platforms, from embedded microcontrollers to supercomputers.
Like most procedural languages in the ALGOL tradition, C has facilities for structured
programming and allows lexical variable scope and recursion. Its static type
system prevents unintended operations. In C, all executable code is contained
within subroutines (also called "functions", though not strictly in the sense of functional
programming). Function parameters are always passed by value. Pass-by-reference is
simulated in C by explicitly passing pointer values. C program source text is free-format,
using the semicolon as a statement terminator and curly braces for grouping blocks of
statements.
The C language also exhibits the following characteristics:

 There is a small, fixed number of keywords, including a full set of control


flow primitives: if/else , for , do/while , while , and switch . User-defined names are
not distinguished from keywords by any kind of sigil.
 There are a large number of arithmetic, bitwise and logic
operators: + , += , ++ , & , || , etc.
 More than one assignment may be performed in a single statement.
 Function return values can be ignored when not needed.
 Typing is static, but weakly enforced; all data has a type, but implicit conversions are
possible.
 Declaration syntax mimics usage context. C has no "define" keyword; instead, a
statement beginning with the name of a type is taken as a declaration. There is no
"function" keyword; instead, a function is indicated by the parentheses of an
argument list.
 User-defined ( typedef ) and compound types are possible.
o Heterogeneous aggregate data types ( struct ) allow related data elements to be
accessed and assigned as a unit.
o Union is a structure with overlapping members; only the last member stored is
valid.
o Array indexing is a secondary notation, defined in terms of pointer arithmetic.
Unlike structs, arrays are not first-class objects: they cannot be assigned or
compared using single built-in operators. There is no "array" keyword in use or
definition; instead, square brackets indicate arrays syntactically, for
example month .
o Enumerated types are possible with the enum keyword. They are freely
interconvertible with integers.
o Strings are not a distinct data type, but are conventionally implemented as null-
terminated character arrays.
 Low-level access to computer memory is possible by converting machine addresses
to typed pointers.
 Procedures (subroutines not returning values) are a special case of function, with an
untyped return type void .
 Functions may not be defined within the lexical scope of other functions.
 Function and data pointers permit ad hoc run-time polymorphism.
 A preprocessor performs macro definition, source code file inclusion, and conditional
compilation.
 There is a basic form of modularity: files can be compiled separately
and linked together, with control over which functions and data objects are visible to
other files via static and extern attributes.
 Complex functionality such as I/O, string manipulation, and mathematical functions
are consistently delegated to library routines.
While C does not include certain features found in other languages (such as object
orientation and garbage collection), these can be implemented or emulated, often
through the use of external libraries (e.g., the GLib Object System or the Boehm
garbage collector).

C language IDE
C programs with output illustrate various programming concepts - operators, loops,
functions, single and double dimensional arrays, performing operations on strings, files,
pointers, etc. Download executable files and execute them without compiling the source
file. Code::Blocks IDE is used to write programs, most of these will work with GCC
and Dev C++ compilers. The first program prints "Hello World" on output device.
Rules in programming language
GENERAL PROGRAMMING RULES

Programming rules are an attempt summarize the programming experience of


programmers, and the theoretical considerations raised by computer scientists. Some
programming rules apply to all programming language, they stem from general principles
like:

A) Modern computers are very powerful, memory became relatively cheap, and modern
compilers automatically optimize code better than the average programmer.

So, saving memory or CPU time is no longer of prime importance: what is important is
creating programs that are easy to VALIDATE (check that the results are correct) and
MAINTAIN (change to suit different future needs).

B) The building units of program code, procedures and functions, should be made as
GENERAL (suitable for many similar applications) and FLEXIBLE (able to handle different
types of input and computing requirements) as possible.

This principle promotes CODE REUSABILITY (using parts of old programs in new ones),
and also helps improve coding since programs that don't rely on special assumptions tend
to be more reliable.

C) Programs should have a well organized internal structure. The MODULARITY


PROGRAMMING PARADIGM requires partitioning every program into relatively small
units, each performing a well defined task.

The interaction between code units can be described by a PROCEDURE CALLING


TREE, the calling tree makes clear also the internal structure of the program.

A subprogram call has a performance cost, so sometimes you don't partition the program
to many subprograms but just arrange it in well defined blocks, optimizing compilers does
such things automatically (procedure inlining).

(Some new programming paradigms like OBJECT ORIENTED PROGRAMMING and


VISUAL PROGRAMMING are not yet supported directly by the current Fortran languages
and dialects. It seems that implementing these paradigms degrade performance.)

D) Programs should be fully documented. Documentation consists of:

1) Self-explaining names for variables, procedures etc.

2) Short comments explaining the algorithms used, variables' roles and computation
steps

3) Program header containing: A general description, bugs and problems, planned


improvements, copyright and redistribution information

4) Procedure headers similar to the program header

5) A text file explaining how to compile, link, install and use the program (and/or a Make
file).
E) Programs should be portable. To achieve this goal you should:

1) Strictly adhere to the FORTRAN STANDARD


2) Avoid using operating system routines
3) Avoid using any processor dependent features

Languages standards are technical specifications describing a programming language in


detail. Compiler writers check their compilers against the standard, and so ensure that a
program that compiled correctly on one standard conforming compiler will compile
correctly on another such compiler.

The problem is that most compilers offer nice LANGUAGE EXTENSIONS, that
sometimes are quite tempting to use, and may even be included in future revisions of the
standard. However, if you use language extensions, your program might not compile on
other machines without some rewriting, and so might be less useful.

F) A program source is really just a text file; as such it can and should be as READABLE
and EASY TO EDIT as possible.

Readable programs are easier to maintain and validate.

In the chapter on program layout we will try to set some FORTRAN guidelines and give
some useful references.

G) A program should not depend on assumptions about the correctness of user's input,
guesses about expected data etc, this is called DEFENSIVE PROGRAMMING.

Make your program check user's input and key computation results, if wrong, try to
recover - go back to the last trusted point, or just give a detailed message and abort the
program.

H) It is very important to carefully select appropriate algorithms.

SUMMARY OF PROGRAMMING RULES

a) Clarity is more important than efficiency


b) Generalize your code
c) Write modular programs
d) Document your program
e) Write standard FORTRAN
f) Improve your layout
g) Program defensively
h) Use appropriate algorithms

Features of C language
 It is a robust language with rich set of built-in functions and operators that can be
used to write any complex program.
 The C compiler combines the capabilities of an assembly language with features
of a high-level language.
 Programs Written in C are efficient and fast. This is due to its variety of data type
and powerful operators.
 It is many time faster than BASIC.
 C is highly portable this means that programs once written can be run on another
machines with little or no modification.
 Another important feature of C program, is its ability to extend itself.
 A C program is basically a collection of functions that are supported by C library.
We can also create our own function and add it to C library.
 C language is the most widely used language in operating systems and embedded
system development today.

Potrebbero piacerti anche