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

David Lundgren:
The allure of static proxies
Mar 02, 2017 @ 16:52:47

David Lundgren has a post to his site talking about the allure of static proxies in your development and some of his own experiences using them in his own code (and in using Laravel).

Several weeks ago I started playing with Laravel. Primarily because several colleagues are using it, and have suggested that I take a look at it. During my time reviewing how to build a view template I came across references to Html, Form, View and other static calls. Initially I was not impressed due to the use of so many static calls. I have come to an understanding about how static calls in certain circumstances can actually enhance code readability.

He talks about how static calls have been considered an anti-pattern for a long time due to difficulty testing and tight coupling issues. That being said, he did start to see the value in using them in certain situations, how his use relates to the proxy design pattern and some of his own conclusions about using static calls.

tagged: allure static proxy opinion laravel facade cleancode

Link: http://davidscode.com/blog/2017/02/27/the-allure-of-static-proxies/

SitePoint PHP Blog:
Cleaning up Code: Is Refactoring for Aesthetics worth It?
Jul 18, 2016 @ 15:16:17

On the SitePoint PHP blog Tobias Schlitt has an article posted that tries to answer the question "is refactoring for aesthetics worth it" for most development groups out there.

Most development teams want to get their codebase into a better, more maintainable state. But what definition of better should be chosen? In many cases, it is not necessary to dig deep into Domain Driven Design (DDD) to achieve this goal. Sometimes, it's even counter productive. But one of the most basic collections of principles can help each team a lot already: Clean Code.

The Clean Code book by Robert C. Martin summarizes many simple and advanced improvements to get better, understandable, and therefore more maintainable code.

He goes on with a bit of example code, showing a getJobs method that has room for improvement. He makes recommendations on cleanup steps like: renaming variables for clarity and breaking up code more visibly based on functionality. He then talks about the "methodology of refactoring" and how to take "baby steps" in your updates rather than major jumps. He ends by pointing out that refactoring for "beauty" sake isn't a good idea nor is doing it without a sufficient level of automated testing to ensure changes didn't break the application.

tagged: refactoring aesthetics babysteps opinion example naming cleancode

Link: https://www.sitepoint.com/cleaning-up-code-is-refactoring-for-aesthetics-worth-it/

SitePoint PHP Blog:
Clean Code Architecture and Test Driven Development in PHP
Feb 09, 2016 @ 15:13:28

The SitePoint PHP blog has an article posted by Vitalij Mik showing you how to merge the concepts of "clean code architecture" and test-driven development to make solid, maintainable code. The ideals of the "clean code architecture" were first proposed by Robert C. Martin in this post on the 8thlight blog.

The idea was to create an architecture which is independent of any external agency. Your business logic should not be coupled to a framework, a database, or to the web itself. [...] Frameworks will continue to change and evolve. With composer, it is easy to install and replace packages, but it is also easy to abandon a package (composer even has the option to mark a package as abandoned), so it is easy to make “the wrong choice”.

In this tutorial, I will show you how we can implement the Clean Code Architecture in PHP, in order to be in control of our own logic, without being dependent on external providers, but while still using them. We will create a simple guestbook application.

He starts with a first test, evaluating that a list of entries for the guestbook is empty. The code shows the "fakes" for the different object types Uncle Bob recommended in his article and how it fails because none of them exist yet. He extends this with a "can see entries" test and then starts in on the "use case" class to start making the test pass. He updates the case to pull in entries from the repository, another external dependency created later in the tutorial. He then goes through creating the classes for the "fakes" in the test and refactoring the test based on some of his changes during their development. In the remainder of the post he talks about the independence of the current setup and how to add in pagination functionality on the entries objects.

tagged: cleancode architecture testdriven development tdd tutorial entity repository decouple

Link: http://www.sitepoint.com/clean-code-architecture-and-test-driven-development-in-php/

Loosely Coupled Podcast:
Episode 2: My Code Is Perfect
Apr 16, 2014 @ 18:59:40

The Loosely Coupled podcast (with PHP community member hosts Jeff Carouth and Matt Frost) has released their latest episode, Episode #2: My Code is Perfect.

Writing clean code isn’t something you pick up overnight, nor is it a brand new topic. In this episode Jeff and Matt discuss the characteristics and mechanics of creating clean code and how to approach your project from a clean code perspective. [...] In this episode, Jeff and Matt talk about code quality and beautiful code. Beautiful code follows a standard. If you don’t have one, find one and adopt it.

There's some great notes in the post to accompany the recording with other suggestions, resources and links to other sources that can help you write cleaner, better code. You can listen to this latest episode either through the in-page player or by downloading the mp3 directly. You can also subscribe to their feed to get the latest episodes as they're released.

tagged: looselycoupled podcast ep2 code perfect standard cleancode

Link: http://looselycoupled.info/blog/2014/04/14/episode-2-my-code-is-perfect/


Trending Topics: