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 @ 10: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/

Tomas Votruba:
Brief History of Tools Watching and Changing Your PHP Code
Oct 24, 2018 @ 10:52:23

Tomas Votruba has a new post to his site sharing a listing of some of the more useful and well-established development tooling for PHP and related technologies.

From coding standard tools, over static analysis to instant upgrade tools. This post is going to be a geeky history trip.

Which tool was first? How they build on shoulders of each other?

Are you a lazy programmer who wants to delegate as much work as possible to 3rd party code? Today, you'll become even lazier.

He breaks the article down into three sections, each with several tools linked under them:

  • Coding Standard Tools
  • Static Analysis Tools
  • Instant Upgrade Tools

The items under each link to more information about the tool and provides a brief summary of how it helps you and your code. There's not any examples of them in use, though. You'll need to visit the project's page for more information about that.

tagged: tools code quality standards upgrade summary list

Link: https://www.tomasvotruba.cz/blog/2018/10/22/brief-history-of-tools-watching-and-changing-your-php-code/

Matthias Noback:
Reusing domain code
Sep 05, 2018 @ 09:38:01

Matthias Nobak has continued his series of posts covering software architecture and class structure. In a previous article he talked about using interfaces and in this latest tutorial he covers the reuse of "domain code", the main logic of your application (rather than the structure).

Last week I wrote about when to add an interface to a class. The article finishes with the claim that classes from the application's domain don't usually need an interface. The reason is that domain code isn't going to be swapped out with something else. This code is the result of careful modelling work that's done based on the business domain that you work with. And even if you'd work on, say, two financial software projects in a row, you'll find that the models you produce for each of them will be different in many subtle (if not radical) ways. Paradoxically you'll find that in practice a domain model can sometimes be reused after all. There are some great examples out there. In this article I explain different scenarios of where and how reuse could work.

He then goes on to cover three "reuse" situations, providing a summary for each:

  • Reuse-in-the-small
  • Reuse-in-the-large and software diversity
  • Reuse-in-the-even-larger: reusing entire subdomains

He finishes up the article sharing some thoughts about which of the types seems more obtainable and, in his experience, useful.

tagged: domain code reuse tutorial small large larger subdomain

Link: https://matthiasnoback.nl/2018/09/reusing-domain-code/

Christian Maioli Mackeprang:
Strategies for dealing with poor code in limited time
Aug 17, 2018 @ 12:52:49

Christian Maioli Mackeprang has a new post to his site sharing some of his recommendations of how you can deal with poor code in limited time when making changes (or adding new features) to an older codebase.

You’ve been given the task of implementing a new feature on an old codebase, but the code looks awful. How can you understand it as quickly as possible? Here are several shortcuts to help learn the important parts of new code without getting lost in the irrelevant details.

His list includes both technical and "people" related suggestions including:

  • Ask for help
  • Make it easy to reproduce bugs
  • Prepare for automated testing
  • Get on familiar ground before tackling critical code

For each item in the list he includes a summary of what's involved along with "dos" as well as "donts".

tagged: strategy code poor quality suggestion tutorial

Link: https://chrismm.com/blog/strategies-for-dealing-with-poor-code-in-limited-time/

Matthias Noback:
More code comments
Aug 16, 2018 @ 10:06:58

In response to a comment he saw on Twitter about comments in code, Matthias Noback has written up a post with some of his own thoughts.

Recently I read a comment on Twitter by Nikola Poša. [...] He was providing us with a useful suggestion, one that I myself have been following ever since reading "Clean Code" by Robert Martin. The paraphrased suggestion in that book, as well as in the tweet, is to consider a comment to be a naming issue in disguise, and to solve that issue, instead of keeping the comment. By the way, the book has some very nice examples of how comments should and should not be used.

Matthias starts with the suggestion that, when correctly written, code shouldn't need comments to be clear about what's happening. He encourages the use of the "refactor for clarity" method to remove comments and make the code more clear. He finishes the post by breaking down the types of comments (explanatory, todo and "wtf"), what they are/examples and in what situations they can be useful for.

tagged: code comment refactor opinion clarity types usefulness

Link: https://matthiasnoback.nl/2018/08/more-code-comments/

php[architect]:
August 2018 Issue Release - Masterful Code Management
Aug 06, 2018 @ 11:51:15

php[architect] magazine has posted the announcement of the release of their August 2018 issue: Masterful Code Management.

This issue includes articles like:

  • "Debugging PHP With Xdebug" by Mark Niebergall
  • "Pro Parsing Techniques with PHP, Part Three: Using Regular Expressions" by Michael Schrenk
  • "MySQL Generated Columns, Views, and Triggers" by Dave Stokes

All of the usual columns are back too including tips for using PhpStorm, using gitflow, secure token management and PHP community. You can pick up a copy to call our own from the php[architect] site and, if you're curious about the contents and want to "try before you buy", they've posted a free PDF of the "Using Regular Expressions" article to give you a taste.

