When in doubt, turn to _why
judofyr.net
judofyr.net
The style of programming that in any way values a lot of weird unreadable characters is a relic of the past, and it is not in any way related to skill level or intelligence, as a lot of people seem to think.
Code should always be made as clear as possible first, and should only be made more obscure when performance is critical, and there is no clear way of writing the same block.
I think sometimes developers forget about coding as a means of artistic expression. I love Ruby for pretty much the exact same reasons so many of you dislike it: It's an amazingly expressive language and code like this is nothing but art.
This was the first time I’ve ever heard of the merge block. It’s not even properly documented! But it’s a very simple and very powerful feature...
...doesn't inspire confidence. :)
Some context might help: http://redhanded.hobix.com/bits/campingAMicroframework.html http://github.com/why/camping/tree/master
How is it better then?
You may end up with non-scalable, unreadable, and/or untested code in a production system for a number of reasons. Some I can think of off the top of my head include performance and schedule pressure. Introducing it for fun sounds like bad news bears to me.
The same applies for code.
"key[subkey][subsubkey]" => "some_value"
is parsed into {"key" => {"subkey" => {"subsubkey" => "some_value"}}}
for any depth of nesting.Valid keys would be:
"key"
"key[subkey]"
"key[subkey][subsubkey]"
etc.
I hope I got the spec right. Pretty tired right now, been coding all day. :) let Right x = paramTree [("a[x]","b"),("a[b]","c"),
("a[b][c]","d"),("bc[de]","f")] in putStrLn (drawTree x)
{ "a" => { "b" => <conflict>, "x" => "b" }, "bc" => {
"de" => "f" } }yc.hs:35:34: No instance for (Monad (Either String)) arising from a use of `mapM' at yc.hs:35:34-52 Possible fix: add an instance declaration for (Monad (Either String)) In a 'do' expression: keys <- mapM parseKey names In the expression: do keys <- mapM parseKey names return (toTree (zip keys values)) In the definition of `paramTree': paramTree nameValues = do keys <- mapM parseKey names return (toTree (zip keys values)) where (names, values) = unzip nameValues
(Edit: I'm sorry that the error message's whitespace gets messed up here.)
Also your groupings function is only used in conjunction with Data.Map.fromList. Did you consider using something like Data.Map.fromListWith (++) instead? Of course you'd have to wrap your would-be Map values in singleton lists first.
instance Error e => Monad (Either e) where
...
I didn't consider Data.Map.fromListWith; I didn't know about it. (Thanks.)$parsed = str_replace('{', '{"', '{'.str_replace(Array('[', ']'), Array('" => {', ''), $string)) .str_repeat('}', substr_count($string, '[')+1);
Here's an example of a nested hash: "XXX". Here's what normally happens in Rack: "XX". Here's what we want to happen: "XX". Here's a couple solutions.
Ding, now everyone is clearly on the same page, instead of reading the article twice trying to figure out what's going on.