Code Comparison
In Java, the specification is divided into classes: Input, Output, Controller, and Timer. Timer objects are created each time the method startimer() is invoked. Threads and synchronization are used to guarantee aspects of the controller’s behavior.
An example of the Controller structure: public class SAController { … public void control(int steering_speed, …) { if(steering_speed != last_steering_speed) { startimer(); } ... } public void startimer() { timer1 = new Timer(); } public synchronized void notifycontroller(…) { try { wait(); } ... catch(InterruptedException e) { return; } … }
In C, each function is defined as a set of if-then (as in Java) and switch-case statements satisfying the transition conditions. There are no objects or threads. Memory management is specified by the programmer.
The behavior specification has the following form: void steering_speed(steering_speed, …) { … L1: switch(condition) { case 1 : goto L2; case 2 : goto L3; } L2: if(detect_high_speed) { goto L4; } else { … } } goto L6; … end: always_cleanup(proc); return; … }