On Sep 10, 2005, at 12:53 PM, Devin Mullins wrote:
>> Separate from the "because it's what certain people expect"  
>> factor, I  consider the current method of appending strings to  
>> "_erbout" less  convenient/ideal than using muscle-memory-friendly  
>> methods like #puts.
>
> Can you give me an example of when appending to _erbout is  
> necessary or preferred rather than saying "%>some text<%" or "%><% 
> =some value%><%"?

It's never necessary, as %><%=foo%><% is equivalent to _erbout <<  
foo.to_s
It's preferred (by me) in cases where control whitespace is  
important, or where the typing of the above is far more cumbersome  
than typing "puts foo"

Contrived Example 1:
<ul>
<% items.each do |item|
     _erbout << "\t<li>#{item.value}</li>\n"
end
%></ul>

compared with
<ul>
<% items.each do |item|
     <li><%=item.value%></li>
<% end
%></ul>

(Not only is the newline sort of annoying in the above, but "\t" is  
clearly a single tab character, where indentation on your editor may  
use spaces to precede the <li>)

Contrived Example 2:
<%
sum = 0
100.times do |i|
     _erbout << i.to_s
     sum += i
end
_erbout <<  (sum / 100).to_s
foo.bar()
%>

compared with:
<%
sum = 0
100.times do |i|
     %><%=i%><%
     sum += i
end
%><%=sum/100%><%
foo.bar()
%>

compared with:
<%
sum = 0
100.times do |i|
     print i
     sum += i
end
print sum / 100
foo.bar()
%>


> The exact same functionality *is* available when you puts or print.  
> With your change, people expecting to spit out debug messages would  
> have to do $stdout.puts...

That's a good point. I suppose it seems 'correct' to me because (for  
me) it's DWIM. As for for debug messages, I argue that debug messages  
should be done with #warn anyhow (which would remain unchanged) as  
STDERR is more appropriate (I think) than STDOUT. And, I simply  
didn't believe that anyone was actually using the puts-in-erb-for- 
debug functionality. (And I suppose I still won't, until someone says  
"Yes, I use that!")


>> The more ERB 'just works' right out of  the box, the greater a  
>> tool it becomes to lure people to Ruby.
>
> Understood. Well, for what it's worth right now, the features it  
> has work almost exactly as they do in JSP, including the separation  
> between puts (System.out.println, as usual) and _erbout (newly  
> conceived out.println).

So it currently meshes well for people coming from JSP, eh? That's  
good to know.


> Well, yes, but that's because I know how it works. I understand  
> that newbs don't see it that way. Those that know say, "Don't hide  
> the truth! Make the newbs learn!" You say, "Make the abstraction so  
> pure that newbs don't /need/ to learn!" There is some validity in  
> that argument, but, sadly, I'm going to side with Joel[1] on this one.
>
> Devin
> [1] http://www.joelonsoftware.com/articles/LeakyAbstractions.html

Thanks for the article. I love reading Joel :)