Thinking in C and *nix (CSC 295/282 2014S) : Outlines
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] [FAQ] [Teaching & Learning] - [Calendar]
Current: [Outline] [EBoard] [Reading] [Lab] [Assignment]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines]
Reference: [EBook] - [ISO] [GNU Coding Standards] [GCC Documentation] - [TAoUP] [Make3]
Related Courses: [CSC 295 2013S]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker]
Held: Thursday, 23 January 2014
On to Outline 02 - Some Basic Tasks and Corresponding Tools.
Summary
We begin the course with an overview of some important principles and a few basic exploratory exercises.
Related Pages
Overview
Administrivia
This course is an extension of a seminar I ran in spring 2012 and that students asked me to repeat in spring 2013. That seminar was an outgrowth of things I observed and was told in CSC 362 2011F. In particular, the students in that course had much less familiarity with Makefiles than I would have liked and they told me that they generally did not use gdb when debugging their programs. I also observed that many of them were less than competent at dealing with memory leaks in their programs.
I do not blame my students for these flaws in their background. Rather, I expect that it's a consequnce of our decision to teach these issues relatively early in their careers and of different faculty opinions on what is important to teach. (I'm not sure that students who took 161 from me have substantially different backgrounds from those who took it from someone else.)
A few of the students asked me to spend some additional time teaching the things that I consider important (and that they quickly found were important). But we didn't have class sessions to spare. This class is therefore my attempt to address some of the weaknesses that I or the students observed. I hope to offer it every year.
Since I'm teaching this course, I get to impose my favorite practices on you. (I'll note that most of our students who leave Grinnell and go on to careers in programming find that I'm right about most of these things.)
You can take all of these with a grain of salt (or much more salt) when you're just writing quick-and-dirty code to get stuff done. Keep in mind that your typical goal is efficiency. You don't need to comprehensively test a few-line throwaway program. However, you should document the program, because you may want to do a similar thing later.
Unix and its descendents have been around a long time. They must be doing something right. So, what are the principles that have made nix so successful? Here are a few particularly important principles that many C/nix programmers follow. (We will expand upon these as the seminar continues.)
That first principle may seem a bit daunting. Do you always write programs to do tasks? No, you can certainly use programs. Here are ways you better do things "by program".
In addition to the general programming practices I've mentioned above, there are a few approaches that C programmers should master. (We'll add more as the semester goes on.)
There are also things one should learn about over the longer term, including threads, signals, and some common libraries (such as libraries for processing the command line). Due to limited time, we probably won't cover those in this course.
The following code comes from K&R (although it is reformatted). What does it do?
char *
fun (char *t, char *s)
{
while (*t = *s);
return t;
} // fun
Activity/Discussion
To illustrate my point that understanding memory in C is important, let's continue with a problem that a friend gave to me a while ago. He showed me the following fragment of C code.
x = malloc (...); foo (); bar (); free (x);
The program was crashing on the call to free.
Here are some things he discovered.
* If he removed the call to free, the program ran through
to completion.
* If he moved the call to free before the call to
bar, the program ran through to completion.
* He had no calls to free in bar.
What is likely to be wrong with his code?
Activity
Here are some tasks that I find it useful to think about. They illustrate some kinds of tasks that people often find they have to do and give you the opportunity to explore different approaches. For each problem, we'll make a list of ways to approach the problem (e.g., "Write a C program") and estimate the time each would take.
LastName,FirstName,Assignment,NumericGrade <img ... src="*URL*" ...>
img can have any capitalization (img,
IMG, Img, iMg, etc.)img and the
src. (That text cannot include a greater than sign.)Homework
This will appear online some time in the near future (probably over the weekend).
Repository: https://github.com/Grinnell-CSC282/hw1
Read chapter 1 of Raymond to get a deeper understanding of the *nix Philosophy.
Find good solutions to any of the tasks we did not solve in class. (That is, write a program or command to solve the task.) Put them in a folder with your name in the GitHub repository.
Make a list of *nix tools and utilities that you've found useful (or
even that you've just heard of). Try to categorize and add a short
description. Put them in the tools.md file in the repository.
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] [FAQ] [Teaching & Learning] - [Calendar]
Current: [Outline] [EBoard] [Reading] [Lab] [Assignment]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines]
Reference: [EBook] - [ISO] [GNU Coding Standards] [GCC Documentation] - [TAoUP] [Make3]
Related Courses: [CSC 295 2013S]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker]
Copyright (c) 2013 Samuel A. Rebelsky.

This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this
license, visit http://creativecommons.org/licenses/by/3.0/
or send a letter to Creative Commons, 543 Howard Street, 5th Floor,
San Francisco, California, 94105, USA.