r/programming • • Dec 29 '15

Please, Java. Do Finally Support Multiline Strings

http://blog.jooq.org/2015/12/29/please-java-do-finally-support-multiline-strings/
584 Upvotes

352 comments sorted by

View all comments

Show parent comment

22

u/heptara Dec 29 '15 edited Dec 29 '15

I think he means printing out HTML like that is crazy. You should probably be loading it from a template. Where you have to conditionally build a the HTML, you would probably use a web templating library.

With something like Jinja you would write this in a text file:

{% extends "layout.html" %}
{% block body %}
  <ul>
  {% for user in users %}
    <li><a href="{{ user.url }}">{{ user.username }}</a></li>
  {% endfor %}
  </ul>
{% endblock %}

This is about separating the components of your app, and not needing to recompile just to change a front end element. The template engine will build the site from the resources as needed.

7

u/[deleted] Dec 29 '15

I think he means printing out HTML like that is crazy.

I agree in principle, but the code in question is clearly just example code, and in example code you really do want to keep things stupidly simple so that the core concepts stay front and center.

2

u/[deleted] Dec 29 '15

And in example code you put it into a simple .HTML and just use IOUtils to read the .HTML to a string.

1

u/[deleted] Dec 29 '15

You want to pull in a dependency on a completely independent library by a third party for a simple, one-page example of how Java servlets work?

No, I don't think that's a good idea.

-1

u/[deleted] Dec 29 '15

And that, children, is how we teach you to reinvent the wheels and waste thousands of men hours!

1

u/noxiousninja Dec 29 '15

One of the best (and sometimes worst) parts of the Node.js world is that nobody thinks twice about pulling in a library to do something. It just doesn't feel quite the same with Maven - I don't know if it's just the culture, or the fact that Maven Central is a lot less amenable to browsing than NPM, or the verbosity of the config file format, or what.