上游充通大 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Computational Thinking and Approach Lecture 4 Dr.Jialiang LU Jialiang.lu@situ.edu.cn
Computational Thinking and Approach Lecture 4 Dr. Jialiang LU Jialiang.lu@sjtu.edu.cn 1
上游充通大 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Functions MODULAR PROGRAMMING 2
MODULAR PROGRAMMING Functions 2
上游充通大 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Motivations Divide huge tasks to blocks:divide programs up into sets of cooperating functions. Define new functions with function calls and parameter passing. Use functions to reduce code duplication and increase program modularity. ·Easy to: -Design→Implement→Test→Maintain→Reuse 3
Motivations • Divide huge tasks to blocks: divide programs up into sets of cooperating functions. • Define new functions with function calls and parameter passing. • Use functions to reduce code duplication and increase program modularity. • Easy to: – Design Implement Test Maintain Reuse 3
上游充通大 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Function of Functions Decomposition and abstraction through functions Break up into modules Suppress detail Create "new primitive' 4
Function of Functions • Decomposition and abstraction through functions – Break up into modules – Suppress detail – Create “new primitive” 4
上游充通大 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Functions,Informally A function is like a subprogram,a small program inside of a program. The basic idea-we write a sequence of statements and then give that sequence a name.We can then execute this sequence at any time by referring to the name. 5
5 Functions, Informally • A function is like a subprogram, a small program inside of a program. • The basic idea – we write a sequence of statements and then give that sequence a name. We can then execute this sequence at any time by referring to the name