I did not have time for a real post this week on Magento 2, so I thought I would replace it with a community question. I am personally interested in Magento community opinions as a litmus test to work out trends of Magento versus more general PHP community.
Reading http://www.matthias-zeis.com/archiv/magento-neuigkeiten-32 there was a comment that type hinting in PHP just missed the vote, so the current proposal was rejected. I was reflecting upon the importance of getting type hinting right in PHP for Magento.
If I was trolling I would ask a question like “Do you think Magento in the long term is a good fit for a programming language without good type hinting?” Personally, I do not. But I can never see Magento moving off PHP. So that is not the question I want to ask.
Magento (especially Magento 2) uses type hints in all around the place already using comments for the IDE to pick up. It makes autocompletion easier in the IDE and provides a form of structured documentation – it tells you what is expected and what to return.
So what is my real question then?
How important do you think it is for Magento to get type hinting into PHP?
Personally I think it would be a huge benefit. Not one that Magento could make use of for a few years (we need to support older versions of PHP for a while), but I am am definitely hoping it makes it into PHP 7.
I am not an expert on the PHP debates over type hinting, but I found http://marktrapp.com/blog/2015/02/08/php-type-hinting-rfc/ which talks a bit about potential problems with the current proposal. That is, it’s not type hinting that is bad, but there are problems with the proposed approach.
So what do you think? Do you think the type hinting proposals are important to get right for Magento?
Disclaimer: THIS POST IS COMPLETELY MY OPINIONS AND NOT THAT OF MY EMPLOYER. THERE ARE NO PLANS TO MOVE MAGENTO OFF PHP. THERE ARE NO PLANS TO FORK PHP TO ADD TYPE HINTING TO MAGENTO’S VERSION OF PHP. THERE ARE NO PLANS FOR OTHER CRAZY IDEAS. Internal focus is on getting Magento 2 shipped. Hopefully that is enough of a disclaimer to stop tweets such as “Alan thinks we should port Magento to Scala to get Scala type hinting into Magento”. (Hey, now there is an interesting idea…. 🙂
I agree huge benefit. Whenever I switch from Java to PHP it shocks me how much room I have to introduce error and not realise it.
I think issue is that PHP is used not just for Magento, and in a lot of scenarios keeping it weakly typed is fine. Magento has almost outgrown PHP. Let’s fork it 🙂
It would be a win to have PHP behave statically typed for Magento. Of course, being able to quickly hack something together without bothering about types at all is also something that PHP still should be able to do. Both of those are two very different goals, and benefit very different types of scripts, um, applications.
I agree with Vinai: having type hinting and in the same time a way to workaround (force any type ?!?) it would be the perfect world solution …
I think we should have the ability to force a variable into a static type. It would greatly help.
For example for me, I always have to discuss with the front-end guys to explain which variables are what and most of the times they based themselves on the variable name to know what it is. With type hinting they would be autonomous in using the variables I give them.
Type hinting is great and leads the developer through the framework. I hate it to add debug statements or start debugging to get the type of the parameter – type hints will improve the coding experience and hopefully it will stop “programmers” from passing 3 different variable types in the same function (depending on the location).
How about Hack ?
I suspect there would never be sufficient community agreement to move from PHP to Hack (developed by one company). I understand the technical merits.