Click here to Skip to main content
15,891,657 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: switch statement Pin
PIEBALDconsult2-Aug-17 7:12
mvePIEBALDconsult2-Aug-17 7:12 
GeneralRe: switch statement Pin
Rainbird Developer2-Aug-17 8:44
Rainbird Developer2-Aug-17 8:44 
GeneralRe: switch statement Pin
BillWoodruff2-Aug-17 22:10
professionalBillWoodruff2-Aug-17 22:10 
GeneralRe: switch statement Pin
kalberts4-Aug-17 0:36
kalberts4-Aug-17 0:36 
GeneralRe: switch statement Pin
Clifford Nelson4-Aug-17 4:16
Clifford Nelson4-Aug-17 4:16 
GeneralRe: switch statement Pin
kalberts2-Aug-17 22:47
kalberts2-Aug-17 22:47 
GeneralRe: switch statement Pin
Clifford Nelson4-Aug-17 4:18
Clifford Nelson4-Aug-17 4:18 
GeneralRe: switch statement Pin
kalberts4-Aug-17 4:56
kalberts4-Aug-17 4:56 
The CHILL language, providing this, was essentially developed to program network switches. If you have been much in contact with communication guys, you have certainly noted that they love designing protocols as state machines:

Any entity is at any time in one of a limited number of states. Whatever happens in the interface is modeled as an atomic event; the event ID being one of a limited set of values. The processing of the event depends on the current state and the event ID. Processing is (conceptually) atomic, and changes the entity state into a new value. So a very common usage would be like (in quasi-C syntax, Chill was somewhat different)

switch (state, eventID) {
(disconnected, setupReq): ... code to handle a call setup request...
(transferMode, dataPacket): ...
... more state/event combinations, with their specific handling ...
(transferMode, ELSE): ... error hadling, protocol error, not allowed in transferMode state...
ELSE: ... general error handling for illegal event in current state, not treated as a specific case...

Now, some protocols are so complex that a "pure" state machine would end up with thousands of states. So the protocol spec defines from one up to a small handful of state variables, which may be thought of as sub-states in most cases (not always, but "sort of like"). So you could add one or more of those state variables as the third switch field, if they should lead to distinctly different handling. (For many switch cases, the switch label would be "Don't care" for that state/eventID combination.)

So, for protocols defined as state machines, the multidimensional switch statement is a perfect match.

I love that kind of protocol specification! It is terse, lucid, unambiguous, and most of all: It pinpoints all protocol error situations and makes it very clear to you where you should define an error handler, and the reasons for raising this error condition.
GeneralRe: VB haters, look away Pin
Jose A Pascoa2-Aug-17 6:33
Jose A Pascoa2-Aug-17 6:33 
NewsRe: The truth... Pin
Jeremy Falcon2-Aug-17 6:41
professionalJeremy Falcon2-Aug-17 6:41 
GeneralRe: The truth... Pin
ZurdoDev2-Aug-17 6:56
professionalZurdoDev2-Aug-17 6:56 
GeneralRe: The truth... Pin
Jeremy Falcon2-Aug-17 7:21
professionalJeremy Falcon2-Aug-17 7:21 
GeneralRe: The truth... Pin
ZurdoDev2-Aug-17 7:26
professionalZurdoDev2-Aug-17 7:26 
GeneralRe: VB haters, look away Pin
dandy722-Aug-17 6:50
dandy722-Aug-17 6:50 
GeneralRe: VB haters, look away Pin
ZurdoDev2-Aug-17 6:57
professionalZurdoDev2-Aug-17 6:57 
GeneralRe: VB haters, look away Pin
Marc Clifton2-Aug-17 7:07
mvaMarc Clifton2-Aug-17 7:07 
GeneralRe: VB haters, look away Pin
Jeremy Falcon2-Aug-17 7:25
professionalJeremy Falcon2-Aug-17 7:25 
GeneralRe: VB haters, look away Pin
KarstenK2-Aug-17 7:35
mveKarstenK2-Aug-17 7:35 
GeneralRe: VB haters, look away Pin
theoldfool2-Aug-17 7:51
professionaltheoldfool2-Aug-17 7:51 
GeneralRe: VB haters, look away Pin
dandy722-Aug-17 9:04
dandy722-Aug-17 9:04 
GeneralRe: VB haters, look away Pin
RedDk2-Aug-17 8:35
RedDk2-Aug-17 8:35 
GeneralRe: VB haters, look away Pin
atverweij2-Aug-17 22:54
atverweij2-Aug-17 22:54 
GeneralRe: VB haters, look away Pin
Bryan Schuler3-Aug-17 5:54
Bryan Schuler3-Aug-17 5:54 
GeneralRe: VB haters, look away Pin
ZurdoDev3-Aug-17 5:59
professionalZurdoDev3-Aug-17 5:59 
GeneralRe: VB haters, look away Pin
ClockMeister3-Aug-17 8:05
professionalClockMeister3-Aug-17 8:05 

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.