Your SlideShare is downloading. ×
Virtues of platform development
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Virtues of platform development

1,890
views

Published on

The virtues of platform development on Magento in comparison with other technologies like Zend Framework and Laravel

The virtues of platform development on Magento in comparison with other technologies like Zend Framework and Laravel

Published in: Technology

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,890
On Slideshare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
4
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. VIRTUES OF PLATFORM DEVELOPMENT
  • 2. Introduction Phillip Jackson Something Digital @philwinkle github.com/philwinkle
  • 3. Frameworks Let You Build ...Something.
  • 4. Frameworks should… • Be tasked to build large application structures • Be lean and unopinionated • Contain toolkits that help you solve hard programming problems • I need access control • I need to talk to a database • I need to write some stuff to cache storage
  • 5. General-purpose libraries form general-purpose communities.
  • 6. Framework development is for really really smart people. .. I‟m not one of them.
  • 7. Platform Development Teaches You to Build Rapidly • Platforms help you solve hard business problems • I need a customer login form • I need to add products to a cart • I need to accept multiple forms of payment • It helps you think in terms of solving real-world problems
  • 8. Stand on the Shoulders of Giants
  • 9. Everything I know I learned from Magento
  • 10. “Don‟t talk to strangers” • Class types (final, abstract) • Class/variable scope • Private/protected
  • 11. “Hold Mommy‟s hand” • Factories • Autoloaders • Bootstrap
  • 12. “Look both ways before crossing the street” • Consult the documentation • I kid, I kid. • For the most part, Magento obeys its own rules, follow them! • Ask the community
  • 13. Examples of Core „documentation‟ • Queued workers • Indexing • ACL • Customer Account route/controllers • Form validation • Customer registration form • Orm/Resource models • Sales, Wishlist • Grids • Sales and Reports • Reports • Direct SQL (haha jklol) – see here: http://magento.stackexchange.com/a/7963/336
  • 14. “Don‟t talk with your mouth full” • Lazy Loading Don’t do this: Mage::getModel(‘sales/order’)->getCollection()->load(); Do this: Mage::getModel(‘sales/order’)->getCollection()->getFirst(); …or this: $collection = Mage::getModel(‘sales/order’)->getCollection(); foreach($collection as $order){ //stuff }
  • 15. “Your face will get stuck like that” • Dirty Hacks • Best Practice I‟m just going to do this: echo $product->getMyAwesomeAttribute(); //=> null //hack- fix it later $myProduct = Mage::getModel(‘catalog/product’)->load($product- >getId()); //=> ‚this is working‛
  • 16. …cont $collection = Mage::getModel('catalog/product')->getCollection(); $backendModel = $collection->getResource()- >getAttribute('media_gallery')->getBackend(); foreach ($collection as $product){ //add gallery to the product $backendModel->afterLoad($product); }
  • 17. “Use your manners” • Depends • Controller rewrites • Observers
  • 18. Predispatch strategy: <?xml version="1.0"?> <global> <events> <controller_action_predispatch_customer_account_index> <observers> <myevent_this_should_be_unique> <class>YourCompany_YourModule_Model_Observer</class> <method>yourMethodName</method> </myevent_this_should_be_unique> </observers> </controller_action_predispatch_customer_account_index> </events> </global>
  • 19. “Don‟t talk back” • Closures • Create new closures and hand them around • They‟re first-class functions – handy for array_walk: array_walk($array,function(&$var){ //do stuff to $var });
  • 20. Don‟t do this (but it‟s fun) Mage::register(‘closure’,function( return ‚hello world‛; )); //later… $closure = Mage::registry(‘closure’); $closure(); //=>‛hello world‛ …avoiding-difficult-things-to-debug-as-a-service
  • 21. “Use your inside voice” • Dependency/constructor injection LIVE DEMO (oh boy…)
  • 22. If at first you don‟t succeed, TRY, try again • Exception routing patterns Avoid: try { $model>doSomething(); //=>throws } catch(Exception $e){ $this->setSomething(‘wuuuuut’); } if($this->getSomething()){ //….blah }
  • 23. Exceptions cont… Rather: try { $model>doSomething(); //=>throws } catch(Exception $e){ $session->addError($this->__(‘wuuuuut’)); }
  • 24. “If you can‟t say something nice, don‟t say it at all.” • Return patterns (this is just good programming) Avoid: public function getMyStuff($id){ $model = Mage::getModel(‘test/test’)->load($id); if($model->getId()){ return $model; } else { return false; } }
  • 25. Cont… Rather: public function getMyStuff($id){ $model = Mage::getModel(‘test/test’)->load($id); if(!$model){ return false; } return $model; }
  • 26. “If you can‟t say something nice, don‟t say it at all.” (cont…) • Return patterns (this is just good programming) • Models return null • Observers that error don‟t halt the next observers in the chain
  • 27. “Do unto others” • Avoid joins on production sales tables • Shard out BI queries to read slaves • Schedule maintenance overnight • Don‟t forget the maintenance.flag file • Check for running tasks before executing • Queue and batch
  • 28. “You‟re not leaving this house dressed like that” • Default theme does a lot • Catalog_Navigation is the most overridden class on the Magento Connect marketplace!
  • 29. “Wait 30 minutes before getting in the POOL” • Code pools; haha get it? • Don‟t copy class files to app/code/local • Override only if necessary • Use observers liberally • Theme fallback is awesome • Has some limitations • Magento 2 has major improvements • There are extensions to help you set up child themes, etc.
  • 30. “If you play with it you‟ll go blind”
  • 31. price.phtml Don‟t bother trying to restyle price.phtml. It‟s not worth it.
  • 32. Common myths of platform development
  • 33. Myths of platform development • Platforms box you in • I can build it better myself • The platform is more complicated than the problem it solves • It‟s so complex - I don‟t know where to start
  • 34. “Why does Magento require me to do *.*” • Be unopinionated about simple problems • Shipping rates • Layout • Display logic • Inventory • Be extremely opinionated about complicated problems • Taxes • Multi-store • Multi-shipping • Time zone / locale / language • Complex discount rules • Magento didn’t make up your crazy business rules
  • 35. “It‟s too Zend-like” Zend is established and secure. Where used, it steps up to the challenge. Zend pre-existed namespaces, closures, even JSON encoding as part of the core library.
  • 36. “It‟s not Zend enough” “Where is my config.ini and why do I have to write so much XML?”
  • 37. “There‟s so much XML” • YAML was the weird thing that Doctrine used • JSON was the weird thing that required eval, right? • Code generation tools make this a bit nicer • Magento 2 is worse • XML supported and understood by “enterprise” adopters
  • 38. “There‟s no jQuery” • Install any one of 5k+ plugins and I guarantee you they‟ll install jQuery for you • Learning prototype is actually a blast - consider it a challenge
  • 39. “The performance is lousy” • It‟s gotten better • It‟s not meant to be run on a shared server at GoDaddy or Hostgator • Plugins • Hardware • Full Page Cache • Varnish
  • 40. “Magento is overengineered for what I need” • Magento Go? • OK but seriously, Magento Go. • OK - fine. There are a ton of options out there - check out Shopify.
  • 41. Zend is old because namespaces and IOC / DI
  • 42. “It‟s too complex” • Fair enough. http://magento.stackexchange.com/a/4700/336
  • 43. Success == Recognizing and filling a need in the marketplace
  • 44. Conclusion
  • 45. There is a huge need for developers. There are practically no Magento developers who can hit the ground running. [It takes weeks] to ramp a new hire up. eBay [paraphrased]
  • 46. Come support “MageOverflow” http://magento.stackexchange.com Fastest Answers: https://twitter.com/kalenjordan/status/385062073475923968
  • 47. THANK YOU
  • 48. We’re hiring!! Jon Tudhope – Director of Software
  • 49. Q&A