www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2002] New: Add keyword for a function definition

reply d-bugmail puremagic.com writes:

           Summary: Add keyword for a function definition
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: gaboonviper gmx.net

Like C and C++, D doesn't have a keyword for function definitions. In C you can
get away with it, since it's a simple language with few possibilities. The
complexity of the C++ and D languages make this approach unsuitable.

Adding a function definition keyword makes the language easier to read.
Consider the following function definition:

int doSomething(int someParam)


function int doSomething(int someParam)

For the second function definition it's immediatly clear that we're declaring a
function here. No need for second glances, this is definitely a function. The
first one on the other is not as intuitive, except perhaps for C/C++

While for a simple function the readability improvement may be marginal. When
we consider storage classes and type modifiers, the keyword's influence is much

private static const int doSomething(int someParam){}


private static const function int doSomething(int someParam){}

In the first declaration it's a game of 'what belongs to who', whereas the
declaration with the function keyword is a lot more expressive. And with some
good syntax highlighting its effect will be even larger.

It's also more consistent with the rest of D syntax. Especially if you'd ommit
the void type, which the keyword would make possible. 

struct X;
class X;
template X();
function X();
macro X();

So basically using a function definition keyword will decrease the learning
curve needed for D. It will increase the readability of D code. And it could
possibly make it easier to parse.

I hope you will consider implementing it.

Boyd van Oosterhout

Apr 16 2008
next sibling parent d-bugmail puremagic.com writes:

------- Comment #1 from brunodomedeiros+bugz gmail.com  2008-04-26 12:58 -------
This proposal is too fresh from the NG. It had little discussion, and received
little to no support (other than yourself).


Apr 26 2008
prev sibling parent d-bugmail puremagic.com writes:

------- Comment #2 from gaboonviper gmx.net  2008-04-26 13:24 -------
Yes, that's why I posted it here. On the newsgroup there wasn't much of a
reaction. What reaction there was, was moderately positive, not too
enthousiastic though.

Here it can either be permanently rejected, left alone until more pressing
matters are resolved, or discussed on a more longterm basis. The newsgroup
simply isn't suitable for that.


Apr 26 2008