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

I know that this is a pedantic criticism, but isn't that convoluted "kill stray mongrels" command just a simple pkill? The first example is made excessively complicated as well (why not just grep -c)?

Certain things are definitely annoying to do with just the standard set of UNIX tools, but not knowing them well certainly won't help.



The first example is made excessively complicated as well (why not just grep -c)?

"grep -c" is great if you know it. The problem is it's a trick which only works for grep, and learning and keeping track of all of these tricks for every tool you use is a real pain. Never mind that "grep -c" will never be as flexible as wc.

It's more reliable to follow the Unix philosophy:

Write programs that do one thing and do it well. Write programs to work together.


"grep -c" is great if you know it.

This is a tough criticism, since "wc -l" is great if you know it too. And that, in the rush version, you need to use .lines on the result of .search() in order to get something you can call .size on to get the exact result you want (because it seems you can't just call .size on the result of .search(), I suspect that would just return a count of files where the string appears at least once).

In that vein, with a pipeline, you can look at each bit independently and reason about it. You can't reason about what .size returns (lines or bytes or whatever) without looking at what is immediately to the left of it (and then you have to know that .lines returns an array and that .size is returning the length of that array). And you have to know that whatever .lines returns actually has a .size method. wc -l always counts lines, no matter what its context is, because it's only ever dealing with text based input, never more complexly structured data like objects or arrays. This may or may not be what you want, but it does lend itself to wider (re)usability.


I think you've mistaken my argument as being against pipelines, but in fact I was arguing in favor of pipelines and against one-off tricks like "grep -c". Yes, "wc -l" needs to be memorized, but once, for everything you ever wish to count, as opposed to once for every command. In this respect, "grep -c" has the same problem as you pointed out concerning "lines".


Agreed.

   myproj['**/*.rb'].search(/^\s*class/).lines.size
And they say perl looks like line noise. The ratio of ispunct to isalpha in that line is 2:3.


the majority of that punctuation isn't part of the ruby syntax, to be fair.


Good point. These are idiomatic constructs that require familiarity in order to effectively use them.




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

Search: