In article <f4aaff9dbf58ca3c0e5da7fe278b5a87@
www.novabbs.com>,
mhx <
mhx@iae.nl> wrote:
On Fri, 20 Jun 2025 5:36:05 +0000, minforth wrote:
>
Counter-example: a good number of my apps involve structs, arrays
and signal vectors in heap memory. Stack juggling? Absolutely not.
The code would be unreadable and a nightmare to debug.
>
Factoring in smaller code portions is often impossible because
you can't always distribute data, that inherently belongs together,
over separate words.
>
Then why factor, when with using named parameters = locals, the
code is already short, readable, maintainable, and bug-free.
>
Interesting questions. My experience says that arrays and vectors are
ok, but structs are dangerous, (especially?) when nested. In a 'C'
project that I contribute to, structs arbitrarily glue data together,
and then forwardly defined macros hide the details.
It is impossible to debug this code without tools to decompile/inspect
the source. It is very difficult to change/rearrange/delete struct
fields, because they may be used in other places of the code for a
completely different purpose. The result is that structs only grow
and nobody dares to prune them. The only remedy is to completely
start over.
I took over the maintenance of manx (that Marcel wrote) and
I gave up on maintenance because of the structs.
The following example uses mini objects.
A part is a subdivision of a musical score that is played on the
same instrument. A timeline is used to keep track of the focus
when the playing of the piece progresses.
Now look at Forth objects that generalizes CREATE/DOES>
Here the actions (methods) are directly linked to the
offset in the object ("struct"):
Note that mbeat !mbeat (mbeat) work on the same offset (0)
where an arbitrary value (_) is initialised (using comma `,).
These three words can be reordered with impunity.
The same applies to the TIED-group.
You could interchange the TIED-group with the mbeat-group
without affecting other parts of the program.
Methods of the real time "field" uses !mbeat, so this group
then must move after the beat-group.
m/note m/beat etc. are approcimately "fields", and can be
reordered among themselves.
\ -----------------------------------------------
\ The class of a time line of a part.
\ Each part has a time line, and then there is the real time.
class TIMELINE
M: mbeat @ M; \ Return current play TIME.
M: !mbeat 0 SWAP ! M; \ Initialise timeline.
M: (mbeat) M; _ , \ The timeline of this part.
\ The real time in TICKS is associated with the current midi time
\ and made the reference time.
M: reference-ticks @ M;
M: SET-TIME ! !mbeat M;
0 , \ Real time corresponding to mbeat = 0 .
\ \ The moment of the latest bar, in midibeats since the start.
\ M: latestbar M; _ ,
M: m/note M; _ , \ The current note duration in midibeats.
M: m/beat M; _ , \ The current beat duration in midibeats.
M: m/measure M; 0 , \ The current measure duration in midibeats.
\ The amount of semitones the playing is higher than the score.
\ Negative means lower.
M: TRANSPOSE M; 0 ,
\ Ratio between actual and formal note duration.
M: (ARTICULATION) M; 1 , 1 , \ Default : legato.
M: TIED-NOTES M; HERE 20 CELLS ALLOT !BAG \ A BAG with tied ``NOTE''s.
M: TIED! TRUE SWAP ! M; \ Next note must be tied.
M: UNTIED! FALSE SWAP ! M; \ .. must not ..
M: TIED? @ M; 0 , \ "This note MUST be tied."
endclass
>
Ask yourself why the Forth Scientific Library makes heavy use of
locals.
>
Because the original algorithms do.
Case in point the original manx from Marcel did not use too
many locals, in the new manx they are not used at all.
>
Of course things look different with simpler applications.
>
And then Einstein's famous quote spoils the fun.
The new manx is eminently servicable. There are version of
different (ARM) hardware where the lowlevel control is
completely different (Originally meant for the parallel port
in MSDOS). The instrument drivers are of course hardware
dependant, they are just plugged in.
The original instruments were percussion, where the note-off
from midi was ignored.
Later the organ came along, that uses the note-off midi messages,
without any repercussions on the architecture of the program.
Please note that I introduced many names, but not named
"local values".
>
-marcel
-- Temu exploits Christians: (Disclaimer, only 10 apostles)Last Supper Acrylic Suncatcher - 15Cm Round Stained Glass- Style WallArt For Home, Office And Garden Decor - Perfect For Windows, Bars,And Gifts For Friends Family And Colleagues.