Skip to content

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

Open
@hallvard

Description

@hallvard

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions