Omittable parens is an evil

Simen Kjaeraas simen.kjaras at gmail.com
Sun Jul 20 15:27:33 PDT 2008


Tomasz Sowiñski <tomeksowi at gmail.com> wrote:

> downs Wrote:
>
>> bearophile wrote:
>> > Tomasz Sowiñski:
>> >> When coding, at first, I was glad to be able to snip the parens  
>> (makes code look cleaner), but then I came to the same conclusion - the  
>> illusory cleanness of code strikes back in the form of trouble with  
>> telling "something" and "do something" apart.<
>> >
>> > I agree that omittable parens is bad, I always put them.
>> > If parens become compulsive you don't need to use "&somefunc", you  
>> just use "somefunc" to denote the pointer/delegate and "somefunc()" to  
>> call it.
>> >
>> > Bye,
>> > bearophile
>>
>> Seeing as I don't share your opinion on this topic, I humbly submit  
>> that this is not a problem with the language but with the coders,  
>> specifically, people who have used function pointers in C.
>>
>> Since I acquired D before I had much need for that atrocious syntax,  
>> &function has always made more sense to me.
>>
>> Because of this, I do not see a problem with foo or foo() - both are  
>> clearly not the function address.
>
> I think functions should be called thisWay() and function addresses  
> should be obtained &thisWay.
>
> But then we would have the question what should thisWay symbol mean  
> without parens or ampersand? Maybe it shouldn't mean anything? or use it  
> only to pass functions into other functions as arguments? hm...
>
> Tomek

I usually think that a function called without parens should have no
side effects (except, of course, when used as the lhs. Also, debug
code and logging are also allowed to have side effects). So,

	SomeFunc(); // is a valid line
	SomeFunc; // is invalid
	SomeVar = SomeFunc; // is valid (getter)
	SomeOtherFunc = SomeFunc(); // is valid (setter)

Of course, this is only a coding standard I have set for myself, but
I think it makes code easier to read and understand. As we all know,
WTFs/min is the best way to measure code quality.
http://www.osnews.com/images/comics/wtfm.jpg

-- Simen



More information about the Digitalmars-d mailing list