4 ms·
Why do people write five lines of inefficient Ruby when a more direct single line shell script would suffice?
by jdub 14y ago
Why do people write five lines of inefficient Ruby when a more direct single line shell script would suffice?
- qxcv 14y agoBecause they're used to using Ruby. The efficiency difference is negligible. $ time sh -c exit real 0m0.002s user 0m0.001s sys 0m0.000s $ time ruby -e exit real 0m0.009s user 0m0.008s sys 0m0.000s OTOH I do agree that it is a bit silly to start a Ruby interpreter if you're only going to use it to shell out :)
- batista 14y agoBecause the "inefficiency" is negligible and "premature optimization" is the root of all evil. Because the time it would take them to check the arcane shell syntax would dwarf the time it takes for them to throw a Ruby script together. Because they like using a superior programming language over the cruft that are the shell syntaxes. Because they can add more fancy stuff and features to the Ruby version far more easily. Because they can incorporate the Ruby version to a larger program later on.
- quarterto 14y agoBecause file="~/.gitshots/$(date).jpg" echo "Taking capture into ${file}!" imagesnap -q -w 3 $file is so arcane.
- batista 14y agoNo, the options when you need to add something more are arcane. Plus the above wont even work as is, since $(date) contains spaces.
- adobriyan 14y ago> Plus the above wont even work as is, since $(date) contains spaces. This would be "more direct" part.
- jdub 14y agoEven better (the silence principle): #!/bin/sh imagesnap -q -w 3 "~/.gitshots/$(date).jpg" (date(1) with spaces will be fine due to the double quotes, although it won't be in date order when sorted by name, which would annoy me...)