[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Benefits of CSP Based Programming Languages



>From a simple programmer's perspective (i.e. leaving aside the formal
part), I find CSP can express certain communication/event constructs
that other languages have a hard time doing.  If you want to wait for
either channel A or channel B you just write (excuse my pseudo-occam,
it's been a little while!):

ALT
  A ? x
    ...
  B ? y
    ...

It is surprising how difficult in can be in other languages and APIs to
express the same idea, especially when the two events you want to wait
for are not both of the same type (a non-embedded example would be
waiting for either a GUI button press or a socket event).  Equally,
waiting for two channels or a time-out can be hard.

The in-built parallelism in occam is also handy.  To send on channels A
and B simultaneously, you write:

PAR
  A ! x
  B ! y

Most other languages/APIs would require you to send the data
sequentially, or to use asynchronous IO (you would have to start the
output on A, then start the output on B, then wait for them both to
finish - not usually worth the hassle!).  

Another benefit of CSP-based languages is that of easy component
substitution.  So if you have a process:

PROC int.processor(CHAN INT in?,CHAN INT out!)

That process can be very simply substituted for any other process with
the same signature (such as id).  Object-orientation allows similar,
but you must have defined a common base class already; i.e. you must
know that you might want to swap it out before you actually need to.



On a side note, there is a feature of occam I was wondering about.  When
I recently had to create a debug wrapper for a java class, I had to
define all 37 of the classes methods as passing the call on to the
inner class, and put debug statements in only 2 of them.  Which is
obviously a big pain.  CSP-like things could do well at this wrapping;
I could read in data on the incoming call-like channel, then pass it on
if I didn't care, or deal with it if I did.  So I'd want something like
the following:

in ? CASE
  clear.screen
    ... Do some DEBUG output ...
    out ! clear.screen
  DEFAULT
    out ! CASE

The intended meaning being that the incoming PROTOCOL is forwarded
untouched in the DEFAULT case, but in the clear.screen case I'd want to
actually do something else too.  What would be good is if the "out !
clear.screen" line could also be "out ! CASE".  Does occam already have
this feature that I am not aware of, or is it possible to add?  Anyway,
that's a bit of a diversion, for occam programmers/developers.

Hopefully I've given you some points to think about anyway.  Others on
the list should feel free to add to or correct my suggestions.

Thanks,

Neil.

> -------- Original Message --------
> Subject: Benefits of CSP Based Programming Languages
> From: william.luitje@xxxxxxxxxxxxxxxx
> Date: Tue, November 01, 2005 11:30 pm
> To: occam-com@xxxxxxxxxx
> 
>  
> I am a new list member, so please pardon me if this topic has already been covered. 
>  
> I am writing a paper for the Society of Automotive Engineers spring congress about what potential benefits developers of automotive embedded software are missing when they write in C. I plan to use occam as an example of how pervasive embedded computing concepts, like time, concurrency, multiprocessing and communications, can be built into a language. I have already created small example programs in occam that illustrate how handling these difficult issues can be greatly simplified when using a suitable programming language. 
>  
> That should serve to motivate a claim that use of such a language could result in greatly reduced development time and a higher quality finished product, which are both hot topics in the field of automotive software. Has anyone actually performed an experiment or done a study with a CSP based language to see if such benefits are actually realized? If so, what degree of improvement was observed? 
>  
> There is also great interest in the automotive industry in doing testing and validation. CSPs are rigorously defined mathematical constructs that can be manipulated with a calculus. Since occam implements them directly, it should be easy to analyze. That suggests the possibility of tools to perform automated analysis or formal proofs of consistency, deadlocks, timing, etc. From looking at Hoare's CSP book that seems theoretically possible. Are such tools currently available? If so, what kinds and how practical are they? What other kinds of testing and validation are facilitated? 
>  
> Thanks for any information you can provide and remember you needn't restrict answers to occam.