Introduction to Scientific Programming in C++17/Fortran2008

Categories:

Recommended

Chapter 1 – Introduction

1.1 Programming and computational thinking

In this chapter we take a look at the history of computers and computer programming, and think a little about what programming involves.

1.1.1 History

In the early days of computing, hardware design was seen as challenging, while programming was little more than data entry. The fact that one of the earliest programming languages was called ‘Fortran’, for ‘formula translation’, speaks to this: once you have the math, programming was thought to be nothing more than translating the math into code. The fact that programs could have subtle errors, or bugs , came as quite a surprise to the earliest computer designers. The fact that programming was not as highly valued also had the side-effect that many of the early programmers were women. Before electronic computers, a ‘computer’ was a person executing computations, probably with a mechanical calculating device, and often these were women. From this, the earliest people programming electronic computers to perform these calculations were, usually mathematically educated, women. Two famous examples were Navy Rear-admiral Grace Hopper, inventor of the Cobol language, and Margaret Hamilton who led the development of the Apollo program software. This situation changed after the 1960s and certainly with the advent of PCs1.

1.1.2 Is programming science, art, or craft?

As the previous section argued, programming is more than simple translation of math into instructions for hardware. Could it be a science? There are certainly scientific aspects to programming:

  • Algorithms and complexity theory have a lot of math in them.
  • Programming language design is another mathematically tinged subject.

However, programming itself is not a science.

The term ‘software engineering’ may lead you to suspect that designing and producing software is an engineering discipline, but this is also not quite the case. There is no certification for software engineers, and there is no body of accepted techniques the way there is for civil engineering and such disciplines.

For a large part programming is a discipline. What constitutes a good program is a matter of taste. That does not mean that there aren’t recommended practices. In this course we will emphasize certain practices that we think lead to good code, as likewise will discourage you from certain idioms.

None of this is an exact science. There are multiple programs that give the right output. However, programs are rarely static. They often need to be amended or extended, or even fixed, if erroneous behavior comes to light, and in that case a badly written program can be a detriment to programmer productivity. An important consideration, therefore, is intelligibility of the program, to another programmer, to your professor in this course, or even to yourself two weeks from now.

1.1.3 Computational thinking

Mathematical thinking:

  • Number of people per day, speed of elevator⇒ yes, it is possible to get everyone to the right floor.
  • Distribution of people arriving etc.⇒ average wait time.

Sufficient condition ̸= existence proof.

Computational thinking: actual design of a solution

  • Elevator scheduling: someone at ground level presses the button, there are cars on floors 5 and 10; which one do you send down?

Coming up with a strategy takes creativity!

Exercise 1.1. A straightforward calculation is the simplest example of an algorithm.
Calculate how many schools for hair dressers the US can sustain. Identify the relevant factors, estimate their sizes, and perform the calculation.

Exercise 1.2. Algorithms are usually not uniquely determined:
there is more than one way solve a problem.
Four self-driving cars arrive simultaneously at an all-way-stop intersection. Come up with an algorithm that a car can follow to safely cross the intersection. If you can come up with more than one algorithm, what happens when two cars using different algorithms meet each other?

Looking up a name in the phone book

  • start on page 1, then try page 2, et cetera
  • or start in the middle, continue with one of the halves.

What is the average search time in the two cases?
Having a correct solution is not enough!

A powerful programming language serves as a framework within which we organize our ideas. Every programming language has three mechanisms for accomplishing this:

  • primitive expressions
  • means of combination
  • means of abstraction

Abelson and Sussman, The Structure and Interpretation of Computer Programs

  • The elevator programmer probably thinks: ‘if the button is pressed’, not ‘if the voltage on that wire is 5 Volt’.
  • The Google car programmer probably writes: ‘if the car before me slows down’, not ‘if I see the image of the car growing’.
  • . . . but probably another programmer had to write that translation. A program has layers of abstractions.

Abstraction means your program talks about your application concepts, rather than about numbers and characters and such.

Your program should read like a story about your application; not about bits and bytes.

Good programming style makes code intelligible and maintainable. (Bad programming style may lead to lower grade.)

The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague — Edsger Dijkstra

Category:

Attribution

Victor Eijkhout (2017-22), Introduction to Scientific Programming in C++17/Fortran2008, URL: https://www.apexcalculus.com/

This work is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0):  (https://creativecommons.org/licenses/by/4.0/).

VP Flipbook Maker

Share your work as attractive digital flipbook with Visual Paradigm Online Flipbook Maker! You can convert your work from other formats to flipbook. You can also choose to create a new book with the design tool. Try it now!