PHP Internals News: Episode 61: Stable Sorting – Derick Rethans

PHP Internals News: Episode 61: Stable Sorting

In this episode of “PHP Internals News” I chat with Nikita Popov (Twitter, GitHub, Website) about his Stable Sorting RFC.

The RSS feed for this podcast is https://derickrethans.nl/feed-phpinternalsnews.xml, you can download this episode’s MP3 file, and it’s available on Spotify and iTunes. There is a dedicated website: https://phpinternals.news

Transcript

Derick Rethans 0:18

Hi, I’m Derick, and this is PHP internals news, a weekly podcast dedicated to demystifying the development of the PHP language. This is Episode 61. Today I’m talking with Nikita Popov about a rather small RFC that he’s proposing called stable sorting. Hello Nikita, how are you this morning?

Nikita 0:36

Hey, Derick, I’m great. How are you?

Derick Rethans 0:38

Not too bad myself. Let’s jump straight in here. The title of the RFC is stable sorting, what does that mean, what is stable sorting, or what is sorting stability?

Nikita 0:48

Sorting stability refers to the behaviour of the sort when it comes to equal elements. And equal share means that we sort comparison function. For example, the one you pass to usort says the elements are equal, but there is still some way to distinguish them. For example, if you’re sorting some objects, to take the example from the RFC, we have an array with users, and users have an age, and we use usort to only sort the users by age. Then according to the comparison callback all users with the same age are equal. But of course, the user also has other fields on which we can distinguish it. And the question is now in what order will equal elements appear. If we have a stable sort, then they will appear in the order they were originally in. So it’s something not going to change.

Derick Rethans 1:41

And that is not what PHP sorting mechanism currently does?

Nikita 1:44

Right. PHP currently uses an unstable sort, which means that the order is simply unspecified. It will be deterministic. I mean if you take the same input array and sort it, then every time we will get the same result. But there is no well specified order or relative order of elements. There’s just some order. The reason why we have this behaviour is that well there are, I would say, two, the only two sorting algorithms. There is merge sort. Which is a guaranteed n log n sort that the stable, but has the disadvantage that that requires additional memory to perform the merge step. The other side there is a quicksort, which is an average case n log n sorting algorithm and is unstable, but does not require any additional memory. And in practice, everyone uses one of these algorithms, usually with a couple of extensions on sort of merge sort. Nowadays we use timsort, but which is still based on the same underlying principle, and for quicksort, we have sort which is better than quicksort, which tries to avoid some of the bad worst case performance which quicksort can have. PHP currently uses us a quicksort, which means that our sorting results are unstable.

Derick Rethans 3:07

Okay, and this RFC suggesting to change that. How would you do that? How would you modify quicksort to make it stable?

Nikita 3:15

Two ways. One is to just change the sorting algorithm. So as I mentioned, the really popular stable sorting is timsort, which is used by Python by Java and probably lots of other languages at this point. And the other possibility is to stick with an unstable source. So to stick with quicksort, but to artificially enforce that the comparison function does not have, does not report equal elements that a

Truncated by Planet PHP, read more at the original (another 5853 bytes)

PHP 8.0.0 Alpha 2 available for testing – PHP: Hypertext Preprocessor

The PHP team is pleased to announce the second testing release of PHP 8.0.0, Alpha 2. This continues the PHP 8.0 release cycle, the rough outline of which is specified in the PHP Wiki. For source downloads of PHP 8.0.0 Alpha 2 please visit the download page.Please carefully test this version and report any issues found in the bug reporting system.Please DO NOT use this version in production, it is an early test version. For more information on the new features and other changes, you can read the NEWS file, or the UPGRADING file for a complete list of upgrading notes. These files can also be found in the release archive. The next release will be Alpha 3, planned for 23 Jul 2020.The signatures for the release can be found in the manifest or on the QA site.Thank you for helping us make PHP better.

Release of the Advanced Web Application Architecture book – Matthias Noback

Book cover

100% done

I’m happy to announce that my latest book “Advanced Web Application Architecture” is now complete.
With ~390 pages it has become a well-rounded book full of useful design patterns and architectural principles built around the notion of object-pure code, that will help you create decoupled applications that are testable by definition, and support a domain-first approach to software development.

Use this link to get 10% off the price: https://leanpub.com/web-application-architecture/c/RELEASE_DAY

“This book helped me to improve myself and I recommend it to any developer who wants to learn how to solve problems in a better way.” — Iosif Chiriluta

“Matthias has a knack for distilling decades of experience into simplified rules of thumb. Explained with practical examples, the rules in this book are accessible to developers of any level of experience. I expect to recommend this book for many years to come.” — Ramon de la Fuente

A second round of book club sessions

Read with the author

In the past few months we’ve been having some really interesting sessions with early-access readers of the book.
With the book fully finished, I decided to plan another round of sessions starting in September.
To join these sessions make sure to select the package “The Book + 6 Book club sessions” when buying your copy of the book.

“This book is a most welcome simplification of modern web application architecture concepts, making the topic accessible for a wide audience. By guiding the reader through classic web application scenarios and applying a couple of simple rules and principles while staying very pragmatic, the author achieves what most others don’t – making the core idea so simple that it is near impossible for the reader to get it wrong. The only architecture book I would recommend even to my junior colleagues.” — Ondřej Bouda

Print edition

