6 ms·
Maybe I'm being pedantic, but half of these use ";" to separate statements so I wouldn't really call them one liners.
by eyegor 7y ago
Maybe I'm being pedantic, but half of these use ";" to separate statements so I wouldn't really call them one liners.
- tyingq 7y agoGuess you could replace ; with && for many of them. More typing though.
- kbenson 7y agoA one liner does not mean "one line of source code in a file", it means "a single shell statement". That's why the Ruby command is prefixing them all. I routinely write 10-20 statement Perl one-liners at work for one off things. For example, just yesterday it was to parse a log, grep for specific lines, pull out a time and a number per line, display name, number, and some number of characters afterwards as a quick abnd dirty graph of the magnitude to make it obvious if there were major outliers and to try to see trends over time. Still a one-liner.
- bdcravens 7y agoIn theory, couldn’t you then compile a Rails app into a one-liner? (Seems the max line length varies, but is at least hundreds of thousands of characters in most OSes)
- kbenson 7y agoYou could, but it would be stupid to do so if it wasn't a trivial app, since nobody wants to support something like that, even if it's lifetime is measured in minutes or hours. It's a one-liner, just a pointless one. That said, if rails has a super simple default startup that could serve a file, then it might be useful to start that as a one liner in select circumstances.
- vinceguidry 7y agoRails has generators for that. Invaluable for greenfielding projects in an iterative manner. Blow everything away and recreate with a single command. https://guides.rubyonrails.org/generators.html https://guides.rubyonrails.org/generators.html
- vcavallo 7y agonobody wants to support weird looking one-liners either
- eyegor 7y agoSure, but then you could refactor most programs into "one line" (similar to what another commenter pointed out). I was expecting more of a functional piping or chaining style as opposed to distinct statements and defining local variables.
- anonytrary 7y agoYou're not being pedantic. The term "one-liner" is a misnomer. In many languages, whether or not a program can fit on a single line is a pointless metric, since a program can be rewritten into a single line (e.g. with semicolons or commas). People use the term "one-liner" as if it meant "concise code" which isn't necessarily true. It would be more accurate to just say "concise code".
- Zhyl 7y agoI would expand on that and say 'concise code executed by directly invoking the parser in a shell-like environment using special flags such as a,n,p and e.'