Re: Retired programmer wants to learn programming



In article <dsfa09$g65$1@xxxxxxxxxxxxxxxxxxxx>, kers@xxxxxxxxxx says...
Gerry Quinn wrote:

Wikipedia seems to agree with me, on the face of it:
"In computer science, self-modifying code is code that modifies itself
on purpose.

Well, see, this description doesn't seem to be terribly well-founded.
It would make accidental modifications not "self-modifying code", which
is an ... interesting ... choice of views.

I think you are engaged in evasion. The obvious interpretation of the
above is that the expression "self-modifying code" is not intended to
include bugged code that trashes memory, etc.

But I guess a quibbler can always find another quibble.

Self-modifying code is quite straightforward to write when
using assembly language (taking into account the CPU cache).

Yes.

It is also
supported by some high level language interpreters such as SNOBOL4 or
the Lisp programming language."

Well ... neither Snobol4 nor Lisp /require/ an interpreter; and there
are several widespread Lisps which differ in this regard; the three I
can name off the top of my head are Scheme, Common Lisp, and Emacs Lisp.

Also, Pop11 - which is on all extant implementations a compiled language -
has what you are calling self-modifying code.

That would make the sentence above wrong, then, if it had used the
words "otherwise only" instead of "also". It might have been better if
it had included the words "for example".

So the description doesn't do a good job, which suggests ...

....that someone propose a better one, preferably with some degree of
authority?

But your "so" does not appear justified, given that you imply that the
assertion is incorrect rather than incomplete.

If I am interpreting it right, that suggests my definition is not at
all idiosyncratic.

... that this inference isn't well-founded, quite apart from whether or
not Wikipedia well-reflects the usage of the community.

Usages of this kind can be reconsidered when found to be misleading.
Clearly more than one community is involved, and 'self-modifying code'
is not a phrase whose usage seems to have ever been sealed in stone
anyway. At least Wikipedia tries. Encyclopaedia Britannica doesn't
mention it at all. Maybe there's some dictionary / encyclopaedia of
programming / authoritative text that you can point to?

Not if the "widespread" use is of the "special cases". For example, if
you claim that higher-order functions count as self-modifying code
(a claim that, frankly, I find bizarre, but I'll let that pass for the
moment) you'd also have to claim that they're not one of the special
(good) cases, and support that claim in some way.

Why do you think they ARE a special good case?

Because they don't have the property of being hard to understand and
non-productive, of course.

I don't know where you pulled "non-productive" out of. And "hard to
understand" is also somewhat misleading. What matters is whether a
methodology produces code that is hard to understand.

That looks like evading the issue to me. Compilers always generated
code, and nobody objected. Nobody said self-modifying code is
necessarily a bad idea in all cases.

In which case, saying that something "is" self-modifying code doesn't
make it a bad thing - although the argument you appear to be advancing
(X is [equivalent to] self-modifying code, therefore X is a bad thing)
appears to rely on it.

No, it implies that it may be a bad thing in some circumstances. And
it is. Code that is generated by a program is invisible to the
programmer, because it doesn't exist until runtime. That is the
obvious problem with self-modifying code. Templates in C++ have the
same problem. (Self-modifying machine code has an additional problem -
it is not portable, and it adds an extra language to the mix.)

It may be that in many cases there are mitigating circumstances in
which self-modifying code is actually clearer than the alternatives.
In those circumstances, the use of self-modifying code is a good thing.

And if self-modifying code is the most efficient way to do something,
or to make libraries with desirable properties, it is a good thing.

Once code is fully written, debugged, and cleared to be used forever,
its structure does not matter except to maintainers. It is irrelevant
that linkers modify code, for example.

I would make an analogy with templates in C++. These are a powerful
tool for creating libraries. But template metaprogramming is in
general, bad practice except for special uses. The reason is the same
as with self-modifying code - obscurity.

- Gerry Quinn



.



Relevant Pages

  • Re: Retired programmer wants to learn programming
    ... Self-modifying code is quite straightforward to write when using assembly ... language. ... Lisp supported SMC in the sense that is not disputed. ... a function definition. ...
    (comp.programming)
  • Re: Retired programmer wants to learn programming
    ... If you think the distinction is ... self-modifying code is code that modifies itself on purpose. ... language. ... Lisp supported SMC in the sense that is not disputed. ...
    (comp.programming)
  • Re: Retired programmer wants to learn programming
    ... If you can create and execute a function X, ... Self-modifying code /modifies/ itself so that it does something ... being exposed as equivalent to a programming practice that has often ... code is quite straightforward to write when using assembly language ...
    (comp.programming)
  • Re: C++ sucks for games
    ... Self-modifying code is one example. ... > to generate enthusiasm for a programming language. ... But there's lots of finished projects written in Lisp. ... > interested in programming than in shipping software. ...
    (comp.lang.cpp)
  • Re: C++ sucks for games
    ... Self-modifying code is one example. ... > to generate enthusiasm for a programming language. ... But there's lots of finished projects written in Lisp. ... > interested in programming than in shipping software. ...
    (comp.lang.lisp)