Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. State Machines - my brain won't do what I want it to

State Machines - my brain won't do what I want it to

Scheduled Pinned Locked Moved The Lounge
tutorial
34 Posts 21 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • honey the codewitchH honey the codewitch

    I'm trying to come with a simple article on building state machines. I figured it wouldn't be too complicated, nor should it be since I wanted the article to be accessible to beginners. The trouble is, I can't think of a simple example of a state machine that is real world at all, and I don't want to lead with something contrived because I also want to explain the "why" of state machines with a practical example. This shouldn't be very complicated. I've been writing state machines for various things since the mid 1980s. In all that time I must have done something simple, especially since I was coding on a 16-bit machine back in the beginning. Grrrr

    Real programmers use butterflies

    P Offline
    P Offline
    PIEBALDconsult
    wrote on last edited by
    #4

    I'll assume you mean finite state machines...

    honey the codewitch wrote:

    I don't want to lead with something contrived

    They're all contrived. I dunno, but now you have me wondering how close to a finite state machine my JSON reader is.

    honey the codewitchH 1 Reply Last reply
    0
    • honey the codewitchH honey the codewitch

      I've really done it. Ever since I wrote my GLR parser generator, which can create parsers that even parse human language I have run out of things to code. I jumped the shark. Now I've been slumming it writing small tips instead of whole articles.

      Real programmers use butterflies

      S Offline
      S Offline
      Super Lloyd
      wrote on last edited by
      #5

      I am having a slum in my motivation too... since I got stopped on my UI math problem... (like.. 3 years ago?) Although.. I started my app recently and got a few new ideas! :) But then, I started playing Assassin's Creed: Odyssey again! ^_^ I think the key here is, are there anything you want to learn? That's what usually start the creative juice again! ;) Like even now, every now and then, there is a new tech that popup at work that make do some more homework. Like Blazor, Blazor is cool. Though I am holding off for the official WebAssembly release now!

      A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

      honey the codewitchH 1 Reply Last reply
      0
      • S Super Lloyd

        I am having a slum in my motivation too... since I got stopped on my UI math problem... (like.. 3 years ago?) Although.. I started my app recently and got a few new ideas! :) But then, I started playing Assassin's Creed: Odyssey again! ^_^ I think the key here is, are there anything you want to learn? That's what usually start the creative juice again! ;) Like even now, every now and then, there is a new tech that popup at work that make do some more homework. Like Blazor, Blazor is cool. Though I am holding off for the official WebAssembly release now!

        A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

        honey the codewitchH Offline
        honey the codewitchH Offline
        honey the codewitch
        wrote on last edited by
        #6

        Yeah I thought about learning Blazor but I have little reason to do web dev anymore, except maybe writing blazor components for other people to use. Still, WebAssembly seems iffy to me to use for a production website, if only because I can't imagine the load times on a large blazor app given how WebAssembly works. Then again, if it's all demand loaded maybe it's not so bad, but I don't see how they can demand load parts of System.dll (or equiv) for example. Then again, I've never used it - only read about it and have a fair understanding of the general principle, being a more refined, evolved version of web based virtual machines compared to asm.js (which I'm familiar with)

        Real programmers use butterflies

        S 1 Reply Last reply
        0
        • P PIEBALDconsult

          I'll assume you mean finite state machines...

          honey the codewitch wrote:

          I don't want to lead with something contrived

          They're all contrived. I dunno, but now you have me wondering how close to a finite state machine my JSON reader is.

          honey the codewitchH Offline
          honey the codewitchH Offline
          honey the codewitch
          wrote on last edited by
          #7

          Heh @ implementing non-finite state machines inside an LBA finite state machine AKA a computer. I don't know if they're all contrived. I bet your JSON reader uses a state machine if it chunks (rather than reading the entire JSON stream at once) - mine is - I wrote one too because I wanted something fast for bulk processing.

          Real programmers use butterflies

          1 Reply Last reply
          0
          • honey the codewitchH honey the codewitch

            Yeah I thought about learning Blazor but I have little reason to do web dev anymore, except maybe writing blazor components for other people to use. Still, WebAssembly seems iffy to me to use for a production website, if only because I can't imagine the load times on a large blazor app given how WebAssembly works. Then again, if it's all demand loaded maybe it's not so bad, but I don't see how they can demand load parts of System.dll (or equiv) for example. Then again, I've never used it - only read about it and have a fair understanding of the general principle, being a more refined, evolved version of web based virtual machines compared to asm.js (which I'm familiar with)

            Real programmers use butterflies

            S Offline
            S Offline
            Super Lloyd
            wrote on last edited by
            #8

            Have a look.... This is NOT Blazor, but it's a Ginormous WebAssembly demo... [https://windowstoolkit-wasm.platform.uno/\](https://windowstoolkit-wasm.platform.uno/) My first page load is... indeed taking sometime.. :o Although.. For Blazor WebAssembly they do a lot of work on trimming down everything... And the runtime will be cached using HTML5 file access for longer persistance.. And app themselves are usually pretty small... I guess we shall see soon, the release ETA is sometimes this month! :)

            A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

            honey the codewitchH 1 Reply Last reply
            0
            • S Super Lloyd

              Have a look.... This is NOT Blazor, but it's a Ginormous WebAssembly demo... [https://windowstoolkit-wasm.platform.uno/\](https://windowstoolkit-wasm.platform.uno/) My first page load is... indeed taking sometime.. :o Although.. For Blazor WebAssembly they do a lot of work on trimming down everything... And the runtime will be cached using HTML5 file access for longer persistance.. And app themselves are usually pretty small... I guess we shall see soon, the release ETA is sometimes this month! :)

              A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

              honey the codewitchH Offline
              honey the codewitchH Offline
              honey the codewitch
              wrote on last edited by
              #9

              Yeah, my point was I don't see it scaling well for large or otherwise complex apps with a big codebase. If the US wasn't lagging behind in fiber-to-the-curb it would be more practical here because you wouldn't still have people on 3Mbps connections

              Real programmers use butterflies

              1 Reply Last reply
              0
              • honey the codewitchH honey the codewitch

                I'm trying to come with a simple article on building state machines. I figured it wouldn't be too complicated, nor should it be since I wanted the article to be accessible to beginners. The trouble is, I can't think of a simple example of a state machine that is real world at all, and I don't want to lead with something contrived because I also want to explain the "why" of state machines with a practical example. This shouldn't be very complicated. I've been writing state machines for various things since the mid 1980s. In all that time I must have done something simple, especially since I was coding on a 16-bit machine back in the beginning. Grrrr

                Real programmers use butterflies

                P Offline
                P Offline
                Peter_in_2780
                wrote on last edited by
                #10

                Most of the FSMs I've written were for low level communications protocols (think HDLC/X.25, SDLC/SNA). Never did implement the new-fangled TCP/IP. ;P One interesting side-effect of implementing some of the older ones (Bisync flavours, anyone?) was proving that the protocols as documented were incomplete. They needed a catch-all state "Human intervention required". Maybe a toy poll/response protocol? Two interacting FSMs, one for master, one for slave. Cheers, Peter

                Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012

                honey the codewitchH 1 Reply Last reply
                0
                • honey the codewitchH honey the codewitch

                  I've really done it. Ever since I wrote my GLR parser generator, which can create parsers that even parse human language I have run out of things to code. I jumped the shark. Now I've been slumming it writing small tips instead of whole articles.

                  Real programmers use butterflies

                  D Offline
                  D Offline
                  David ONeil
                  wrote on last edited by
                  #11

                  Make a tool to create languages...

                  The forgotten roots of science | C++ Programming | DWinLib

                  honey the codewitchH 1 Reply Last reply
                  0
                  • honey the codewitchH honey the codewitch

                    I'm trying to come with a simple article on building state machines. I figured it wouldn't be too complicated, nor should it be since I wanted the article to be accessible to beginners. The trouble is, I can't think of a simple example of a state machine that is real world at all, and I don't want to lead with something contrived because I also want to explain the "why" of state machines with a practical example. This shouldn't be very complicated. I've been writing state machines for various things since the mid 1980s. In all that time I must have done something simple, especially since I was coding on a 16-bit machine back in the beginning. Grrrr

                    Real programmers use butterflies

                    OriginalGriffO Offline
                    OriginalGriffO Offline
                    OriginalGriff
                    wrote on last edited by
                    #12

                    There are quite a few real-world examples if you think in overview what a FSM requires: 1) Inputs that brought the machine to this state 2) The current state of the machine and the outputs that arriving there generated 3) The new state the machine will have as a response to new inputs So: navigating a vehicle on an small island could be modeled as an FSM. A drinks vending machine. Traffic lights (sooooo simple, very small set of states). Voting systems (could get humorous). Good luck!

                    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony AntiTwitter: @DalekDave is now a follower!

                    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                    "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                    1 Reply Last reply
                    0
                    • P Peter_in_2780

                      Most of the FSMs I've written were for low level communications protocols (think HDLC/X.25, SDLC/SNA). Never did implement the new-fangled TCP/IP. ;P One interesting side-effect of implementing some of the older ones (Bisync flavours, anyone?) was proving that the protocols as documented were incomplete. They needed a catch-all state "Human intervention required". Maybe a toy poll/response protocol? Two interacting FSMs, one for master, one for slave. Cheers, Peter

                      Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012

                      honey the codewitchH Offline
                      honey the codewitchH Offline
                      honey the codewitch
                      wrote on last edited by
                      #13

                      That's an interesting idea. I'll consider it. It also made me think of another idea involving an asynchronous implementation of an HTTP request/response cycle.

                      Real programmers use butterflies

                      1 Reply Last reply
                      0
                      • D David ONeil

                        Make a tool to create languages...

                        The forgotten roots of science | C++ Programming | DWinLib

                        honey the codewitchH Offline
                        honey the codewitchH Offline
                        honey the codewitch
                        wrote on last edited by
                        #14

                        I've already created a lot of tools for building compiler front-ends. I even developed my own language (actually a subset of C#) for reasons. This however, would be too complicated for the examples I intend to present.

                        Real programmers use butterflies

                        D 1 Reply Last reply
                        0
                        • honey the codewitchH honey the codewitch

                          I've already created a lot of tools for building compiler front-ends. I even developed my own language (actually a subset of C#) for reasons. This however, would be too complicated for the examples I intend to present.

                          Real programmers use butterflies

                          D Offline
                          D Offline
                          David ONeil
                          wrote on last edited by
                          #15

                          You said you were bored. Think greater! A program for generating any language! :laugh: An 'inverse-parser' if you will! It could spit out anything, and each syntax could take experts hundreds of years to decipher (or you could make that your next project!) :laugh: :laugh:

                          The forgotten roots of science | C++ Programming | DWinLib

                          1 Reply Last reply
                          0
                          • honey the codewitchH honey the codewitch

                            I'm trying to come with a simple article on building state machines. I figured it wouldn't be too complicated, nor should it be since I wanted the article to be accessible to beginners. The trouble is, I can't think of a simple example of a state machine that is real world at all, and I don't want to lead with something contrived because I also want to explain the "why" of state machines with a practical example. This shouldn't be very complicated. I've been writing state machines for various things since the mid 1980s. In all that time I must have done something simple, especially since I was coding on a 16-bit machine back in the beginning. Grrrr

                            Real programmers use butterflies

                            CPalliniC Offline
                            CPalliniC Offline
                            CPallini
                            wrote on last edited by
                            #16

                            As Griff already suggested, a vending machine would probably fit the bill.

                            In testa che avete, signor di Ceprano?

                            1 Reply Last reply
                            0
                            • honey the codewitchH honey the codewitch

                              I'm trying to come with a simple article on building state machines. I figured it wouldn't be too complicated, nor should it be since I wanted the article to be accessible to beginners. The trouble is, I can't think of a simple example of a state machine that is real world at all, and I don't want to lead with something contrived because I also want to explain the "why" of state machines with a practical example. This shouldn't be very complicated. I've been writing state machines for various things since the mid 1980s. In all that time I must have done something simple, especially since I was coding on a 16-bit machine back in the beginning. Grrrr

                              Real programmers use butterflies

                              G Offline
                              G Offline
                              Garth J Lancaster
                              wrote on last edited by
                              #17

                              There was a QA a while ago about 'decoding' some data - the eventual solution was proposed using a RegEx - I was in two minds about it, I personally would have used a state-machine, or maybe it was a 'borderline case' (as opposed to me, 'nut case')

                              1 Reply Last reply
                              0
                              • honey the codewitchH honey the codewitch

                                I'm trying to come with a simple article on building state machines. I figured it wouldn't be too complicated, nor should it be since I wanted the article to be accessible to beginners. The trouble is, I can't think of a simple example of a state machine that is real world at all, and I don't want to lead with something contrived because I also want to explain the "why" of state machines with a practical example. This shouldn't be very complicated. I've been writing state machines for various things since the mid 1980s. In all that time I must have done something simple, especially since I was coding on a 16-bit machine back in the beginning. Grrrr

                                Real programmers use butterflies

                                R Offline
                                R Offline
                                Rage
                                wrote on last edited by
                                #18

                                honey the codewitch wrote:

                                a simple example of a state machine that is real world at all

                                Do you own a car ? Think about any car part that is based on electronics or electrical actors -> It runs a state machine. Embedded is full of state machines. Actually, state machines are the AI of embedded world.

                                Do not escape reality : improve reality !

                                1 Reply Last reply
                                0
                                • honey the codewitchH honey the codewitch

                                  I'm trying to come with a simple article on building state machines. I figured it wouldn't be too complicated, nor should it be since I wanted the article to be accessible to beginners. The trouble is, I can't think of a simple example of a state machine that is real world at all, and I don't want to lead with something contrived because I also want to explain the "why" of state machines with a practical example. This shouldn't be very complicated. I've been writing state machines for various things since the mid 1980s. In all that time I must have done something simple, especially since I was coding on a 16-bit machine back in the beginning. Grrrr

                                  Real programmers use butterflies

                                  Greg UtasG Offline
                                  Greg UtasG Offline
                                  Greg Utas
                                  wrote on last edited by
                                  #19

                                  An example that could grow into something non-trivial, but that everyone understands, is a set of four traffic lights.

                                  Robust Services Core | Software Techniques for Lemmings | Articles

                                  <p><a href="https://github.com/GregUtas/robust-services-core/blob/master/README.md">Robust Services Core</a>
                                  <em>The fox knows many things, but the hedgehog knows one big thing.</em></p>

                                  1 Reply Last reply
                                  0
                                  • honey the codewitchH honey the codewitch

                                    I'm trying to come with a simple article on building state machines. I figured it wouldn't be too complicated, nor should it be since I wanted the article to be accessible to beginners. The trouble is, I can't think of a simple example of a state machine that is real world at all, and I don't want to lead with something contrived because I also want to explain the "why" of state machines with a practical example. This shouldn't be very complicated. I've been writing state machines for various things since the mid 1980s. In all that time I must have done something simple, especially since I was coding on a 16-bit machine back in the beginning. Grrrr

                                    Real programmers use butterflies

                                    F Offline
                                    F Offline
                                    F ES Sitecore
                                    wrote on last edited by
                                    #20

                                    If you can't think of a real world example then maybe it's not something people particularly need to know about?

                                    1 Reply Last reply
                                    0
                                    • honey the codewitchH honey the codewitch

                                      I'm trying to come with a simple article on building state machines. I figured it wouldn't be too complicated, nor should it be since I wanted the article to be accessible to beginners. The trouble is, I can't think of a simple example of a state machine that is real world at all, and I don't want to lead with something contrived because I also want to explain the "why" of state machines with a practical example. This shouldn't be very complicated. I've been writing state machines for various things since the mid 1980s. In all that time I must have done something simple, especially since I was coding on a 16-bit machine back in the beginning. Grrrr

                                      Real programmers use butterflies

                                      Sander RosselS Offline
                                      Sander RosselS Offline
                                      Sander Rossel
                                      wrote on last edited by
                                      #21

                                      When I hear "state machine" I think of games. Maybe you could write something about that? Also, don't know if I used it right, but I once used a state machine for order processing. The order could go from "ordered" to "paid" and "paid" to shipped, but never "ordered" to "shipped", or something like that. It was a bit more complicated than that, but it's been a while so I don't remember, but it was something like that.

                                      Best, Sander sanderrossel.com Migrating Applications to the Cloud with Azure arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly

                                      F 1 Reply Last reply
                                      0
                                      • honey the codewitchH honey the codewitch

                                        I'm trying to come with a simple article on building state machines. I figured it wouldn't be too complicated, nor should it be since I wanted the article to be accessible to beginners. The trouble is, I can't think of a simple example of a state machine that is real world at all, and I don't want to lead with something contrived because I also want to explain the "why" of state machines with a practical example. This shouldn't be very complicated. I've been writing state machines for various things since the mid 1980s. In all that time I must have done something simple, especially since I was coding on a 16-bit machine back in the beginning. Grrrr

                                        Real programmers use butterflies

                                        T Offline
                                        T Offline
                                        Tim Deveaux
                                        wrote on last edited by
                                        #22

                                        How about an elevator. Or a set of elevators in a building, programmed to most efficiently seek a state of best efficiency to service the next floor request when at rest. ...er *puff* yeah... something like that...

                                        R Mircea NeacsuM F 3 Replies Last reply
                                        0
                                        • T Tim Deveaux

                                          How about an elevator. Or a set of elevators in a building, programmed to most efficiently seek a state of best efficiency to service the next floor request when at rest. ...er *puff* yeah... something like that...

                                          R Offline
                                          R Offline
                                          Rich Leyshon
                                          wrote on last edited by
                                          #23

                                          That takes me back a LONG time to my student days. It was an assignment I remember, writing something exactly like this in assembly on some 8 bit processor (6809 rings a vague bell). Can't remember how, but our programs could then be loaded into a board based computer connected to a miniature elevator for everyone to have a go at defeating other people's software. The tricky bit was deciding when to accept and when to ignore a request from a button push on a given floor or if e.g. someone presses a button to request a lift to take the up, then gets in and presses the button for a lower floor. Decisions would then be based on all the "in-lift" requests plus the "out of lift" requests plus the current direction of travel. Surprising fun and games for such a simple system.

                                          T K 2 Replies Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups