WHAT IS PROGRAMMING ?
Programming, also known as
coding, is the
process of giving instructions to a computer to perform specific tasks by
writing code in a programming language. It involves designing and implementing algorithms, which are step-by-step
procedures, to solve problems.
Programming
• it's hard to do the programming to get something done
• details are hard to get right, very complicated, finicky
• not enough skilled
people to do what is needed
• therefore, enlist machines to do some of the work – leads
to programming languages
• it's hard to manage the resources of the computer
• hard to control sequences of operations
• in ancient times,
high cost of having machine be idle
• therefore, enlist machines to do some of the work – leads
to operating systems
Evolution of programming languages
• 1940's: machine level – use binary or equivalent notations for actual numeric values
• 1950's: "assembly language" – names for instructions: ADD instead of 0110101, etc. – names for locations: assembler keeps track of where things are in memory; translates this more humane language into machine language – this is the level used in the "toy" machine – needs total rewrite if moved to a different kind of CPU
loop get # read a number
if zero done # no more input if number is zero
add sum # add in accumulated sum
store sum # store new value back in sum
go to loop # read another number
done load sum # print sum
stop sum 0 # sum will be 0 when program starts
Evolution of programming languages 1960's
• "high level" languages -- Fortran, Cobol, Basic – write in a more natural notation, e.g., mathematical formulas – a program ("compiler", "translator") converts into assembler – potential disadvantage: lower efficiency in use of machine – enormous advantages: accessible to much wider population of users portable: same program can be translated for different machines more efficient in programmer time
sum = 0
10 read(5,*) num
if (num .eq. 0) goto 20
sum = sum + num
goto 10 20 write(6,*) sum
stop
end
Evolution of programming languages 1970's
• "system programming" languages -- C – efficient and expressive enough to take on any programming task writing assemblers, compilers, operating systems – a program ("compiler", "translator") converts into assembler – enormous advantages: accessible to much wider population of programmers portable: same program can be translated for different machines faster, cheaper hardware helps make this happen
#include<stdio.h>
int main()
{
int num, sum = 0;
while (scanf("%d", &num) != -1 && num != 0)
sum += num;
printf("%d\n", sum);
}
C code compiled to assembly language (SPARC):
#include<stdio.h>
{
int num, sum = 0;
while (scanf("%d", &num) != -1
&& num != 0)
sum = sum + num;
printf("%d\n", sum);
}
C code compiled to assembly language:
}
Evolution of programming languages 1980's :
#include<stdio.h>
Evolution of programming languages, 1990's :
• "scripting", Web, component-based, : Java, Perl, Python, Visual Basic, Javascript, – write big programs by combining components already written – often based on "virtual machine": simulated, like fancier toy computer – enormous advantages: portable: same program can be translated for different machines faster, cheaper hardware helps make this happen
var sum = 0, num; // javascript
num = prompt("Enter new value, or 0 to end")
while (num != 0)
{
sum = sum + parseInt(num)
num = prompt("Enter new value, or 0 to end")
}
alert("Sum = " + sum)