News for hackers. Stuff that matters.
Re:PHP 8.1.0 by krisrm on Thursday November 25, 2021 @03:49PM (#29344857)
Elegant is not the word I'd use to describe PHP. Solid, perhaps. Undoubtedly useful. But if there is elegant PHP, I haven't seen it.
Re:PHP 8.1.0 by KerryJones on Thursday November 25, 2021 @05:52PM (#29345782)
Have you looked at any Laravel code? As someone who has worked from small startups to FAANG and inbetween, Javascript to PHP to Python to Go, I haven't found anything more elegant.
Re:PHP 8.1.0 by sergiosgc on Friday November 26, 2021 @10:26AM (#29351032)
I have. Elegant it is not. Actually, it smells like Enterprise Java code, which made me flee from the Java ecosystem. To each his own, but this is not an elegant event listener (copied from the examples page):

  use App\Events\ArtistInformationFetched;
  use App\Services\MediaMetadataService;
  use Throwable;
  
  class DownloadArtistImage
  {
      private MediaMetadataService $mediaMetadataService; 
  
      public function __construct(MediaMetadataService $mediaMetadataService)
      {
          $this->mediaMetadataService = $mediaMetadataService;
      }
  
      public function handle(ArtistInformationFetched $event): void
      {
          $info = $event->getInformation();
          $artist = $event->getArtist();
  
          $image = array_get($info, 'image');
  
          if (!$artist->has_image && $image && ini_get('allow_url_fopen')) {
              try {
                  $this->mediaMetadataService->downloadArtistImage($artist, $image);
              } catch (Throwable $e) {
              }
          }
      }
  }
Source: https://laravelexamples.com/example/koel/events-listeners
Re:PHP 8.1.0 by KerryJones on Friday November 26, 2021 @03:33PM (#29353803)
It's interesting to me how to show your example you chose something from a 3rd party, non Laravel site (just because it has a laravel in the name doesn't), and chose something which inherently doesn't follow PHP or laravel coding standards (snake_case variables, for instance), when you could easily pull something from the main Laravel website?

https://laravel.com/docs/8.x/container#introduction

Or, if you wanted something perhaps at least use one of their featured partners for real code? https://github.com/tighten/jigsaw/blob/main/src/Jigsaw.php

I also would argue that the majority of code I see in other languages is equally or worse than the example you gave.

You can write terribly in any language, Laravel included.

Re:PHP 8.1.0 by path411 on Thursday November 25, 2021 @09:01PM (#29346876)
I think most people outside php have no idea what Laravel is, while anyone working in php is using Laravel so basically our viewpoint is Laravel = php. I don't know what it is about the normal personality that anyone using something you don't understand just be "doing it wrong"
Re:PHP 8.1.0 by 0x0nyandesu on Thursday November 25, 2021 @07:36PM (#29346462)
I see php sort of like a trusty hammer. It's a hammer. Doesn't have to be elegant. It's a hammer.

The nails are http requests and PHP is a damn good hammer.

Re:PHP 8.1.0 by paulryanrogers on Friday November 26, 2021 @09:59AM (#29350757)
Cue the infamous double-claw hammer meme. I'd agree PHP is quite useful for web work, especially backend. And like a specialty hammer it wouldn't be useful in a lot of situations such as desktop apps or DB procedures.
Re:PHP 8.1.0 by donatj on Friday November 26, 2021 @01:15AM (#29347897)
Hello World in PHP is literally

    Hello World
I know no other language that elegant.
Re:PHP 8.1.0 by rei_ayanami on Friday November 26, 2021 @06:16AM (#29349187)
If programing stopped there we wouldn't have an argument, its when you design high performant code that is maintained for over 10 years etc.
Re:PHP 8.1.0 by mejutoco on Friday November 26, 2021 @06:44AM (#29349350)
From the top of my head, Javascript and Common Lisp will also work with "Hello World" (with quotes).
Re:PHP 8.1.0 by donatj on Friday November 26, 2021 @07:13AM (#29349552)
I can’t speak for Lisp, but JavaScript isn’t going to write that to standard out, it would just be a statement that didn’t do anything.

You would need something like

    import { stdout } from 'process';
    
    stdout.write("Hello World");
Re:PHP 8.1.0 by mejutoco on Monday November 29, 2021 @04:53AM (#29377985)
Fair enough. On the client (just opening dev tools) it would return the string, but as you say, it depends on what we count as valid (repl, server-side, client). Probably the closest would be

    console.log("Hello World")
Re:PHP 8.1.0 by chippiewill on Friday November 26, 2021 @07:32AM (#29349669)
Being able to do a trivial hello world doesn't make a language elegant.
Re:PHP 8.1.0 by richrichardsson on Friday November 26, 2021 @06:57AM (#29349449)
The easiest Quine imaginable!
Re:PHP 8.1.0 by Karellen on Friday November 26, 2021 @06:42AM (#29349329)
m4
Re:PHP 8.1.0 by rhengles on Thursday November 25, 2021 @04:54PM (#29345333)
This depends a little on the taste of each person, but personally the most elegant way of doing PHP apps I ever found is with Siler: https://siler.leocavalcante.dev/v/main/ and Create Siler App: https://github.com/leocavalcante/create-siler-app
Re:PHP 8.1.0 by ipaddr on Thursday November 25, 2021 @06:06PM (#29345861)
PHP is elegant and useful. The spread operator is ...$array is elegant. $var ? "not found"; is really elegant.
Re:PHP 8.1.0 by eloisius on Thursday November 25, 2021 @08:48PM (#29346821)
It’s also about ten years later than everyone else to get those splat and null coalesce operators so it’s not like that elegance is unique or even timely for PHP.
Re:PHP 8.1.0 by ipaddr on Thursday November 25, 2021 @09:19PM (#29346953)
Your post is 10 years too late because we are talking about php today. PHP was elegant in different ways 10 years ago.
Re:PHP 8.1.0 by keyle on Friday November 26, 2021 @12:09AM (#29347633)
I think you meant ?? or ?= ?