From: Robert Klemme Date: 2008-02-16T07:04:56+09:00 Subject: Re: array of here documents On 15.02.2008 20:09, Leonard Cuff wrote: > > > On 2/9/08 3:09 AM, "Robert Klemme" wrote: > >>> On 09.02.2008 12:04, Mark Woodward wrote: >>> On Fri, 8 Feb 2008 18:17:28 -0500 >>> Xavier Noria wrote: >>> >>> Is there any reason you wouldn't set up the heredocs first and then add >>> them to an array? >>> >>> HD1 = <>> This is a heredoc. >>> The first of 2. >>> ENDHD1 >>> >>> HD2 = <>> This is the second heredoc. >>> ie the last. >>> ENDHD2 >>> >>> a=[HD1,HD2] >> Waste of constants / variables. >> >> robert >> > > I didn't know constants and variables were in short supply, I'll try to be > more frugal. :-) :-) Simpler is often better so frugality might not be the worst course you could take. :-) > I hope you laugh rather than take offense. No offense taken and it definitively made me smile. (-: > I do want to make the point that code that is easier to understand by > novices is inherently more maintainable. Writing "compact" code is often > over valued, IMHO. I would much prefer to see Marks code, because of the > ease of understanding it. Completely agreed. There is of course room for interpretation. If code is very elaborate to make understanding easier for novices it can defy the purpose of ease of reading. If code gets compacted for compactness reasons (famous one liners) then it usually becomes hard to read. A simple example: some people (former C programmers?) like to use assignments in if conditions, which is completely unnecessary and can easily be confused with equivalence checks: 1. bad if foo = calc_foo() ... 2. good foo = calc_foo() if foo ... There is really only one reason where assignment in conditions makes sense because the code becomes easier that way: in loops: 1. nice and short while line = gets() ... end 2. awful, because redundant line = gets() while line ... line = gets() end Back to the particular example at hand: in this case I would at least replace constants with regular local variables. If you use constants as shown above, you would have to justify exposing these strings. This usually only makes sense, if they are reused individually. If they are not and are just temporarily there then local helper variables are definitively preferred. I would even go as far as to put those here docs directly into the array. Kind regards robert