Live data from Hacker News

PHP – The Right Way

phptherightway.com

331–340 of 349 posts

Re: PHP – The Right Way

#331
post #227

PHP is still full of awkward decisions. One that baffles me is that 8.0 changed it so all scripts default to a "C" (i.e. english, ascii-only) locale. [0] So this is now a scripting language that requires you to call `setlocale` for every script manually. Contrast python, which tries to fix the locale so it's at least UTF-8 aware. [1] [0]: From https://www.php.net/manual/en/migration80.incompatible.php "The default lo…

It seems awkward, but it's not. It picks picks a deterministic default instead of a "whatever you have in your OS environment".

It practice all these env config initialization things are handled by the php.ini, and/or by a framework.

(Plus using the mb_string ext is how any minimally sane string handling is done in PHP nowadays.)

Yes, probably in ~10 years the PHP world too will move to a unicode by default setup :)

But hey, progress!

Re: PHP – The Right Way

#332
post #153

Actually, that make me remember statements of Linus Torvalds on Git at Google Tech Talk Conference: But I did end up using CVS for seven years at a commercial company and I hated it with a passion. When I say I hate CVS with a passion, I have to also say that if there are any SVN users in Subversion, users in the audience, you might want to leave because my hatred of CVS has meant that I see Subversion as being the m…

Funny considering Linus Torvalds believes that C is the best since sliced bread. https://www.google.com/search?q=c+the+right+way

He seems pretty chill about Rust, maybe even positive.

He hates C++ with a passion though. (Like CVS.) And .. it's understandable. C++ did not fix anything back then, that he cared about. Quite the opposite, only made things even worse for low-level code, because it was even more undecipherable by mere mortals. (And ... mostly still is.)

Re: PHP – The Right Way

#333
post #330

Earlier quoted context omitted.

Surprising php has a lot of FP aspects.

It .. really doesn't. (Sure, probably a tiny bit more than Python.) It's not static types FP like Haskell/Scala (or even TS), as it just recently started gaining some type safety, and while it had map/reduce call_user_func, it wasn't that big in PHP world. It simply has/had too much mutability for it, and most PHP practice focused on trying to implement OOP ideas in it in a nice way.

FWIW, I don't consider type safety a major issue with FP vs. OOP vs. procedural. I think type safety is just that, a safety net. I've ported things between C#, Scala, and PHP for fun, and regularly find PHP to be more concise due to it's lack of type safety than it being a hinderance. Sure, it sucks that the IDE can't help me out more (lack of generics cough) but static analysis tools really help there, like Psalm and PHPStan. As a side note, Psalm's security scans have pointed out security issues with the original code it was ported from, so that's something...

You can do some pretty fancy things with arrays that you usually only see in FP type languages:

  $arr1 + $arr2 (non-numeric keys) // scala: arr1 ++ arr2
  array_merge($arr1, $arr2) // scala: (arr1 ++ arr2) distinct
  array_unique(array_merge($arr1, $arr2)) // scala: arr1 union arr2
  array_intersect($arr1, $arr2) // scala: arr1 intersect arr2
  array_combine($arr1, $arr2) // scala: arr1 zip arr2
  array_filter(array_map($mapper(...), $arr)) // scala: arr.flatmap(mapper)
