VIRTUES OF
PLATFORM
DEVELOPMENT
Introduction
Phillip Jackson
Something Digital
@philwinkle
github.com/philwinkle
Frameworks Let You
Build ...Something.
Frameworks should…
• Be tasked to build large application structures
• Be lean and unopinionated
• Contain toolkits that h...
General-purpose libraries
form general-purpose
communities.
Framework
development is for really
really smart people. ..
I‟m not one of them.
Platform Development
Teaches You to Build Rapidly
• Platforms help you solve hard business problems
• I need a customer lo...
Stand on the
Shoulders of
Giants
Everything I know I
learned from Magento
“Don‟t talk to strangers”
• Class types (final, abstract)
• Class/variable scope
• Private/protected
“Hold Mommy‟s hand”
• Factories
• Autoloaders
• Bootstrap
“Look both ways before
crossing the street”
• Consult the documentation
• I kid, I kid.
• For the most part, Magento obeys...
Examples of Core „documentation‟
• Queued workers
• Indexing
• ACL
• Customer Account route/controllers
• Form validation
...
“Don‟t talk with your mouth full”
• Lazy Loading
Don’t do this:
Mage::getModel(‘sales/order’)->getCollection()->load();
Do...
“Your face will get stuck like that”
• Dirty Hacks
• Best Practice
I‟m just going to do this:
echo $product->getMyAwesomeA...
…cont
$collection = Mage::getModel('catalog/product')->getCollection();
$backendModel = $collection->getResource()-
>getAt...
“Use your manners”
• Depends
• Controller rewrites
• Observers
Predispatch strategy:
<?xml version="1.0"?>
<global>
<events>
<controller_action_predispatch_customer_account_index>
<obse...
“Don‟t talk back”
• Closures
• Create new closures and hand them around
• They‟re first-class functions – handy for array_...
Don‟t do this (but it‟s fun)
Mage::register(‘closure’,function( return ‚hello world‛; ));
//later…
$closure = Mage::regist...
“Use your inside voice”
• Dependency/constructor injection
LIVE DEMO (oh boy…)
If at first you don‟t succeed,
TRY, try again
• Exception routing patterns
Avoid:
try {
$model>doSomething();
//=>throws
}...
Exceptions cont…
Rather:
try {
$model>doSomething();
//=>throws
} catch(Exception $e){
$session->addError($this->__(‘wuuuu...
“If you can‟t say something
nice, don‟t say it at all.”
• Return patterns (this is just good programming)
Avoid:
public fu...
Cont…
Rather:
public function getMyStuff($id){
$model = Mage::getModel(‘test/test’)->load($id);
if(!$model){
return false;...
“If you can‟t say something nice,
don‟t say it at all.” (cont…)
• Return patterns (this is just good programming)
• Models...
“Do unto others”
• Avoid joins on production sales tables
• Shard out BI queries to read slaves
• Schedule maintenance ove...
“You‟re not leaving this house dressed like
that”
• Default theme does a lot
• Catalog_Navigation is the most overridden c...
“Wait 30 minutes before getting in
the POOL”
• Code pools; haha get it?
• Don‟t copy class files to app/code/local
• Overr...
“If you play with it you‟ll
go blind”
price.phtml
Don‟t bother trying to restyle price.phtml. It‟s not worth it.
Common myths of
platform development
Myths of platform development
• Platforms box you in
• I can build it better myself
• The platform is more complicated tha...
“Why does Magento require me to do *.*”
• Be unopinionated about simple problems
• Shipping rates
• Layout
• Display logic...
“It‟s too Zend-like”
Zend is established and secure. Where used, it steps up to the
challenge. Zend pre-existed namespaces...
“It‟s not Zend enough”
“Where is my config.ini and why do I have to write so much XML?”
“There‟s so much XML”
• YAML was the weird thing that Doctrine used
• JSON was the weird thing that required eval, right?
...
“There‟s no jQuery”
• Install any one of 5k+ plugins and I guarantee you they‟ll
install jQuery for you
• Learning prototy...
“The performance is lousy”
• It‟s gotten better
• It‟s not meant to be run on a shared server at GoDaddy or
Hostgator
• Pl...
“Magento is overengineered for what I
need”
• Magento Go?
• OK but seriously, Magento Go.
• OK - fine. There are a ton of ...
Zend is old because
namespaces and IOC / DI
“It‟s too complex”
• Fair enough.
http://magento.stackexchange.com/a/4700/336
Success == Recognizing and
filling a need in the marketplace
Conclusion
There is a huge need for developers. There are practically
no Magento developers who can hit the ground running. [It
takes...
Come support “MageOverflow”
http://magento.stackexchange.com
Fastest Answers:
https://twitter.com/kalenjordan/status/38506...
THANK YOU
We’re hiring!!
Jon Tudhope – Director of Software
Q&A
Upcoming SlideShare
Loading in …5
×

Virtues of platform development

2,262 views

Published on

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
2,262
On SlideShare
0
From Embeds
0
Number of Embeds
1,283
Actions
Shares
0
Downloads
5
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Virtues of platform development

  1. 1. VIRTUES OF PLATFORM DEVELOPMENT
  2. 2. Introduction Phillip Jackson Something Digital @philwinkle github.com/philwinkle
  3. 3. Frameworks Let You Build ...Something.
  4. 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. 5. General-purpose libraries form general-purpose communities.
  6. 6. Framework development is for really really smart people. .. I‟m not one of them.
  7. 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. 8. Stand on the Shoulders of Giants
  9. 9. Everything I know I learned from Magento
  10. 10. “Don‟t talk to strangers” • Class types (final, abstract) • Class/variable scope • Private/protected
  11. 11. “Hold Mommy‟s hand” • Factories • Autoloaders • Bootstrap
  12. 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. 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. 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. 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. 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. 17. “Use your manners” • Depends • Controller rewrites • Observers
  18. 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. 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. 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. 21. “Use your inside voice” • Dependency/constructor injection LIVE DEMO (oh boy…)
  22. 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. 23. Exceptions cont… Rather: try { $model>doSomething(); //=>throws } catch(Exception $e){ $session->addError($this->__(‘wuuuuut’)); }
  24. 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. 25. Cont… Rather: public function getMyStuff($id){ $model = Mage::getModel(‘test/test’)->load($id); if(!$model){ return false; } return $model; }
  26. 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. 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. 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. 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. 30. “If you play with it you‟ll go blind”
  31. 31. price.phtml Don‟t bother trying to restyle price.phtml. It‟s not worth it.
  32. 32. Common myths of platform development
  33. 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. 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. 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. 36. “It‟s not Zend enough” “Where is my config.ini and why do I have to write so much XML?”
  37. 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. 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. 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. 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. 41. Zend is old because namespaces and IOC / DI
  42. 42. “It‟s too complex” • Fair enough. http://magento.stackexchange.com/a/4700/336
  43. 43. Success == Recognizing and filling a need in the marketplace
  44. 44. Conclusion
  45. 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. 46. Come support “MageOverflow” http://magento.stackexchange.com Fastest Answers: https://twitter.com/kalenjordan/status/385062073475923968
  47. 47. THANK YOU
  48. 48. We’re hiring!! Jon Tudhope – Director of Software
  49. 49. Q&A

×