Compsci 06/101, Fall 2010 10.1 How to build a program l Create a module  Can be used by other modules via import  Collection of functions, later collection.

Slides:



Advertisements
Similar presentations
1 CSC 221: Computer Programming I Fall 2006 interacting objects modular design: dot races constants, static fields cascading if-else, logical operators.
Advertisements

CSE 303 Lecture 16 Multi-file (larger) programs
Scope and Lifespan of Identifiers. Every function has a scope What does that mean? That means that every identifier that is created in a function (that’s.
Communication between modules, cohesion and coupling
Internal Documentation Conventions. Kinds of comments javadoc (“doc”) comments describe the user interface: –What the classes, interfaces, fields and.
Procedures and Stacks. Outline Stack organization PUSH and POP instructions Defining and Calling procedures.
API Design CPSC 315 – Programming Studio Fall 2008 Follows Kernighan and Pike, The Practice of Programming and Joshua Bloch’s Library-Centric Software.
Objects First With Java A Practical Introduction Using BlueJ Designing object-oriented programs How to write code in a way that is easily understandable,
1 Programming for Engineers in Python Autumn Lecture 5: Object Oriented Programming.
Sub Programs To Solve a Problem, First Make It Simpler.
Memory Allocation. Three kinds of memory Fixed memory Stack memory Heap memory.
1 Introduction to Software Engineering Lecture 42 – Communication Skills.
Run time vs. Compile time
Computer Science 1620 Function Scope & Global Variables.
1 Run time vs. Compile time The compiler must generate code to handle issues that arise at run time Representation of various data types Procedure linkage.
CS 180 Recitation 8 / {30, 31} / Announcements Project 1 is out –Due 10:00pm –Start early! –Use the newsgroup for your questions –LWSN B146.
Algorithm Programming Coding Advices Bar-Ilan University תשס " ו by Moshe Fresko.
CMSC 104, Version 8/061L18Functions1.ppt Functions, Part 1 of 4 Topics Using Predefined Functions Programmer-Defined Functions Using Input Parameters Function.
Design-Making Projects Work (Chapter7) n Large Projects u Design often distinct from analysis or coding u Project takes weeks, months or years to create.
Object Oriented Programming Philosophy. Part 1 -- Basic Understanding & Encapsulation.
Functions Part I (Syntax). What is a function? A function is a set of statements which is split off into a separate entity that can be used like a “new.
Fixtures Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design First Edition by Tony Gaddis.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 6 Functions.
1 Names, Scopes and Bindings Aaron Bloomfield CS 415 Fall
Introduction to Programming Using C Modularity. 2 Contents Modularity Functions Preprocessor Comments Global variables.
CSC 107 – Programming For Science. Today’s Goal Variables  Variable  Variable name location to store data  Only for humans; 0 x 7E8A2410 harder to.
Compsci 101.2, Fall PFThursday l Review Organization and Problem-Solving  Defining functions, calling functions  Return types, print, None l.
Program style. Global area Place comment s at beginning of the program: 1.purpose 2.author 3.the date the program was written 4.the data and description.
Python – May 11 Briefing Course overview Introduction to the language Lab.
C++ Memory Overview 4 major memory segments Key differences from Java
C463 / B551 Artificial Intelligence Dana Vrajitoru Python.
Compsci 6/101, Spring PFTW: Sequences aka Strings&Lists l From Return values to Random-ness [aka two R's]  What power does random provide? 
Self-Documenting Code Chapter 32. Kinds of Comments  Repeat of code  Explanation of code  Marker in code  Summary of code  Description of code’s.
Covenant College November 27, Laura Broussard, Ph.D. Professor COS 131: Computing for Engineers Chapter 5: Functions.
Compsci 101.2, Fall PFTWeek l Introduce new Python concepts  Control: if, elif, else, for  Data: Strings, Lists Operators on data: slicing,
Chapter 7 Implementation. Implementation Approaches F Big bang –Code entire system and test in an unstructured manner F Top-down –Start by implementing.
Functions Chapter 6. Modular Programming Modular programming: breaking a program up into smaller, manageable functions or modules Function: a collection.
VHDL Discussion Subprograms IAY 0600 Digital Systems Design Alexander Sudnitson Tallinn University of Technology 1.
MTA EXAM HTML5 Application Development Fundamentals.
CompSci 101 Introduction to Computer Science February 4, 2016 Prof. Rodger compsci101 spring161.
Swing Threading Nested Classes COMP 401 Fall 2014 Lecture 23 11/25/2014.
1 UMBC CMSC 104, Section Fall 2002 Functions, Part 1 of 3 Topics Top-down Design The Function Concept Using Predefined Functions Programmer-Defined.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to.
Functions, Part 1 of 3 Topics  Using Predefined Functions  Programmer-Defined Functions  Using Input Parameters  Function Header Comments Reading 
CPS What's in Compsci 100? l Understanding tradeoffs: reasoning, analyzing, describing…  Algorithms  Data Structures  Programming  Design l.
Class Diagrams Revisited. Parameterized Classes Parameterized Classes - are used to represent relationships between templates.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
Variable Scope. When you declare a variable, that name and value is only “alive” for some parts of the program  We must declare variables before we use.
CPS 100, Spring Interlude for trees l Joyce Kilmer Joyce Kilmer l Balanced Trees  Splay  Red-Black  AVL  B-tree.
CompSci 101 Introduction to Computer Science
Reviewing Code A guide to smelling another developer’s source code.
Coupling and Cohesion 1.
Compsci 201 Linked Lists from A-Z
Topic: Functions – Part 2
Variables, Expressions, and IO
Compsci 6/101: PFTW What is Python? What is a programming language?
CompSci 230 Software Construction
Compsci 101, APTs and Sequences and Selection
2008/11/05: Lecture 15 CMSC 104, Section 0101 John Y. Park
Microsoft Visual Basic 2005 BASICS
Functions, Part 1 of 3 Topics Using Predefined Functions
Lesson 5: Building an App: Clicker Game
UMBC CMSC 104 – Section 01, Fall 2016
Writing Functions.
Herbert G. Mayer, PSU CS Status 8/2/2013
Functions, Part 1 of 3 Topics Using Predefined Functions
Functions, Part 1 of 3 Topics Using Predefined Functions
2008/11/05: Lecture 15 CMSC 104, Section 0101 John Y. Park
CompSci 101 Introduction to Computer Science
Presentation transcript:

Compsci 06/101, Fall How to build a program l Create a module  Can be used by other modules via import  Collection of functions, later collection of classes  How do the functions in one module communicate? l Sometimes functions in one module interact  Easy if one function calls another  Harder if state must be saved between function calls l Enter global variables  The scourge of human kind

Compsci 06/101, Fall Global variables l Why are these bad?  Leaky information from one module to another  If implementation changes, hard to maintain code  So, NEVER access global state/variables outside a module  Eventually move toward understanding of name spaces l When using a global variable you must  Declare the variable as global in a function  Not for read-only, don't need to be declared, but just do it l Designing and using classes will change this

Compsci 06/101, Fall Programming Style l Functions return a value  If they don’t they do anyway: None  Sometimes it's ok not to, the function has a side effect  Could be printing, could be altering global state  Could be … l Functions have a comment indicating their purpose  Describe functionality  Describe parameters  Describe return type  Describe exceptions (later)

Compsci 06/101, Fall Lynn Conway See Wikipedia and lynnconway.com l Joined Xerox Parc in 1973  Revolutionized VLSI design with Carver Mead l Joined U. Michigan 1985  Professor and Dean, retired '98 l NAE '89, IEEE Pioneer '09 l Helped invent dynamic scheduling early '60s IBM l Transgender, fired in '68