4 ms·
> 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, expre
by maest 4y ago
> 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.
- smcl 4y agoWhat 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 :)
- cout 4y agoFor 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.
- smcl 4y agoOh 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 :-)
- benj111 4y agoI 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.
- xigoi 4y agoIn 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.
- benj111 4y agoThat'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.
- smcl 4y agoYeah 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