SlideShare a Scribd company logo
1 of 80
Download to read offline
EFFECTIVE MODULE DEVELOPMENT
FOR MAGENTO 2
!(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
1.
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
OPTIMIZE THE
FEEDBACK LOOP
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
TDD !(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
REPL !(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
[R]ead
[E]val
[P]rint
[L]oop
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
n98-magerun2 dev:console
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
Next best thing after TDD
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
Interactive development
Poke the system with a stick & see what happens
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
Predeclared ObjectManager as $di
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
(REPL DEMO)
▸ Code Generation
▸ Testing Glue Code (e.g. ORM)
▸ Testing ObjectManager Config
▸ Inspecting the ObjectManager Config
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
2.
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
SEPARATE CUSTOM LOGIC
FROM FRAMEWORK CODE
!(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
Entry Point:
any custom method that is called by Magento
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
Plugins
Action Controllers
Observers
Blocks
Section Sources
Total Models
...
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
(ENTRY POINTS CODE EXAMPLE)
▸ Action Controller
▸ Extension Attributes
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
3.
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
EXPLICIT
IS BETTER THAN
IMPLICIT
!(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
Calling methods that
are not on the interface
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
MagentoFrameworkAppRouterBase
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
Assuming a specific implementation
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
MagentoCatalogModelProductRepository
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
What are the consequences?
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
breaks static code analysis
makes testing harder
makes refactoring harder
makes code harder to understand
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
It violates the interface contract
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
What to do instead?
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
Make the implicit explicit
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
Instead of assuming an implementation,
depend on the implementation
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
4.
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
COMPOSITION
OVER
INHERITANCE
!(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
What does this mean?
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
Inheritance Example:
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
// ClanMember inherits Customer
class ClanMember extends Customer
{
public function getFullName()
{
return __(
'%1 of the %2',
$this->getName(), // inherited method
$this->getClanName()
);
}
public function getClanName() {...}
}
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
Every call to a parent method
is like a call to a different object
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
// ClanMember is composed with Customer
class ClanMember
{
/** @var Customer */
private $customer;
public function __construct(Customer $customer)
{
$this->customer = $customer;
}
public function getName()
{
return $this->customer->getName()
}
public function getFullName()
{
return __('%1 of the %2', $this->getName(), this->getClanName());
}
public function getClanName() { ... }
}
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
What about extending a class
for customization?
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
Decorator Pattern
!
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
DECORATOR
▸ Wrap original instance instead of extending it
▸ No inheritance
▸ Implement same interface
▸ Implement changed methods
▸ Unchanged methods just call delegate
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
Example of inheritance based customization:
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
// inherit to customize render() via overwrite
class OrdinalPlaceholderRenderer extends Placeholder
{
private static $ordinal = ['first', 'second', 'third', 'fourth'];
public function render(array $source, array $arguments)
{
$source[] = reduce(keys(self::$ordinal), [$this, 'replaceOrdinalWithInt'], pop($source));
return parent::render($source, $arguments);
}
private function replaceOrdinalWithInt($source, $ordinalIdx)
{
$pattern = '/%' . self::$ordinal[$ordinalIdx] . 'b/';
$replacement = '%' . ($ordinalIdx + 1);
return preg_replace($pattern, $replacement, $source);
}
}
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
Decorator example:
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
class OrdinalPlaceholderRendererDecorator implements RendererInterface
{
/** @var RendererInterface */
private $delegate;
private static $ordinal = ['first', 'second', 'third', 'fourth'];
public function __construct(RendererInterface $delegate)
{
$this->delegate = $delegate;
}
public function render(array $source, array $arguments)
{
$source[] = reduce(keys(self::$ordinal), [$this, 'replaceOrdinalWithInt'], pop($source));
return $this->delegate->render($source, $arguments);
}
private function replaceOrdinalWithInt(string $source, int $ordinalIdx): string
{
$pattern = '/%' . self::$ordinal[$ordinalIdx] . 'b/';
$replacement = '%' . ($ordinalIdx + 1);
return preg_replace($pattern, $replacement, $source);
}
}
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
Consequences
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
- More complex
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
+ Better code reuse
+ Easier to change
+ Easier to test
+ More upgradeable
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
5.
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
ATTITUDE
!(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
IMAGINE A LEGENDARY
DEVELOPER WILL REVIEW
IN 2 HOURS...!(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
Grace Hopper
Grace Hopper
Kent Beck
Margaret Hamilton
Margaret Hamilton
Rich Hickey
What would _ _ _ _ do?
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
I am responsible for my attitude
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
6.
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
BUILD STRATEGIES
!(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
Strategy 1: From one to many
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
Get one working
private function replaceOrdinalWithInt($source, $ordinalIdx)
{
$pattern = '/%' . self::$ordinal[$ordinalIdx] . 'b/';
$replacement = '%' . ($ordinalIdx + 1);
return preg_replace($pattern, $replacement, $source);
}
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
Then apply to many
$source[] = reduce(
keys(self::$ordinal),
[$this, 'replaceOrdinalWithInt'],
pop($source)
);
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
array_map
array_filter
array_reduce
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
Simpler to test
Simpler to reason about
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
Strategy 2: Favor immutability
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
After a variable is initialized,
never overwrite it's value
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
Simpler to refactor
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
Strategy 3: Favor pure functions
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
Same input, same output
No side effects
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
Simpler to test
Simpler to change
Simpler to compose
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
Strategy 4: Follow a design recipe
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
name, input, output, examples
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
A) When writing a function, start with a name
(but no arguments yet)
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
B) Add a docblock
document the inputs and output
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
C) Add one example of inputs and expected output
per execution branch
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
D) Write the method
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
E) Finally check the behavior matches the examples
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
Thank you for your attention!
!
Questions? !
(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24

More Related Content

Similar to Vinai Kopp - How i develop M2 modules

Getting your hands dirty testing Magento 2 (at MageTitansIT)
Getting your hands dirty testing Magento 2 (at MageTitansIT)Getting your hands dirty testing Magento 2 (at MageTitansIT)
Getting your hands dirty testing Magento 2 (at MageTitansIT)vinaikopp
 
Getting your Hands Dirty Testing Magento 2 (at London Meetup)
Getting your Hands Dirty Testing Magento 2 (at London Meetup)Getting your Hands Dirty Testing Magento 2 (at London Meetup)
Getting your Hands Dirty Testing Magento 2 (at London Meetup)vinaikopp
 
Writing Testable Code (for Magento 1 and 2) 2016 Romaina
Writing Testable Code (for Magento 1 and 2)  2016 RomainaWriting Testable Code (for Magento 1 and 2)  2016 Romaina
Writing Testable Code (for Magento 1 and 2) 2016 Romainavinaikopp
 
Magento 2 TDD Code Kata
Magento 2 TDD Code KataMagento 2 TDD Code Kata
Magento 2 TDD Code Katavinaikopp
 
WordBench Kobe #76 @078kobe
WordBench Kobe #76 @078kobeWordBench Kobe #76 @078kobe
WordBench Kobe #76 @078kobeAtsushi Ando
 
Testing Magento 2
Testing Magento 2Testing Magento 2
Testing Magento 2vinaikopp
 
クラスメソッドにおける Web API エンジニアリングの基本的な考え方と標準定義 - Developers.IO 2018 (2018-10-05)
クラスメソッドにおける Web API エンジニアリングの基本的な考え方と標準定義 - Developers.IO 2018 (2018-10-05)クラスメソッドにおける Web API エンジニアリングの基本的な考え方と標準定義 - Developers.IO 2018 (2018-10-05)
クラスメソッドにおける Web API エンジニアリングの基本的な考え方と標準定義 - Developers.IO 2018 (2018-10-05)都元ダイスケ Miyamoto
 
WordPress Meetup - Top 9 September 2015
WordPress Meetup - Top 9 September 2015WordPress Meetup - Top 9 September 2015
WordPress Meetup - Top 9 September 2015David Bisset
 
Dos donts of js content optimisation - Digital Olympus 2018
Dos donts of js content optimisation - Digital Olympus 2018Dos donts of js content optimisation - Digital Olympus 2018
Dos donts of js content optimisation - Digital Olympus 2018Chris Green
 
Contribution day guide. MM19ES 2019
Contribution day guide. MM19ES 2019Contribution day guide. MM19ES 2019
Contribution day guide. MM19ES 2019Oleksii Korshenko
 
Meaningful Data - Best Internet Conference 2015 (Lithuania)
Meaningful Data - Best Internet Conference 2015 (Lithuania)Meaningful Data - Best Internet Conference 2015 (Lithuania)
Meaningful Data - Best Internet Conference 2015 (Lithuania)Simo Ahava
 
emflConf 2016 - Travis Wright Closing Keynote
emflConf 2016 - Travis Wright Closing KeynoteemflConf 2016 - Travis Wright Closing Keynote
emflConf 2016 - Travis Wright Closing Keynoteemfluence
 
Magento Commerce Global contribution day 2020
Magento Commerce Global contribution day 2020Magento Commerce Global contribution day 2020
Magento Commerce Global contribution day 2020Slava Mankivski
 
Big Data Seminar: Analytics, Hadoop, Map Reduce, Mongo and other great stuff
Big Data Seminar: Analytics, Hadoop, Map Reduce, Mongo and other great stuffBig Data Seminar: Analytics, Hadoop, Map Reduce, Mongo and other great stuff
Big Data Seminar: Analytics, Hadoop, Map Reduce, Mongo and other great stuffMoshe Kaplan
 
DroidKaigi 2018報告会(公式アプリへのコントリビュート)
DroidKaigi 2018報告会(公式アプリへのコントリビュート)DroidKaigi 2018報告会(公式アプリへのコントリビュート)
DroidKaigi 2018報告会(公式アプリへのコントリビュート)Hironytic
 
Todo apps
Todo appsTodo apps
Todo appscat509
 
SMX West 2014 - Schemas & Microdata
SMX West 2014 - Schemas & MicrodataSMX West 2014 - Schemas & Microdata
SMX West 2014 - Schemas & MicrodataBenu Aggarwal
 
Contribution Day Guide - MM19JP
Contribution Day Guide - MM19JPContribution Day Guide - MM19JP
Contribution Day Guide - MM19JPOleksii Korshenko
 
Schemas and Microdata
Schemas and Microdata Schemas and Microdata
Schemas and Microdata Benu Aggarwal
 

Similar to Vinai Kopp - How i develop M2 modules (20)

Getting your hands dirty testing Magento 2 (at MageTitansIT)
Getting your hands dirty testing Magento 2 (at MageTitansIT)Getting your hands dirty testing Magento 2 (at MageTitansIT)
Getting your hands dirty testing Magento 2 (at MageTitansIT)
 
Getting your Hands Dirty Testing Magento 2 (at London Meetup)
Getting your Hands Dirty Testing Magento 2 (at London Meetup)Getting your Hands Dirty Testing Magento 2 (at London Meetup)
Getting your Hands Dirty Testing Magento 2 (at London Meetup)
 
Writing Testable Code (for Magento 1 and 2) 2016 Romaina
Writing Testable Code (for Magento 1 and 2)  2016 RomainaWriting Testable Code (for Magento 1 and 2)  2016 Romaina
Writing Testable Code (for Magento 1 and 2) 2016 Romaina
 
Magento 2 TDD Code Kata
Magento 2 TDD Code KataMagento 2 TDD Code Kata
Magento 2 TDD Code Kata
 
WordBench Kobe #76 @078kobe
WordBench Kobe #76 @078kobeWordBench Kobe #76 @078kobe
WordBench Kobe #76 @078kobe
 
Testing Magento 2
Testing Magento 2Testing Magento 2
Testing Magento 2
 
クラスメソッドにおける Web API エンジニアリングの基本的な考え方と標準定義 - Developers.IO 2018 (2018-10-05)
クラスメソッドにおける Web API エンジニアリングの基本的な考え方と標準定義 - Developers.IO 2018 (2018-10-05)クラスメソッドにおける Web API エンジニアリングの基本的な考え方と標準定義 - Developers.IO 2018 (2018-10-05)
クラスメソッドにおける Web API エンジニアリングの基本的な考え方と標準定義 - Developers.IO 2018 (2018-10-05)
 
WordPress Meetup - Top 9 September 2015
WordPress Meetup - Top 9 September 2015WordPress Meetup - Top 9 September 2015
WordPress Meetup - Top 9 September 2015
 
Dos donts of js content optimisation - Digital Olympus 2018
Dos donts of js content optimisation - Digital Olympus 2018Dos donts of js content optimisation - Digital Olympus 2018
Dos donts of js content optimisation - Digital Olympus 2018
 
Contribution day guide. MM19ES 2019
Contribution day guide. MM19ES 2019Contribution day guide. MM19ES 2019
Contribution day guide. MM19ES 2019
 
Directory Submissions
Directory SubmissionsDirectory Submissions
Directory Submissions
 
Meaningful Data - Best Internet Conference 2015 (Lithuania)
Meaningful Data - Best Internet Conference 2015 (Lithuania)Meaningful Data - Best Internet Conference 2015 (Lithuania)
Meaningful Data - Best Internet Conference 2015 (Lithuania)
 
emflConf 2016 - Travis Wright Closing Keynote
emflConf 2016 - Travis Wright Closing KeynoteemflConf 2016 - Travis Wright Closing Keynote
emflConf 2016 - Travis Wright Closing Keynote
 
Magento Commerce Global contribution day 2020
Magento Commerce Global contribution day 2020Magento Commerce Global contribution day 2020
Magento Commerce Global contribution day 2020
 
Big Data Seminar: Analytics, Hadoop, Map Reduce, Mongo and other great stuff
Big Data Seminar: Analytics, Hadoop, Map Reduce, Mongo and other great stuffBig Data Seminar: Analytics, Hadoop, Map Reduce, Mongo and other great stuff
Big Data Seminar: Analytics, Hadoop, Map Reduce, Mongo and other great stuff
 
DroidKaigi 2018報告会(公式アプリへのコントリビュート)
DroidKaigi 2018報告会(公式アプリへのコントリビュート)DroidKaigi 2018報告会(公式アプリへのコントリビュート)
DroidKaigi 2018報告会(公式アプリへのコントリビュート)
 
Todo apps
Todo appsTodo apps
Todo apps
 
SMX West 2014 - Schemas & Microdata
SMX West 2014 - Schemas & MicrodataSMX West 2014 - Schemas & Microdata
SMX West 2014 - Schemas & Microdata
 
Contribution Day Guide - MM19JP
Contribution Day Guide - MM19JPContribution Day Guide - MM19JP
Contribution Day Guide - MM19JP
 
Schemas and Microdata
Schemas and Microdata Schemas and Microdata
Schemas and Microdata
 

More from Meet Magento Italy

Dirk Pinamonti - Come affrontare la sfida del nuovo mercato multicanale e del...
Dirk Pinamonti - Come affrontare la sfida del nuovo mercato multicanale e del...Dirk Pinamonti - Come affrontare la sfida del nuovo mercato multicanale e del...
Dirk Pinamonti - Come affrontare la sfida del nuovo mercato multicanale e del...Meet Magento Italy
 
Eugene Shaksuvarov - Tuning Magento 2 for Maximum Performance
Eugene Shaksuvarov - Tuning Magento 2 for Maximum PerformanceEugene Shaksuvarov - Tuning Magento 2 for Maximum Performance
Eugene Shaksuvarov - Tuning Magento 2 for Maximum PerformanceMeet Magento Italy
 
Muliadi jeo - How to sell online in Indonesia
Muliadi jeo - How to sell online in IndonesiaMuliadi jeo - How to sell online in Indonesia
Muliadi jeo - How to sell online in IndonesiaMeet Magento Italy
 
Max Pronko - 10 migration mistakes from Magento 1 to Magento 2
Max Pronko - 10 migration mistakes from Magento 1 to Magento 2Max Pronko - 10 migration mistakes from Magento 1 to Magento 2
Max Pronko - 10 migration mistakes from Magento 1 to Magento 2Meet Magento Italy
 
Alessandro La Ciura - Progettare la migliore integrazione tra live chat ed e-...
Alessandro La Ciura - Progettare la migliore integrazione tra live chat ed e-...Alessandro La Ciura - Progettare la migliore integrazione tra live chat ed e-...
Alessandro La Ciura - Progettare la migliore integrazione tra live chat ed e-...Meet Magento Italy
 
Bodin - Hullin & Potencier - Magento Performance Profiling and Best Practices
Bodin - Hullin & Potencier - Magento Performance Profiling and Best PracticesBodin - Hullin & Potencier - Magento Performance Profiling and Best Practices
Bodin - Hullin & Potencier - Magento Performance Profiling and Best PracticesMeet Magento Italy
 
Giulio Gargiullo - Strategie di marketing digitale per avviare l’e-commerce i...
Giulio Gargiullo - Strategie di marketing digitale per avviare l’e-commerce i...Giulio Gargiullo - Strategie di marketing digitale per avviare l’e-commerce i...
Giulio Gargiullo - Strategie di marketing digitale per avviare l’e-commerce i...Meet Magento Italy
 
Jacopo Nardiello - From CI to Prod: Running Magento at scale with Kubernetes
Jacopo Nardiello - From CI to Prod: Running Magento at scale with KubernetesJacopo Nardiello - From CI to Prod: Running Magento at scale with Kubernetes
Jacopo Nardiello - From CI to Prod: Running Magento at scale with KubernetesMeet Magento Italy
 
James Zetlen - PWA Studio Integration…With You
James Zetlen - PWA Studio Integration…With YouJames Zetlen - PWA Studio Integration…With You
James Zetlen - PWA Studio Integration…With YouMeet Magento Italy
 
Talesh Seeparsan - The Hound of the Malwarevilles
Talesh Seeparsan - The Hound of the MalwarevillesTalesh Seeparsan - The Hound of the Malwarevilles
Talesh Seeparsan - The Hound of the MalwarevillesMeet Magento Italy
 
Miguel Balparda - A day in support
Miguel Balparda - A day in supportMiguel Balparda - A day in support
Miguel Balparda - A day in supportMeet Magento Italy
 
Volodymyr Kublytskyi - Develop Product, Design Platform
Volodymyr Kublytskyi - Develop Product, Design PlatformVolodymyr Kublytskyi - Develop Product, Design Platform
Volodymyr Kublytskyi - Develop Product, Design PlatformMeet Magento Italy
 
Rosario Toscano - Processi di ottimizzazione per una crescita continua
Rosario Toscano - Processi di ottimizzazione per una crescita continuaRosario Toscano - Processi di ottimizzazione per una crescita continua
Rosario Toscano - Processi di ottimizzazione per una crescita continuaMeet Magento Italy
 
Henrik Feld Jakobsen - How to sell online Scandinavia
Henrik Feld Jakobsen - How to sell online ScandinaviaHenrik Feld Jakobsen - How to sell online Scandinavia
Henrik Feld Jakobsen - How to sell online ScandinaviaMeet Magento Italy
 
Rabia Qureshi - How to sell online in UK
Rabia Qureshi - How to sell online in UKRabia Qureshi - How to sell online in UK
Rabia Qureshi - How to sell online in UKMeet Magento Italy
 
Matteo Schuerch - How to sell online in Switzerland
Matteo Schuerch - How to sell online in SwitzerlandMatteo Schuerch - How to sell online in Switzerland
Matteo Schuerch - How to sell online in SwitzerlandMeet Magento Italy
 
Il data-driven nell’e-commerce: il caso studio Alessi
Il data-driven nell’e-commerce: il caso studio AlessiIl data-driven nell’e-commerce: il caso studio Alessi
Il data-driven nell’e-commerce: il caso studio AlessiMeet Magento Italy
 
Philippe Bernou - Seamless omnichannel solutions with Magento order management
Philippe Bernou - Seamless omnichannel solutions with Magento order managementPhilippe Bernou - Seamless omnichannel solutions with Magento order management
Philippe Bernou - Seamless omnichannel solutions with Magento order managementMeet Magento Italy
 
Giovanni Cappellotto - Navigare nelle acque agitate del marketing su Amazon e...
Giovanni Cappellotto - Navigare nelle acque agitate del marketing su Amazon e...Giovanni Cappellotto - Navigare nelle acque agitate del marketing su Amazon e...
Giovanni Cappellotto - Navigare nelle acque agitate del marketing su Amazon e...Meet Magento Italy
 
Alan Rhode - GDPR: la nuova normativa privacy per l’Europa
Alan Rhode - GDPR: la nuova normativa privacy per l’EuropaAlan Rhode - GDPR: la nuova normativa privacy per l’Europa
Alan Rhode - GDPR: la nuova normativa privacy per l’EuropaMeet Magento Italy
 

More from Meet Magento Italy (20)

Dirk Pinamonti - Come affrontare la sfida del nuovo mercato multicanale e del...
Dirk Pinamonti - Come affrontare la sfida del nuovo mercato multicanale e del...Dirk Pinamonti - Come affrontare la sfida del nuovo mercato multicanale e del...
Dirk Pinamonti - Come affrontare la sfida del nuovo mercato multicanale e del...
 
Eugene Shaksuvarov - Tuning Magento 2 for Maximum Performance
Eugene Shaksuvarov - Tuning Magento 2 for Maximum PerformanceEugene Shaksuvarov - Tuning Magento 2 for Maximum Performance
Eugene Shaksuvarov - Tuning Magento 2 for Maximum Performance
 
Muliadi jeo - How to sell online in Indonesia
Muliadi jeo - How to sell online in IndonesiaMuliadi jeo - How to sell online in Indonesia
Muliadi jeo - How to sell online in Indonesia
 
Max Pronko - 10 migration mistakes from Magento 1 to Magento 2
Max Pronko - 10 migration mistakes from Magento 1 to Magento 2Max Pronko - 10 migration mistakes from Magento 1 to Magento 2
Max Pronko - 10 migration mistakes from Magento 1 to Magento 2
 
Alessandro La Ciura - Progettare la migliore integrazione tra live chat ed e-...
Alessandro La Ciura - Progettare la migliore integrazione tra live chat ed e-...Alessandro La Ciura - Progettare la migliore integrazione tra live chat ed e-...
Alessandro La Ciura - Progettare la migliore integrazione tra live chat ed e-...
 
Bodin - Hullin & Potencier - Magento Performance Profiling and Best Practices
Bodin - Hullin & Potencier - Magento Performance Profiling and Best PracticesBodin - Hullin & Potencier - Magento Performance Profiling and Best Practices
Bodin - Hullin & Potencier - Magento Performance Profiling and Best Practices
 
Giulio Gargiullo - Strategie di marketing digitale per avviare l’e-commerce i...
Giulio Gargiullo - Strategie di marketing digitale per avviare l’e-commerce i...Giulio Gargiullo - Strategie di marketing digitale per avviare l’e-commerce i...
Giulio Gargiullo - Strategie di marketing digitale per avviare l’e-commerce i...
 
Jacopo Nardiello - From CI to Prod: Running Magento at scale with Kubernetes
Jacopo Nardiello - From CI to Prod: Running Magento at scale with KubernetesJacopo Nardiello - From CI to Prod: Running Magento at scale with Kubernetes
Jacopo Nardiello - From CI to Prod: Running Magento at scale with Kubernetes
 
James Zetlen - PWA Studio Integration…With You
James Zetlen - PWA Studio Integration…With YouJames Zetlen - PWA Studio Integration…With You
James Zetlen - PWA Studio Integration…With You
 
Talesh Seeparsan - The Hound of the Malwarevilles
Talesh Seeparsan - The Hound of the MalwarevillesTalesh Seeparsan - The Hound of the Malwarevilles
Talesh Seeparsan - The Hound of the Malwarevilles
 
Miguel Balparda - A day in support
Miguel Balparda - A day in supportMiguel Balparda - A day in support
Miguel Balparda - A day in support
 
Volodymyr Kublytskyi - Develop Product, Design Platform
Volodymyr Kublytskyi - Develop Product, Design PlatformVolodymyr Kublytskyi - Develop Product, Design Platform
Volodymyr Kublytskyi - Develop Product, Design Platform
 
Rosario Toscano - Processi di ottimizzazione per una crescita continua
Rosario Toscano - Processi di ottimizzazione per una crescita continuaRosario Toscano - Processi di ottimizzazione per una crescita continua
Rosario Toscano - Processi di ottimizzazione per una crescita continua
 
Henrik Feld Jakobsen - How to sell online Scandinavia
Henrik Feld Jakobsen - How to sell online ScandinaviaHenrik Feld Jakobsen - How to sell online Scandinavia
Henrik Feld Jakobsen - How to sell online Scandinavia
 
Rabia Qureshi - How to sell online in UK
Rabia Qureshi - How to sell online in UKRabia Qureshi - How to sell online in UK
Rabia Qureshi - How to sell online in UK
 
Matteo Schuerch - How to sell online in Switzerland
Matteo Schuerch - How to sell online in SwitzerlandMatteo Schuerch - How to sell online in Switzerland
Matteo Schuerch - How to sell online in Switzerland
 
Il data-driven nell’e-commerce: il caso studio Alessi
Il data-driven nell’e-commerce: il caso studio AlessiIl data-driven nell’e-commerce: il caso studio Alessi
Il data-driven nell’e-commerce: il caso studio Alessi
 
Philippe Bernou - Seamless omnichannel solutions with Magento order management
Philippe Bernou - Seamless omnichannel solutions with Magento order managementPhilippe Bernou - Seamless omnichannel solutions with Magento order management
Philippe Bernou - Seamless omnichannel solutions with Magento order management
 
Giovanni Cappellotto - Navigare nelle acque agitate del marketing su Amazon e...
Giovanni Cappellotto - Navigare nelle acque agitate del marketing su Amazon e...Giovanni Cappellotto - Navigare nelle acque agitate del marketing su Amazon e...
Giovanni Cappellotto - Navigare nelle acque agitate del marketing su Amazon e...
 
Alan Rhode - GDPR: la nuova normativa privacy per l’Europa
Alan Rhode - GDPR: la nuova normativa privacy per l’EuropaAlan Rhode - GDPR: la nuova normativa privacy per l’Europa
Alan Rhode - GDPR: la nuova normativa privacy per l’Europa
 

Recently uploaded

The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 

Recently uploaded (20)

The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 

Vinai Kopp - How i develop M2 modules

  • 1.
  • 2. EFFECTIVE MODULE DEVELOPMENT FOR MAGENTO 2 !(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 3. 1. (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 4. OPTIMIZE THE FEEDBACK LOOP (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 5. TDD !(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 6. REPL !(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 7. [R]ead [E]val [P]rint [L]oop (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 8. n98-magerun2 dev:console (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 9. Next best thing after TDD (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 10. Interactive development Poke the system with a stick & see what happens (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 11. Predeclared ObjectManager as $di (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 12. (REPL DEMO) ▸ Code Generation ▸ Testing Glue Code (e.g. ORM) ▸ Testing ObjectManager Config ▸ Inspecting the ObjectManager Config (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 13. 2. (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 14. SEPARATE CUSTOM LOGIC FROM FRAMEWORK CODE !(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 15. Entry Point: any custom method that is called by Magento (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 16. Plugins Action Controllers Observers Blocks Section Sources Total Models ... (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 17. (ENTRY POINTS CODE EXAMPLE) ▸ Action Controller ▸ Extension Attributes (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 18. 3. (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 19. EXPLICIT IS BETTER THAN IMPLICIT !(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 20. Calling methods that are not on the interface (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 21. MagentoFrameworkAppRouterBase (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 22. Assuming a specific implementation (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 23. MagentoCatalogModelProductRepository (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 24. What are the consequences? (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 25. breaks static code analysis makes testing harder makes refactoring harder makes code harder to understand (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 26. It violates the interface contract (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 27. What to do instead? (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 28. Make the implicit explicit (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 29. Instead of assuming an implementation, depend on the implementation (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 30. (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 31. 4. (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 32. COMPOSITION OVER INHERITANCE !(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 33. What does this mean? (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 34. Inheritance Example: (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 35. // ClanMember inherits Customer class ClanMember extends Customer { public function getFullName() { return __( '%1 of the %2', $this->getName(), // inherited method $this->getClanName() ); } public function getClanName() {...} } (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 36. Every call to a parent method is like a call to a different object (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 37. // ClanMember is composed with Customer class ClanMember { /** @var Customer */ private $customer; public function __construct(Customer $customer) { $this->customer = $customer; } public function getName() { return $this->customer->getName() } public function getFullName() { return __('%1 of the %2', $this->getName(), this->getClanName()); } public function getClanName() { ... } } (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 38. What about extending a class for customization? (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 39. Decorator Pattern ! (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 40. DECORATOR ▸ Wrap original instance instead of extending it ▸ No inheritance ▸ Implement same interface ▸ Implement changed methods ▸ Unchanged methods just call delegate (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 41. Example of inheritance based customization: (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 42. // inherit to customize render() via overwrite class OrdinalPlaceholderRenderer extends Placeholder { private static $ordinal = ['first', 'second', 'third', 'fourth']; public function render(array $source, array $arguments) { $source[] = reduce(keys(self::$ordinal), [$this, 'replaceOrdinalWithInt'], pop($source)); return parent::render($source, $arguments); } private function replaceOrdinalWithInt($source, $ordinalIdx) { $pattern = '/%' . self::$ordinal[$ordinalIdx] . 'b/'; $replacement = '%' . ($ordinalIdx + 1); return preg_replace($pattern, $replacement, $source); } } (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 43. Decorator example: (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 44. class OrdinalPlaceholderRendererDecorator implements RendererInterface { /** @var RendererInterface */ private $delegate; private static $ordinal = ['first', 'second', 'third', 'fourth']; public function __construct(RendererInterface $delegate) { $this->delegate = $delegate; } public function render(array $source, array $arguments) { $source[] = reduce(keys(self::$ordinal), [$this, 'replaceOrdinalWithInt'], pop($source)); return $this->delegate->render($source, $arguments); } private function replaceOrdinalWithInt(string $source, int $ordinalIdx): string { $pattern = '/%' . self::$ordinal[$ordinalIdx] . 'b/'; $replacement = '%' . ($ordinalIdx + 1); return preg_replace($pattern, $replacement, $source); } } (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 45. Consequences (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 46. - More complex (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 47. + Better code reuse + Easier to change + Easier to test + More upgradeable (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 48. 5. (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 49. ATTITUDE !(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 50. IMAGINE A LEGENDARY DEVELOPER WILL REVIEW IN 2 HOURS...!(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 57. What would _ _ _ _ do? (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 58. I am responsible for my attitude (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 59. 6. (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 60. BUILD STRATEGIES !(c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 61. Strategy 1: From one to many (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 62. Get one working private function replaceOrdinalWithInt($source, $ordinalIdx) { $pattern = '/%' . self::$ordinal[$ordinalIdx] . 'b/'; $replacement = '%' . ($ordinalIdx + 1); return preg_replace($pattern, $replacement, $source); } (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 63. Then apply to many $source[] = reduce( keys(self::$ordinal), [$this, 'replaceOrdinalWithInt'], pop($source) ); (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 64. array_map array_filter array_reduce (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 65. Simpler to test Simpler to reason about (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 66. Strategy 2: Favor immutability (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 67. After a variable is initialized, never overwrite it's value (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 68. Simpler to refactor (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 69. Strategy 3: Favor pure functions (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 70. Same input, same output No side effects (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 71. Simpler to test Simpler to change Simpler to compose (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 72. Strategy 4: Follow a design recipe (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 73. name, input, output, examples (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 74. A) When writing a function, start with a name (but no arguments yet) (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 75. B) Add a docblock document the inputs and output (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 76. C) Add one example of inputs and expected output per execution branch (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 77. D) Write the method (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 78. E) Finally check the behavior matches the examples (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24
  • 79.
  • 80. Thank you for your attention! ! Questions? ! (c) Vinai Kopp - http://vinaikopp.com - twitter://@VinaiKopp - Meet Magento IT on 2018-05-24