For those who prefer a paper book there’s also a print edition available via Lulu.
This includes a free copy of the e-book.
You’ll find instructions for obtaining it inside the book.

The making of

Back in April 2019 I started working on this project.
It all started with the family visiting friends in France while I stayed at home, alone, with a bunch of post-it’s.

Post-it's

From this first brainstorm session I created a preliminary table of contents:

Original TOC part 1Original TOC part 2

The rough outline was there, but I started working on the setup first.

So far I’ve only used Leanpub’s Markdown-based publishing process.
They first convert the Markdown manuscript to LaTeX, then to PDF, html, EPUB and MOBI.
I thought it would be nice to have more control over all the build artifacts, so I worked on my own LaTeX-based setup.
This was a silly decision.
I didn’t keep track of all the hours that went into this, but it has probably taken me about 50 hours to get it right.
Of course, I keep running into little things that don’t work.
But I do have a fully automated local book writing process now.
Being able to add all kinds of other generated artifacts is really helpful.
For instance, I can edit the book cover in Gimp and it will be automatically resized for the different e-book formats, and also flattened for the print cover.
The same goes for the diagrams: if I modify them using the Draw.io desktop editor, they will be automatically prepared for inclusion in the manuscript.
Cool!
But also: very costly.

With the technical stuff out of the way, the writing process was great in the beginning, but seemed to last for ages in the end.
I’ve spent a total of 208 hours of actual writing (including writing the code samples and creating the diagrams).
I generally aim to get everything right the first time (of course), but revising

Truncated by Planet PHP, read more at the original (another 962 bytes)

Byte-sized functional programming: Pure functions encourage small code – larry@garfieldtech.com

Byte-sized functional programming: Pure functions encourage small code

One of the many pieces of advice for a long-term sustainable code base is to keep code small. The larger a code base is, the more effort it takes to understand all the moving parts. Your brain can only keep so much mental model of your code in it at once, and if the code you’re looking at is too large then what you can fit in your own “active memory” at once then you will have an increasingly hard time understanding it.

Most useful applications tend to grow larger than what the typical human can fit in their active memory, however, so you need a way to break up your code so you can load a relevant piece into your brain at once to understand and debug it. Usually that takes the form of encapsulation, coupling, cohesion, and other common object-oriented vernacular.

But what about just a pure function?

A pure function is a function that:

Larry
6 July 2020 – 5:13pm

PHP Internals News: Episode 60: OpenSSL CMS Support – Derick Rethans

PHP Internals News: Episode 60: OpenSSL CMS Support

In this episode of “PHP Internals News” I chat with Eliot Lear (Twitter, GitHub, Website) about OpenSSL CMS support, which he has contributed to PHP.

The RSS feed for this podcast is https://derickrethans.nl/feed-phpinternalsnews.xml, you can download this episode’s MP3 file, and it’s available on Spotify and iTunes. There is a dedicated website: https://phpinternals.news

Transcript

Derick Rethans 0:16

Hi, I’m Derick, and this is PHP internals news, a weekly podcast dedicated to demystifying the development of the PHP language. This is Episode 60. Today I’m talking with Eliot Lear about adding OpenSSL CMS supports to PHP. Hello Eliot, would you please introduce yourself.

Eliot Lear 0:34

Hi Derick, it’s great to be here. My name is Eliot Lear, I’m a principal engineer for Cisco Systems working on IoT security.

Derick Rethans 0:41

I saw somewhere on the internet, Wikipedia I believe that he also did some RFCs, not PHP RFC, but internet RFCs.

Eliot Lear 0:49

That’s correct. I have a few out there I’m a jack of all trades But Master of None.

Derick Rethans 0:53

The one that piqued my interest was the one for the timezone database, because I added timezone support to PHP a long long time ago.

Eliot Lear 1:01

That’s right, there’s a whole funny story about that RFC, we will have to save it for another time but there are a lot of heroes out there in the volunteer world, who keep that database up to date, and currently the they’re corralled and coordinated by a lovely gentleman by the name of Paul Eggert and if you’re not a member of that community it’s really a wonderful contribution to make, and they need people all around the world to send an information but I guess that’s not why we’re here today.

Derick Rethans 1:29

But I’m happy to chat about that at some other point in the future. Now today we’re talking about CMS support in OpenSSL and the first time I saw CMS. I don’t think that means content management system here.

Eliot Lear 1:41

No, it stands for cryptographic message syntax, and it is the follow on to earlier work which people will know as PKCS#7. So it’s a way in which one can transmit and receive encrypted information or just signed information.

Derick Rethans 1:58

How does CMS, and PKCS#7 differ from each other.

Eliot Lear 2:03

Actually not too many differences, the externally the envelope or the structure of the message is slightly better formed, and the people who worked on that at the Internet Engineering Task Force were essentially just making incremental improvements to make sure that there was good interoperability, good for email support and encrypted email, and signed email, and for other purposes as well. So it’s very relatively modest but important improvements, from PKCS#7.

Derick Rethans 2:39

How old are these two standards?

Eliot Lear 2:42

Goodness. PKCS#7, I’m not sure actually of how old the PKCS#7 is, but CMS dates back. Gosh, probably a decade or so I’d have to go look. I’m sorry if I don’t have the answer to that one,

Derick Rethans 2:56

A ballpark figure works fine for me. Why would you want to use CMS over the older PKCS#7?

Eliot Lear

Truncated by Planet PHP, read more at the original (another 15109 bytes)