Revised RFC on range design for D2

KennyTM~ kennytm at gmail.com
Sat Sep 27 01:03:18 PDT 2008


0ffh wrote:
> Sergey Gromov wrote:
>> In article <gbjihf$2803$1 at digitalmars.com>, 
>> frank at youknow.what.todo.interNETz says...
>>> [...]
>>> I wouldn't go so far as to call that property of C a design mistake in
>>> light of the actual intensions of K&R. But I definitely would defend
>>> the choice of a language designer to change that feature in light of
>>> more modern programming paradigms.
>>
>> Functions in D are first-class values.  It's awkward that a 
>> first-class value cannot be accessed by its identifier.
> 
> Awkward my sed! Why should a parameterless call be *the* natural meaning
> of function identifier access, as opposed to the reference or content?
> I don't go for that kind of absolutism, and you don't make sense to me.

It may not be "the" natural thing, but it is confusing.

Someone may hate it, but let me compare with other popular languages:

          Function call         Func. ptr. / Func. obj. / delegate   Note
D        func(), func          &func, func (as a template argument)
C-like   func()                func, &func                          [1]
Python   func()                func
Perl     func, func()          "func" (access by &{"func"}())       [2]
VB 6     func                  AddressOf func                       [2]
VB.NET   func()                AddressOf func                     [2,3]
C#       func()                new DelegateType(func)               [3]
Ruby     func, func()          &:func (??)                        [2,4]
Java     func()                <<No such thing??>>
PHP      func()                func, "func" ($x="f";$x();)
Pascal   func                  func                                 [5]
awk      func()                <<No such thing>>                    [6]
sed      b label               <<No such thing>>                    [6]

So, from this table, we see that (except Pascal), if the language calls 
a function by f(a,b,c,d), then only f() will be considered a valid 
function call, and a function pointer / function object / delegate is 
mostly accessed using f, &f or "f".

If D deviates from the norm, fine, since I'm not a language designer, 
but from the view of programmers also familiar with, hmm, C, C++, 
ECMAScript, Python and/or PHP, this decision will very likely introduce 
obstacles or even bugs in development.

Note:
  1. "C-like" includes C, C++ and ECMAScript (Javascript).
  2. I haven't tried what func will give in VB.NET and C#
  3. In VB 6, Perl and Ruby it is acceptable to write "func 4,5" to mean 
func(4,5), so it may be unfair to compare with D which "func 4,5" is 
syntax error.
  4. The &:func syntax for Ruby never worked for me. But I'm using Ruby 1.8.
  5. I haven't tested what func really does in Pascal/Delphi, but from 
online sources (JFGI) it seems that func will return a function pointer 
if it is passed to a function pointer type.
  6. Since you mentioned AWKward my SED... ;p


More information about the Digitalmars-d-announce mailing list