ModernJava icon indicating copy to clipboard operation
ModernJava copied to clipboard

A more conceptual introduction to the structure of (procedural) program

Open hallvard opened this issue 7 months ago • 3 comments

I miss a more conceptual presentation of what a program is. One approach is introducing it by means of recipes, e.g. for cooking, as metaphor and explain how the main elements are present in a program:

  • statements - steps that are performed reach some goal, often operations on data (- conditions and loops also exist in cooking!)
  • data - the stuff that is operated on
  • types - the rules for what is allowed to do with various kinds data, crucial for ensuring the code makes sense
  • functions - reusable parts that encapsulate a set of steps
  • ... interfaces, classes and inheritance may also be "explained" this way, but that should wait for later The aspects of the metaphor that don't fit, are also interesting, e.g. digital data is discrete, food is not, e.g. how does blending ingredients carry over to computer code. Data can be copied, food cannot, etc.

Statements are introduced early, to explain how program execution proceeds. However, expressions are just as fundamental and is also needed for understanding how statements are executed. I agree you cannot go into too much detail early of all the ways expressions are composed, but I think it should be exemplified in the context of print (the stuff inside parenthesis is "evaluated" first, e.g. sum of two numbers). With expressions you also need to explain the concept of type and how it is crucial for ensuring meaningful and correct code. Expressions are useful for arguing for variables, to split it up and reuse results.

hallvard avatar May 27 '25 20:05 hallvard

Would a few sections like https://javabook.mccue.dev/hyrums_law be an adequate solution?

bowbahdoe avatar May 27 '25 21:05 bowbahdoe

I am cognizant of at least a few limitations in form that the book has - this kinda bumps into one of them. Really i'd want to take the mechanics order and turn it into an actual curriculum where explanations / metaphors like this would fit in

bowbahdoe avatar May 27 '25 21:05 bowbahdoe

Introducing a metaphor may help gaining an intuition about what programming is, providing detailed (enough) instructions for making some machine perform some task. Elements of the metaphor can be revisited later, e.g. when introducing methods for abstracting and reusing steps. The section you refer to above is more a reflection on software development, than something helping you to understand the mechanics of java. That has it's place, but a different purpose.

BTW, the material for the course I taught is here: https://www.ntnu.no/wiki/display/tdt4100 (in Norwegian, but google translate works pretty well). Note that it followed a one-semester Python course, so is necessarily different from your book. When commenting, I'm envision how I'd approach it as the first programming course, rather than a follow-up to a first course (using Python).

hallvard avatar May 27 '25 21:05 hallvard