Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Your Python version is def neater and more compact. However there's something really elegant about using the | operator to compose commands (or using |> in OCaml/F# or iirc $ in Haskell) that I can't quite articulate :)


> something really elegant about using the | operator

For me, it's the fact that it nicely maps to high level steps I would use to manipulate the option, expressed quite tersely.


What I mean is that even if the steps would otherwise be identical, I can't really explain why I feel like structuring them like this:

    get_users
    |> filterActiveUsers
    |> sortByDateCreated
    |> getEmail
or even this:

    get_users |> filterActiveUsers |> sortByDateCreated |> getEmail
feels neater than:

    getEmail(sortByDateCreated(filterActiveUsers(get_users())))
My example is a bit stupid but I hope it's clear what I mean. Maybe it's just that as someone who only knows left-to-right languages, the flow of the data matches the order the steps appear? Actually I'm now curious if Arabic or Hebrew speakers feel the same way. Or maybe I'm overthinking this :)


I think it's flow order.

But then you could say the same about forth.

get_users filterActiveUsers sortByDateCreated getEmail

Would be valid forth. But that doesn't seem to match people's brain in the same way.

Maybe humans are weird and inconsistent?

Or maybe it's because it would end up as & "file" -f 5 --bar get_users?

Although the shell doesn't really parse the options so you could cheat a bit and do

&Get_users -f "file" --bar 5

Which to me seems more readable than standard shell.


In Forth, you have to reason about how many things each command takes off the stack and leaves on the stack, whereas with pipes, it's always exactly one thing.


That's true I suppose, but is the the only issue with forth?

Or perhaps it's that a stack is good for certain things, but not for everything?

If your language just consisted of map() you'd soon run into its limits.


Yeah I think it’s one of the less-hard things about Forth. For what it’s worth I quite enjoyed fiddling with Forth, and went through a bit of a “stack computing” phase. I never made the connection with the the pipe operator tho


For me, the last example feels messy for two reasons. First, I have to worry about matching parens. That can feel mentally exhausting even for simple cases. Second, it's written all on one line, so it's harder to mentally separate all the steps. I usually break expressions like that apart into separate lines, but that means finding concise yet meaningful names for temporary variables.


Oh yeah I would definitely split them up into little intermediate steps. But then I’d get a bit sad that I don’t have the pipe operator :-)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: