Sprong is a useful trick for Macintosh C programmers.
It's a block of punctuation which looks like this:
When you have a pointer to a struct, C lets you use
a->b or (*a).b .
Most people use a->b as it keeps the punctuation
in one block, and it nests more easily -
a->b->c is always preferred to
(*(*a).b).c
That left-to-right dereferencing wins every time.
However the Macintosh normally uses Handles, not pointers, and you
are forced to use the * notation, doing things like
(**(**a).b).c or
(*(*a)->b)->c.
Most Mac programmers have been using this notation for a while, and
the best thing you can say about it, is that you get used to it after
a year or two.
The solution is to use a very useful chunk of punctuation called
"sprong", which looks like this-
It is directly equivalent to ^^. in pascal, and is
very useful when dealing with handles to structs. Because C treats
arrays and pointers the same, a[0] is the same as
*a, and a[0]->b is the same
as
(**a).b or (*a)->b.
It's cool because it is easier to dereference left to right than nest
loads of brackets and stars. I prefer this:
short mainDepth = GetMainDevice() [0]-> gdPMap
[0]-> pixelSize;
to this:
short mainDepth = (**(**GetMainDevice()).gdpMap).pixelSize;
The first time you see a[0]->b[0]->c it looks
a bit strange, but once you've got over the initial shock, it's
really a big improvement. You can set up a keyboard macro to type
[0]-> for you, and all you have to do is type
identifiers, hitting the sprong key inbetween. I find it is more
readable than the alternatives. It is no less clean. It generates the
same code. It is just less familiar.
Also, consider the alternative - just think back to the first time
you saw that nested brackets and stars notation, and how many tries
it took to get the code right. Basically it sucks. You end up with
loads of nested brackets all over the place, and it isn't very
readable.
Try it - you'll like it.
I just liked the sound of it. It's a bit like "pling" which some
people use for exclamation mark, and sprong looks a bit springy.
Ronny Wichers Schreur tells me it means "jump" in Dutch.
Maf means "a bit under the weather" in a Belgian language
apparently.
There is no reason why a[0]->b should give you
different object code from (**a).b
A dereference is a dereference.
No, that's more like this -
O-|->
Sprong FAQ - Maf Vosburgh <maf@goat.demon.co.uk>