Lecture for ECE 175 David MacQuigg 5/1/08
Using C in the Real World
C is an excellent foundation for freshman computer engineers and scientists, but currently, C is not being used much in later classes. One way it could be very useful is in conjuction with a high-level language. The high-level language provides the overall framwork for a solution, and C provides the fast, efficient code that may be needed at "bottlenecks" where the high-level language is too slow.
The example in this lecture is computation of Mandelbrot images. We have a simple program written in Python to compute these images and display them using a graphics package we downloaded from the Internet. The only problem is it runs way too slow. Python has a nice interface for adding C-code inline, however. Replacing a few lines of Python with C allows us to speed the generation of these images by a factor of 100.
Mandel_zoom_00
- speed of computation is important, 2500 x 2000 pixels
- zoom in on "seahorse valley"
Mandel_zoom_14 Julia Island
- magnification 60 billion!
Background on Languages
- languages poster
- progression of languages 1 2
- domain-specific (FORTRAN, COBOL)
- general-purpose, high-level (C)
- one step above assembler
- problem was complexity, one big pile of data
- object-oriented (C++)
- data now contained within independent objects
- human oriented (Java, Python)
- garbage collection
- dynamic typing
Links to tools and further reading
HW Problem
- docstrings
- doctests, unit testing, Test-Driven Design (TDD)
pydemo.py demo2
- everything is an "object"
- yes, even a simple integer has a lot of moving parts !!
mandel_weave.py
- compare versions of getpts
- C 100X faster than Python
QnA - questions from students
- python-variables.htm
- dynamic_typing.txt
- mutable_args.py
- calling_methods.py