45 comments
Comment actions Permalink

With preprocessing it's very,
very difficult to support correct refactoring.


I'd say the most difficult thing is correct definition on what correct
refactoring is in presence of header files. Same syntactic construction has
different meaning in different context. The same problem appears in JSP
though.


--

Best regards,
Maxim Shafirov
JetBrains, Inc / IntelliJ Software
http://www.intellij.com
"Develop with pleasure!"



0
Comment actions Permalink

There are other kinds of prepocessoors - such as CamlP4:
http://caml.inria.fr/camlp4/
This preprocessor for a fucntional language Objective Caml is not a
macro-based preprocessor, but an extensible parser of a language.

IMO, ability to extend syntax of one's language in formalized way is
a very powerful feature which none of "production" languages and very few of
research languages possess. If syntax is extended in formalized way, one
can imagine IDE (IDEA?) being able to understand such syntax extensions and
support them...

Just imagine yourself being able to add a 'foreach' statement to Java - a
mere 10 lines of grammar code - and javac and IDEA being able to understand
that...

Friendly,
Dmitry

P.S. See also on this topic:
http://www.research.avayalabs.com/user/wadler/steele-oopsla98.pdf

Timur Zambalayev wrote:

Yep.

"Preprocessors are not a good thing in my opinion: makes it harder to
build IDEs (mainly the editing tools as the source doesn't have to conform
to the underlying language syntax) and increases the distance from source
to executable form. Also, preprocessors have traditionally been used by
C/C++ headers that make things even more difficult (header files are
themselves a bad thing)." (Terrence Parr, the creator of ANTLR,

http://www.cs.usfca.edu/~parrt/course/652/lectures/language.impl.overview.pdf

)

>> One of the reasons it's not done yet for C++ is, I
>> think, preprocessing. With preprocessing it's very,
>> very difficult to support correct refactoring.
>>
>> --
>> Dmitry Skavish
>> -


>> Boston, MA, USA
>> tel. +1 781 370-6909
>> http://www.jzox.com
>> http://www.flashgap.com

--
Dmitry Lomov
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

0
Comment actions Permalink

Thank you for the links!

foreach. It's a bad example. :)
As we all know, it will be part of 1.5, hopefully ( http://jcp.org/aboutJava/communityprocess/jsr/tiger/enhanced-for.html , http://www.jcp.org/en/jsr/detail?id=201 ). So javac and IDEA will soon understand


"Growing a Language". They chose the same title for the recent article at java.sun.com: http://java.sun.com/features/2003/05/steele_qa.html .


Timur

There are other kinds of prepocessoors - such as
CamlP4:
http://caml.inria.fr/camlp4/
This preprocessor for a fucntional language Objective
Caml is not a
macro-based preprocessor, but an extensible parser of
a language.

IMO, ability to extend syntax of one's language in
formalized way is
a very powerful feature which none of "production"
languages and very few of
research languages possess. If syntax is extended in
formalized way, one
can imagine IDE (IDEA?) being able to understand such
syntax extensions and
support them...

Just imagine yourself being able to add a 'foreach'
statement to Java - a
mere 10 lines of grammar code - and javac and IDEA
being able to understand
that...

Friendly,
Dmitry

P.S. See also on this topic:
http://www.research.avayalabs.com/user/wadler/steele-o
psla98.pdf

0
Comment actions Permalink

My concerns here are, that the language handles one special interface
(Collections) differently than anything else. That's why I do not want to
have it in the language. For me the following code looks not too
complicated to do such an hack to Java (I hope, the generics pattern is
correct):

Collection collection;
for (Iterator it = collection.iterator(); it.hasNext(); ) {
   String s = it.next();
}
]]>


Tom

0
Comment actions Permalink

Timur Zambalayev wrote:

Thank you for the links!

foreach. It's a bad example. :)
As we all know, it will be part of 1.5, hopefully (
http://jcp.org/aboutJava/communityprocess/jsr/tiger/enhanced-for.html ,
http://www.jcp.org/en/jsr/detail?id=201 ). So javac and IDEA will soon
understand

 for (String s : collection) {
>    // ...
> }
> ]]>


Foreach is a bad example indeed, but not for the reason you stated :)
What I wanted to say, in a sense, was that by adding a language feature
in formalized way you can capture the ideas (or paradigms or whatever) you
use in your code. For example:
Suppose you define in you grammar that
(Words in CAPITAL are keywords in your metalanguage):
==================
THERE IS A NEW statement WITH SYNTAX
foreach( : ) WHICH IS IN PLAIN JAVA CODE MEANS for(Iterator it = .iterator(); it.hasNext();) { = () it.next(); ]]>
}
==================
and then you just type in your code

foreach(String s : e.getChildren()) {
System.out.println(s);
}

and preprocessor preprocesses this, and you do not need a JDK 1.5,
and IDEA understands that, and the concept you use is clear in your code.
This is, in fact, a Live Template done right - that is, a Live Template with
a round trip - but without the heavy weight intentional programming
framework.


"Growing a Language". They chose the same title for the recent article at
java.sun.com: http://java.sun.com/features/2003/05/steele_qa.html .


The original Gosling's talk itself is a rare example of a scientific paper
that is fun to read. Highly recommended :)

Cheers,
Dmitry

--
Dmitry Lomov
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

0
Comment actions Permalink

Yes it is called Hieginic macro extension. You can find an example http://www.ai.mit.edu/~jrb/jse/index.htm
The idea is to have the language defined in a flexible way that allows developers to define custom construct. They define what comes down to transform rules to convert the custom syntax to a true language structure.
The compiler then use these production rules to convert these syntax extension into true language and compile them.
A few bloggers have mentioned that it would be a superior approach to current java extension jsrs which are really driven by C# competition.

