49
VIRTUES OF PLATFORM DEVELOPMENT

Virtues of platform development

Embed Size (px)

DESCRIPTION

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

Citation preview

Page 1: Virtues of platform development

VIRTUES OF PLATFORM DEVELOPMENT

Page 2: Virtues of platform development

Introduction

Phillip JacksonSomething Digital

@philwinklegithub.com/philwinkle

Page 3: Virtues of platform development

Frameworks Let You Build ...Something.

Page 4: Virtues of platform development

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

Page 5: Virtues of platform development

General-purpose libraries form general-purpose communities.

Page 6: Virtues of platform development

Framework development is for really really smart people. ..

I’m not one of them.

Page 7: Virtues of platform development

Platform DevelopmentTeaches 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

Page 8: Virtues of platform development

Stand on the Shoulders of Giants

Page 9: Virtues of platform development

Everything I know I learned from Magento

Page 10: Virtues of platform development

“Don’t talk to strangers”

• Class types (final, abstract)• Class/variable scope• Private/protected

Page 11: Virtues of platform development

“Hold Mommy’s hand”

• Factories• Autoloaders• Bootstrap

Page 12: Virtues of platform development

“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

Page 13: Virtues of platform development

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

Page 14: Virtues of platform development

“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}

Page 15: Virtues of platform development

“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”

Page 16: Virtues of platform development

…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);

}

Page 17: Virtues of platform development

“Use your manners”• Depends• Controller rewrites• Observers

Page 18: Virtues of platform development

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>

Page 19: Virtues of platform development

“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});

Page 20: Virtues of platform development

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

Page 21: Virtues of platform development

“Use your inside voice”• Dependency/constructor injection

LIVE DEMO (oh boy…)

Page 22: Virtues of platform development

If at first you don’t succeed,TRY, try again• Exception routing patternsAvoid:

try { $model>doSomething(); //=>throws} catch(Exception $e){ $this->setSomething(‘wuuuuut’);}

if($this->getSomething()){//….blah}

Page 23: Virtues of platform development

Exceptions cont…Rather:

try { $model>doSomething(); //=>throws} catch(Exception $e){ $session->addError($this->__(‘wuuuuut’));}

Page 24: Virtues of platform development

“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;}

}

Page 25: Virtues of platform development

Cont…

Rather:

public function getMyStuff($id){$model = Mage::getModel(‘test/test’)->load($id);if(!$model){ return false;}

return $model;}

Page 26: Virtues of platform development

“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

Page 27: Virtues of platform development

“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

Page 28: Virtues of platform development

“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!

Page 29: Virtues of platform development

“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.

Page 30: Virtues of platform development

“If you play with it you’ll go blind”

Page 31: Virtues of platform development

price.phtmlDon’t bother trying to restyle price.phtml. It’s not worth it.

Page 32: Virtues of platform development

Common myths of platform development

Page 33: Virtues of platform development

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

Page 34: Virtues of platform development

“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

Page 35: Virtues of platform development

“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.

Page 36: Virtues of platform development

“It’s not Zend enough”“Where is my config.ini and why do I have to write so much XML?”

Page 37: Virtues of platform development

“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

Page 38: Virtues of platform development

“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

Page 39: Virtues of platform development

“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

Page 40: Virtues of platform development

“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.

Page 41: Virtues of platform development

Zend is old because namespaces and IOC / DI

Page 42: Virtues of platform development

“It’s too complex”• Fair enough.

http://magento.stackexchange.com/a/4700/336

Page 43: Virtues of platform development

Success == Recognizing and filling a need in the marketplace

Page 44: Virtues of platform development

Conclusion

Page 45: Virtues of platform development

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]

Page 46: Virtues of platform development

Come support “MageOverflow”http://magento.stackexchange.com

Fastest Answers:

https://twitter.com/kalenjordan/status/385062073475923968

Page 47: Virtues of platform development

THANK YOU

Page 48: Virtues of platform development

We’re hiring!!Jon Tudhope – Director of Software

Page 49: Virtues of platform development

Q&A