C Programming Tools Lectures: May/June 2019
d.white@imperial.ac.ukI have just given the third and fourth of these 4 first year lectures on C Programming Tools, building a toolbox of useful tools, and the craft skills to use them effectively, in order to make C programming easier.
In the lectures, I strongly recommend The Pragmatic Programmer by Hunt & Thomas. The woodworking metaphor and many inspirational tips comes from there. A few years ago, I wrote a review of this book in my Practical Software Development webpages, please find it here.
This year's brief for the lectures is given by the following syllabus, as each lecture is ready, we'll add a link here to the lecture materials (slides and examples tarball):
Lecture 1: Thursday 23rd May 2019, noon-1pm, room 308
- Intro: Pragmatic programming, toolbox approach.
- Editing: A quick review of what to expect from a decent programming environment, especially extendability, choose one and specialise.
- Compiling: Description of Make and work through an example in detail. Give tips on how you can build your own simple makefiles even for small projects. Give an example of CMake for larger projects.
- Multi-directory C projects, Makefiles and libraries, covering the include path, lib dir path, -lLIB syntax, one Makefile per directory.
- First Lecture Materials Here
Lecture 2: Thursday 30th May 2019, noon-1pm, room 308
The second of these lectures covers:
- Debugging: description and basic use of gdb.
- Memory leak detection: application of Valgrind to a leaky hash table example.
- Profiling: noone understands even their own code's runtime behaviour. Work through profiling example using gprof.
- Automatic Testing: Highlighting the importance of testing and describing the concepts of unit tests and TDD. 'make test'.
- Second Lecture Materials Here
Lecture 3: Thursday 6th June 2019, 11am-noon, room 308
The third of these lectures covers:
- Building your own tools - aka, what to do if the tool you want doesn't exist: consider building it yourself, to save time over the long term. Core principle: Spot patterns, bore easily, automate, save time!
- Build tools at a range of scales:
- Tiny: Build shortlived tools (eg Perl one liners or awk/sed/grep pipelines, or their C equivalents), short throwaway programs that you write in minutes, use for minutes and then discard. Examples: generating repetitive output from simpler input forms.
- Medium: Generating C prototypes automatically: a tool called proto that I wrote a long time ago to solve a problem that irritated me.
- Build/gather a collection of reusable ADT modules (hashes, sets, lists, trees etc), well tested, general purpose, that you know well.
- Building Large tools: Why not generate ADT modules automatically from Haskell style "inductive data declarations": my tool called datadec, and wider lessons: do you think "make" is amazing? it only exists because someone sat down and wrote it. You can do something like that too!
- Third Lecture Materials Here
Lecture 4: Thursday 6th June 2019, noon-1pm, room 308
- Building little languages easily by using parser generator and lexer generator tools (eg. the combination of Yacc/Bison, Lex/Flex, and datadec for Abstract Syntax Trees).
- Series of worked examples starting with a calculator, ending up with a tiny Haskell Subset.
- Code generator spits out C, so without noticing it we end up writing a compiler that translates a tiny subset of Haskell to C, along the way.
- Better yet, we only write ~15% of the code and our tools write the rest.
- Conclusions: use tools as much as you can. choose ones you like; become expert in their use. build a toolkit of trusted tools. Build your own tools where necessary. Define your own little languages, use parser generator tools to help.
- Fourth Lecture Materials Here
d.white@imperial.ac.uk
Updated: 5th June 2019Back to my Personal Pages. ![]()
![]()