August 19, 2007

The preponderance of C

I first learned the C programming language in about 1978. We used it for the firmware of the 1240 logic analyzer at Tektronix.

Over the years it's been amazing to see how C has set a standard for what a language should look like, and to see how other languages either consciously imitate it -- or consciously deviate from it.

I've been studying Flash, and I'm starting to get into "ActionScript". ActionScript 2.0 is essentially C, except with some odd changes. It's nice to see that the "switch" statement is exactly the same, for instance, and they use braces and semicolons exactly the same way. On the other hand, as an interpreter it's a lot more loose about variables. And it doesn't have an "enum" type.

We didn't have that initially, either. But it's one of the great additions to the language, and Actionscript doesn't support it. Bummer.

I just figured out a way to emulate that ability, however. The only problem is that compiler doesn't enforce rigor the way it would with a true enum:

public var state:Number;
public static const state_off:Number = 1;
public static const state_init:Number = 2;
public static const state_running:Number = 3;
public static const state_stopping:Number = 4;

This at least allows me to use names to assign the state instead of magic numbers.

Parallel programming is interesting. I grew up in serial programming models. The 1240 had two processors in it, but communications between them was a drastic bottleneck and one was a lot smaller and slower than the other, so it wasn't really parallel programming.

My first encounter with a completely parallel execution model was a "language" called "LabView" from National Instruments. I put scare-quotes around "language" because you didn't enter it using text. You created a "program" using a graphics editor, because a "program" looked like a circuit diagram.

What you were doing was to create dataflow diagrams. Execution was the problem of the run time engine, which would run a process block whenever there was enough data to make it possible for it to run.

Once I got used to it, it was actually a really neat way to do the thing I was trying to do. If I'd had to write that program in C it would have taken me 6 months. As it was, I got it working in about 3 weeks -- but the first week and a half of that was getting over the cognitive shock and trying to learn how to think parallel instead of serial.

Flash isn't quite that parallel, but the way you can have multiple things running at once, plus the way you can nest or unnest them, is very flexible. I'm beginning to get my mind around that part, but Actionscript is a bit more complicated.

I'm beginning to think that for some of the kinds of things I want to do, I'm actually better off creating entire independent state machines to run different parts of the display, and letting them communicate with each other using flags and state variable changes. I know that's gross, but it's cleaner than the alternative.

Using a request flag means that the governing state machine can do a clean startup and a clean shutdown and can guarantee that it doesn't stop running in the middle of a loop iteration. The result is a cleaner visual result, without jarring transitions. And at least you can encapsulate it inside of public functions, to hide the grossness a little.


You are getting sleepy... sleepy...

But nesting animations is fun, too. You can get some very complex motions, especially if you make the loop-lengths different. The blue arm's cycle is 52 frames, the orange arm's cycle is 40 frames, and the spring's cycle is 16.

Posted by: Steven Den Beste in Site Stuff at 05:25 PM | Comments (5) | Add Comment
Post contains 629 words, total size 4 kb.

1

So how long until it repeats? My answer:

Posted by: Steven Den Beste at August 19, 2007 06:09 PM (+rSRq)

2

Pixy: Bug or feature? Someone asked me how I ran into Shingu originally, and I was trying to find my earliest posts about it here. Of course, the string "Shingu" has been used here in probably 50 posts. (It's been in the title of at least 30.)

When I searched for "Shingu" I got 20 hits, which look like the most recent 20 posts containing that term. What I didn't get was any ability to see more than that e.g. a "next page of hits" control.

Is that deliberate or an oversight?

Posted by: Steven Den Beste at August 19, 2007 09:20 PM (+rSRq)

3 It's an oversight;  most likely all I need to do is tweak the template a little.  Hang on a bit while I try that.

Posted by: Pixy Misa at August 19, 2007 11:00 PM (PiXy!)

4 Hrm. No, not quite so simple. I can't paginate the results of a POST request (because it doesn't remember the query data) and all forms including the search are currently POSTs. Also, it's selecting the 20 most recent results but sorting in ascending order, which is kind of weird.

What I need to do is make the search function a GET, and then the pager will automatically work. That should be straightforward enough - I should be able to get to that tomorrow, I think. In the meantime I can change the limit of the result set... Done.

Posted by: Pixy Misa at August 19, 2007 11:41 PM (PiXy!)

5

Ah, Labview.  As I recall they called their graphical programming languange 'G', so there was even a bit of homage to C there.  My first real professional programming was done in Labview...

Posted by: DrHeinous at August 21, 2007 08:25 AM (/Y+Yb)

Hide Comments | Add Comment

Enclose all spoilers in spoiler tags:
      [spoiler]your spoiler here[/spoiler]
Spoilers which are not properly tagged will be ruthlessly deleted on sight.
Also, I hate unsolicited suggestions and advice. (Even when you think you're being funny.)

At Chizumatic, we take pride in being incomplete, incorrect, inconsistent, and unfair. We do all of them deliberately.

How to put links in your comment

Comments are disabled. Post is locked.
10kb generated in CPU 0.0119, elapsed 0.0236 seconds.
20 queries taking 0.0156 seconds, 22 records returned.
Powered by Minx 1.1.6c-pink.