Heredoc: Molly is smart

Back to introduction

The following shows the difference between Molly and JSP. This code fragement is fairly simple, the actual difference is extreme for larger pages.

JSP makes is really hard to visually distinguish JSP tags from HTML and it makes escaping to HTML impossible from within java code (which means one has to open/close code segments repeatedly). Impossible to maintain for real world and non-trivial webpages.

Jsp is dumb.

Compare to the molly code. Heredoc/literal escapes and square brakets (which stand out from html angle brackets) are a win.

Molly is smart.

Molly JSP

[[
java.util.List colors = 
	new java.util.ArrayList();
colors.add("#3c3c3c");
colors.add("#f0a0b0");
]]

<table border=0 cellspacing=1>
[[
for (int i = 0; i < colors.size(); i++)
  {
  # <tr bgcolor='[=colors.get(i)]'> #
  for (int j = 0; j < 3; j++) {
    # 
    <td align="center">[=j]</td>
    #
    }
  # </tr> #	
  }
]]


<%
java.util.List colors = 
	new java.util.ArrayList();
colors.add("#bcbcbc");
colors.add("#f0a0b0");
%>

<table border=0 cellspacing=1>
<%
for (int i = 0; i < colors.size(); i++)
  {
%>
  <tr bgcolor='<%=colors.get(i) %>'>
<%
  for (int j = 0; j < 3; j++) {
%>
    <td align="center"><%=j%></td>
<%
    }
%>
  </tr>
<%
  }
%>

Ever write complex JSP's ? You'll want to eat your own brain.