in all of these cases, the original array(s) remains untouched. In most OOP languages, the array would probably be mutable (or require some juggling between mutable and immutable types, like C#). That's why its surprising. It's quite verbose in PHP, but the foundations for a FP approach is all there.

What's even more surprising is when performance is comparable to a language like C# on some random benchmarks I've run[1] (opcache + JIT turned on in PHP, C# in "release" optimized compilation). I'd consider it a pretty good contender for serious things.

[1]: https://github.com/withinboredom/distributed-hashmap/blob/23...

Re: PHP – The Right Way

#334
post #194

Earlier quoted context omitted.

> Same can be said (and to me is verrrry true) fro JavaScript. Not if you use JS like Scheme: https://www.crockford.com/little.html In fact JS is much more pleasant to write than PHP, the main reason to move way from PHP after using it for over 10 years.

JavaScript: the language that can barely understand itself is better than PHP! The language, where JetBrain's IDE (arguably one of the best IDEs when it comes to understanding languages, consistently better than any LSPs among other things) can barely understand it fully, is better than PHP! The language that has consistently added new features, but have yet to fix horrible messes of legacy design. The majority of Ga…

It can't fix its legacy design for backward compatibility reasons in browsers

Re: PHP – The Right Way

#335

PHP is a language with various features that might make it attractive to certain people: • CGI-like execution model when used for the web, making resource leaks very difficult and encouraging scalable design • not only integers and floats, but also strings, lists and dictionaries as mutable value types (copy-on-write) — this is a big difference from JavaScript and Python • unusually for a dynamic “scripting” language…

> a standard library that doesn't require import statements I consider this a non-feature in JS. The global namespace is enormous and growing rapidly. As I recall, PHP’s global namespace is similarly enormous (and notorious for its inconsistencies and redundancies). I understand that there are ergonomic advantages to not having to import built-ins, but I think framing it as a feature deserves a healthy asterisk :) >…

I think JavaScript global namespace is massive in the browser. Under nodejs things are much saner.

Re: PHP – The Right Way

#336

Earlier quoted context omitted.

> a standard library that doesn't require import statements I consider this a non-feature in JS. The global namespace is enormous and growing rapidly. As I recall, PHP’s global namespace is similarly enormous (and notorious for its inconsistencies and redundancies). I understand that there are ergonomic advantages to not having to import built-ins, but I think framing it as a feature deserves a healthy asterisk :) >…

I think JavaScript global namespace is massive in the browser. Under nodejs things are much saner.

It’s increasingly almost the same, aside from very DOM/*ML rendering contexts, and getting more similar as time goes on. Which is good for portability but JS (ECMAScript/TC-39) is huge in itself, and the various compatible things in the JS runtime ecosystem (browsers/Node/Deno) is also huge. Node was historically more limited here but given how much the language itself is expanding they have to choose compat.

Re: PHP – The Right Way

#337
post #325
post #259

Earlier quoted context omitted.

Before 2017-12-01, the documentation for count() said: > Returns the number of elements in array_or_countable. When the parameter is neither an array nor an object with implemented Countable interface, 1 will be returned. There is one exception, if array_or_countable is NULL, 0 will be returned. If the languages developers did not want programmers to use that behavior they should have said that it is undefined when t…

Do you not think languages should evolve? Do you think the count() behaviour should never have changed because at some point the documentation said this? How do you propose languages deal with evolution if not graceful deprecation? This isn't Go or Rust that have been around for a few years, this is a 30 year old language that was designed for an entirely different web than what we have today and has had to reinvent…

In case of count this is more likely not because of a different web but the changes we can see for stdClass, arrays and the object model.

And give peace a chance, it is not always love on first sight when something unexpected happens.

Re: PHP – The Right Way

#338
post #259
post #214

Earlier quoted context omitted.

Quoted post unavailable.

Before 2017-12-01, the documentation for count() said: > Returns the number of elements in array_or_countable. When the parameter is neither an array nor an object with implemented Countable interface, 1 will be returned. There is one exception, if array_or_countable is NULL, 0 will be returned. If the languages developers did not want programmers to use that behavior they should have said that it is undefined when t…

> When you document how something behaves in any particular case programmers are going to use it, especially in a case like this where the behavior is actually useful.

This is true and also the reason of the extraordinary warning and the years-long phase-out.

The old count is not really a sharp-shooter, however once we got accustomed to it, we all have our habits.

I only once needed it, IIRC:

  function good_old_count(mixed $mixed): int
  {
      return (is_array($mixed) || ($mixed instanceof Countable))
          ? count($mixed)
          : ( (int) ( null !== $mixed ) )
          ;
  }

Re: PHP – The Right Way

#339
post #185

Earlier quoted context omitted.

3. Executing code for a request is single-threaded. This is almost always what you want; And now with fibers you can launch "threads", which are not threads but work like them.

Aren’t fibers designed from the perspective of usage in underlying libraries, rather than something for everyday end users in the fashion of async/await?

Nothings forbids you to use them directly but yes.

Re: PHP – The Right Way

#340

Earlier quoted context omitted.

We use Asp.NET and it is a giant surprise how good it is. We are unix ppl, Linux & MacOS so not a MS shop at all. We deploy to on-prem and AWS so no Azure.

Do you deploy to Linux images on AWS? I'm actually very interested in your dev setup. Do your devs use Linux machines? What IDE?

Great questions. I am going to write a detailed article about it because you are not the first person asking these.

We have two deployment modes:

- lambda

- ec2 instance

Depending on how you would like to target Lambda you have multiple options. On ec2 too.

We use VS Code on both Linux and MacOS. The tooling is kind of meh at the moment, Ionide is not ready for prime time we run into issues frequently with it. We are considering to switching to Rider soon.

https://www.jetbrains.com/help/rider/F_Sharp.html

* I do not have time to write your a detailed answer but I promise to get back with an article sometime this month.

Post reply on HN