News for hackers. Stuff that matters.
Re:Build command line apps using PHP 7 by TazeTSchnitzel on Sunday September 03, 2017 @04:05PM (#15163560)
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.
Re:Build command line apps using PHP 7 by NightlyDev on Sunday September 03, 2017 @05:12PM (#15163947)
I 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.
Re:Build command line apps using PHP 7 by camus2 on Sunday September 03, 2017 @05:20PM (#15163989)
> 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.

Re:Build command line apps using PHP 7 by terminalcommand on Sunday September 03, 2017 @06:19PM (#15164283)
I 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.
Re:Build command line apps using PHP 7 by camus2 on Sunday September 03, 2017 @09:05PM (#15164920)
PHP 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.

Re:Build command line apps using PHP 7 by combatentropy on Sunday September 03, 2017 @07:08PM (#15164501)

  >  .  . . argument parsing . . .
  > Node has none.
https://nodejs.org/docs/latest/api/process.html#process_proc...
Re:Build command line apps using PHP 7 by camus2 on Sunday September 03, 2017 @08:58PM (#15164892)
> 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.

Re:Build command line apps using PHP 7 by VMG on Sunday September 03, 2017 @04:46PM (#15163812)
How would you compare it to python?
Re:Build command line apps using PHP 7 by astrodust on Sunday September 03, 2017 @05:03PM (#15163900)
It's like Python that forgot to shave. For fifty years.
Re:Build command line apps using PHP 7 by TazeTSchnitzel on Sunday September 03, 2017 @05:49PM (#15164126)
It'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.
Re:Build command line apps using PHP 7 by ComputerGuru on Sunday September 03, 2017 @04:57PM (#15163866)
Like python but easier to dive into for anyone that’s used C before?
Re:Build command line apps using PHP 7 by astrodust on Sunday September 03, 2017 @04:57PM (#15163865)
How 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.

Re:Build command line apps using PHP 7 by wongarsu on Sunday September 03, 2017 @06:14PM (#15164252)
>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_l...

Re:Build command line apps using PHP 7 by TazeTSchnitzel on Sunday September 03, 2017 @05:50PM (#15164129)
> How is C-like syntax a plus?

Well, versus whatever abomination bash uses, it's quite readable…

Re:Build command line apps using PHP 7 by astrodust on Sunday September 03, 2017 @07:20PM (#15164543)
Also better than M4, but this is not really a high bar.
Re:Build command line apps using PHP 7 by justbaker on Sunday September 03, 2017 @04:58PM (#15163874)
I'm dying in laughter here :) +1
Re:Build command line apps using PHP 7 by justbaker on Wednesday September 06, 2017 @09:06AM (#15183297)
> 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..

Re:Build command line apps using PHP 7 by revmoo on Sunday September 03, 2017 @04:40PM (#15163778)
Agreed. Also cli apps with Laravel are amazing if you need to schedule jobs.
Re:Build command line apps using PHP 7 by qualitytime on Sunday September 03, 2017 @04:07PM (#15163573)
Hear, hear.