Presentation is loading. Please wait.

Presentation is loading. Please wait.

School of Computing Science CMT1000 Ed Currie © Middlesex University Lecture 2: 1 CMT1000: Introduction to Programming Ed Currie Lecture 2B: Programming.

Similar presentations


Presentation on theme: "School of Computing Science CMT1000 Ed Currie © Middlesex University Lecture 2: 1 CMT1000: Introduction to Programming Ed Currie Lecture 2B: Programming."— Presentation transcript:

1 School of Computing Science CMT1000 Ed Currie © Middlesex University Lecture 2: 1 CMT1000: Introduction to Programming Ed Currie Lecture 2B: Programming Languages

2 School of Computing Science CMT1000 Ed Currie © Middlesex University Lecture 2: 2 Giving Plans To Computers To get a computer to do things we must give it detailed plans in a form it understands (programs) What language do we write the detailed plans in? –English? –Swahili? Human Languages are not suitable We use special programming languages

3 School of Computing Science CMT1000 Ed Currie © Middlesex University Lecture 2: 3 Why? … Human languages are –Hard to process –Ambiguous This is why we have the most powerful computers on Earth in our heads!

4 School of Computing Science CMT1000 Ed Currie © Middlesex University Lecture 2: 4 Why Special Languages? Do we just need to be careful? –Laws/contracts are written that way –Lawyers have been making $$$ because of the ambiguities for centuries Delia Smith's cookery books use careful English –I still can't make a good cheese sauce every time "stir until thickened"?? –Mr Kipling makes exceedingly identical cakes though … How?

5 School of Computing Science CMT1000 Ed Currie © Middlesex University Lecture 2: 5 Programming Languages Designed to be –unambiguous –easy to process –consist of instructions the computer knows about –and how to follow BUT We can use English to help us solve the problem –only the last step needs to be in a programming Language

6 School of Computing Science CMT1000 Ed Currie © Middlesex University Lecture 2: 6 Computer Languages There are lots. Here are just a few that have been popular at different times. 1960sALGOLFORTRAN COBOL 1970sSIMULAPASCAL ADA 1980sMODULA-2C++ 1990sMODULA-3JAVA

7 School of Computing Science CMT1000 Ed Currie © Middlesex University Lecture 2: 7 Why Different Languages? There are many reasons why there are so many different languages –Evolution New ones might be easier to use than older ones e.g., include features for avoiding errors –Different jobs nuclear power plant controller human computer interfaces graphics programming www programming –Different prejudices/fashions brevity

8 School of Computing Science CMT1000 Ed Currie © Middlesex University Lecture 2: 8 Aim Of This Course You should understand the common programming concepts –Java will be used as an example good programming practice how to find and avoid programming errors

9 School of Computing Science CMT1000 Ed Currie © Middlesex University Lecture 2: 9 What A Computer Really Understands 0000010101001010010100010101101 0100010101000100110001010010001 0100100100000000101010001001100 0101000010100010101101010001010 1000100110001010010001010010010 0000000100101000101011010100101 0001010110101001010001010110101 0…

10 School of Computing Science CMT1000 Ed Currie © Middlesex University Lecture 2: 10 // Prints ‘Hello’ on the screen in a dialog box import javax.swing.JOptionPane; // import class JOptionPane public class Hello1 { public static void main( String args[] ) { JOptionPane.showMessageDialog(null, "Hello!" ); System.exit( 0 ); // terminate the program }

11 School of Computing Science CMT1000 Ed Currie © Middlesex University Lecture 2: 11 Compiling To turn a program into a form the computer can execute –it must be compiled. A compiler just translates a program written in one language (as above) into another –where the only letters allowed in the language are 1 and 0

12 School of Computing Science CMT1000 Ed Currie © Middlesex University Lecture 2: 12 Compiler Detected Errors When humans write programs - they always make mistakes –like when I try to speak French! The compiler picks up many simple errors. These errors are similar to errors I might make if trying to write in a foreign language –or even in English sometimes

13 School of Computing Science CMT1000 Ed Currie © Middlesex University Lecture 2: 13 English Syntax Errors punctuation and spelling: –The cat sat on the mat i eight fish grammar: –The sat cat on the mat. I fish ate. These are called syntax errors. –You do not need to know the meaning of the sentences to see these are mistakes, just the rules of grammar –eg "there should be a verb next” There are similar "syntax" rules for programs –punctuation, spelling and grammar rules

14 School of Computing Science CMT1000 Ed Currie © Middlesex University Lecture 2: 14 Run-time Errors Run-time errors are ones the compiler cannot detect. Consider: "I was born on the 35th December, 1864.” –This is perfectly good English but it has a semantic error. –You need to know more than grammar to see this. –You must know what the words mean. Programs can also have semantic errors –they are only detected by running the program. –The program is a perfectly good program –it just does something other than what was intended They will often be due to mistakes in the algorithm.

15 School of Computing Science CMT1000 Ed Currie © Middlesex University Lecture 2: 15 Summary Plans must be written using special languages for computers which are: –unambiguous –easy to process Different languages have evolved from each other for different purposes A compiler converts the program to a form the computer can execute. It also catches syntax errors but not semantic errors.


Download ppt "School of Computing Science CMT1000 Ed Currie © Middlesex University Lecture 2: 1 CMT1000: Introduction to Programming Ed Currie Lecture 2B: Programming."

Similar presentations


Ads by Google