Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 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 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

2 Compsci 06/101, Fall 2010 10.2 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

3 Compsci 06/101, Fall 2010 10.3 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)

4 Compsci 06/101, Fall 2010 10.4 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


Download ppt "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."

Similar presentations


Ads by Google