Over the past couple of months in between my day job of running WebShopApps/ShipperHQ (which keeps me more than busy) I’ve been writing Magento 2 extensions. For fun? No not exactly, we were asked to write them by Magento for the Merchant Beta, the rest of my team is maxed so I get the short straw.
I wanted to jot down some of my experiences so far, and my conclusions at this point in time. I realise you will not all agree, in fact far from it. But someone needs to raise these issues. Because many of them are valid I’m sure.
Magento 2 is a total rewrite of all our code
What I’ve found is that pretty much without exception we need to rewrite all our extension code. In the most part I have no issue with this. Its a chance to refresh, do things differently, regroup. But where I do have an issue is where I have code written in the last year and I’m finding that very little can be re-used due to the changes in Magento 2. And worse, if I do take the code and copy into Magento 2 extension I then have hours of painstakingly boring and meticulous work pulling out all the objects into the constructors, creating the factories, adding namespaces, switching around the way many many mechanisms work. The IDE is not helpful, coming from using IntelliJ on Java in the past 2 years I find PHPStorm is just utterly frustrating on every level. And its written by the same company, so clearly many of the isues are actually with the PHP language. Hopefully Magicento can help us!
Magento 2 is changing
It’s clear from looking at the Magento 2 codebase that not all of it has been fully refactored. In between Merchant Beta and a release just 3 weeks later my Magento 2 extn broke because of changes to the core code. The code is inconsistent, e.g. the use and non-use of underscores for variable names is frankly totally frustrating, as if you try to adhere to not using underscores (as seems to be recommended) you then find you are either repeating variable definitions in parent classes or have this rather odd mix of underscore and non-underscore in your own code (which looks awful). I get its in beta. We are being asked for code for ‘free’ against beta. Its frustrating.
There are many other examples around this area, for instance there was a full-on debate the other day raised by myself on whether Observers still are valid or are replaced by Plugins. TBH I felt like I was a leper even questioning the concept, and I was shouted down initially with a very firm argument against me saying that Observers were dead (which in my mind went against core computing principles around the use of interceptors). In fact they aren’t, as became apparent later. What if I hadn’t have questioned this (and if Alan Storm didn’t raise many of the very valid questions around Magento 2)?. In my mind these basic principles of the Magento framework should be fully decided, documented, and ideally adhered to throughout the codebase so we have examples (especially when there is a lack of clear documentation).
The biggest point here is that I don’t believe Magento really appreciate the knock-on effect of constant fiddling with the Magento 2 code. Agile is good, quicksand is not. They are asking us to write extensions on Magento 2. This is not a quick job, its tens of thousands of dollars worth of investment. And then if Magento go change everything we need to rewrite. This is why I personally stopped coding in Magento 2 between Feb and July, it just seemed that it was changing far too much to justify my investment of time.
Documentation is Sparse
There is an extreme lack of documentation to help us. The DevDocs area is non-searchable (yep I know the reasons why) and from my perspective its not adding value. Alan Kent and Alan Storm blogs are what I’m looking at most, apart from that I’m reading core code (hello 2008). I just hoped we would be further along by now, I don’t want to be investing my time in debugging the core or searching google, I just want to get a job done and fast.
Yes, I hear you say, write some docs for it. I have updated some docs. I’d do more but I have my own docs to deal with. I’d love to have hours to spend on writing Magento 2 docs but I have my own business to run. Magento is not my life, its a platform I integrate onto.
Design Pattern Overdose
It feels like some programmers swallowed some books on design patterns when I look at Magento 2. I get that architecture on such a large system needs to move towards standards and in an ideal world I’m sure we would all love to be using SOLID principles and never write an else statement, it seems to me that the resulting code is:
- Bulky, difficult to navigate and frankly overly verbose
- Written with unit testing as its primary goal
- Inconsistent in its use of computer science techniques
What Magento does is great, and I have the utmost respect for the Ukrainian development team that largely put this together.
I think whats bothering me is that as a company I’m being forced to write in this new way too. And actually whilst I think they have some great ideas I don’t agree with all of them (e.g. lets dependency inject the world even if we will never ever ever mock/change that), and they just added a ton of dev time to my projects.
I should say that I’m familiar with design patterns, have used them recently and in the past. I’ve read GoF many times, and variations of it. Do I live my life by it – no. I’m not trying to be the best programmer in the world, I’m not interested in winning the award for anything. I’m trying to deliver quality timely solutions to my customers within a reasonable budget such that I can pay staff wages and my mortgage. I have nothing to prove academically.
TDD
We all want to do test driven development (in theory). In reality few do. I’ve done pair programming, I’ve done TDD, in various languages, and its very hard to make that the way you function. There are many articles on TDD. Personally I think that unit tests are extremely useful, especially when it comes to refactoring and regression testing code, and I push all my staff to create.
But writing tests when you don’t understand the framework you are using is nigh on impossible, so following TDD when you start writing Magento 2 code IMO is very hard.
TDD is also time consuming. And unfortunately we don’t all have massive budgets or unlimited resources. Its a massive re-pivot to ask a company to follow a TDD approach, especially initially. I have no doubt it will happen, and it will be a good thing, but I’m just not sure automated unit tests will be there from day 1, and by enforcing it you are saying that companies need to have more funds (i.e. its becoming an enterprise product).
As a FYI we use automated unit testing very successfully in ShipperHQ, we also have automated unit tests on several of our Magento 1.x extensions. I’m not against unit testing at all (and I believe in the long run it will improve the quality of extension codebase massively).
Do we need Magento 2?
This is the biggest thing I’ve been struggling with. I know we need Magento 2 in theory, I totally get that we need higher quality, more testable code, and we need to bring the technologies upto date.
But – you know what we are all busy. And I have a team that is trained in Magento 1. Yes there are issues in 1, do I want to throw away a years worth of work at this time – frankly no. And it’s not just a years worth of work, because what I’ve found is that you end up just refreshing everything.
Add to this the fact that everyone is busy. We are all earning money right now and need to keep up with that. Do we have the time to invest in Magento 2? It is not 2008, there are many alternatives (including 1.x), maybe as businesses we decide not to invest in it.
Personally I do think we need Magento 2, well we need a replacement. I’m just not looking forward to the pain of what it is!
Integrating as a Technology Partner
From my experience thus far in Magento 1.x and 2.x our base investment in Magento is at least 100 times what we are investing to plugin into other eCommerce platforms. The ongoing investment for supporting an existing extn is massively more (though hopefully some of this will be alleviated with the introduction of service contracts and clear interfaces when they are completed).
Personally I think technology partners just want to worry about their own area of expertise, whether thats email, ERP, shipping, payment, or whatever. And they just want to plug in to Magento as easily and quickly as possible. With other platforms we don’t have our codebase under anywhere near the level of scrutiny as we are having to go thro with Magento. And it actually just works, nowhere near the level of site issues (in fact there are no site integration issues due to the way platforms such as Bigcommerce/Shopify define their apis).
Conclusion
I love Magento, and all its about. The merchants, the code, the community, the ecosystem. Magento 2 promises us many things, reduced conflicts between extensions, better performance, higher quality, to name but a few.
But I feel like no-one is flagging these very real concerns, and they should be flagged. Because it will affect us all directly or indirectly. If this blog makes one of the Magento developers sit down and write more developer documentation or helps push Magento publish a functional roadmap outside of github then my job here will be done.
If Magento 2 is hard to learn and does result in longer more expensive projects then I’m not actually sure companies will move to it. I think agencies might try one project, find out that it costs them a fortune and revert back to 1.x. I think extension companies will write basic extensions, see what the uptake is before investing significant money in building out more.
What I see is that Magento 2 today is destined to be an Enterprise solution. For definite anyone with a Magento site < 1million in revenue (and a decent profit) should really be looking at other solutions for their needs. You are going to see design agencies disappear, extn agencies disappear. And you will see new ones enter. But I’d be very surprised if the agency prices on Magento 2 implementations don’t rise dramatically. A big reason within this is that Magento developer salaries will rise further, because many will struggle with it.
What I’d like is for Magento to tell us where Magento 2 is pitched. And be clear about that. So that thousands of agencies/developers/merchants dont invest in this and then find that all their hard earned cash is sucked up in a money pit with no return.
And actually I’d love to be proved wrong on all of the above. Because personally the thought of this community become a small cliche of elite programmers and gold solution agencies just doesn’t appeal.