An example of a poor naming convention in the Magento core code 👇 Poor naming patterns can cause tons of headaches, and they could be easily avoided in your own custom code. Here's the issue: In the Magento_Customer module's Customer model, there's an "authenticate" function that accepts two args: - $login - $password The problem? $login is completely ambiguous. Could it be: - an auth key? - a username? - an email address? - something else? The first line of that function calls loadByEmail($login). So this hints at it being an email address. But it gets a bit more convoluted because loadByEmail accepts a parameter named $customerEmail. Why was "customer" prepended to the variable name? As Nate Bargatze says… “Nobody knows” 😂 Let's call this what it is: horribly written spaghetti code. The concession is that this code can be traced back to a commit from 14 years ago. So it was likely imported from Magento 1 and never corrected or refactored. While we can't fix legacy code like this, we can prevent writing it moving forward in our own code. This is exactly why code reviews matter. Keeping code and naming conventions top-of-mind, and as simple as possible, is also always a good decision. If you hate those "pedantic" pushbacks in your code reviews... just remember this code analysis as a great example of why a review session can prevent your own codebase from becoming a big plate of spaghetti. // Macademy is the simplest way to learn Magento 🟧 // Join 9,000+ devs & get three free video lessons every week → link in bio
Don’t forget the most ambiguous variable name used in Magento, $item. 🤣
Software Developer @ London | Magento, Node.js, PHP, MySQL, JavaScript, OpenAI API
3moDo you advocate for creating a facade/adapters for all Magento core code that is spaghetti or hard to read? There is a lot of horrible code there, as you mentioned, a lot of the code was copied from older versions of Magento so after many updates we've lost a lot of context creating code that appears hard to understand.