Send Close Add comments: (status displays here)
Got it!  This site "www.robinsnyder.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.
Some fallacies in programming and teaching beginning programming that can be avoided before becoming a learned habit
by RS  admin@robinsnyder.com : 1024 x 640


1. Some fallacies in programming and teaching beginning programming that can be avoided before becoming a learned habit
Programming fallacySome fallacies in programming and teaching beginning programming that can be avoided before becoming a learned habit.

There were too many to include all of them. A subset was selected. Relevance:

2. Teaching
[chairs, computer science vs. business]

Information sign More: Teaching

3. ASCUE publications
ASCUE logo


Information sign More: ASCUE publications

4. Abstract
A programming fallacy is something about programming that many people believe is true, but is not actually true. For various reasons, many of these fallacies get taught in beginning programming courses. Eventually, the student needs to realize this and change how they do programming before they start teaching new students the same fallacies. Some of these will be covered with examples and how one might integrate the ideas into a beginning programming course (as done by the author). Understanding the general nature of the fallacies is useful for anyone working with programmers, managing programmers, etc. The (now retired) author, with a PhD in computer science in the area of applied programming language theory, has spent many years teaching in academia, doing software research and development in industry, and, in the process, writing about a thousand pages of code each year for useful programs, small and large, in many different programming languages.

5. Programming fallacies
Programming fallacyTruth: Programming fallacies, once learned, are hard to unlearn.
A programming fallacy is something about programming that many people believe is true, but is not actually true. For various reasons, many of these fallacies get taught in beginning programming courses. Eventually, the student needs to realize this and change how they do programming before they start teaching new students the same fallacies.

6. Lies
Lies and truthsThere are a terrible lot of lies going about the world, and the worst of it is that half of them are true. Winston Churchill (British statesman)

So how does one determine what is true and what is not true?

Information sign More: Winston Churchill

7. Truth types
For most purposes, the following are considered categories of truth. Levels of truth

8. Learning
New way Old wayThere is only one thing that is harder than learning something new.

What is it? The only thing that is harder than learning something new is unlearning something old.

Confirmation biasThis can be seen as a "confirmation bias". Everyone has it.

9. Fortran
In the 1970's, John Backus told programmers to use functional languages (data driven) rather than Fortran (code driven).

BNF = Backus-Naur Form grammars are named for Backus.

They laughed at and ignored him. Who is this John Backus anyway to be telling "us" what to do?

Information sign More: The Fortran programming language
Information sign More: John Backus

10. Unlearning
Perfecting oneself is as much unlearning as it is learning. Edsger Dijkstra (computer scientist)

A common saying that applies here is the following. Old habits die hard.

Information sign More: Edsger Dijkstra

11. Try the following
Qwery vs. Dvorak keyboard layoutTry the following.
Indentation is important but you need more than good indentions.

12. Tricks
No thinking any timeYou cannot teach an old dog new tricks. One should not use programming "tricks" except when necessary and then they should be well documented/commented.

13. CS: Code tricks
TrickOne should not use coding "tricks" unless necessary. Sometimes such "tricks" are necessary.

When necessary, such "tricks" should be documented/commented appropriately. Bad comments explain the code or overly explain the algorithm used, etc.

In general, KISS = Keep It Simple Stupid. This is line with Occam's razor, also known as the "law of parsimony".

Information sign More: CS: Code tricks

14. Fun and coding
Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program. Linus Torvalds (Finnish-American software engineer who created what is called Linux)

Information sign More: Linus Torvalds

15. Personal projects
[comment on the typical student CMS = Content Management System. as a TPS = Transaction Processing System]

16. Text formatter system
Format all

17. Source examples
Chapter model Embedded code model Separate code
Chapter model Embedded code model Code model
[slide user interface demo, UI state, content changes]

18. Source to target languages
Source to target languagesnLua, PHP, Python
JavaScript, Java, Kotlin
Bash, Batch, PowerShell
PostScript, Forth, Perl
R, SQL, XUL, AHK
ASP, ASPX, VBA, VBS
C, D, C++, C#, Rust
Go, Julia, Pascal, Ruby
Clojure, Haskell, F#
Racket, Scala, XSLT
Erlang, Prolog