My other gripe is inner classes. Why not give us true blocks/closures like in smalltalk/lisp/perl/ruby...

Sometimes I wish Sun wasn't holding java so tight!

0
Comment actions Permalink

It will work with the (new) interface: java.lang.Iterable (or an array). java.util.Collection will implement this interface. So it's not only for Collections.

My concerns here are, that the language handles one
special interface
(Collections) differently than anything else. That's
why I do not want to
have it in the language. For me the following code
looks not too
complicated to do such an hack to Java (I hope, the
generics pattern is
correct):

 Collection collection;
> for (Iterator it = collection.iterator();
> it.hasNext(); ) {
>    String s = it.next();
> }
> ]]>


Tom


0
Comment actions Permalink

Foreach is a bad example indeed, but not for the
reason you stated :)
What I wanted to say, in a sense, was that by adding
a language feature
in formalized way you can capture the ideas (or
paradigms or whatever) you
use in your code. For example:
Suppose you define in you grammar that
(Words in CAPITAL are keywords in your metalanguage):
==================
THERE IS A NEW statement WITH SYNTAX
foreach(<t:type> <ID:identifier> : <c:expression>)
<s:statement>
WHICH IS IN PLAIN JAVA CODE MEANS
for(Iterator it = <c>.iterator(); it.hasNext();) {
<t> <ID> = (<t>) it.next();
<s>
}
==================
and then you just type in your code

foreach(String s : e.getChildren()) {
System.out.println(s);
}

and preprocessor preprocesses this, and you do not
need a JDK 1.5,
and IDEA understands that, and the concept you use is
clear in your code.
This is, in fact, a Live Template done right - that
is, a Live Template with
a round trip - but without the heavy weight
intentional programming
framework.


Interesting ideas. It will be nice to see something like this as a prototype. The key phrase here is "IDEA understands that". One of the problems with extensions, code generations, mini-languages and maxi-languages without adequate "understanding" support, is that all you have is a basic editor, (maybe) some highlighting and no understanding (from your editor) of the underlying structure of the code/language (i.e. no refactoring, no FindUsages, etc). It's tough once you get used to the level of support IDEA provides for Java and other file types.

"Growing a Language". They chose the same title for

the recent article at

java.sun.com:

http://java.sun.com/features/2003/05/steele_qa.html .

The original Gosling's talk itself is a rare example
of a scientific paper
that is fun to read. Highly recommended :)


What talk do you mean? A link, please?


Cheers,
Dmitry

--
Dmitry Lomov
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"



Timur

0
Comment actions Permalink

How about

THERE IS A NEW <csharpLanguage:compilationUnit> WITH SYNTAX

WHICH IS IN PLAIN JAVA CODE MEANS


? :)

There's a more general request:
http://www.intellij.net/tracker/idea/viewSCR?publicId=9634

Suppose you define in you grammar that
(Words in CAPITAL are keywords in your metalanguage):
==================
THERE IS A NEW statement WITH SYNTAX
foreach(<t:type> <ID:identifier> : <c:expression>)
<s:statement>
WHICH IS IN PLAIN JAVA CODE MEANS
for(Iterator it = <c>.iterator(); it.hasNext();) {
<t> <ID> = (<t>) it.next();
<s>
}
==================

0
Comment actions Permalink

Timur Zambalayev wrote:

>>
>> The original Gosling's talk itself is a rare example
>> of a scientific paper
>> that is fun to read. Highly recommended :)


What talk do you mean? A link, please?


I meant the one I posted before:
http://www.research.avayalabs.com/user/wadler/steele-oopsla98.pdf

Dmitry

--
Dmitry Lomov
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

0
Comment actions Permalink

>> The original Gosling's talk itself is a rare
example
>> of a scientific paper
>> that is fun to read. Highly recommended :)


What talk do you mean? A link, please?


I meant the one I posted before:
http://www.research.avayalabs.com/user/wadler/steele-o
psla98.pdf


I see. I got confused by "Gosling's".

0
Comment actions Permalink

You are right. But from my point of view the problem still remains: the
language contains a special element, that depends on an implementation
detail of the language, an special interface.

Best regards,
Thomas Singer
_____________
smartcvs.com

0
Comment actions Permalink

BTW, I also think, the serialization is a big hack that does not fit in the
otherwise well-formed and light language. But since I can't change the
decision, I shut up.

Tom


On Fri, 09 May 2003 09:24:35 +0200, Thomas Singer
<thomas.singer@noregnisspam.de> wrote:

You are right. But from my point of view the problem still remains: the
language contains a special element, that depends on an implementation
detail of the language, an special interface.

>

Best regards,
Thomas Singer
_____________
smartcvs.com

>


0
Comment actions Permalink

The same, of course, could be said for the special handling of java.lang.String. Literals, overloaded operators, and an implicit marking of 'immutable', all things that a user-defined class can't have.

--Dave Griffith

0
Comment actions Permalink

Timur Zambalayev wrote:

>> >> The original Gosling's talk itself is a rare
>> example
>> >> of a scientific paper
>> >> that is fun to read. Highly recommended :)
>> >
>> > What talk do you mean? A link, please?
>>
>> I meant the one I posted before:
>> http://www.research.avayalabs.com/user/wadler/steele-o
>> psla98.pdf


I see. I got confused by "Gosling's".


Oops sorry - been looking at too much papers at once ;)

Cheers,
Dmitry
--
Dmitry Lomov
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

0

Please sign in to leave a comment.