CS1 - Fundamentals of Computer Science An Introduction for Scientists and Engineers We are in the midst of a revolution - a fundamental change in the way scientists, engineers, and other technical professionals use computers. No longer do we need a professional programmer as an intermediary to write programs for us. Powerful personal computers and modern, high-level languages are making programming a vital tool for non-programmers. Like the word-processing revolution that made typists obsolete, there is a saving of time and money, but the impact of this revolution is much deeper, especially for those of us whose work depends on an "exploratory" or interactive kind of computing. Now we can write programs while staying focused on our project, and it is no more difficult than using a computer to write a technical report. === Focus on Fundamentals === This course differs from the standard introduction to CS in that there is less time spent on the complexities of languages and tools needed by professional programmers, and more on the fundamentals that are important to technical professionals who will be writing their own programs. After completing this course a student should have: 1) An excellent undertanding of high-level program design, and how to make complex problems simple. 2) A fundamental understanding of low-level operations, and how to get maximum performance in a computation. To reach these goals in a one-semester course, it is important to chose the right languages and methodologies. In the choice of languages there is a tradeoff of performance versus productivity. No one language is best in both areas. In our choice of methodologies, we put major emphasis on object-oriented programming. While many technical professionals never create their own custom objects, the methodology is so fundamental to modern programming, that we think it deserves a prominent place in an introductory course for all technical professionals. === Choosing the Right Languages === C is our choice for a high-performance language. For compact code to fit in an embedded system, or fast code to perform a scientific computation, C allows maximum control of machine-level details while still being portable across many different machines. Python is our choice for a high-productivity language. While not as popular as Java or C#, it is equally powerful and much simpler. Textbook examples are clear and concise. All CS texts claim to focus more on science than syntax. With Python, that really is possible. As an interpreted language, Python provides immediate feedback when each new statement or function is entered. Syntax can be learned with a quick set of "tutorial" exercises, before focusing on the topic of a chapter. Various "introspection" functions help students and busy professionals remember what they learned. This is a language students should find very useful in their later courses and careers. Python has an interface for embedding C-code inline. Students will learn to solve problems first with sketches and pseudocode, then refine the pseudocode to working, fully-debugged Python, and only then write low-level code in C for the few sections that really need high performance. We include a brief introduction to Java, just enough that students will be able to write simple programs and meet the pre-requisites for a second-year course in Java. Learning Java, C#, or any of the other "industrial" languages, is much easier once you have a good understanding of basic concepts. The Java section is optional. For students who will not be continuing with Java, we have several interesting and challenging projects using Python and C to solve problems from various areas of engineering and science. === Choosing the Right Texts === Zelle, "Python Programming: An Introduction to Computer Science", 2004, $36. An excellent introduction to computer science, with just the right emphasis on object-oriented programming. Excellent examples using graphics functions. Goldwasser & Letscher, "Object-Oriented Programming in Python", 2007, $73. Also an excellent introduction to computer science, a little more advanced than Zelle, but worth the effort for students who are serious about science and engineering. Nice appendix on the transition to Java. We'll probably try this text first, then drop back to Zelle if necessary. Kernighan & Ritchie, "The C Programming Language", 2nd ed. 1988, $43. The Bible on C, terse, but just what we need if we are using Python for the high-level topics, and C for the machine level. Hanly & Koffman, "Problem Solving and Program Design in C", 5th ed. 2007, $103. Best choice if using C for everything, including high-level programming. We will use it as a reference and source of examples. === Building Good Habits === Documentation and testing are boring and often neglected parts of writing a program. Python's "doctest" facility solves both these problems in a very elegant way. Tests that you run in the interpreter window during normal development can be copied directly into the "docstrings" at the beginning of each function. These doctests then serve as both documentation of what the function does and as built-in tests that run automatically every time the program is modified. Doctests are an excellent way to get students in habit of writing tests for every function. Often writing these tests *before* the function is written can clarify exactly what the function is supposed to do, and make writing the function easier. This is the essense of Test-Driven Design. Function headers with docstrings can serve as an "Interface Definition Language" for a large program following a "top down" design methodology. In fact, Python is a good IDL for projects in Java, adding more detail at each stage, with the final step being working Java code. Nice examples of doctests can be found at http://en.wikipedia.org/wiki/Doctest === Boosting Productivity === Python is ideal for students and non-programmers, and is surprisingly useful for professional programmers, who often find their productivity greatly increased. * "Why I Love Python", Bruce Eckel, Python Conference 2001, http://www.mindview.net/FAQ/FAQ-012 - Python 5-10 times more productive than Java! *"Why Python?", Eric Raymond, Linux Journal (May 2000). http://www.linuxjournal.com/article/3882 * "Java & Python, A Side-by-Side Comparison", Stephen Ferg, upd 2007-05-01, http://www.ferg.org/projects/python_java_side-by-side.html Many objections to Python disappear once you have tried the language. Experienced Python programmers don't worry about these things, but for those who need some discussion: * "Python: Myths about Indentation", Oliver Fromme http://www.secnetix.de/~olli/Python/block_indentation.hawk * "Strong Typing vs. Strong Testing", Bruce Eckel, 05-02-03, http://mindview.net/WebLog/log-0025 * "Python Answers", Bruce Eckel, 07-02-03, http://www.mindview.net/WebLog/log-0036 * "Static vs Dynamic", Bruce Eckel, 11-16-04, http://www.mindview.net/WebLog/log-0066 === Having Fun === Core Wars Buffer Overflow Attack === Blogger Comments === Excerpts from discussions on C and Python. "Write time-critical functions in C, and let Python deal with all the memory management, human interface, file management, command line arg parsing and all the messy bits ..." "Run As Fast or Faster Than The Rate At Which It Will Be Converted To Analog. Python and Java still don't replace C in this area. (Mainly audio, video, and high-speed mechanical control.)" "For real-time, you need deterministic memory management, and the native speed of C." "That's the sad fact; many of the kids being cranked out of schools today can't code their way out of a paper bag without a compiler/interpreter that does most of the dirty work for them." "Yes, there are pointers flying around, but they are out of sight, and managed by code that actually does things properly for you." "With a primitive language like C, we can actually see the "values" and "references" we are passing. Nothing is "under the hood". The concept is still helpful with Python, however, If we know that a call in Python is like call-by-reference in C, we will know that the caller's arguments are subject to modification, and we will be careful about passing any objects that must be protected."