CSC 282.01, Class 03: Thinking in C and Unix, Revisited
Overview
- Preliminaries
- Notes and news
- Upcoming work
- Extra credit
- Questions
- C reading recap
- Binary search, revisited
- Thinking like a real programmer, revisited
- Sample *nix tasks
- Looking ahead to the shell
News / Etc.
- I’m using a new (well, new to me) site development system. If you notice things not working on the site (e.g., when the “Current Reading” link leads to nothing), please let me know. I’ll fix them as soon as I can.
- Homework tends to depend on what gets accomplished in class. I’ll email you the homework and reading before the weekend.
- One of you referred to last week’s class as “a roast”. That was not how it was intended. I wanted to make it clear that you are expected to (a) remember important things, like the running times of algorithms, (b) think on your feet (or, since you are sitting, on your …).
Upcoming Work
Forthcoming
Good things to do
- 11:00 a.m. Scholars Convocation! JRC 101. Go and learn.
- 4:15 p.m. Cool talk on computer graphics. Science 3821. Go and learn.
- Saturday, 6:30 p.m. High school large group speech showcase. High school auditorium.
- Meet the track this weekend.
Questions
C reading recap
- There are Makefiles, but they are confusing. Sam needs to write better instructions and give lectures.
- Compilation is a sequence of steps: Preprocessing, generate assembly (translation), assembly, link.
- We should follow coding standards (for this class, GNU coding standards). When multiple people code together, it enhances readability.
- The Schlemiel the Painter problem and Joel S writes much better than Sam.
- Good C program development leads to a variety of files, including headers, tests, Makefiles, and prayers.
- We should spend the time writing better tests.
Binary search, revisited
Lessons from looking at the code
- Please follow GNU style guidelines. Note that using
indentwill help a lot, particularly for those who have trouble understanding the guidelines.indenthas some strange choices on where comments belong. Deal.
- Sam uses
:1,$!indent - The Capital Octopus uses
gg=G, but they don’t care about nice looking code. - What belongs in a
.h?- Signatures of public procedures.
- That weird
ifndefstuff Sam uses. - Other includes.
- Documentation.
- Type definitions.
- Macros.
- Anything else you might want to share or specify.
- Use camelCase or snake_style, but not both. (GNU prefers snake_style.)
maindoes not belong in your utility code!
Fun code to explore
(int) floor (((double) n) / 2)- “Find the exact middle and then round down, then convert back to int.”
- “Find the quotient of n and 2.”
- A very complicated way to write
n/2. (In C, Java, Python2.) - Yes, this is one of those behaviors that is carefully specified
in the C standard, just as rounding behavior is carefully specified
in the Scheme standard.
- (round 1/2) => 0
- (round 3/2) => 2
&vals[halfint]- What’s the PEMDAS (precedence order) for C?
&(vals[halfint])vals + halfint- Remember: Brackets dereference