Hacker News new | past | comments | ask | show | jobs | submit login
Ask HN: The importance of heredoc
1 point by stcredzero on June 25, 2009 | hide | past | favorite | 7 comments
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.



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.


The syntax is a complication to implement, not to just program with.


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.


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?


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.


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.


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.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: