1 / 18

Introduction to programming languages, Algorithms & flowcharts

Introduction to programming languages, Algorithms & flowcharts. What are Program and programming language?. Program : Set of instructions which a computer can “ interpret ” to solve problems, make calculations, perform tasks, etc.

davisw
Download Presentation

Introduction to programming languages, Algorithms & flowcharts

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to programming languages, Algorithms & flowcharts Slides borrowed from Instructor: Wajih Alouini

  2. What are Program and programming language? • Program : Set of instructions which a computer can “interpret” to solve problems, make calculations, perform tasks, etc. • Programming Language : A formal language that is intended for the expression of computer programs

  3. Why study programming languages? • Programming languages are important for students in all disciplines of engineering because they are the primary tools of the central activity of any science.

  4. Why study programming languages? (cont.) • To improve your ability to develop effective algorithms and to improve your use of your existing programming language. • To increase your vocabulary of useful programming constructs. • To allow a better choice of programming languages. • To make it easier to learn a new language.

  5. A short history of programming Languages 1950 : Numerically based languages. FORTRAN (55) • Business languages. COBOL(60) • Artificial intelligence languages. LISP, ALGOL(58) • LISP, FORTRAN (55) ALGOL • 1970 : PLs Ada, C, Pascal, Smalltalk • 1980 : Development of functional programming: ML, Miranda Object-oriented programming: Smalltalk, C++

  6. A short history of programming languages (cont.) • 90s: • Fourth-generation languages • Productivity tools (such as spreadsheets) • Visual languages : Delphi • Scripting languages : Perl • Expert systems shells • Network computing : Java

  7. Low-level vs. High-level Programming Languages • Low-level: • Machine code • Assembly • High-level: (abstraction from the computer details) • Basic, C, Java, Pascal, C++, Perl, Python, …

  8. Styles of Computer Programming • Procedural: procedures, routines, subroutines, methods, or functions • e.g. C, Pascal, Basic, Fortran • Functional • Mathematical functions • e.g. Lisp, Erlang, Haskell, ML, … • Object-oriented • e.g. C++, Java, Smalltalk • Rule-based (or Logic) : facts, rules • e.g. Prolog

  9. Examples (1/5) • Fibonacci numbers • Fn = Fn-1 + Fn-2 , n>=2F0 = 0, F1 = 1 • How to program? • 0,1,1,2,3,5,8,13

  10. Examples (2/5) • Functional: (Haskell) • fib 0 = 0fib 1 = 1fib n = fib (n-1) + fib (n-2)

  11. Examples (3/5) • Procedural: (C) • int fib(int n){ int first = 0, second = 1; for (int i=0, i<n; i++) { int sum = first+second; first = second; second = sum; } return first;}

  12. Examples (4/5) • Assembly: (in x86 using MASM syntax) • mov edx, [esp+8]cmp edx, 0 ja @f mov eax, 0 ret @@: cmp edx, 2 ja @f mov eax, 1 ret @@: push ebx mov ebx, 1 mov ecx, 1 @@: lea eax, [ebx+ecx] cmp edx, 3 jbe @f mov ebx, ecx mov ecx, eax dec edx jmp @b @@: pop ebx ret

  13. Examples (5/5) • Machine code • 8B542408 83FA0077 06B80000 0000C383 FA027706 B8010000 00C353BB 01000000 B9010000 008D0419 83FA0376 078BD98B C84AEBF1 5BC3

  14. Attributes of a good language • Ease of program verification • Proof of correctness, desk checking, test • Simplicity of semantic and syntax • Programming environment • Portability of programs • Cost of use • Program execution • Program translation • Program creation, testing, and use • Program maintenance

  15. Attributes of a good language (another view: to make a software reliable, maintainable, efficient) • Reliability • Writability • Readability • Simplicity • Safety (no goto, no pointers) • Robustness (undesired events can be trapped, like arithmetic overflow, invalid inputs) • Maintainability • Factoring (modularity) • Locality • Efficiency

  16. Issues for all Languages • Can it be understood by people and processed by machines? • although translation may be required • Sufficient expressive power? • can we say what needs to be said, at an appropriate level of abstraction?

  17. Translation • Compilation • Translate into instructions suitable for some other (lower level) machine • During execution, that machine maintains program state information • Interpretation • May involve some translation • Interpreter maintains program state

  18. Trade-offs • Compilation • lower level machine may be faster, so programs run faster • compilation can be expensive • examples: C (and Java?) • Interpretation • more ability to perform diagnostics (or changes) at run-time • examples: Basic, UNIX shells, Lisp

More Related