Dynamic is Self-Modifying

Dynamic anything is the same as saying it is self-modifying.

Self-Modifying Code

Self-modifying code is hard to maintain.


Self-modifying code is hard to understand by reading only.  One has to watch its behaviour over time.

Flunk

My friend got a grade of 0% on an exercise in University because he excelled at doing what the professor wanted.


The professor asked us to write an efficient loop in assembler, that changed its behaviour half-way through.  We would be marked on efficiency of the result.


Most people wrote an if-then-else block of code.


My friend wrote code that poked itself and rewrote the loop instead of writing an if-then-else loop.


His code was, by far, the fastest (most efficient) code in the class.


He received a grade of 0% on the assignment.


The professor lectured us about self-modifying code as an explanation for my friend's low grade.

Other Forms of Self-Modifying Code

GOTOs

Static GOTOs are bad because they lead to unmaintainable code.


1st-class functions and closures are GOTOs on steroids.


CPS is GOTO-full programming.  


Unstructured.


Dynamic GOTOs.

Become

Become is a dynamic change in the behaviour of code.


Dynamic code sounds better than self-modifying code but is essentially the same thing.


Become can easily be replaced by StateCharts.  Or by a poor-man's version of StateCharts — switch statements.

Listener/Observer

The Listener/Observer pattern can lead to dynamic changes in the behaviour of code.


Listener/Observer sounds better than self-modifying code but is essentially the same thing.


Listening is a dependency.  


Dependencies should not be changed during runtime.


Listening should be made explicit (e.g. a line on a diagram, or, whatever).