Home > Archive > Compilers > May 2007 > Java compiler courses
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Java compiler courses
|
|
|
| Why do they exist.
Why would anybody want to teach a compiler course in Java when it
seems that there are more and better resources (books, tools)
supporting a compilers course based on C (aside from the obvious -
students are taught Java and not C).
Why would anybody want to write a compiler in Java (unless it's the
only language they know).
| |
| Russell Shaw 2007-04-23, 8:08 am |
| wooks wrote:
> Why do they exist.
>
> Why would anybody want to teach a compiler course in Java when it
> seems that there are more and better resources (books, tools)
> supporting a compilers course based on C (aside from the obvious -
> students are taught Java and not C).
>
> Why would anybody want to write a compiler in Java (unless it's the
> only language they know).
Because C is too hard for teachers brought up on VB, and they usually
don't have the experience to write decent code in it.
And anyway, that would be giving the students something actually
useful and efficient in the real world and we couldn't have that
happening now could we? ;)
| |
| Andy Johnson 2007-04-23, 8:08 am |
| For one thing, to continue the tradition. Many compilers have been written
in the same language as they are compiling (e.g. javac). If you are
bootstrapping a compiler, it's always good to have your own killer test
application, which is the compiler itself.
Pascal compilers were all written in Pascal. Most C++ compilers are written
in C++. They may have originally started off as a small compiler written in
some other language, but as soon as this compiler became sufficiently
useful, it was used to bootstrap the self-hosted compiler, and was never
used again. Why should Java be any different? I was involved in an
ahead-of-time Java compiler project several years ago, and we deliberately
chose to write it in Java.
-AndyJ
"wooks" <wookiz@hotmail.com> wrote in message
news:07-04-074@comp.compilers...
> Why do they exist.
>
> Why would anybody want to teach a compiler course in Java when it
> seems that there are more and better resources (books, tools)
> supporting a compilers course based on C (aside from the obvious -
> students are taught Java and not C).
>
> Why would anybody want to write a compiler in Java (unless it's the
> only language they know).
>
| |
| glen herrmannsfeldt 2007-04-23, 8:08 am |
| wooks wrote:
> Why do they exist.
> Why would anybody want to teach a compiler course in Java when it
> seems that there are more and better resources (books, tools)
> supporting a compilers course based on C (aside from the obvious -
> students are taught Java and not C).
Well, first, Java compilers are likely to be written in Java,
following the tradition of writing compilers in the language
that they compile.
> Why would anybody want to write a compiler in Java (unless it's the
> only language they know).
Java has much better support for string handling than C does. It is
likely slower, but that isn't always a limitation for a compiler.
Computers are now fast enough, and with JIT java is usually
pretty fast. Debugging mistakes in string handling in C,
such as overrunning the end of a string, is not easy. Java
checks string bounds, simplifying debugging.
Now, why would anyone want to write a compiler in C?
-- glen
| |
| Hans-Peter Diettrich 2007-04-23, 8:08 am |
| wooks wrote:
> Why would anybody want to write a compiler in Java (unless it's the
> only language they know).
What should the students learn: writing compilers in C, or writing
compilers in general? IMO it's easier to port a compiler model, designed
in Java, to any other programming language, than modifying or extending
a compiler model implemented in C. Java doesn't encourage hacks, which
often are found in C code. While speed may be an argument in an
commercial compiler, a compiler course should spot the principles of an
compiler, not the details. A modular OO approach, as required by Java,
IMO is a good starting point for every big project.
DoDi
| |
| Chris Dollin 2007-04-23, 8:08 am |
| wooks wrote:
> Why do they exist.
Java compiler courses? For people who want to write compilers,
and are willing to learn using Java.
> Why would anybody want to teach a compiler course in Java when it
> seems that there are more and better resources (books, tools)
> supporting a compilers course based on C (aside from the obvious -
> students are taught Java and not C).
I'm not sure that your premise is correct, and I'm not sure why
you're so willing to discount the obvious.
> Why would anybody want to write a compiler in Java (unless it's the
> only language they know).
It's got type checking [1] (and with new! added! generics!), garbage
collection, polymorphism, portability to a useful range of systems,
and extensive libraries.
Why shouldn't people want to write compilers in Java?
[Disclaimer: Java isn't my favourite language by any means, and I /have/
written a compiler-plus-shortcode-interpreter in C, but I don't see
any deep reasons why one shouldn't write a compiler in Java.]
[1] I mean the sort that helps you avoid mistakes, not the sort that
insists that it has to be done at compile-time and leaves you
solitary and afraid at run-time.
--
"Life is full of mysteries. Consider this one of them." Sinclair, /Babylon 5/
Hewlett-Packard Limited Cain Road, Bracknell, registered no:
registered office: Berks RG12 1HN 690597 England
| |
| Karsten Nyblad 2007-04-25, 4:16 am |
| wooks wrote:
> Why do they exist.
>
> Why would anybody want to teach a compiler course in Java when it
> seems that there are more and better resources (books, tools)
> supporting a compilers course based on C (aside from the obvious -
> students are taught Java and not C).
>
> Why would anybody want to write a compiler in Java (unless it's the
> only language they know).
>
Most of the students on are never going to write a compiler. They are
studying the subject for two purposes:
First because they want to know how their code is transformed into
machine code such that they can better predict how some piece of code
will work. Who cares what language the compiler is written in in that case?
Secondly because lots of computer programs read text files. You can use
the theory for front ends when writing code to read such text files.
Such readers will typically be written in same the language as the rest
of the project. Thus there is no particular reason to believe that the
students later in will use their knowledge in projects using C.
Finally, a curse on on compiler design should not be a curse on
debugging code or data structures. There is no reason why students
should fight memory leaks in C code or reimplement stacks, maps, etc.,
when they can use library functions in other languages. The students
have only so much time for their student projects, and there is a lot of
compiler theory they will not have time for trying in practice.
Karsten Nyblad
148f3wg02 at sneakemail dot com
| |
|
| On Apr 23, 12:49 pm, glen herrmannsfeldt <g...@ugcs.caltech.edu>
wrote:
> wooks wrote:
>
> Well, first, Java compilers are likely to be written in Java,
> following the tradition of writing compilers in the language
> that they compile.
But that presupposes the course is aiming to build a compiler for Java
- which may be the case - and then may not. If you are on a 10 w
course being asked to design a compiler for an OO subset is like
being asked to run before you've learnt to walk.
>
> Java has much better support for string handling than C does. It is
> likely slower, but that isn't always a limitation for a compiler.
> Computers are now fast enough, and with JIT java is usually
> pretty fast. Debugging mistakes in string handling in C,
> such as overrunning the end of a string, is not easy. Java
> checks string bounds, simplifying debugging.
Those are all the sort of arguments one could make for writing
compilers in ..... (insert your favourite higher level (than C)
language).
> Now, why would anyone want to write a compiler in C?
For the reasons I stated in my post.
1. Better documented C based tools (lex/flex, yacc/bison). Hence why
instructors on Java courses keep referring students to the GNU
documentation in preference to CUP.
2. More books to choose from so that you can find the right one for
you (and there's a better chance that you can find it in the library)
which is important. There are only 3 Java books - Appel, Watt and the
one by Patrick Terry (not available via Amazon.com and a hefty 46GBP
2nd hand in the UK).
3. Don't need to get to grips with the non intuitive Visitor Pattern -
if you're on a course thats taught over 10 w s there's enough new
concepts to worry about in that short period of time.
PS - C is not my language of choice for programming in general - it
just seems that it is best suited for this application.
| |
| Hans-Peter Diettrich 2007-04-25, 4:16 am |
| Andy Johnson wrote:
> For one thing, to continue the tradition. Many compilers have been written
> in the same language as they are compiling (e.g. javac). If you are
> bootstrapping a compiler, it's always good to have your own killer test
> application, which is the compiler itself.
A very good point! Really :-)
But is the N-th reimplementation, of an compiler for an already existing
*general purpose* programming language, a practical situation for
compiler writers in real life? And is the implementation of an compiler
really a practical test case for students, which are trying to implement
their first compiler at all?
Many of the languages, to be implemented at work, may not be very well
suited for the implementation of an compiler, or may not be
Turing-complete at all.
Therefore I think that the choice of the language should be splitted for
educational purposes, into the compiler implementation and application
language. The implementation lanugage must come with all the required
libraries, whereas the application language should allow to write test
cases, without a need for implementing a huge runtime system, in
addition to the compiler itself.
DoDi
| |
|
|
| Hans-Peter Diettrich 2007-04-28, 8:06 am |
| Torben Ęgidius Mogensen wrote:
>
>
> Modular, yes. OO, maybe. I have yet to see any major benefits OO
> gives you in compiler writing that you can't get through polymorphism
> and ML-style modules. And ML-style datatstructres are (IMO) much
> easier than objects for representing syntax trees etc.
>
> Torben
> [I entirely agree. Data structures and pattern matching are really useful,
> OOP isn't for writing compilers. So I write stuff in perl. -John]
My point of OOP was related to the design phase, in detail in education.
It makes a difference whether a language *allows* for OOP, or *requires*
OOP. When OOP is a requirement, a project must be structured in the
first step, before one can start hacking code ;-)
For the implementation itself, other languages may be more comfortable.
Pattern matching and other tree processing certainly is a criterium for
the choice of a concrete implementation language, for compiler projects.
DoDi
| |
| Hans-Peter Diettrich 2007-04-28, 8:06 am |
| George Neuner wrote:
>
>
> I'm willing to bet that few people would take a course in compilers
> for that particular reason. It is so well known that code generation
> is implementation dependent that anyone can learn that much simply by
> lurking in her favorite programming newsgroup. The stock reply to
> such an inquiry is to turn on assembler listings, try different things
> and compare the results.
IMO an understanding, of how compilers work, is a must for code
writers. Compilers are not restricted to machine code creation, they
are around everywhere, when it comes to modeling and source code
transformation in general (scripting, XML...). It's easier to
understand the right use of such tools, with a certain background in
parsing and transformation of parse trees. The compiler back ends are
of lesser interest in such a general understanding of text processing.
> To that end, compilers are complex programs that intersect many skill
> areas. A professional developer will certainly need to successfully
> read and write files, parse input, format output, manipulate complex
> data structures, manage resources, plan strategy and schedule
> operations. Even a simple compiler touches on all of these things.
> Certainly, the student should be able to use any facility of the
> implementation language to help herself - but debugging comes with the
> territory.
ACK.
> Moreover, compiler courses are not "Intro to Programming" courses ...
Also right. In so far a single compiler course could tie together,
what is or has already had been covered by other courses. In my
studies the compiler course had been splitted into multiple parts,
starting very soon with the first part, and accompanied by courses in
related areas (languages etc.). IMO a "compiler" is something that
integrates a lot of other areas, and as such helps the students to get
a big picture, and a concrete example, for the application of other
more abstract stuff.
DoDi
| |
| George Neuner 2007-04-29, 7:07 pm |
| On 27 Apr 2007 11:28:06 -0400, Hans-Peter Diettrich
<DrDiettrich1@aol.com> wrote:
>IMO an understanding, of how compilers work, is a must for code
>writers.
I agree with you and I happen to have a compiler specific education,
but in practice all a performance developer needs is to understand how
her particular compiler translates a particular program construct.
I've done a significant amount of high performance and hard real-time
programming where understanding what output the compiler produced was
vitally important. But it was never the case that I needed intimate
knowledge of the compiler's algorithms to do my work ... it was
sufficient to know how a procedure frame was layed out and be able to
map HLL inputs to assembler outputs.
George
| |
| Hans-Peter Diettrich 2007-04-29, 7:07 pm |
| George Neuner wrote:
>
>
> I agree with you and I happen to have a compiler specific education,
> but in practice all a performance developer needs is to understand how
> her particular compiler translates a particular program construct.
This is just *not* what I meant. IMO it's much easier to understand
e.g. how to write recursive procedures, when one has an idea of how
procedure calls (parameters, stackframes...) are translated into
machine code. Visibility rules for symbols, the difference between
static and dynamic initialization of variables, error messages, and
much more can be understood easier, when having an idea of how a
compiler works in general.
DoDi
| |
| glen herrmannsfeldt 2007-04-29, 7:07 pm |
| Hans-Peter Diettrich wrote:
(snip, someone wrote)
[color=darkred]
> This is just *not* what I meant. IMO it's much easier to understand
> e.g. how to write recursive procedures, when one has an idea of how
> procedure calls (parameters, stackframes...) are translated into
> machine code.
(snip)
In writing portable programs, one can't depend on the way a particular
compiler works, but on general principles. In general recursive
programs must generate a separate instance of local (automatic)
variables for each instance of the recursive procedure. There
is normally some overhead to doing that, though less one some machines
and more on others.
It is interesting to me how as machines get faster more work is
being done to speed up the procedure calling mechanism than
in the days of slower machines.
I would say, then, that one should understand both the general
principles and those of the machine/compiler one uses most.
-- glen
| |
|
|
|
|
|
|
| Marco van de Voort 2007-05-10, 10:09 pm |
| On 2007-04-26, Michael Klemm <usenet@gmx.info> wrote:
> From my experience (tutor for compiler construction both in C and
> later in Java), the students are able to produce a more stable
> compiler in Java more quickly than in C. For Java, all gory details
> that make programming tough (esp. memory management) comes almost for
> free.
I somewhat wonder why people think that Java is easier to learn than
C. In ome of my classes I found the opposite (which surprised me too),
specially if the students had no prior IT knowledge (they were classes
for graduated non IT bachelors).
They consistently found C easier to handle. The reason was pretty
simple, more transparant, less knowledge required for an initial
program (of any kind). We had them doing walking pointer trees in 5
w s, while in the paralel Java class they were still struggling with
inheritance, and explaining what was needed to make a minimal program.
Now, I agree that this is partially due to the tools and
libraries. (with all their form designing logic) But I don't assume
people writing this here are using special educational versions of
Java?
| |
| Torben Ęgidius Mogensen 2007-05-13, 4:26 am |
| Marco van de Voort <marcov@stack.nl> writes:
> On 2007-04-26, Michael Klemm <usenet@gmx.info> wrote:
>
> I somewhat wonder why people think that Java is easier to learn than
> C. In ome of my classes I found the opposite (which surprised me too),
> specially if the students had no prior IT knowledge (they were classes
> for graduated non IT bachelors).
We are getting a bit off topic here, but being easier to learn does
not equate being easier to use, once you have mastered it.
But I agree that Java is not an easy language to learn, mostly because
the OO model is rather arcane compared to the imperative or functional
models. I would not choose any OO language as the first language to
teach students, unless the OO parts are so isolated that you can use
the language effectively without ever using objects (like in, say,
O'Caml), and then I would simply ignore the OO parts for the first
course.
Torben
| |
| Chris Dollin 2007-05-13, 4:26 am |
| Marco van de Voort wrote:
> On 2007-04-26, Michael Klemm <usenet@gmx.info> wrote:
>
> I somewhat wonder why people think that Java is easier to learn than
> C.
I don't know if Java is easier to /learn/ than C. It depends a bit what
you count, since Java has a /much/ larger set of libraries and suffers
less from portability issues. I think Java is easier to /use/ than C,
because it suffers rather less from one-wrong-step-and-cut-your-throat.
> In ome of my classes I found the opposite (which surprised me too),
> specially if the students had no prior IT knowledge (they were classes
> for graduated non IT bachelors).
>
> They consistently found C easier to handle. The reason was pretty
> simple, more transparant, less knowledge required for an initial
> program (of any kind).
That depends, I think, on how one gets taught. The initial C program
#include <stdio.h>
int main(void)
{
printf( "Hello, world!\n" );
return 0;
}
and the parallel Java program
public class HelloWorld
{
public static int main( String [] args )
{
System.out.println( "Hello, world!" );
}
}
aren't /that/ different to a beginner.
> We had them doing walking pointer trees in 5 w s, while in the
> paralel Java class they were still struggling with inheritance, and
> explaining what was needed to make a minimal program.
Then IMAO someone misfabricated the Java course.
I can't decide whether I'd start people off with an IDE or stick with
the command-line. Pros and cons, cons and pros ...
--
"It is seldom good news." ~Crystal Ball~, /The Tough Guide to Fantasyland/
| |
| glen herrmannsfeldt 2007-05-13, 4:26 am |
| Marco van de Voort wrote:
(snip)
> I somewhat wonder why people think that Java is easier to learn than
> C. In ome of my classes I found the opposite (which surprised me too),
> specially if the students had no prior IT knowledge (they were classes
> for graduated non IT bachelors).
I think that depends on how you teach Java. If you teach it as
a replacement for C, I don't think it is much different.
> They consistently found C easier to handle. The reason was pretty
> simple, more transparant, less knowledge required for an initial
> program (of any kind). We had them doing walking pointer trees in 5
> w s, while in the paralel Java class they were still struggling with
> inheritance, and explaining what was needed to make a minimal program.
For a minimal program, you don't need any much inheritance, and you
don't even need to understand it. Similarly, you don't need to
understand what #include <stdio.h> does to start writing C. I would
say it isn't so much the difference in the language as the way people
want to teach it.
I would say that Object reference trees are easier to understand
and debug than C pointer trees, but not so much different.
> Now, I agree that this is partially due to the tools and
> libraries. (with all their form designing logic) But I don't assume
> people writing this here are using special educational versions of
> Java?
I would say teaching the C library, including proper handling of null
terminated strings, is harder to teach than the equivalent parts of
the Java library. If you took a C course and substituted Java in
place of C, the appropriate Java library routines in place of C
library routines, etc., I think it would work and take about the same
amount of time to learn.
(Note that Java is closer to C than C++ is to C.)
But I don't think that is the way people teach Java. I didn't
learn Java from a class, and my Java programs probably look
more like C than they should.
-- glen
| |
|
| On May 11, 4:01 am, Chris Dollin <chris.dol...@hp.com> wrote:
>
> Then IMAO someone misfabricated the Java course.
I agree with that, but it can be difficult to design a good Java
course until you've had a lot of experience teaching it. I use memory
diagrams heaviliy to explain inheritance and virtual methods, and
garbage collection. I use a white board because I often get questions
and I change my diagrams in order to answer questions. But the single
most important thing I do is to engage students in discussions almost
every day, and I assign somewhat difficult homework. Instead of giving
them 10 or 20 questions I often give them less than 5 questions, but
they are questions that make them think. And I go over the homework in
class to make sure they "get it". Their grades on the homework tend
towards the low side of the scale (60 as opposed to 80), but I throw
away their lowest scores and I don't weight their homework heavily.
Their midterm and final grades tend to be high because they are
definitely ready by then.
A well-taught C course has some of the same problems. To teach C you
need a lot of memory diagrams to explain pointers and malloc, etc.
Structs that go on the heap are somewhat similar to class instances.
> I can't decide whether I'd start people off with an IDE or stick with
> the command-line. Pros and cons, cons and pros ...
I typically use a very lean IDE that is not much more than a syntax
highlighter and a compile button. I like full-featured IDEs, of
course, but I don't have enough time to teach them. I have to select
my agenda items carefully to give them a good working knowledge of the
language and the platform in only one class. I haven't taught an
advanced class yet, but if I do, I'll teach Eclipse and I'll drill
down more heavily on the Virtual Machine and the low-level platform
issues.
Eric
|
|
|
|
|