tagged: phparchitect magazine release august2018 masterful code management

Link: https://www.phparch.com/magazine/2018-2/august/

Matthias Noback:
Negative architecture, and assumptions about code
Aug 06, 2018 @ 10:16:42

In a post to his site Matthias Noback looks at an interesting idea when it comes to the structure of your code: the idea of negative architecture and making assumptions.

In "Negative Architecture", Michael Feathers speaks about certain aspects of software architecture leading to some kind of negative architecture. Feathers mentions the IO Monad from Haskell (functional programming) as an example, but there are parallel examples in object-oriented programming. For example, by using layers and the dependency inversion principle you can "guarantee" that a certain class, in a certain layer (e.g. domain, application) won't do any IO - no talking to a database, no HTTP requests to some remote service, etc.

[...] A negative architecture is what's "between the lines". You can look at all the code and describe a positive architecture for it, but given certain architecture or design rules, there's also the background; things we can be sure will never happen.

He goes on to give a few examples of "negative architecture":

  • "An object does nothing meaningful in its constructor"
  • "An object doesn't also fetch dependencies statically if it also gets any number of dependencies injected"
  • "If a class is not marked final, it has at least one subclass"
  • "If a property is not marked "private", it's used by at least one subclass"
  • "An abstract class won't use methods that aren't part of its published interface"
  • "If an object has one public method, it won't have any public static methods"

For each item in the list there's a summary (and sometimes code) included to help clarify the point.

tagged: tutorial negative architecture assumption code

Link: https://matthiasnoback.nl/2018/08/negative-architecture-and-assumptions-about-code/

Matt Stauffer:
Introducing Laravel Nova: A Tool for Building Admin Panels and Custom CMSes
Jul 27, 2018 @ 10:16:01

Matt Stauffer has a new post to his site that takes a "deep dive" into Laravel Nova, the recently announced administration panel that's developed by the Laravel project. This is the first post in a new series.

These are my notes that I took during the announcement on 2018-07-25. I hope to go back later and update this after a more careful re-watching of the YouTube recording that's now up, so I could get some of my code samples more exact and catch anything I missed.

If you notice anything I missed or got wrong, please let me know on Twitter! And please check back in a few days so I have time to fix this up. :)

The post reads more like a live stream than a formal write up, but the good stuff is all there:

  • the basics of what Nova provides
  • how it works
  • defining a resource
  • working with fields
  • actions/filters
  • lenses
  • searching
  • auditing

...and much more. The post goes through each item, providing screenshots, context and code to show off the feature. If you want to see the announcement for yourself, check out the video over on YouTube.

tagged: laravel nova administration dashboard indepth features code

Link: https://mattstauffer.com/blog/introducing-laravel-nova-a-tool-for-building-admin-panels-and-custom-cmses/

TechBeacon:
9 ways to master awful code, fast
Jul 25, 2018 @ 10:24:58

On the TechBeacon site there's a new tutorial posted sharing a list of nine ways to master awful code and make it more efficient, easier to maintain and clearer.

You've been given the task of implementing a new feature on an old codebase, but the code looks awful. How can you understand it as quickly as possible? Here are several shortcuts to help learn the important parts of new code without getting lost in the irrelevant details.

Their suggestions range from technical to non-technical and include:

  • Ask for help
  • Make it easy to reproduce bugs (add version control, build environments)
  • Prepare for automated testing
  • At first, work on a small task

For each item in the list there's an explanation and links (or screenshots) of other resources to help illustrate their point.

tagged: master awful code refactor top9 list suggestion developer

Link: https://techbeacon.com/9-ways-master-awful-code-fast

Robert Basic:
Legacy code is 3rd party code
Jul 19, 2018 @ 09:43:50

In a post to his site Robert Basic makes an interesting suggestion about older codebases (legacy code) and how they should be handled. He suggests treating legacy code like 3rd party code.

Within the TDD community there’s an advice saying that we shouldn’t mock types we don’t own. I believe it is good advice and do my best to follow it. [...] This hidden advice is that we should create interfaces, clients, bridges, adapters between our application and the 3rd party code we use.

[...] What if we start looking at our legacy code the same way we look at the 3rd party code? This might be difficult to do, or even counterproductive, if the legacy code is in a maintenance-only mode, where we only fix bugs and tweak bits and pieces of it. But if we are writing new code that is (re)using legacy code, I believe we should look at legacy code the same way we look at 3rd party code, at least from the perspective of the new code.

He suggests that legacy code and new code should live in different parts of the application's structure and that, in order to use the legacy code, the new code should use interfaces to it rather than using it directly. He gives an example, showing the use of a User class from the legacy code and interfaces that could be used from the new code to work with it.

tagged: legacy code 3rdparty opinion interface separation

Link: https://robertbasic.com/blog/legacy-code-is-3rd-party-code/