On Tuesday, December 15, 2020 at 10:25:37 AM UTC+1, Anton Ertl wrote:
> Marcel Hendrix <
m...@iae.nl> writes:
> >On Monday, December 14, 2020 at 3:47:11 PM UTC+1, Anton Ertl wrote:
> >> Anyway, my takeaway from the workshop was that
> >> Factor's typing gets in the way rather than having a good effect.
> >
> >Do you remember any motivating examples of serious errors that are
> >caught by such a checker?
> I have had difficulties in debugging code where a lot of addresses of
> structures are flying around. It's no easy to see which address is
> which, and if the structures contain other addresses, I don't see it
> when looking at what the addresses point to, either.
>
> There are classic Forth approaches like testing each word individually
> that I did not do sufficiently for that code, IIRC because quite a bit
> of data needs to be built up before the words can be fully tested.
Actually, that is a real problem I encounter a lot with more ambitious
and longer living Forth projects (like my SPICE simulator). After a few
iterations datastructures get modified to add new features, and
inevitably bugs are introduced. At that point it is usually not obvious
anymore when and how a datastructure comes into existence.
(An example would be an internal list of circuit nodes with their attributes,
versus a list of the symbolic names of these nodes as used by the netlist.)
What I usually do is put a break at a point after such a structure is initialized,
and then debug on the commandline. It can be quite frustrating when
it takes a long time for the program to generate the necessary data,
especially when the Forth dies immediately after the bug manifests itself.
> I have been thinking about adding type knowledge to structures and
> structure access words in order to facilitate debugging such code, but
> have not taken action yet.
I don't see how these errors would be easier caught when types
are introduced. My experience is that the problem most often has to do
with time: the program wants to use data that is not created yet, or wants
to store data in a not yet created structure, or storing or retrieving depends
on yet another structure with an implicit temporal behavior.
Thinking about this suggests that something could be done with a sort
of dynamic 'validation' of structures, or by giving them an 'uninitialized'
property. I am not sure this would qualify as 'typing.'
What I see myself do for bigger programs is adding lots of seemingly
superfluous tests that give detailed error reports (file, line number, name
of excuting word, content of stack(s), suggestion for action) and that try
to prevent crashing before any meaningful output is generated.
And I couldn't survive without the word ^^ , which single steps the code
showing the active file and line number (my text editor can show line
numbers).
> In any case, a Forth type checker would have to know about structures
> to help in such cases.
>
> Other than that, type errors have not been a problem in Forth in my
> experience. I think the reason is that Forthers have a variety of
> ways to avoid such problems (e.g., testing individual words); people
> coming from languages with more typechecking may miss their type
> checker in Forth because they have not yet acquired these skills.
-marcel