Send Close Add comments: (status displays here)
Got it!  This site "creationpie.com" uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.  Note: This appears on each machine/browser from which this site is accessed.
Programming abstractions
by RS  admin@creationpie.com : 1024 x 640


1. Programming abstractions
In programming terms, to abstract is to replace one or more parts of a program with a name that refers to the replaced parts (thus hiding the details). Here are some programming constructs that are used for abstraction.

2. Programming language work
Much of the work that I assign for programming language assignments follows the following general pattern. Here is the setup. Here is the requirement. By understanding A and B, including a lot of textual abstracting, one can then write/construct a program to do C.

3. Example programming abstraction
Consider the following pattern (which could go on more in an extended example).
Two times 0 is 0. Two times 1 is 2. Two times 2 is 4. Two times 3 is 6. Two times 4 is 8. Two times 5 is 10. Two times 6 is 12. Two times 7 is 14. Two times 8 is 16. Two times 9 is 18.

A good programmer would immediately visually recognize the pattern and, if asked, could write a simple program such as the following to output that pattern. Here is the C code [#1] Here is the output of the C code.
A not-so-good programmer would not see the pattern and might attempt the following.

Here is the C code [#2]
Here is the output of the Lua code.

4. Comparison in general
In both cases, the program has the same output.

The first program has less redundancy (repetition) and is considered the better program.

In general, the smaller the program that produces the same effect is considered the better program.

5. Comparison in specific terms
Specifically, the better program is smaller but also minimizes any non-computer-checked redundancy.

That means that any parameter or concept that is important in the program and that could be changed should be changeable in one and only one place.

Note: If the computer is checking the redundancy (and not a human) than that redundancy is not necessarily bad. (Backup systems are redundant but useful). And there is redundancy in a program that cannot be avoided (e.g., variables with the same name - when they represent the same or different memory locations).


6. Bloom's taxonomy
Bloom taxonomyBloom's taxonomy of educational objectives has a foundation of knowledge and remembering and a goal of abstract problem solving - evaluation and creating.

7. Musical analogies to programming
C scale Puzzle 2To help understand the relationship between computer science and coding, a musical analogy may be useful to help put the puzzle pieces together.

Information sign More: Musical analogies to programming

8. Abstraction

9. Abstraction
Abstraction is looking at similarities and ignoring differences.

Abstraction 1
To abstract is to take away from the essentials and thereby to ignore certain differences.
The similarity is what is the same. The difference is what is different.

Human brains are built for complex abstraction.

The Latin word "abstractus""take away from". In abstract art, something is taken away, something remains, one needs to then interpret what is meant or intended.

Information sign More: Abstraction

10. Abstraction and psychological chunking
Part of the process of abstraction is what Hofstadter calls "psychological chunking". Hofstadter, D. (1979). Gödel, Escher, Bach: An eternal golden braid. New York: Vintage Books., p. 285-287.

Hofstadter relates how Adriaan de Groot performed studies of expert and novice chess players in the 1940's.

Information sign More: Abstraction and psychological chunking

11. Chess chunking
Briefly, each was given a small amount of time to look at a chess board with chess pieces and then asked to reconstruct what they saw.

On board positions where pieces were placed such that they had realistic strategic meaning in a chess game, the beginners tended to make mistakes at random while the experts tended to place entire groups of pieces incorrectly, but with a somewhat similar strategic positioning. On the other hand, when the pieces were placed at random, the experts were found to be no better than beginners at reconstructing the board. One conclusion is that while the expert and the beginner see the same board, the expert chunks the information into a meaningful context. As such, the expert does not see bad moves.

12. Musical analogy, etc.
One would postulate that professional musicians can chunk entire phrases of music at a time, while beginning musicians may be stuck with one note at a time. And so on in other areas.

13. Programming language style
This same phenomena occurs in programming language notation. While the beginning programmer tends to be confused by rules of syntax, the experienced programmer is more concerned with semantics and can often, at a glance, take in an entire page of programming text, so long as it adheres to familiar guidelines of making us of white space such as blank lines and consistent indentation to reduce visual noise. Just like the expert chess player and the expert musician, the expert programmer simply does not see bad program syntax, greatly simplifying the task of programming.

14. Indentation rules
If you mix tabs and spaces, what looks good to you may not look good in other editors.


15. Good and bad style
Good style: Bad style:
main ... { while ... { if { } } }

main ... { while ... { if { } } }


16. Grouping and chunking parts of a program
Blank lines can be used to group parts of code that logically go together.

You should not use more than one blank line. It uses more rows on the valuable screen space and does not help much for chunking.

17. Consistent style
Use a visually consistent style. General rule: Do similar things in the same way.

18. Conditional statement
Avoid the single line if statement.
if (b) s1; else s2;

Always use the full if with braces and the else part if needed. Do not omit the braces.

Use:
if (b) { s1; } else { s2; }

Avoid:
if (b) s1; else s2;

For all advice: Unless you have a really good reason.

19. End of page

by RS  admin@creationpie.com : 1024 x 640