Notes for Lecture 1 - January 16, 2007 ====================================== * Questions for discussion: ** What is programming? ** Why do people write programs? ** Who uses programs? ** Why might one want to learn how to program? ** Why program in C? * Different views of programs ** A means to solve a particular problem ** A description of the dynamic process of computation. ** An object having many properties of interest *** Functionality *** Size *** Maintainability and understandability *** Efficiency * Problem-solving languages ** Examples: basic, perl, python, scheme, ruby ** Primary goal: easy to use -- succinct algorithm description ** Desired behavior easily expressible ** Highly abstract -- characteristics of underlying machine hidden from user ** Intended for small to medium-size tasks ** Programmer and end user are often the same * Software-construction languages ** Examples: C, C++ ** Primary goal: produce production-quality software ** Give user control over the use of memory and hardware devices ** Less abstract -- machine characteristics reflected in language ** Intended for large tasks as well as small ** Can interface to operating system and other software components ** Portability is major concern ** End user is different from programmer * Some steps in the software development process ** Goals and requirements ** Specification ** Implementation ** Testing * Can't Stop example ** Description of Can't Stop game ** Goals and requirements *** Represent and display puzzle board *** Assist user in playing game **** How does user interact with program? **** How is the data entered? *** Computer play -- strategy ** Specification *** Drive by goals and requirements *** Must spell out desired behavior and user interface ** Implementation *** Driven by specification *** Program structure should reflect problem structure *** Principle of locality ** Testing *** Critical part of software development *** Test suite is set of test cases designed to exercise all parts of program *** Pay special attention to extreme cases * C programming environment ** File types *** Source files: .c and .h **** .h files is header (interface) file for a module **** .c file is code (implementation) file for a module **** Object files .o -- machine-code form on a module **** Precompiled libraries are collections of .o files ** Steps to build an executable file *** Compiler (gcc -c) produces .o file from .c and .h files. *** Linker (gcc without "-c") produces executable from .o files and libraries ** Example: *** gcc -c -o hello.o hello.c Generates "hello" from "hello.c" *** gcc -o hello hello.o Generates "hello" from hello.o and libraries that are searched automatically