19. Text formatter system
The text formatter system can format itself.
 ▶ 
 + 
 - 
 1. Old Python formatter - Sprint 
 2. New Python formatter - Python 
 3. New new Python formatter 
 4. Python formatter fixed point 



Movie: Back to the future part 2Keep in mind the "Back to the future" movie series and what Doc. Brown tells Marty.

20. Text decisions
In the formatting system, text decisions can be made at the following places. [demo on content change] [advice about UI (User Interface) decisions]

21. Source code
The same document source code can be formatted into the following. The same program code source code can be formatted into many different programming languages.

Code (in many languages using the same macro format) in the document can be run, with input from the document, to generate output that is included/embedded in the document.

22. Distributed output
All document and program diagnostic output can be clicked on and the user is taken to the source code or the source data (if applicable).

Debugging output is distributed and can appear on one of many target computer systems.

Mouse and keyboard are seamlessly connected via Synergy among 10 to 20 monitors (as needed).

23. Editor assistance
SciTE editorSource code change are made in the editor. A good editor is important. I use SciTE (based on SCIntilla) customized.

Some editors provide editor macro support to help automate tasks. An "issue system" can help in feedback of changes from the formatter to the editor - since user approval is needed. Example: case of identifiers.

24. Case sensitivity
A case sensitive notation means that the following names are all different.
DELETE dELETE DeLETE deLETE DElETE dElETE DelETE delETE DELeTE dELeTE DeLeTE deLeTE DEleTE dEleTE DeleTE deleTE DELEtE dELEtE DeLEtE deLEtE DElEtE dElEtE DelEtE delEtE DELetE dELetE DeLetE deLetE DEletE dEletE DeletE deletE DELETe dELETe DeLETe deLETe DElETe dElETe DelETe delETe DELeTe dELeTe DeLeTe deLeTe DEleTe dEleTe DeleTe deleTe DELEte dELEte DeLEte deLEte DElEte dElEte DelEte delEte DELete dELete DeLete deLete DElete dElete Delete delete

A case insensitive notation would consider the all of the above the same identifiers. In general, try not to use case-sensitive identifiers. I like case-retention with formatter macro issue support to make source consistent.

Information sign More: Case sensitivity

25. Servers
Servers help process the distributed user interface and processing. Cluster computing is used when needed.

26. Top down programming


Information sign More: Top down programming

27. Computer science
Programming fallacyFallacy: You should require beginning programming students to use top-down programming.
Problem solving in computer science is best done using top-down programming. Why do many computer science programs require beginning students to do "top-down programming"?

28. Top-down programming
Question to famous computer scientist Tony Hoare (British computer scientist) . Why is it so hard to teach (or require) beginning programmers top-down programming?

29. Top-down programming
Arrow illusion verticalYou cannot teach beginners top-down programming, because they don't know which end is up. Tony Hoare.

Problem-solving methodology:
Compare to Waterfall method, SDLC (Systems Development Life Cycle), etc.

Information sign More: Tony Hoare

30. Top-down programming
Programming fallacyFallacy: One should implement a computer program in a top-down manner.
The phrase "top-down programming" is deceptive. Have you ever tried to write a program "top-down"?

Do it once and you will see that it does not work very well. The phrase "top down programming" refers to a "top-down program design" and then a "bottom-up program implementation".

Many people try to do "top down programming" by doing "top-down coding".

Some teachers who have never really used the method will teach this fallacy to their students. How would you define a "programmer".

31. Divide and conquer
Divide each difficulty into as many parts as is feasible and necessary to resolve it René Descartes (French philosopher, mathematician and statistician)

Information sign More: René Descartes

32. Fix-it decision tree

 ▶ 
 + 
 - 
 1. First decision 
 2. Second decision 
 3. True positive 
 4. True negative 
 5. False positive 
 6. False negative 
 7. Decision tree 



Information sign More: Divide and conquer

33. Maze generation

 ▶ 
 + 
 - 
 1. Maze 1 
 2. Maze 2 
 3. Maze 3 
 4. Maze 4 
 5. Maze 5 
 6. Maze 6 
 7. Maze 7 
 8. Maze 8 
 9. Maze 9 
 10. Maze 10 
 11. Maze 11 
 12. Maze 12 
 13. Maze 13 
 14. Maze 14 
 15. Maze 15 

Web site:

