News for hackers. Stuff that matters.

Ask HN: The importance of heredoc

I wish to ask Rubyists and Shell programmers: Does heredoc still have a place? Is it still worth its syntactic weight? I can see how it would be great for one-off scripts producing a bit of text. But I can picture a number of ways to get almost the same effect (readable one-offs producing text) in a scripting language without complicating the syntax.
( 7 comments | on HN )
Re:Ask HN: The importance of heredoc by gamache on Thursday June 25, 2009 @11:51AM (#673856)
Oh, heredocs absolutely still have a place. It's the right choice for any multiline string which might contain quoting characters.

And what's so complicated about the syntax? Even if you have never seen a heredoc before, it's generally very easy to figure out what's going on from context.

Re:Ask HN: The importance of heredoc by stcredzero on Thursday June 25, 2009 @10:44PM (#674856)
The syntax is a complication to implement, not to just program with.
Re:Ask HN: The importance of heredoc by mbrubeck on Thursday June 25, 2009 @12:49PM (#673999)
Perl and PHP also use shell-style heredoc syntax. The main alternative is to provide a newline-friendly quote delimiter, like the """string""" syntax in Python.
Re:Ask HN: The importance of heredoc by villageidiot on Thursday June 25, 2009 @11:47AM (#673848)
I've never had a problem with heredoc. I'm curious what you mean when you say "I can picture a number of ways to get almost the same effect . . . without complicating the syntax". Would you care to illustrate your point with an example so we can make the discussion a little bit more concrete?
Re:Ask HN: The importance of heredoc by stcredzero on Thursday June 25, 2009 @10:43PM (#674851)
Put the text from a heredoc in a comment with special tags. Have a special method that lets you retrieve the text in the same source file. This puts zero syntactic load on the language, but has much the same effect. You can even have embedded methods, source debugging, regexes. But there's no additional syntax.
Re:Ask HN: The importance of heredoc by firebug on Thursday June 25, 2009 @11:54AM (#673865)
heredocs are great. I use them all the time for metaprogramming. I don't see them going out of style anytime soon. Not sure what you mean about complicated syntax.

I supect you may be new to Ruby and confused by the heredoc sytnax. If so, this post has a review of some of the syntactical issues with heredocs:

http://log.gmarik.info/2007/12/rubys-here-document-heredoc-m...

Hope that helps.

Re:Ask HN: The importance of heredoc by stcredzero on Thursday June 25, 2009 @10:43PM (#674854)
Not confused. Heredoc is one of the things that complicates Ruby syntax from the implementer's POV.

Use heredoc for metaprogramming? Now I'm starting to believe in the Lisp dogma.