Re: GoTo in Java
- From: "Oliver Wong" <owong@xxxxxxxxxxxxxx>
- Date: Fri, 27 Jan 2006 17:00:44 GMT
"Richard" <riplin@xxxxxxxxxxxx> wrote in message
news:1138298486.064822.222920@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>> If you had the "reverse compile to different language" feature, you
>> could have the example written once, and then reverse compile it.
>
> The problem with that is that you would never wind up with the example
> as 'language x program' but as a 'language y program in x syntax'. The
> way the code is best arranged for one language depends on features of
> that and 'translation' requires 'complete rewrite'. It would require
> that the translator identify idioms.
>
> Cobol:
> OPEN INPUT file
> IF ( File-Status-1 NOT = "0" )
> DISPLAY "Not found"
> ELSE
> PERFORM UNTIL EoF
> READ file
> AT END SET EoF
> NOT AT END
> process
> END READ
> END-PERORM
> CLOSE file
> END-IF
>
> C:
> if ( file = fopen(filename, "r") )
> {
> while ( ( recpoint = fgets(record, recmax, file) ) != NULL )
> { process; }
> fclose(file);
> }
> else
> puts("Not found");
>
> Python:
> try:
> file = open(filename, "r")
> except:
> print "file not found"
> else:
> for record in file:
> process
> file.close()
I was mainly envioning this tool to be used in the OSS circles, rather
than corporate environments. There's a few projects on Sourceforge that I'd
like to contribute to, but they are written in languages that I am not very
familiar with (e.g. C++).
So let's say someone writes a library in GPSS and publishes it as open
source, along with example usage in the documentation. I tell my IDE to
translate it to Java, and get some unreadable mess, so I just forget about
it. Someone else comes along, translates it to FORTRAN, and gets poor but
readable code, fixes it up to use standard FORTRAN idioms, adds that to the
example documentation, and publishes it. Someone else then translates it to
C++. Then I come back, and notice there's a C++ version now. I tell my IDE
to translate it to Java, and get something not too bad. I can clean it up a
bit, and add it to the docs too.
To prevent 20 page documentation for a 20 line block of code, the
comments could themselves be structured (perhaps via XML?) so you could
instruct your IDE to filter out the parts that are not relevant to you.
E.g.:
<comment>
<description>This function returns the sum of its two
argumnents</description>
<exampleUsage lang="GPSS">
....
</exampleUsage>
<exampleUsage lang="FORTRAN">
....
</exampleUsage>
<exampleUsage lang="C++">
....
</exampleUsage>
<exampleUsage lang="Java">
....
</exampleUsage>
</comment>
And your IDE would be set up with rules like "Show me the Java-related
comments. If there aren't any, then show me the C# related comments.
Otherwise, show me to C related comments. Otherwise, C++." Etc.
- Oliver
.
- Follow-Ups:
- Re: GoTo in Java
- From: Michael Wojcik
- Re: GoTo in Java
- From: Richard
- Re: GoTo in Java
- References:
- GoTo in Java
- From: Howard Brazee
- Re: GoTo in Java
- From: Oliver Wong
- Re: GoTo in Java
- From: Frank Swarbrick
- Re: GoTo in Java
- From: Oliver Wong
- Re: GoTo in Java
- From: Richard
- GoTo in Java
- Prev by Date: Re: GoTo in Java
- Next by Date: Re: PowerCobol
- Previous by thread: Re: GoTo in Java
- Next by thread: Re: GoTo in Java
- Index(es):
Relevant Pages
|