In-line SVG (formatter Lua)
Lua to SVG
JavaScript and SVG
JavaScript and SVG and D3
R
Julia
Python
Java
C#

Information sign More: Divide and conquer

34. Divide and conquer
A divide and conquer problem solving method starts with a goal. At each point in the implementation, unit testing is added for each part and abstractions made as needed.

Information sign More: Divide and conquer

35. Top-down vs. bottom-up

 ▶ 
 + 
 - 
 1. Direct to goal 
 2. Indirect to goal 
 3. Missing goal 
 4. What goal? 

A top-down design insures one will get to the goal.

A bottom-up design may require extra work and may not get to the goal.

36. Divide and conquer: top-down and bottom-up

 ▶ 
 + 
 - 
 1. Top down 
 2. Backward chaining 
 3. Top down - flipped 
 4. Backward chaining - flipped 

There are various names for a top-down backward-chaining divide and conquer problem solving strategy.

Information sign More: Divide and conquer: top-down and bottom-up

37. Code development
Programming fallacyFallacy: Type in all your code and then make changes until it works.
Should a teacher help a student debug their code that they typed in, changed, etc., and the code does not appear to be working correctly? How about using stepwise/iterative refinement?

There is only one way to eat an elephant: a bite at a time. Desmond Tutu.

38. Code development

 ▶ 
 + 
 - 
 1. Code dev 1 
 2. Code dev 2 
 3. Code dev 3 
 4. Code dev 4 
 5. Code dev 5 

In order to develop code, a code development process is needed.

Most students write lots of code and then try to get it working.

This does not work very well.

Information sign More: Code development

39. Command line
There are tools for doing automatic compares. Described below.

Every beginning course should cover how to use the command line to complete an assignment. If the IDE = Integrated Development Environment stops working ,the student has a way to complete the assignment (on time).

Students should be able to install software without help.

40. Bash scripts
Logo: Bash for Bourne-again shellInstead of having students type everything at the command line, I created a Bash script system to make it much easier to edit,, compile and run. On every compile, the (one) source code (file) is uniquely saved. (Lots of research data for me).

Bash is short for "Bourne Again Shell" which is a play on words on Bourne, who created the better scripting system for Linux and the "Born Again" religious movement (made famous by President Jimmy Carter).

41. Change management
The SED = Shortest Edit Distance is a dual problem of the LCS = Longest Common Subsequence problem.
nematode-knowledge empty-bottle

LCS example
emt-ole

This algorithm is the basis of change management and regression testing systems.

42. Example in WinMerge
LCS example in WinMergeSome analysis/compare programs.
nematode-knowledge empty-bottle



Information sign More: Longest common subsequence

43. Exact math approximates reality

44. Exact math approximates reality
Missing blockA common programming fallacy taught to beginning students is to use floating point variables when it is not appropriate.

An exact mathematical solution involving real numbers (which are not really real, they are assumed to be real) is only an approximation.

Any floating point number (e.g., that represent real numbers) has an inherent rounding error.

Information sign More: Exact math approximates reality
Note: We are here ignoring discrete mathematics that involve only integers.

45. Slide rules
USMA slide ruleA slide rule (not slide ruler) was once used to do manual computations.

Whenever a slide rule is used, it is very evident that any computation involving real numbers is an approximation.

46. Mathematics and computation
What are the values of the following (using a computer program)?
1/10 1/10 + 1/10 1/10 + 1/10 + 1/10 1/10 + 1/10 + 1/10 + 1/10 1/10 + 1/10 + 1/10 + 1/10 + 1/10 1/10 + 1/10 + 1/10 + 1/10 + 1/10 + 1/10 1/10 + 1/10 + 1/10 + 1/10 + 1/10 + 1/10 + 1/10 1/10 + 1/10 + 1/10 + 1/10 + 1/10 + 1/10 + 1/10 + 1/10 1/10 + 1/10 + 1/10 + 1/10 + 1/10 + 1/10 + 1/10 + 1/10 + 1/10 1/10 + 1/10 + 1/10 + 1/10 + 1/10 + 1/10 + 1/10 + 1/10 + 1/10 + 1/10

Note: These are rational numbers, not irrational like √2 or transcendental numbers like π or e.

