[M3devel] Shorthand type declarations?

Tony Hosking hosking at cs.purdue.edu
Wed Feb 3 09:37:52 CET 2010


On 3 Feb 2010, at 00:28, Jay K wrote:

> This is not where Modula-3 falls down due to verbosity.
>  
>  
> Many C and C++ programmers discourage such terseness:
> int a, b, c(), d();
> typedef int T1, T2;
>  
>  
> preferring:
> int a;
> int b;
> int c();
> int d();
> typedef int T1;
> typedef int T2;
>  
>  
> Where is falls down, perhaps, is not using curly braces.
>   (And perhaps for gyrations needed for safety, see my recent NTObjFile.m3 changes.
>   Can they be safe and not duplicate code, or only one?)
>  
>  
> My editor is geared toward curly braces and helps using them tremendously.
> I can't switch editors. I've tried many times.

... emacs...  :-)

>  I find the terseness Modula-3 does allow:
> PROCEDURE(VAR a, b:INTEGER);

Both are VAR.  VAR distributes over the list.

> TYPE A = RECORD c, d: INTEGER:= 0; END.

They both get 0.

:= distributes over the list.

>  ambiguous.
>  
> I don't know if a and b are both VAR.
> I don't know if c and d both have the initializer.
> I'd prefer to see:
> PROCEDURE(VAR a: INTEGER; VAR b:INTEGER);
> TYPE A = RECORD c: INTEGER := 0; d: INTEGER:= 0; END.
>  
>  
> (and I'm not sure that is equivalent, but I do know what it means.)
> (newlines omited in RECORD just for *email brevity*: RECORD should have a newline per field!)
>  
> I would be in favor of removing all these shorthands from the cm3 tree,
> and maybe even warning about them. But they surely are all well defined
> if you know the language well. It is meant to be a small language,
> but goes a bit too far here I think.

I've never really found this to be the case.  Perhaps because I learnt to program in Pascal.

>  
>  
>  - Jay
> 
>  
> > Date: Tue, 2 Feb 2010 21:37:33 -0600
> > From: rodney_bates at lcwb.coop
> > To: m3devel at elegosoft.com
> > Subject: Re: [M3devel] Shorthand type declarations?
> > 
> > 
> > 
> > Chris wrote:
> > > Alright, I'm finally getting the hang of things.
> > > 
> > > One quick question..
> > > 
> > > Is there a shorthand for declaring a whole bunch of types as one type? i.e....
> > > 
> > > TYPE 
> > > Window, Pixmap, Cursor = unsigned_int;
> > > 
> > > Or something similiar?
> > > 
> > > Doing this
> > > TYPE
> > > Window = unsigned_int;
> > > Pixmap = unsigned_int;
> > > Cursor = unsigned_int;
> > > etc...
> > > Adds up to whole lot of typing.(No pun intended)
> > 
> > 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.
> > 
> > 
> > > 
> > > Any tips would be most welcome.
> > > 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20100203/24451814/attachment-0002.html>


More information about the M3devel mailing list