[antlr-interest] philosophy about translation
Andy Tripp
antlr at jazillian.com
Sat Oct 7 11:04:39 PDT 2006
Monty Zukowski wrote:
> ...
>
>> > Just for the record I am opposed to the translation you show here.
>> > That is not at all what I would expect unless it's clear that those
>> > variables are always constants.
>>
>>
>> Ahh...and therein lies the difference in our approaches. It's not what
>> you'd *expect* because of your background
>> in language tools. But is it what you'd *want* as a customer who wants
>> to replace C code with Java? Answer: customers
>> don't want "JOBOL", and they don't want "Cava". (Although, if they do
>> want C in Java clothes, there's
>> a tool for that: http://ovid.tigris.org/Ephedra/)
>
>
> Note, you missed the fact that it has to be clear that those variables
> are constants. Obviously, if they are not, then you can't do the
> substitution.
Right.
>
> Also as I was thinking about it, I don't like eliminating the
> variables just because they are constants.
Right. And thinking about it more, I think I lied, and I'd produce
System.out.println("hello" + " " + "world");
I do, however, attempt to do what real programmers would do.
Like I might see that a single println() call contains a bunch
of constants, all used only once, and so I should combine them.
I don't do that for C to Java, but I do for COBOL, where the nature of
how you declare variables make that a common occurance.
In COBOL, you very often see roughly:
01 MESSAGE
05 HELLO PIC XXXXX VALUE "HELLO"
05 PIC X VALUE SPACE
05 WORLD PIC XXXXXX VALUE "WORLD"
...
WRITE MESSAGE
Here, not only are they constants, but in fact one of them (the space)
doesn't
even have a name!
> Sometimes programmers do
> things like that to make the code more readable, and crunching it into
> one line again makes it less readable. Without knowing the intent of
> the programmer I would say it should not do such fancy things as
> variable substitution. Worse yet, if the string is overridden later,
> or tested against, or things like that, then you've made the code
> harder to maintain by putting the constant everywhere (perhaps
> embedded in other strings).
Yea, this is the sort of thing I struggle with every day.
>
> Monty
>
More information about the antlr-interest
mailing list