Magento 2 Tips & Tricks

Want more like this?

Get 5 more Magento 2 Tips & Tricks emailed to you over the next couple weeks by signing up here:

Let's get started with one right now: Command Query Separation

Have you ever noticed a lot of things going on within a single function?

There are a lot of problems with throwing too much logic into one function. Let's look at a very simple example:

The idea above shows the common idea of a design pattern called Command Query Separation. This pattern states that a single function should either perform an action, or return data, but not both. By calling the $this->build() function, there is clearly something else going on here that we are unaware of. Running this line of code not only causes another block of code to execute, but conflicts with the intended naming of the function, which is just to "get a title".

The solution is very easy: keep it simple.

By just returning the title property here, we're drastically reducing the complexity of our code, especially when applying this practice across an entire codebase over a long period of time.

Want more like this?

Get 5 more Magento 2 Tips & Tricks emailed to you over the next couple weeks by signing up here:

Meet the instructor

Mark Shust

Mark Shust

Hi there!
I'm Mark, the founder of

My passion over the last decade has revolved entirely around Magento. Starting with the early days of Magento 0.8, I've had a heavy interest in the Zend and Magento Frameworks, and have been devoted to eCommerce & PHP for even longer (over 20 years!). I've held all positions within many organizations, ranging from junior developer to chief solution architect.

During this time I've spoken at conferences such as Magento Imagine and Meet Magento New York, and have been very outspoken in regards to following accepted best practices for Magento.

My numerous years of LAMP stack programming expertise have paved the way for me to become a Zend Certified Engineer and 3x Magento Certified Developer. I love open-source software, and have maintained the most popular development environment for Magento since the release of Magento 2.

I'm married to my wonderful wife Juliann, and we are the proud parents of twin girls Lily and Brielle. I live in Northeast Ohio and love eating chipotle burritos, solving Rubik's cubes, driving my 240sx, and watching Cleveland Browns games.

© 2020 LLC. All rights reserved.
Privacy Policy · Terms of Use