Proposal: Function declaration with keyword

Bill Baxter dnewsgroup at billbaxter.com
Sat Apr 12 05:16:29 PDT 2008


boyd wrote:
> Okay, so I've been working with D for a while now. I stumbled upon it 
> when I was searching for a better language for me to use.
 >
> Other languages always seemed to lack some crucial feature. D is 
> generally easy to use, easy to read and has all the options I wanted. I 
> also love the attention it has given to little details that just make 
> things so much easier.
> 
> It's not perfect by any means, but overal it's better than anything. I 
> currently have gripes with mixins, which are a pain to use. From what I 
> hear Macros are gong to replace them, so for now I'll avoid that subject.

Heartily agree with you there.  For all the complaining I do here, I 
still keep using D, because I really haven't found anything better.

> 
> 
> Instead I've been wondering about a problem that, to my knowledge, 
> hasn't gotten any attention yet: function declaration keyword.
> 
> One thing I never really liked about C++ is the way function 
> declarations look. You can't easily differentiate them from variable 
> declarations. Maybe it's partly because I started with Object Pascal 
> rather than C++, but I never got used to it.
> 
> Anyway, why not use a keyword for function declarations?
> 
>   function void DoSomething(int someParam);

I just hope I don't ever have to type this in D:

   protected override invariant pure function invariant(double)[] 
func(invariant (double)[]) {...}

Scarily, it's looking like that's probably going to be quite a 
reasonable signature for a D2 pure method to have.  (Except for the 
'function' part from your suggestion).

For whatever else, K&R knew the value of keeping common keywords short, 
even if it meant using abbreviations.  That's why we have
- int not integer
- char not character
- const not constant
- enum not enumeration
- float not floating_point
and later, thanks to Stroustrup, I guess:
- bool not boolean


So anyway, if it is going to become required on every function, let's at 
least make it something shorter than 'function'.

I think the chances of it happening are slim and none, though.  Unless 
you can come up with some more compelling reasons for it.  Heck we can't 
even get Walter to remove 'printf' from Object.d.

--bb



More information about the Digitalmars-d mailing list