47. Mathematical point of view
Here is the mathematics result expressed as real (rational) numbers.
1/10 = 0.1 2/10 = 0.2 3/10 = 0.3 4/10 = 0.4 5/10 = 0.5 6/10 = 0.6 7/10 = 0.7 8/10 = 0.8 9/10 = 0.9 10/10 = 1.0


48. Lua program
Here is a simple Lua program to add values of 1/10 as 0.1.

The 17 places in the output is important to being exactly precise.

49. Program output
Here is the result from a computation point of view as the output of the above program.

Even when symbolic math can solve a problem, any attempt to compute real answers involves the same approximations.

50. Error accumulation
The difference is small at each step but the difference can add up to a significant amount over many iterations.

Note: One can fix this specific instance by using a fixed decimal notation, but that only works, in base 10, for numbers and increments that are multiples of 2 or 5, the prime factors of 10.

51. Chaos theory
Rounding errors need to be addressed in fields of computer science such as numerical analysis.

52. Chaos theory
Chaos book coverJames Gleick (American author and historical scientist) has written a very interesting book on the field known as "chaos theory" - a sensitive dependency on initial conditions. The field was accidentally discovered by the young French mathematician Henri Poincaré while attempting to find an exact mathematical solution for the three body problem.

Gleick, J. (1988). Chaos: making a new science. New York: Penguin Books..

Information sign More: James Gleick

53. Two and three body problem
Sun, Earth and MoonExact mathematics can solve the (idealized) two body problem such as the sun and earth or the earth and moon.

An exact solution for the (idealized) three body problem such as the sun, earth and moon has not been found.

Accurate weather prediction requires solving the (idealized) almost infinite particle system.

Information sign More: Two and three body problem

54. Quantum computing in brief
Bit and qubitQuantum computing:

Dunbar number [exponential speedup not clearly defined, like entanglement]qc-11

55. Quantum computing analogies
Bit and qubitQuantum computing analogies: pick the best way

56. Dollars and cents
Programming fallacyFallacy: Dollars and cents should be represented using floating point variables.
The general rule, sometimes taught, that if the number has a decimal point, it should be represented as a floating point variable does not hold for dollars and cents. Rule: Convert dollars and cents to cents, do the arithmetic, then convert back into dollars and cents (for display purposes). This distinction needs to be carefully handled in languages such as JavaScript and Lua which do not have integer variables.

The approximation issue involves floating point division so every such division needs to result in an integer value.

57. Numbers
Programming fallacyFallacy: Social security numbers and phone numbers should be represented using integers.
Phone sign - blueHow should social security numbers and phone numbers be represented? They appear to be numbers. That is, integers.

Are you ever going to add, subtract, multiply or divide these values? If not, use text. Ask your self the following question. If not, represent them using text. Note:

58. Real numbers
3. 1415926535 8979323846 2643383279 5028841971 6939937510 5820974944 5923078164 0628620899 8628034825 3421170679 ...

Chaitin states in his book Meta Mathematics that Émile Borel, in 1927, "pointed out that if you really believe in the notion of a real number as an infinite sequence of digits 3.1415926..., then you could put all of human knowledge into a single real number", Chaitin refers to this Borel number concept as "Borel's amazing know-it-all real number".
Information sign More: Émile Borel

59. Single entry single exit blocks
Single-entry single-exit blocksSESE (Single Entry Single Exit) code blocks are important for program correctness and understanding and reasoning about the behavior of program code.

Almost any group of contiguous statements can be (mentally) considered a block.

KISS = Keep It Simple Stupid.

Information sign More: Single entry single exit blocks

60. Begin and end block style choices
There are many styles for indentation using curly braces. Pascal used begin and end blocks. Modula-2 removed the begin. Lua followed.
In programming, you need more than good indentions.

61. Screen space
ScreenAs one writes bigger programs, a limiting factor in working with code becomes how many contiguous lines one can see on the screen at one time.

Toggling blocks on and off and remembering what is there is tedious and does not really help solve the problem.

62. Table
How many screen lines are required for various indentation styles for the "if then else" construct for condition b?
common style another style my style Go style Python style
6 lines 4 lines 4 lines 3 lines 2 lines
... if (b) { ... } else { ... } ...

... if (b) { ... } else { ... } ...

... if (b) { ... } else { ... } ...

... if (b) { ... }else{ ... } ...

... if b: ... else: ... ...

[indent demo in editor]

63. My style

