[erlang-questions] erlang-questions Digest, Vol 17, Issue 45

Richard O'Keefe ok@REDACTED
Fri Oct 10 05:53:41 CEST 2008


On 10 Oct 2008, at 3:11 pm, Edwin Fine wrote:
> Ok, then to preserve the Principle Of Least Astonishment, let  
> string:split accept a regular expression, which is just a string  
> with special RE operators. If the string contains no RE operators,  
> use an optimized special case of split (like the one you wrote) that  
> does not use an RE engine. Get the best of both worlds.

No, that *violates* the principle of least astonishment, Big Time!

First, absolutely nothing else whatever in the 'string' module
has anything to do with regular expressions.  This would be
highly exceptional and very confusing.

Second, something that splits strings using regular expressions
would be expected in the 'regexp' module, not the 'string' module.
In fact, regexp:split/2 already exists.  It would be rather
astonishing to replicate this in the wrong module.

Third, if there were a string:split/2 that used regular
expressions, that would make it very incompatible with
string:join/2, which doesn't.  I thought we were wanting
	string:join(string:split(String, Sep), Sep)
to give back Sep.

In short, if you want something called 'split' that preserves
the principle of least astonishment, use regexp:split/2.
If you want an opposite of string:join/2, DON'T make it use
regular expressions, and DON'T call i split/2.

By the way, I have a use for
	string:join(reverse([Stuff|tail(reverse(
	string:unjoin(Thing, ".")))]), ".")
so I would be very unhappy to have to write one of
those string literals as "\\." and the other NOT.

>
>
>
> There is, or should be, a regular pattern
>        words <-> unwords
>        lines <-> unlines
>        unjoin <-> join
> Oh well, sort of regular...
>
> Sorry, and no offense meant, but that's really horribly ugly.

So you really hate it that English has "tie" and "untie",
"do" and "undo", "wary" and "unwary", amongst many pairs?

> Reminds me of that sentence, "A not unblack dog chased a not unbrown  
> rabbit across a not ungreen field."

Straw man.  The nasty thing about that sentence is the double
negations.  There is no double negation in unjoin.
"unwords" and "unlines" are not my inventions, they are
from the Haskell standard Prelude.

> Should the opposite of down then be "undown"? Languages (well, I can  
> vouch for two, anyway) contain many complementary words that are not  
> syntactically constructable by adding or removing "un-".

What of it?  The words/unwords lines/unline pattern DOES exist
in the language Erlang copied many of its list processing
function names from.  It's not my invention.  Indeed, the
Haskell community is as familiar with "unfold" as with "fold".
In this specific context, UNdoing the effect of a list
operation, "un-" is an excellent cultural fit.

The fact that for example "add" and "subtract" are not related
in that way really doesn't signify anything, just as the fact
that there are many colours doesn't mean that black is a bad
choice.

> Like split and join, for example. Hard and soft. Big and small.  
> Break and mend. Wake and sleep.

Join is also related to sever, disunite, unfasten, disconnect, unyoke,
separate, put asunder, unlink, disassociate, disaffiliate, resign,
detach, disengage, leave, part, divide, quit, ...

Split is also related to unite, unify, connect, fragmént (stress shown),
and another whole lot of words.

It's not as if "split" and "join" were each other's _only_ relative.





More information about the erlang-questions mailing list