From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Things that OO programming lacks Date: Mon, 17 Nov 2014 21:44:32 +0100 Organization: cbb software GmbH Message-ID: References: <10d9w.55626$8w1.22302@fx12.iad> <150er0b62wsh3$.1xabmp81w5kdw.dlg@40tude.net> <1azsoc77wjhmi$.1grmnnlq033tz.dlg@40tude.net> <5yzci4a8snfg.1dfsqjyvneeym$.dlg@40tude.net> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: wfRpp7ltpEWhI2na6kgpfA.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:23487 Date: 2014-11-17T21:44:32+01:00 List-Id: On Mon, 17 Nov 2014 12:21:42 -0700, Shark8 wrote: > On 17-Nov-14 10:28, Dmitry A. Kazakov wrote: >> FSM are proven to be extremely >> complex to use, error-prone and unmaintainable. That is because states are >> as uncomposable as events are. If you add new or remove old states you are >> in deep trouble. > > Not really; in Ada we'd just say: > > Type Event is ( 'a', 'b', 'c', 'd' ); > Type State is ( Start, middle_1, middle_2, Stop ); > > Type Transition_Table is array (Event, State) of State; > > Type FSM(<>) is private; > Function Create( Transitions : Transition_Table ) return FSM; > Procedure Do_Event( State_Machine : in out FSM; Action : Event ); > > private > Type FSM(Transitions : not null access Transition_Table) is record > Current : State:= Start; > end record; > > -- in the Body ... > > Function Create( Transitions : Transition_Table ) return FSM is > ( Transitions => New Transition_Table'(Transitions), others => <> ); > > Procedure Do_Event( State_Machine : in out FSM; Action : Event ) is > begin > case Action is > when others => null; -- Attach particular/special actions here. > -- Also allow Ada to do case-coverage where > -- possible. > end case; > > State_Machine.Current:= > State_Machine.Transitions(Action, State_Machine.Current); > end Do_Event; In Ada you can implement Post-Turing machine in few lines. Should we run to redesign everything in the tape language? However my personal favorite would be Brainfuck, it should be 100-200 lines in Ada. Have fun! -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de