[Issue 2002] New: Add keyword for a function definition
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Apr 16 13:45:52 PDT 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2002
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 at digitalmars.com
ReportedBy: gaboonviper at 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)
{
...
}
against
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++
programmers.
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
bigger.
private static const int doSomething(int someParam){}
vs
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.
Cheers,
Boyd van Oosterhout
--
More information about the Digitalmars-d-bugs
mailing list