Re: macros (was: Seeking computer-programming job (Sunnyvale, CA))
["Followup-To:" header set to comp.lang.lisp.]
On 2009-05-15, Stefan Ram <ram@zedat.fu-berlin.de> wrote:
pjb@informatimago.com (Pascal J. Bourguignon) writes:
Well at that point I can only say that, well over here we're not (all)
raving maniacs, that we have useful tools that help solve or obviate a
lot of problems found with other programming languages, and point to
that tutorial: http://www.lisperati.com/casting.html
Assume for a moment I had advanced macro capabilities in Java.
I'd write:
public static String getMultiValue( Object valueObject )
{ String result = null;
if( valueObject == null )result = null;
else if( StringValue stringValue =? valueObject )
result = getStringValue( stringValue );
else if( SprayValue sprayValue =? valueObject )
result = getSetValue( setValue );
return result; }
The macro here is marked by the occurence of ?=??, which is
Please don't use non-USASCII characters in comp. discussion groups.
The = character will do.
not a regular Java operator, but part of my hypothetical macro
call pattern.
The problem here is readability:
Is it?
Can others know, what = means in my macro package?
Can they know how to immediately find its documentation?
You should be prepared to raise exactly the same objection for any other
identifier you define: class, function, variable, etc.
Do others know what getMultiValue means in your library?
Can they immediately find its documentation?
Obviously not if there is no documentation, and not
immediately if it's not indexed and cross-referenced.
What does that have to do with anything?
If I invent and use this macro now, will even I myself
remember its meaning a year later?
If you invent a function now, will you remember its meaning?
The same coded in Java without macros /is/ more verbose,
but also more readable to someone who knows Java:
By this logic, the code behind a function is also more readable.
public static String getMultiValue( Object valueObject )
Similarly, I have no clue what this call means:
getMultiValue(valueObject)
Of coruse the name suggests that it gets a multi value, whatever
that is. But macros also have suggestive names just like that.
So now if you replace all occurences of that function
by the following code, it's more obvious:
{ String result = null;
if( valueObject == null )result = null;
else if( valueObject instanceof StringValue )
{ StringValue stringValue =( StringValue )valueObject;
result = getStringValue( stringValue ); }
else if( valueObject instanceof SprayValue )
{ SprayValue setValue =( SprayValue )valueObject;
result = getSetValue( setValue ); }
return result; }
So like, let's not use functions; they obfuscate code.
We should also recursively expand getSetValue too in the above.
Basically, code is only readable when it uses only the built-in syntax, and
only standard library functions that come from the language specification.
Thus, everything should be written as one large brace statement with no
confusing named abstractions that invoke something elsewhere.
A novel reads nicely from cover to cover in one pass, and a program should be
similarly readable from opening brace to closing brace.