... if (Condition) { ... } else { ... } ...

My style, which I started using many years ago, is, essentially, the same style used by Python, Lua, Modula-2, and some others. That is, the open curly brace can be visually omitted, the ending one can be visually omitted (since indentation provides that cue), and fewer expensive screen lines are used (than other styles).

64. Another style

... if (b) { ... } else { ... } ...

This style distracts the eye with the ending curly brace. The popular language Python shows that this ending brace is not needed and, in languages that do need it, it can be "hidden" from the eye with the previous style.

65. Another style

... if (b) { ... } else { ... } ...

This style requires two more lines than the previous styles.

66. Programmed indentation
It is not hard to write a small program to perform (or update) indentation using simple rules. Note: Provided a consistent style is used to start.

Future topic Details are left as a future topic.

67. Control flow charts
Flow chartAn algorithm is a precise step by step method for solving a problem. A control flow chart (or flaw chart) is a pictorial form of an algorithm. Flowcharts are difficult to draw, process, and update. Flowcharts do not easily scale up to handle large programs.

Control flow charts went out of style in the 1970's, but people continue to use them. Avoid flow charts. Data flow (and other) charts are still very useful.

Information sign More: Control flow charts

68. Flaw charts
Programming fallacyFallacy: Control flow charts are a good way to specify algorithms.
Avoid flaw chartsA flow chart has the following properties.

69. Useful charts
Logo: Unified modeling languageThere are many types of useful charts such as UML (Unified Modeling Language) charts.

Sequence diagram for submission Control flow charts are not useful. Instead, use pseudo-code.

[UML jobs, Alan Kay on bricklayers]

Information sign More: Control flow charts

70. Pseudo-code for polygon area
Get units and number of points Set total area to 0.0 FOR EACH pair of adjacent points\ (x1,y1) and (x2,y2) DO IF the pair is the first pair THEN Set the base (x0,y0) to (x1, y1) ELSE Calculate triangle area of points\ (x0,y0) , (x1,y1) , (x2,y2) Add area to total area END IF END FOR Output total area of the polygon


 ▶ 
 + 
 - 
 1. Start with 6 nodes. 
 2. Process from 1 to 6. 
 3. Node 1. No triangle yet. 
 4. Node 2. No triangle yet. 
 5. Node 3. Triangle area of 1 2 3. 
 6. Node 4. Triangle area of 1 3 4. 
 7. Node 5. Triangle area of 1 4 5. 
 8. Node 6. Triangle area of 1 5 6. 

71. Musical analogy
C scaleProvide the pseudo-code to the student in the first course.

Clefs Students learn with examples of how to do things.

Information sign More: Control flow charts

72. Course assignments
Example: Pseudo-code for determining the area of a polygon.

Node 5. Triangle area of 1 4 5.This is an end-of-course goal. Work back from goal to previous assignments (top-down, backward chaining) to get subgoals. Assignment sequences are designed (by the teacher) top-down. Assignments are done (by the student) bottom-up.

73. Programming course
An introductory programming course should emphasis both ideas and mechanics of programming, but not require a high level of intelligence as in requiring the design of solutions for problems. My opinion (since about 2000): The introductory programming course should be the same for all majors. After that course, the student can decide which direction to take, provided the registrar and departments can handle such changes.

Information sign More: Control flow charts

74. Making code run fast
Programming fallacyFallacy: You should make your code run fast.
FASTHere are Jackson's rules of code improvement (to run faster or take less space).
Try to make your code clear as to correctness. If it does not have to work correctly, I can make the code as fast as you want.

75. Fast code
Book: Writing efficient programsA CS student takes courses on simple ways to make code reasonably fast. Making code fast has issues. The same remarks hold for making code take less space.

Before spending time making code fast, or taking less space, get the approval of the manager. [opportunity cost]

Information sign More: CS: code improvement

76. Everything in the program is important
Programming fallacyFallacy: In a well-written production program, every part of the program is important.
In a first programing course, every part of a program code assignment should be important. If not, it should be removed and the program should continue to work as desired.

This rule can be (and should be, at times) violated in larger software systems. Why?

77. Summary
Some common programming fallacies have been presented. Many more were omitted.

78. Questions, comments
Questions and comments and more information. [circle back]

79. End of page

by RS  admin@robinsnyder.com : 1024 x 640