> I think the major obstacle is likely to be the difference in idioms.
> Any substantial idiomatic piece of Clojure is going to be almost
> impossible to automatically translate to _idiomatic_ code in another
> high-level language that uses different idioms.

That could very well turn out to be the case. In the spectrum between
"fully manual" and "fully automated" I can picture scenarios like:
- Mostly manual but with some automatic assistance from the IDE: E.g.
the way Eclipse assists you in coding Java, when you press Ctrl+Space.
It doesn't automatically write code for you but it can narrow down the
choice as to what to type next.
- Most automatic but with some manual assistance from the coder: E.g.
annotate the Clojure code with hints about the idioms to translate to
in the target language. Right now in Clojure we use annotations
like :exposes-methods that aren't strictly for the Clojure
functionality itself but for Java interop. So there could be
annotations like :use-design-pattern-x that dictate the choice of
idiom/design pattern in the compilation to the target language.

> You'd also probably
> have to introduce a number of "coding conventions" to constrain your
> Clojure code in order to avoid "holes" in the translation.

It's probably a question of how unwieldy the produced code is allowed
to get. If you express the goal of "maintainability" in terms of some
metric like lines of code or whatever then I can see hard limits being
reached. If you don't put a limit on that then I don't see any danger
of holes.

> Some questions:
> * How do you translate Clojure functions in namespaces spread across
> multiple files into a Java class?
> [...]

Those are very good questions and I'd have to think about it. Maybe
I'll start a wiki somewhere so we can start collecting "translation
recipes". Generally, if the answer isn't obvious from staring at the
Clojure code, it helps to think about the problems in terms of the
bigger picture, i.e. the business logic/domain knowledge, and then
translate to Blub in the head. E.g. "I want to cache generated web
pages on the disk, how would I do this in Java?"

> * How would code that uses STM translate to a Blub without it?

I like this one in particular. People have written concurrent code
before STM. I do it in my job every day. :) How did that work with
explicit locks again??

> * How idiomatic would Blub code be when Clojure uses immutable data by 
> default?

A good source for this is the O'Reilly book "Functional Programming in
Java". There you can see how idioms from one language can be applied
to another. I think Java code that uses a lot of immutable data, i.e.
"final" variables all around, would still be accepted by the Java
community. The produced code could even leave out the "final" keyword
in order to not cause too much clutter but still not modify the
variables. It violates the principle of least authority but I see that
in real-world code everywhere.

> I think it's a fascinating problem to try to solve for any given
> target Blub but I'm not sure how practical it would be, i.e., how
> readable the generated Blub code would be to an "average" Blub
> programmer...?

The problem may have to be solved first in order to judge the value of
the solution. My day-to-day experience and my guts tell me it's worth
it. :D

You weren't going to the Conj by any chance, were you?

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to