[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Re: Re: better init.d/* : who carres ?

Wed, 21 Sep 2005 09:32:41 +0000, Gerrit Pape wrote:

On Wed, Sep 21, 2005 at 05:07:31AM -0400, Alfie Costa wrote:
Russ Allbery <rra@stanford.edu> wrote:
> I find constructs like ${string#*=} particularly difficult to read,
> since they require that I remember what all the different punctuation
> characters inside this sort of parameter expansion do.  According to
> the bash manual, there are sixteen of them, and I had to read the
> description of ${parameter#word} three times before I completely
> understood what it said.

1) The man page descriptions of these functions could probably be

There shouldn't be any problems with
 $ man dash

OK, so maybe you'd concede the 'bash' version is knotty:

  % man bash | grep -A 12 "r%word"
  Reformatting bash(1), please wait...
       The word is expanded to produce a pattern just  as  in  pathname
       expansion.   If  the  pattern  matches a trailing portion of the
       expanded value of parameter, then the result of the expansion is
       the  expanded value of parameter with the shortest matching pat-
       tern (the ``%'' case)  or  the  longest  matching  pattern  (the
       ``%%''  case)  deleted.   If  parameter  is  @ or *, the pattern
       removal operation is applied to  each  positional  parameter  in
       turn,  and the expansion is the resultant list.  If parameter is
       an array variable subscripted with @ or *, the  pattern  removal
       operation  is  applied  to each member of the array in turn, and
       the expansion is the resultant list.

Now 'dash':

  % man dash | grep -A 4 "r%word"
  Reformatting dash(1), please wait...
  ${parameter%word}   Remove Smallest Suffix Pattern.  The word is
                      expanded to produce a pattern.  The parameter
                      expansion then results in parameter, with the
                      smallest portion of the suffix matched by the pat-
                      tern deleted.

...IS better, but it's like saying that McDonald's burgers are lower fat than Wendy's. Both texts just seem to clog the reader's mental arteries.

Some may infer a distaste for the above texts as invincible ignorance -- and yet I understand what both are trying to say, and have programmed with those useful constructs, (see previous attachment), and wish they were used more. The trouble is that on receiving such tweaks for a slow script, some weary maintainers complain code like that is Greek, "nobody" uses it, it's hard to maintain, they don't want any.

It'd be nice to write an obvious improvement of the '${parameter%word}' text. A few years back I attempted it, (not publicly), but the results weren't satisfactory**. Which is not to suggest it can't be done, but failing then was what inspired thoughts of sidestepping the difficulty using wrapper functions with easy syntax and mnemonic names instead of arbitrary chars like '#' and '%'.

(**A low-budget quandary: finding human guinea pigs to test read such revisions. Preferably it should be somebody who doesn't know anything about it -- if they can understand it, it's probably lucid. Unfortunately such persons are usually so prejudiced against, or
intimidated by, tech text that they often blame themselves or try to
avoid it, saying "oh it's fine, I'm too dumb to understand it", especially if there's no immediate reward. Sadly, experts who are eager to help are often bad test readers, they know too much; it's like asking a weight lifter if some common object is heavy.)

More about the arbitrariness of '%' and '#' -- besides there being no natural connection between a percent sign and a suffix, it's anyone's guess why two percent signs '%%' should mean largest, and one sign '%' should mean smallest. There are mnemonic tricks to help remember arbitrary sets, like:

	The Great Lakes / HOMES

...or, which is which:

	stalagmite	'g' for ground
	stalactite	'c' for ceiling

...but try come up with a rule of thumb for '%%' (big suffix), '#' (small prefix), etc.? Maybe the 'p' in percent is for Prefix -- but no, the Prefix is the hash symbol; two signs are bigger than one, like Roman numerals... it's a puzzle.

That's why the wrapper functions.

Reply to: