Luther Andal wrote:

> All,
>
> I apologize for getting a little puffy it just bothers me in any language when
> people get defensive about of "their language" without looking at what the added
> functionality's potential might contibute to the language.  Your comment kind of
> broke the camels back.  The rest of the people where bashing perl and perl
> really has nothing to do with the comment that I made it just happened to have
> the functionality in it.  Take perl out of the equation.  Tell me which is more
> affective.
>
> Java's Way currently
>
> println("<HTML");
> println("<BODY>");
> println("</BODY>");
> println("</HTML>");
>
> or
>
> println("<HTML>\n<BODY>\n</BODY>\n</HTML>");
>
> An example of what I am talking about, though it may have to be some other type
> of syntax to work.  I don't currently know exactly how it would work but that is
> why I put the idea forth.  To everyone to think about a way to build a class
> with a method that could implement the idea.
>
> printBlock(
>
> <HTML>
> <BODY>
> </BODY>
> </HTML>
>
> );
>
> Of course an HTML page would contain a lot more lines of HTML but this gives an
> idea of what I am talking about
>
> if you had to edit the HTML which one would you prefer?  If you had to generate
> a bunch of HTML say to layout a table for a report which method would you
> prefer.  Say the table needed four nested tables to get the look you wanted and
> when you finished the result of the HTML was that nothing showed up in the
> browser because you forgot a closing </TD> tag.  Which would be easier to debug?
> The last implementation is much cleaner and a non-Java programmer could change
> the HTML in a pinch if necessary.  This is what Web Application Developers using
> Servlets face every day.  Taking table data and generating an HTML GUI from it
> for example.  This is what I am saying not that perl is better or that Java
> sucks but that I would like to have this functionality.
>
> Thanks for your comments and again.  Sorry for any negative response I was
> frustrated that people where missing the point and arguing about Perl and Java,
> not the functionality
>
> Luther Andal
>

With any macro-enabled text editor or IDE, the difference in effort between
maintaining the "out.println" version and the "printBlock" version -- even if Java
were changed to make this possible -- is vanishingly small.

But the real point is that you should do neither of the above in Java, because none
of them meet your criteria of "easy" to maintain.   I would suggest that you
consider one of the following general strategies:

* If your servlet is going to generate the HTML itself, I would strongly
  suggest using an object-oriented mechanism where each object represents
  a particular HTML tag.  An example of this is the htmlKona package that is
  included with BEA/WebLogic's application server, or the Element Construction
  Set (ECS) -- based on essentially the same calling sequences -- available
  at http://java.apache.org for free and with source.

* If you are doing mostly static stuff and just need to plug in information from
  a database (to replace custom tags, for example), consider a template-based
  approach like webmacro (http://www.webmacro.org), which has custom tags
  to make this kind of thing really easy.  It works best when you don't have a lot
  of complicated logic to deal with.

* If you need a more complicated combination of Java-based logic and generated
  HTML, consider using a JavaServer Pages (JSP) implementation.  JSP is designed
  to let you code all of the static part of your output in an HTML-like page (when
the
  tools catch up with the technology, probably using the same kinds of authoring
  tools that people use for static HTML pages today), with embedded references
  to JavaBean objects created by your servlets or other business logic.

Doing what your printBlock() suggestion implies would require changes to the Java
language itself -- and the reason this idea was getting bashed is because it is
much more typical of PERL's "ad hoc" view of programming, rather than the object
oriented view that Java presents to the world.

If you're doing trivially simple applications, out.println() works fine, lasts a
long time.  For anything at all complex, or things that will need to change over
time, you should really consider an approach that separates the computational part
of your application ("what" should be displayed) from the presentation part ("how"
should it be displayed).

Craig McClanahan

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to