Freelance software grandad
software created
extended or repaired
Follow me on Mastodon
Applications, Libraries, Code
Talks & Presentations
STinC++ rewrites the programs in Software Tools in Pascal using C++
I’ve reached the end of the chapter 1 and have written five programs:
For Kernighan and Plauger, each program has been progressively more complex than the last - a simple loop, then a variable, a conditional, then multiple conditions, and several types of loop. They have, through the course of their five programs, managed to show off all the fundamental features of Pascal. In contrast, I have done no such thing in my efforts with C++.
Thanks to the functions provided in the C++ standard library, I have little increase in code complexity for the first four programs. I might have had to get hold of some slightly bigger concepts - iterators, input and output as sequences you can iterate over - but once those are familiar, my wordcount
is no more complicated than where I started with copy
.
Things did get slightly hairier for detab
but not particularly so. There’s a little bit to grapple with around function objects, but nothing too strenuous. That I still haven’t written an explicit loop in C++ helps with understanding the code by eliminating what is essentially boilerplate.
It’s been fun! I’ve learned some new things already - about the tooling I’m using, and also about the C++ library itself. The idea of using std::transform
to massage a sequence of characters into a sequence of strings is, in retrospect, obvious but I hadn’t thought of doing anything like that before.
While I’ve hardly mentioned it, all the code has been written in test-first fashion. At this early stage in my progress through the book, I’m pretty much only dealing with a single function, the boundary cases are obvious, plus, in most cases, I’ve barely written any code. Nonetheless, I’d feel a bit icky just diving straight in and, even with code this straightforward, I have found and prevented bugs that might otherwise have eluded me.
On to chapter two!
Freelance software grandad
software created
extended or repaired
Follow me on Mastodon
Applications, Libraries, Code
Talks & Presentations