====================================== Notes for Lecture 1 - January 15, 2008 ====================================== * 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 * Network languages ** Examples: Java, C# ** Primary goal: portability, machine-independence, safety and security * Differences between levels of languages ** C/C++ programs closer to hardware They have better control over underlying hardware, memory, and operating system functions. ** C/C++ application layer sits just above hardware and OS. ** Problem-solving and network languages hide real machine and OS They implement a virtual machine model that is "nicer" than the one provided by real hardware and real systems. The cost is reduced efficiency and the inability to access certain hardware features. ** Runtime layer sits between hardware and program in prob. solving lang. * Some steps in the software development process ** Goals and requirements ** Specification ** Implementation ** Testing * Hex example ** Description of Hex (see http://en.wikipedia.org/wiki/Hex_(board_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