4 ms·
I routinely use vanilla PHP (no special libraries) for CLI scripts. It's actually fantastic for this. It has a large set of functions that do everything you wan
by TazeTSchnitzel 9y ago
I routinely use vanilla PHP (no special libraries) for CLI scripts. It's actually fantastic for this. It has a large set of functions that do everything you want, no imports required, and it has C-like syntax with real types and functions.
- qualitytime 9y agoHear, hear.
- revmoo 9y agoAgreed. Also cli apps with Laravel are amazing if you need to schedule jobs.
- VMG 9y agoHow would you compare it to python?
- ComputerGuru 9y agoLike python but easier to dive into for anyone that’s used C before?
- astrodust 9y agoIt's like Python that forgot to shave. For fifty years.
- deleted 9y ago[deleted]
- TazeTSchnitzel 9y agoIt's a similar experience. PHP is slightly more Perl-ish (dollar signs, no namespaces for built-in functions, `or die`, native string interpolation) and has type declarations.
- astrodust 9y agoHow is C-like syntax a plus? I know Perl, C, C++ and PHP quite well, but I'd never, ever call C-like syntax a plus. It's astonishing how feeble modern PHP is, that to comapre strings you often have to use strcmp. In 2017. It's like all the cruft of ANSI C with a whole bunch of $ characters spiked in.
- justbaker 9y agoI'm dying in laughter here :) +1
- justbaker 9y ago> How is C-like syntax a plus? It's the most common syntax pattern of popular languages. Statistically, more developers know a language with a "C-like" syntax than Lisp, Haskell, Erlang..
- TazeTSchnitzel 9y ago> How is C-like syntax a plus? Well, versus whatever abomination bash uses, it's quite readable…
- astrodust 9y agoAlso better than M4, but this is not really a high bar.
- wongarsu 9y ago>How is C-like syntax a plus? C-style syntax is fairly popular [1]. If it had lisp syntax or haskell syntax most people would complain that they can't figure out what's going on without learning all that syntax. >that to comapre strings you often have to use strcmp For equality === works just fine. For < and > there is no one obviously correct order, so it's entirely reasonable to use functions for that. 1: https://en.wikipedia.org/wiki/List_of_C-family_programming_languages https://en.wikipedia.org/wiki/List_of_C-family_programming_l...
- deleted 9y ago
- NightlyDev 9y agoI totally agree. I find PHP CLI scripts to have a good balance between functionality, simplicity and performance. It's definitely not suited for every task, but I do think it's great for most tasks.
- camus2 9y ago> I routinely use vanilla PHP (no special libraries) for CLI scripts Vanilla PHP has better argument parsing than many recent hipster language. Go has some sort of ugly non conventional argument library which is barely usable, Node has none. But nothing beats vanilla Python for that tasks IMHO.
- terminalcommand 9y agoI haven't used PHP for CLI scripting, however I've used Python and Golang. I can say that Golang argument library (flag) feels more straightforward to me than Python's argparse. import "flag" var ip = flag.Int("flagname", 1234, "help message for flagname") ... // flag.Parse() once in the main function vs import argparse parser = argparse.ArgumentParser() parser.add_argument("square", help="display a square of a given number", type=int) ... args = parser.parse_args() In the Go example you get a pointer just like in C, in the python example you get a special object and can access its fields. Both are simple, but Golang is IMHO closer to C in this matter.
- camus2 9y agoPHP and C have getopt in their standard library which work mostly the same way. flag package bothers me because it breaks getopt conventions for no good reason.
- combatentropy 9y ago> . . . argument parsing . . . > Node has none. https://nodejs.org/docs/latest/api/process.html#process_process_argv https://nodejs.org/docs/latest/api/process.html#process_proc...
- camus2 9y ago> https://nodejs.org/docs/latest/api/process.html#process_proc.. https://nodejs.org/docs/latest/api/process.html#process_proc.... This is not argument parsing. I'm pretty sure Node doesn't even do anything, it just gets an array of strings from the CLI, argv C style isn't getting options prefixed with - or -- directly from the CLI, and putting them in a map or something. So no, node has no facility in its standard library for that. Node is not known for its extensive standard library in anyway.