
On Sep 23, 2009, at 12:24 PM, James Hartzell wrote:
Well, look at code like this:
wrapParens str = concat [ "(", str, ")" ]
I just did. I'd write it as wrap_parens s = "(" ++ s ++ ")" although I wouldn't use that name, because it's not the parentheses that are wrapped, it's s.
First off, there is a serious issue with the commas.
You should at least be allowed to have a comma after the last element, a la Python.
Oh, I agree about that. I've written an Erlang Extension Proposal for Erlang about that.
concat [ "(", str, ")" -- (oops, no comma!) lineEnd -- forgot I needed this ]
"(" ++ str ++ ")" ++ line_end I'm actually quite serious here. Using infix ++ we have the SAME problem about missing ++ as we do about mssing , After all, someone might have started with ( "(" ++ str ++ ")" ) and ended up with ( "(" ++ str ++ ")" -- (oops, no ++!) lineEnd -- forgot I needed this ) I asked for the trailing comma in Erlang for _social_ reasons, not because I believed it would fix all problems of this type.
And as to the "simplifying your code" idea: however "pure" your code is, you will regularly have to embed lists of things in it (ADTs, export lists, data from the domain). And unless you're claiming it is *almost always bad style to have code looking like (from the proposal):
main = do a <- getChar bracket_ (enter a) (exit a) (do putChar a putStrLn "hello")
The thing about toy examples is that they are toy size. On an example this size, we don't NEED fancy new stuff. Actually, I'd write main = getChar >>= \a -> bracket_ (enter a) (exit a) (putChar a >> putStrLn "hello") so even _with_ this proposal, I'd still need exactly the same parentheses. One thing I might do is this: enter_exit_bracket a body = bracket_ (enter a) (exit a) body and then main = getChar >>= \a -> enter_exit_bracket a (putChar a >> putStrLn "hello") because it looks very much as if enter and exit exist only to be passed (with suitable parameters) to bracket_.
But I would *still* rather have: with a = bracket_ $# enter a exit a
Layout is easier to read than parentheses.
It all depends on size (small things being easy pretty much no matter what you do) and tools (tools where you click just inside parentheses and the bracketed thing lights up, like the traditional Smalltalk interface make parentheses very very easy to read).
In summary, I have to spend a good portion of my time coding Haskell dealing with the fact that I have a lot of {'s, ['s, and ,'s to keep track of, and they rarely fit on one line (records, ADTs, lists). I have to spend a significant amount of my coding time finagling the layout to look sensible, and I don't think anyone would claim that I just shouldn't use records or ADTs.
For what it's worth, the editor I normally use has an "add new element to list" command. Where I'm coming from is this: I do not find meaningless jumbles of special characters combined with overloaded white space readable. It would be so much better if we could discuss a _real_ example.