Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Tomas Votruba:
How to Teach Your Team Private Method Sorting in 3 mins
Nov 05, 2018 @ 16:28:25

Tomas Votruba has written up a new post to his site covering the sorting of private methods in classes and why he considers it important to the quality of your code.

When I started PHP in 2004, all you had to do is to learn a few functions to become the most senior dev in your town. Nowadays, devs have to learn a framework, IDE and coding patterns to get at least to an average level.

Instead of reading 346 pages of Clean Code, you need to produce code and learn as you read it at the same time. There will be never less information than it is today. That's why effective learning is a killer skill. Today we learn how to sort private methods in 2 mins.

He starts off by talking about why private method ordering is important, giving an example of a simple class with several private methods. He suggests that, by ordering private methods within the class more related to the functionality that uses them, developers in the system can more easily relate the functionality. He also includes an example of his the PrivateMethodOrderByUseFixer coding standard service to automate this in your code.

tagged: tutorial private method ordering opinion code clarity

Link: https://www.tomasvotruba.cz/blog/2018/11/01/how-teach-your-team-private-method-sorting-in-3-mins/

MyBuilder Tech Blog:
Using Constraint-based Ordering in PHP
Nov 28, 2016 @ 17:09:18

On the MyBuilder.com Tech blog they've posted a tutorial from Edd Mann looking at the use of constraint-based ordering in PHP applications.

An interesting problem arose last week when we wished to generate a listing of recently completed jobs (along with their shortlist fees). Upon review of some earlier attempts, we did not like the aesthetics present when many of a particular shortlist fee were clustered together (i.e. two or more adjacent jobs with the same shortlist fee). What we were instead looking for was to create a constraint-based ordering that when applied to the recently completed jobs, would give an even distribution of shortlist fees (data-set permitting).

Initially he tried a "low-high" ordering method based on their "fee" value. Instead, to make the solution more "random" he reframed the need and broke it down into three separate actions: sort, partition and interleave. As PHP only has one of those, he came up with his own solutions for the other two (code included). He explains briefly how it all works together and what kind of benefits it has over the low-high solution originally created.

tagged: tutorial constraint based ordering example partition interleave

Link: http://tech.mybuilder.com/using-constraint-based-ordering-in-php/


Trending Topics: