[M3devel] Shorthand type declarations?

Olaf Wagner wagner at elegosoft.com
Wed Feb 3 10:18:14 CET 2010


Quoting Chris <Highjinks at gmx.com>:

> On Tue, 02 Feb 2010 21:37:33 -0600
> "Rodney M. Bates" <rodney_bates at lcwb.coop> wrote:
>
>> Unfortunately, this is the shortest you can get.  I suppose the   
>> language designers
>> thought that, while a whole lot of variables with the same type   
>> were a likely
>> case:
>>
>>    VAR x, y, z, u, v, w, h, i, j, h, ... : INTEGER;   ,
>>
>> that more than just a few type names that are synonyms for the same  
>>  type would not be common.
>>
>> You may think me certifiably masochist, but I go the more   
>> longhanded way and write:
>>
>>   TYPE Window = unsigned_int;
>>   TYPE Pixmap = unsigned_int;
>>   TYPE Cursor = unsigned_int;   ,
>>
>> sacrificing writeability in favor of readability.  (Yes, I repeat   
>> VAR and CONST too,
>> almost every time.
>
> The reason I asked is because I'm doing the interface for   
> /usr/include/xcb/xproto.h
>
> There are a lot of of typedefs in there that are defined as the same  
>  base type.
>
> I've shortened the Iterator types by using...
>
> TYPE T = UNTRACED ROOT OBJECT END;
> TYPE XCB_Iterator = T OBJECT
> 	Rem   : INTEGER;
>         Index : INTEGER
> END;
>
> TYPE XCBAtom = unsigned_int;
> TYPE Atom_Iterator = XCB_Iterator OBJECT
>      Atom_Data : UNTRACED REF XCBAtom;
> END;
>
> But even this is gonna kill me. Heh. xproto.h is a HUGE file.

What exactly is gained by defining all those aliases for unsigned_int?
In M3 all the types are structurally equivalent, so you can use a Cursor
where a Window would be required etc. It looks like a bit of facelifting
to me.

And if it's only for readability and proper naming, all those should
surely be named <x>Handle, shouldn't they?

The same level of abstraction could be achieved by defining just one
XProtoHandle as unsigned_int, couldn't it?

I think I just have never understood the usefulness of interfaces
too large to remember, but that may be a general problem with X...

Olaf
-- 
Olaf Wagner -- elego Software Solutions GmbH
                Gustav-Meyer-Allee 25 / Gebäude 12, 13355 Berlin, Germany
phone: +49 30 23 45 86 96  mobile: +49 177 2345 869  fax: +49 30 23 45 86 95
    http://www.elegosoft.com | Geschäftsführer: Olaf Wagner | Sitz: Berlin
Handelregister: Amtsgericht Charlottenburg HRB 77719 | USt-IdNr: DE163214194




More information about the M3devel mailing list