Click here to Skip to main content
15,914,013 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Windows C++: a bit shocked Pin
Bob100029-Jan-19 23:49
professionalBob100029-Jan-19 23:49 
GeneralRe: Windows C++: a bit shocked Pin
Richard MacCutchan29-Jan-19 5:38
mveRichard MacCutchan29-Jan-19 5:38 
JokeRe: Windows C++: a bit shocked Pin
raddevus29-Jan-19 5:41
mvaraddevus29-Jan-19 5:41 
GeneralRe: Windows C++: a bit shocked Pin
Richard MacCutchan29-Jan-19 6:17
mveRichard MacCutchan29-Jan-19 6:17 
GeneralRe: Windows C++: a bit shocked Pin
raddevus29-Jan-19 7:11
mvaraddevus29-Jan-19 7:11 
GeneralRe: Windows C++: a bit shocked Pin
Rick York29-Jan-19 13:31
mveRick York29-Jan-19 13:31 
GeneralRe: Windows C++: a bit shocked Pin
raddevus30-Jan-19 3:36
mvaraddevus30-Jan-19 3:36 
GeneralRe: Windows C++: a bit shocked PinPopular
kalberts29-Jan-19 9:24
kalberts29-Jan-19 9:24 
Actually, I pity that the mainloop didn't catch on as a programming model Smile | :)

I am not talking about the mainloop itself, but the idea of event-driven programming - designing and implementing your application as a state table: The FSM driver is 20-30 lines of code. Whenever something happens - an event - it indexes the 2D state table by the current state and the event, to find the action to perform and the next state. The state table is where the program logic is expressed.

The action part is application specific code, but you'd be surprise by how few different actions are required, and how simple and fucnctionally isolated they are. 95+ percent of traditional program flow control is replaced by the "next state" logic. In a properly designed FSM application, each state tansition and associated (when required; it often isn't) action is so rapid that there is very little need for any preemptive scheduling (which 16-bit Windows didn't have).

In a proper FSM design, event transition is conceptually instantaneous, from one consistent state to another consistent state, avoiding all racing conditions. "Synchronzing" is not a relevant concept. Complete error handling is very easy to achieve: For every emtpy state table entry, i.e. any state/event combination for which there is no well defined meaningful transition from the current consistent state to another consistent state, you fill in an error action. Any table entry that doesn't have a (normal or error) action filled in will glare at you, reminding you: You must handle this error!

To keep state tables to a moderate size, it is common to accept a few well defined "state variables" accessible for testing and setting from the action routines. In some FSMs, the logic of testing some of these variables are put into the state table: Each state/event entry may list a small sequence (usually no more than 3 or 4) alternate actions guarded by logical expressions on the state variables.

Probably the most complex protocol in the entire OSI protocol stack family, the X.225 Session Protocol, is described by 32 states, 80 events, 79 predicates and 34 transition actions. The 79 predicates can all be expressed as a one-line boolean expression. Most of the 34 actions fill less than 50 lines of code (assuming a proper service interface to the Transport layer). From an FSM modelling point of view, X.225 is a beauty! (I am not saying that the protocol is, I am talking about the modelling of it!)

The old Windows message loop model is ideally fit to this kind of modelling. That's what I am missing: That sort of modelling!

If I, anno 1985, had had the divine power to choose between steering the software world into OO or into FSM, I would definitely have chosen FSM! I still think so - maybe because I learned to code in a style that adopts at least 75% of the OO benefits even without a trace of OO language syntax. On a solid FSM foundation, that coding style becomes quite natural. It has been shown empirically that OO concepts certainly does not naturally lead to FSM style of thinking!

You can do FSM implementation style even within a traditional sequentially-algorithmic framework, if you can succeed in casting everything that happens into one homogenous "event" concept. (That can require some effort!) The major problem is that your co-workers probably has no clue about FSM modelling and want to cast ten minute computations into single state transition actions, and might challenge you into a fistfight if you don't accept it... Computer kids are not trained to do FSM today. That is a pity.

If after that fistfight you need to calm your nerves a bit, search up some old telecom guys. They know what FSM is all about!
GeneralRe: Windows C++: a bit shocked Pin
raddevus29-Jan-19 9:58
mvaraddevus29-Jan-19 9:58 
GeneralRe: Windows C++: a bit shocked Pin
Shuqian Ying29-Jan-19 11:19
Shuqian Ying29-Jan-19 11:19 
GeneralRe: Windows C++: a bit shocked Pin
Joe Woodbury29-Jan-19 9:36
professionalJoe Woodbury29-Jan-19 9:36 
GeneralRe: Windows C++: a bit shocked Pin
raddevus29-Jan-19 10:06
mvaraddevus29-Jan-19 10:06 
GeneralRe: Windows C++: a bit shocked Pin
Joe Woodbury29-Jan-19 12:13
professionalJoe Woodbury29-Jan-19 12:13 
GeneralRe: Windows C++: a bit shocked Pin
raddevus29-Jan-19 12:58
mvaraddevus29-Jan-19 12:58 
GeneralRe: Windows C++: a bit shocked Pin
Joe Woodbury29-Jan-19 13:12
professionalJoe Woodbury29-Jan-19 13:12 
GeneralRe: Windows C++: a bit shocked Pin
raddevus29-Jan-19 13:13
mvaraddevus29-Jan-19 13:13 
GeneralRe: Windows C++: a bit shocked Pin
CPallini29-Jan-19 10:57
mveCPallini29-Jan-19 10:57 
GeneralRe: Windows C++: a bit shocked Pin
Rick York29-Jan-19 13:33
mveRick York29-Jan-19 13:33 
GeneralRe: Windows C++: a bit shocked Pin
CPallini29-Jan-19 21:57
mveCPallini29-Jan-19 21:57 
GeneralRe: Windows C++: a bit shocked Pin
PIEBALDconsult29-Jan-19 15:09
mvePIEBALDconsult29-Jan-19 15:09 
GeneralRe: Windows C++: a bit shocked Pin
raddevus30-Jan-19 3:40
mvaraddevus30-Jan-19 3:40 
GeneralRe: Windows C++: a bit shocked Pin
Super Lloyd29-Jan-19 16:36
Super Lloyd29-Jan-19 16:36 
GeneralRe: Windows C++: a bit shocked Pin
raddevus30-Jan-19 3:44
mvaraddevus30-Jan-19 3:44 
GeneralRe: Windows C++: a bit shocked Pin
Super Lloyd30-Jan-19 4:41
Super Lloyd30-Jan-19 4:41 
GeneralRe: Windows C++: a bit shocked Pin
David O'Neil29-Jan-19 16:51
professionalDavid O'Neil29-Jan-19 16:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.