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

This is well made case - but I'm not sure I buy the central argument. Within some basic limits, I don't think terseness and readability have the contradiction made out here, because in programming we have abstraction, which gives us both.

To take the example command that's given:

beef.txt | grep "lasagna" | sort -n | uniq

Sure, writing the logic out for this in something like python straight out the bat with only the standard library might look messy, but with one basic convenience function it could quickly be:

search(for='lasagna', in='beef.txt', clear_duplicates=False).sorted()

Obviously you have to write the function in the first place, but I'd say if you're doing something like this often, it's easily worth spending that 2 minutes. And if you're not doing this often, you'll have a faster time writing more code, but keeping less heavy lifting of "how does bash pipe together" in your head.

I shared a project here a few weeks ago experimenting with what my dream shell might look like, what surprised me more than anything else, was how easy writing a repl environment actually is. I put a scrappy one together as one person in a few hours, so I don't understand why as developers we've reached general language models before being able to make a powerful, but new-user friendly shell.

Also, completely unrelated note, but posix only allows passing back strings - but isn't this true of web apis too which we use all the time? How come no json as a standard passback from programs?

Shameless plug for the project I mentioned earlier: https://github.com/benrutter/clamshell



Your shell example

    beef.txt | grep "lasagna" | sort -n | uniq
is a lot more compositional than your Python-style example:

    search(for='lasagna', in='beef.txt', clear_duplicates=False).sorted()
The former uses a few general purpose functions, the latter seems to use bigger building blocks that aren't as universal.

You could more faithfully mirror the bash example in Haskell, if you wanted to, if you wrote the necessary library functions:

    cat "beef.txt" | grep "lasagna" | sortBy numeric | uniq
This would be actual valid Haskell syntax.


> Your shell example ... is a lot more compositional than your Python-style example

Yes, the Python equivalent would be:

lines("beef.txt").filter(lambda(x): x.contains("lasagna")).sort(type="natural").remove_duplicates()

Of course, all of those things would need to be generators. Python accepts that kind of code, but most "Python developers" wouldn't think on it. Haskell is a much more natural fit for replacing Bash. (By the way, Haskell has at least one Bash replacement library that I remember, but it's hard to find).


Nit, but a single | can't be an operator in Haskell.


True, I got that piece of the syntax wrong.

I guess you can do something very close, though.


Haskell has `&` in Data.Function. You can try it in ghci:

  Prelude> f a x = a * x
  Prelude> g x = x + 2
  Prelude> g $ f 3 $ 5
  17
  Prelude> :m +Data.Function
  Prelude Data.Function> 5 & f 3 & g
  17
It is like `$` but with the arguments flipped:

  ($) :: (a -> b) -> a -> b
  (&) :: a -> (a -> b) -> b


Absolutely. Almost every group of symbols can be used as an operator, just (as it happens) not a single | because that is reserved for patterns.




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

Search: