C Programming Tools Lectures: May/June 2018
d.white@imperial.ac.ukI have just given the fourth and final 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: Tuesday 29th May 2018, 11am-noon, 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 31st May 2018, noon-1pm, room 308
- 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 either gprof or valgrind profiling.
- 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 7th June 2018, noon-1pm, room 308
- 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 14th June 2018, noon-1pm, room 308
I have just given the fourth and final of these 4 first year lectures.This final lecture covers the following single topic: Making Code Generator Tools easier - autogenerating parser and lexers.
- 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).
- Worked example of 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 16% of the code and our tools write the rest.
- New thoughts on an alternative parsing technique.
- 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: 13th June 2018Back to my Personal Pages. ![]()
![]()