comp.lang.ada
 help / color / mirror / Atom feed
From: alex@cs.umd.edu (Alex Blakemore)
Subject: Re: Function call or variable?
Date: 7 Mar 93 20:27:06 GMT
Date: 1993-03-07T20:27:06+00:00	[thread overview]
Message-ID: <64872@mimsy.umd.edu> (raw)
In-Reply-To: 9303051531.aa21226@Paris.ics.uci.edu

In article <9303051531.aa21226@Paris.ics.uci.edu> lhuynh@siam.ICS.UCI.EDU (Thomas Huynh) writes:
> how can one determine if the identifier "func_or_var"
> is a function call or variable?
>   if (func_or_var) [then]

you cant tell by looking at the reference, but have to look at the definition.
that is IMHO a _very_ good thing.

it means that the implementation can change between parameterless function and
constant and variable and client code need not be modified.
similarly, you can change between a function and an array without changing
client code.  the semantics are the same, just the implementation has changed.

this doesnt mean that you shouldnt care about how something is implemented, but
that you should only record that design decision in one place instead of
propogating the info throughout the code.

the same principle that makes private types so useful.

if not convinced, consider this scenario, you have a constant or variable referenced
throughout your code - and as time goes on, the code to keep it set
correctly gets more and more complex and needs to be invoked from more
and more places.  In Ada, you can replace the variable with a function safely.
Code that only references the variable need not change at all.
in C, you would have to modify every caller.

this syntactic ambiguity allows better information hiding of implementation details.
the compiler needs to know the details, but the caller doesnt.
overloading is another example of a useful apparent ambiguity,
which the compiler resolves based on complete information from the definition.

for this reason, I really object to coding styles which try to distinguish
syntactically those things that the language intentionally does not.
such as using a space or not before left parens to tell distinguish
function calls from array references.  thats a bad idea.

-- 
---------------------------------------------------
Alex Blakemore alex@cs.umd.edu   NeXT mail accepted



  reply	other threads:[~1993-03-07 20:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1993-03-05 23:31 Function call or variable? Thomas Huynh
1993-03-07 20:27 ` Alex Blakemore [this message]
1993-03-08  0:34   ` David Emery
1993-03-13  0:39   ` Adam Beneschan
  -- strict thread matches above, loose matches on Subject: below --
1993-03-17 23:58 Robert I. Eachus
1993-03-23 16:02 ` John English
1993-03-24  2:10   ` Robert I. Eachus
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox