A tale of three programs

Gerard J. Holzmann · IEEE Software · 2017

A look at the generation of prime numbers offers a cautionary tale about the perils of premature optimization. We can code this in any reasonable programming language, and in quite a few unreasonable ones as well. It can be fun to express the algorithm in Python, C, C++, Scala, or Go, or even in scripting languages such as Tcl or Awk. And, yes, I confess that I've tried most of these, including Awk. Each language offers different features that can simplify the job or make it more interesting. For our current purpose, it'll suffice to stick to just plain old C.In a first attempt, we might come up with the version in Figure 1, which assumes that we provide the value of N in some other way-for example, with a macro directive to the C compiler.

Read the paper · More papers on PaperTik