SlideShare a Scribd company logo
1 of 50
© 2016 Magento, Inc. Page | 1
Backward Compatibility
Developer’s guide
Miniailo Igor,
Magento 2 Architect
© 2016 Magento, Inc. Page | 2
© 2016 Magento, Inc. Page | 3
© 2016 Magento, Inc. Page | 4
The main reason we reject a community Pull
Request (PR) or request additional changes is
that the code is not compliant with our Technical
Vision and/or Backward Compatibility Policy.
© 2016 Magento, Inc. Page | 5
© 2016 Magento, Inc. Page | 6
© 2016 Magento, Inc. Page | 7
© 2016 Magento, Inc. Page | 8
• Magento 2 Technical Guidelines
• Versioning
• Backward Compatibility Development
Guide
© 2016 Magento, Inc. Page | 9
Why does BC matter?
For merchants, the process
must be cost-effective, while
developers want their
extensions to be forward-
compatible for as long as
possible.
© 2016 Magento, Inc. Page | 10
Does Magento have a lot of bugs?
Are these bugs annoying for Magento
developers?
© 2016 Magento, Inc. Page | 11
Keep Magento backwards compatible vs.
fixing its flaws?
© 2016 Magento, Inc. Page | 12
We MUST do BOTH
© 2016 Magento, Inc. Page | 13
Backward Compatible Fix
*it works (most of the time), but code quality
is far from good enough
© 2016 Magento, Inc. Page | 14
Backward compatibility (BC)
policy for Magento code
© 2016 Magento, Inc. Page | 15
Semantic Versioning
Version numbers are in the format
MAJOR.MINOR.PATCH, where:
– MAJOR indicates incompatible API changes
– MINOR indicates backward-compatible
functionality has been added
– PATCH indicates backward-compatible bug
fixes
© 2016 Magento, Inc. Page | 16
The backward compatibility policy
applies to PHP code annotated with
@api
© 2016 Magento, Inc. Page | 17
Public and Private code
© 2016 Magento, Inc. Page | 18
Public vs Private code
Private code is not supposed to
be used by third party modules,
so, in most cases, its
modifications will only trigger
PATCH version bumps.
Changes in public code always
trigger MINOR or MAJOR
version bumps.
© 2016 Magento, Inc. Page | 19
What examples of Public code Magento has?
• PHP Interface (marked with @api)
• PHP Class (marked with @api)
• Javascript Interface (marked with @api)
• Javascript Class (marked with @api)
• Virtual Type (marked with @api)
• URL paths
• Console commands and their arguments
• Less Variables & Mixins
• Message queue topics and their data types
• UI component declarations
• Layout handles declared by modules
• Events triggered by component (both static dynamic)
• Schema of configuration types introduced by module
• Structure of System Configuration fields used by module
© 2016 Magento, Inc. Page | 20
API vs SPI (Extension Points)
A PHP Interface in Magento can be used several ways by the core
product and extension developers.
• As an API. An interface is called by PHP code.
• As a Service Provider Interface (SPI). An interface can
be implemented, allowing code to provide functionality to
the platform.
• As both. APIs and SPIs are not mutually exclusive.
© 2016 Magento, Inc. Page | 21
We do not distinguish them separately.
SPIs are annotated the same as APIs.
© 2016 Magento, Inc. Page | 22
Who decides whether interface/class belong to API or SPI?
YOU
© 2016 Magento, Inc. Page | 23
Dependency Rules API
If a module uses (calls) an API, it should be dependent on the MAJOR
version.
API dependency example
{
...
"require": {
"magento/module-customer": "~100.0", // (>=100.0 <101.0.0)
},
...
}
© 2016 Magento, Inc. Page | 24
Dependency Rules SPI
If a module implements an API/SPI, it should be dependent on the
MAJOR+MINOR version.
SPI dependency example
{
...
"require": {
"magento/module-customer": "~100.0.0", // (>=100.0.0 <100.1.0)
},
...
}
© 2016 Magento, Inc. Page | 25
http://devdocs.magento.com/guides/v2.1/release-notes/backward-
incompatible-changes-2.1.html
© 2016 Magento, Inc. Page | 26
What keeps us from making mistakes?
To minimize this risk we have developed a tool Semantic
Version Checker Tool that analyzes two code bases and
determines what part of the version need updating
(MAJOR, MINOR, PATCH). As part of the delivery process,
we must run this tool and use the results for input to the
Version Setter tool.
© 2016 Magento, Inc. Page | 27
Prohibited Code Changes
© 2016 Magento, Inc. Page | 28
• Interface/class removal
• Public & protected method removal
• Introduction of a method to a class or
interface
PHP - Prohibited Code Changes
© 2016 Magento, Inc. Page | 29
MagentoCatalogApiCategoryRepositoryInterface
© 2016 Magento, Inc. Page | 30
MagentoCatalogApiCategoryListInterface
© 2016 Magento, Inc. Page | 31
PHP - Prohibited Code Changes
• Static function removal
• Parameter addition in public methods
• Parameter addition in protected
methods
© 2016 Magento, Inc. Page | 32
© 2016 Magento, Inc. Page | 33
PHP - Prohibited Code Changes
• Method argument type modification
• Modification of types of thrown
exceptions (unless a new exception is
a subtype of the old one)
• Constructor modification
© 2016 Magento, Inc. Page | 34
class ExistingClass
{
/**
* @var NewDependencyInterface $newDependency
*/
private $newDependency;
public function __construct(
OldDependencyIntreface $oldDependency,
$oldRequiredConstructorParameter,
$oldOptinalConstructorParameter = null,
NewDependencyInterface $newDependency = null
) {
...
$this>newDependency = $newDependency ?: MagentoFrameworkAppObjectManager::getInstance()
->get(NewDependencyInterface::class);
...
}
public function existingFunction() {
// Existing functionality
...
// Use $this->newDependency wherever the new dependency is needed
...
}
}
© 2016 Magento, Inc. Page | 35
PHP - Prohibited Code Changes
• Modifying the default values of
optional arguments in public and
protected methods
• Removing or renaming constants
© 2016 Magento, Inc. Page | 36
The main rule is that backwards compatibility
is more important than niceness and effort of
the implementation.
© 2016 Magento, Inc. Page | 37
Do all backward
compatible fixes look
ugly because we are not
allowed to make
refactoring?
© 2016 Magento, Inc. Page | 38
Coupling Between Objects Reaches Its Limit with
a New Dependency
© 2016 Magento, Inc. Page | 39
We MUST do continuous Refactoring!
Backward Compatibility should not be an excuse
for not doing refactoring!
© 2016 Magento, Inc. Page | 40
Refactoring objects that
reach their dependency limit
© 2016 Magento, Inc. Page | 41
Preserve public and protected class
interfaces to maintain backwards
compatibility.
© 2016 Magento, Inc. Page | 42
Turn the existing class into a facade to
prevent existing usages of the
refactored methods from breaking.
© 2016 Magento, Inc. Page | 43
The old public/protected methods
should be marked as deprecated
with the @see tag to suggest the new
implementation for new usages.
© 2016 Magento, Inc. Page | 44
Remove all unused private properties
and methods.
© 2016 Magento, Inc. Page | 45
Mark as deprecated unused protected
properties. Remove the variable type
indicated in the DocBlock to remove
the dependency.
© 2016 Magento, Inc. Page | 46
To preserve the constructor signature:
• Remove type hinting for unused parameters to
remove dependency on their type.
• Add @SuppressWarnings(PHPMD.UnusedForm
alParameter) for unused parameters.
© 2016 Magento, Inc. Page | 47
This is how Backward
Compatible fix should
look like
© 2016 Magento, Inc. Page | 48
Webinar
Link: http://goo.gl/awq7XK
© 2016 Magento, Inc. Page | 49
https://t.co/HI4EF1D79n
© 2016 Magento, Inc. Page | 50
Q & A
@iminyaylo

More Related Content

What's hot

What's hot (20)

Magento 2 Automated Testing via examples of Multi-Source Inventory (MSI)
Magento 2 Automated Testing via examples of Multi-Source Inventory (MSI)Magento 2 Automated Testing via examples of Multi-Source Inventory (MSI)
Magento 2 Automated Testing via examples of Multi-Source Inventory (MSI)
 
Igor Miniailo - Magento 2 API Design Best Practices
Igor Miniailo - Magento 2 API Design Best PracticesIgor Miniailo - Magento 2 API Design Best Practices
Igor Miniailo - Magento 2 API Design Best Practices
 
Valeriy Nayda - Best Practices in Magento 2. Based on Multi Source Inventory ...
Valeriy Nayda - Best Practices in Magento 2. Based on Multi Source Inventory ...Valeriy Nayda - Best Practices in Magento 2. Based on Multi Source Inventory ...
Valeriy Nayda - Best Practices in Magento 2. Based on Multi Source Inventory ...
 
Mli 2017 technical m2 developer experience
Mli 2017 technical m2 developer experienceMli 2017 technical m2 developer experience
Mli 2017 technical m2 developer experience
 
Something Architecture
Something ArchitectureSomething Architecture
Something Architecture
 
Mli 2017 technical first steps to building secure Magento extensions
Mli 2017 technical first steps to building secure Magento extensionsMli 2017 technical first steps to building secure Magento extensions
Mli 2017 technical first steps to building secure Magento extensions
 
Mli 2017 technical intro to magento 2
Mli 2017 technical intro to magento 2Mli 2017 technical intro to magento 2
Mli 2017 technical intro to magento 2
 
Dare to Share Magento Community Engineering
Dare to Share Magento Community Engineering Dare to Share Magento Community Engineering
Dare to Share Magento Community Engineering
 
Mli 2017 technical powering tomorrow_2.2
Mli 2017 technical powering tomorrow_2.2Mli 2017 technical powering tomorrow_2.2
Mli 2017 technical powering tomorrow_2.2
 
Mli 2017 technical EQP & marketplace
Mli 2017 technical EQP & marketplaceMli 2017 technical EQP & marketplace
Mli 2017 technical EQP & marketplace
 
A long way from Monolith to Service Isolated Architecture #MM19NL
A long way from Monolith to Service Isolated Architecture #MM19NLA long way from Monolith to Service Isolated Architecture #MM19NL
A long way from Monolith to Service Isolated Architecture #MM19NL
 
Magento 2 Declarative Schema
Magento 2 Declarative SchemaMagento 2 Declarative Schema
Magento 2 Declarative Schema
 
Extensibility of Magento, the look into the future
Extensibility of Magento, the look into the futureExtensibility of Magento, the look into the future
Extensibility of Magento, the look into the future
 
CQRS and Event-Sourcing in Magento2 by examples of MSI
CQRS and Event-Sourcing in Magento2 by examples of MSICQRS and Event-Sourcing in Magento2 by examples of MSI
CQRS and Event-Sourcing in Magento2 by examples of MSI
 
Magento2.3 API Functional Testing
Magento2.3 API Functional TestingMagento2.3 API Functional Testing
Magento2.3 API Functional Testing
 
Volodymyr Kublytskyi - Develop Product, Design Platform
Volodymyr Kublytskyi - Develop Product, Design PlatformVolodymyr Kublytskyi - Develop Product, Design Platform
Volodymyr Kublytskyi - Develop Product, Design Platform
 
The long way from Monolith to Microservices
The long way from Monolith to MicroservicesThe long way from Monolith to Microservices
The long way from Monolith to Microservices
 
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
 
Chernivtsi Magento Meetup&Contribution day. Naida V.
Chernivtsi Magento Meetup&Contribution day. Naida V.Chernivtsi Magento Meetup&Contribution day. Naida V.
Chernivtsi Magento Meetup&Contribution day. Naida V.
 
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
 

Similar to Backwards Compatibility Developers Guide. #MM17NL

Similar to Backwards Compatibility Developers Guide. #MM17NL (20)

Backward Compatibility Developer's Guide Webinar
Backward Compatibility Developer's Guide WebinarBackward Compatibility Developer's Guide Webinar
Backward Compatibility Developer's Guide Webinar
 
API design best practices
API design best practicesAPI design best practices
API design best practices
 
Backward Compatibility Developer's Guide in Magento 2
Backward Compatibility Developer's Guide in Magento 2Backward Compatibility Developer's Guide in Magento 2
Backward Compatibility Developer's Guide in Magento 2
 
API Design Best Practices by Igor Miniailo
API Design Best Practices by Igor MiniailoAPI Design Best Practices by Igor Miniailo
API Design Best Practices by Igor Miniailo
 
MageConf 2017, Design API Best Practices
MageConf 2017, Design API Best PracticesMageConf 2017, Design API Best Practices
MageConf 2017, Design API Best Practices
 
Max Yekaterinenko - Magento 2 & Quality
Max Yekaterinenko - Magento 2 & QualityMax Yekaterinenko - Magento 2 & Quality
Max Yekaterinenko - Magento 2 & Quality
 
Magento 2.3 Schema and Data Patches
Magento 2.3 Schema and Data PatchesMagento 2.3 Schema and Data Patches
Magento 2.3 Schema and Data Patches
 
Magento Function Testing Framework - Intro and Overview
Magento Function Testing Framework - Intro and OverviewMagento Function Testing Framework - Intro and Overview
Magento Function Testing Framework - Intro and Overview
 
Platform introduction
Platform introductionPlatform introduction
Platform introduction
 
vue-storefront - PWA eCommerce for Magento2 MM17NYC presentation
vue-storefront - PWA eCommerce for Magento2 MM17NYC presentationvue-storefront - PWA eCommerce for Magento2 MM17NYC presentation
vue-storefront - PWA eCommerce for Magento2 MM17NYC presentation
 
Adobe Marketo India VMUG Webhooks and API Basics_02-28.pptx
Adobe Marketo India VMUG Webhooks and API Basics_02-28.pptxAdobe Marketo India VMUG Webhooks and API Basics_02-28.pptx
Adobe Marketo India VMUG Webhooks and API Basics_02-28.pptx
 
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
 
New contribution delivery channel
New contribution delivery channelNew contribution delivery channel
New contribution delivery channel
 
Magento 2 Best Practice MLUK17
Magento 2 Best Practice MLUK17Magento 2 Best Practice MLUK17
Magento 2 Best Practice MLUK17
 
Product Development in the Cloud
Product Development in the Cloud Product Development in the Cloud
Product Development in the Cloud
 
Anypoint new features_coimbatore_mule_meetup
Anypoint new features_coimbatore_mule_meetupAnypoint new features_coimbatore_mule_meetup
Anypoint new features_coimbatore_mule_meetup
 
SFMUG April 2020
SFMUG April 2020SFMUG April 2020
SFMUG April 2020
 
Introduction to tag management webinar
Introduction to tag management webinar Introduction to tag management webinar
Introduction to tag management webinar
 
MDOQ - Platform As A Service Agile Workflow Application for Magento - Launch ...
MDOQ - Platform As A Service Agile Workflow Application for Magento - Launch ...MDOQ - Platform As A Service Agile Workflow Application for Magento - Launch ...
MDOQ - Platform As A Service Agile Workflow Application for Magento - Launch ...
 
Everything about the magento open source 2
Everything about the magento open source 2Everything about the magento open source 2
Everything about the magento open source 2
 

More from Igor Miniailo

More from Igor Miniailo (6)

Magento Storefront architecture
Magento Storefront architectureMagento Storefront architecture
Magento Storefront architecture
 
Magento Developer Talk. Microservice Architecture and Actor Model
Magento Developer Talk. Microservice Architecture and Actor ModelMagento Developer Talk. Microservice Architecture and Actor Model
Magento Developer Talk. Microservice Architecture and Actor Model
 
Applying Code Customizations to Magento 2
Applying Code Customizations to Magento 2 Applying Code Customizations to Magento 2
Applying Code Customizations to Magento 2
 
Modular development in Magento 2
Modular development in Magento 2Modular development in Magento 2
Modular development in Magento 2
 
Мониторинг веб приложений на PHP в режиме реального времени с помощью Pinba. ...
Мониторинг веб приложений на PHP в режиме реального времени с помощью Pinba. ...Мониторинг веб приложений на PHP в режиме реального времени с помощью Pinba. ...
Мониторинг веб приложений на PHP в режиме реального времени с помощью Pinba. ...
 
Сommand Query Responsibility Segregation (CQRS) - Отделяем Мух от Котлет
Сommand Query Responsibility Segregation (CQRS) - Отделяем Мух от КотлетСommand Query Responsibility Segregation (CQRS) - Отделяем Мух от Котлет
Сommand Query Responsibility Segregation (CQRS) - Отделяем Мух от Котлет
 

Recently uploaded

Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
AldoGarca30
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
MayuraD1
 

Recently uploaded (20)

Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
Learn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksLearn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic Marks
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech Civil
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
 
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 

Backwards Compatibility Developers Guide. #MM17NL

  • 1. © 2016 Magento, Inc. Page | 1 Backward Compatibility Developer’s guide Miniailo Igor, Magento 2 Architect
  • 2. © 2016 Magento, Inc. Page | 2
  • 3. © 2016 Magento, Inc. Page | 3
  • 4. © 2016 Magento, Inc. Page | 4 The main reason we reject a community Pull Request (PR) or request additional changes is that the code is not compliant with our Technical Vision and/or Backward Compatibility Policy.
  • 5. © 2016 Magento, Inc. Page | 5
  • 6. © 2016 Magento, Inc. Page | 6
  • 7. © 2016 Magento, Inc. Page | 7
  • 8. © 2016 Magento, Inc. Page | 8 • Magento 2 Technical Guidelines • Versioning • Backward Compatibility Development Guide
  • 9. © 2016 Magento, Inc. Page | 9 Why does BC matter? For merchants, the process must be cost-effective, while developers want their extensions to be forward- compatible for as long as possible.
  • 10. © 2016 Magento, Inc. Page | 10 Does Magento have a lot of bugs? Are these bugs annoying for Magento developers?
  • 11. © 2016 Magento, Inc. Page | 11 Keep Magento backwards compatible vs. fixing its flaws?
  • 12. © 2016 Magento, Inc. Page | 12 We MUST do BOTH
  • 13. © 2016 Magento, Inc. Page | 13 Backward Compatible Fix *it works (most of the time), but code quality is far from good enough
  • 14. © 2016 Magento, Inc. Page | 14 Backward compatibility (BC) policy for Magento code
  • 15. © 2016 Magento, Inc. Page | 15 Semantic Versioning Version numbers are in the format MAJOR.MINOR.PATCH, where: – MAJOR indicates incompatible API changes – MINOR indicates backward-compatible functionality has been added – PATCH indicates backward-compatible bug fixes
  • 16. © 2016 Magento, Inc. Page | 16 The backward compatibility policy applies to PHP code annotated with @api
  • 17. © 2016 Magento, Inc. Page | 17 Public and Private code
  • 18. © 2016 Magento, Inc. Page | 18 Public vs Private code Private code is not supposed to be used by third party modules, so, in most cases, its modifications will only trigger PATCH version bumps. Changes in public code always trigger MINOR or MAJOR version bumps.
  • 19. © 2016 Magento, Inc. Page | 19 What examples of Public code Magento has? • PHP Interface (marked with @api) • PHP Class (marked with @api) • Javascript Interface (marked with @api) • Javascript Class (marked with @api) • Virtual Type (marked with @api) • URL paths • Console commands and their arguments • Less Variables & Mixins • Message queue topics and their data types • UI component declarations • Layout handles declared by modules • Events triggered by component (both static dynamic) • Schema of configuration types introduced by module • Structure of System Configuration fields used by module
  • 20. © 2016 Magento, Inc. Page | 20 API vs SPI (Extension Points) A PHP Interface in Magento can be used several ways by the core product and extension developers. • As an API. An interface is called by PHP code. • As a Service Provider Interface (SPI). An interface can be implemented, allowing code to provide functionality to the platform. • As both. APIs and SPIs are not mutually exclusive.
  • 21. © 2016 Magento, Inc. Page | 21 We do not distinguish them separately. SPIs are annotated the same as APIs.
  • 22. © 2016 Magento, Inc. Page | 22 Who decides whether interface/class belong to API or SPI? YOU
  • 23. © 2016 Magento, Inc. Page | 23 Dependency Rules API If a module uses (calls) an API, it should be dependent on the MAJOR version. API dependency example { ... "require": { "magento/module-customer": "~100.0", // (>=100.0 <101.0.0) }, ... }
  • 24. © 2016 Magento, Inc. Page | 24 Dependency Rules SPI If a module implements an API/SPI, it should be dependent on the MAJOR+MINOR version. SPI dependency example { ... "require": { "magento/module-customer": "~100.0.0", // (>=100.0.0 <100.1.0) }, ... }
  • 25. © 2016 Magento, Inc. Page | 25 http://devdocs.magento.com/guides/v2.1/release-notes/backward- incompatible-changes-2.1.html
  • 26. © 2016 Magento, Inc. Page | 26 What keeps us from making mistakes? To minimize this risk we have developed a tool Semantic Version Checker Tool that analyzes two code bases and determines what part of the version need updating (MAJOR, MINOR, PATCH). As part of the delivery process, we must run this tool and use the results for input to the Version Setter tool.
  • 27. © 2016 Magento, Inc. Page | 27 Prohibited Code Changes
  • 28. © 2016 Magento, Inc. Page | 28 • Interface/class removal • Public & protected method removal • Introduction of a method to a class or interface PHP - Prohibited Code Changes
  • 29. © 2016 Magento, Inc. Page | 29 MagentoCatalogApiCategoryRepositoryInterface
  • 30. © 2016 Magento, Inc. Page | 30 MagentoCatalogApiCategoryListInterface
  • 31. © 2016 Magento, Inc. Page | 31 PHP - Prohibited Code Changes • Static function removal • Parameter addition in public methods • Parameter addition in protected methods
  • 32. © 2016 Magento, Inc. Page | 32
  • 33. © 2016 Magento, Inc. Page | 33 PHP - Prohibited Code Changes • Method argument type modification • Modification of types of thrown exceptions (unless a new exception is a subtype of the old one) • Constructor modification
  • 34. © 2016 Magento, Inc. Page | 34 class ExistingClass { /** * @var NewDependencyInterface $newDependency */ private $newDependency; public function __construct( OldDependencyIntreface $oldDependency, $oldRequiredConstructorParameter, $oldOptinalConstructorParameter = null, NewDependencyInterface $newDependency = null ) { ... $this>newDependency = $newDependency ?: MagentoFrameworkAppObjectManager::getInstance() ->get(NewDependencyInterface::class); ... } public function existingFunction() { // Existing functionality ... // Use $this->newDependency wherever the new dependency is needed ... } }
  • 35. © 2016 Magento, Inc. Page | 35 PHP - Prohibited Code Changes • Modifying the default values of optional arguments in public and protected methods • Removing or renaming constants
  • 36. © 2016 Magento, Inc. Page | 36 The main rule is that backwards compatibility is more important than niceness and effort of the implementation.
  • 37. © 2016 Magento, Inc. Page | 37 Do all backward compatible fixes look ugly because we are not allowed to make refactoring?
  • 38. © 2016 Magento, Inc. Page | 38 Coupling Between Objects Reaches Its Limit with a New Dependency
  • 39. © 2016 Magento, Inc. Page | 39 We MUST do continuous Refactoring! Backward Compatibility should not be an excuse for not doing refactoring!
  • 40. © 2016 Magento, Inc. Page | 40 Refactoring objects that reach their dependency limit
  • 41. © 2016 Magento, Inc. Page | 41 Preserve public and protected class interfaces to maintain backwards compatibility.
  • 42. © 2016 Magento, Inc. Page | 42 Turn the existing class into a facade to prevent existing usages of the refactored methods from breaking.
  • 43. © 2016 Magento, Inc. Page | 43 The old public/protected methods should be marked as deprecated with the @see tag to suggest the new implementation for new usages.
  • 44. © 2016 Magento, Inc. Page | 44 Remove all unused private properties and methods.
  • 45. © 2016 Magento, Inc. Page | 45 Mark as deprecated unused protected properties. Remove the variable type indicated in the DocBlock to remove the dependency.
  • 46. © 2016 Magento, Inc. Page | 46 To preserve the constructor signature: • Remove type hinting for unused parameters to remove dependency on their type. • Add @SuppressWarnings(PHPMD.UnusedForm alParameter) for unused parameters.
  • 47. © 2016 Magento, Inc. Page | 47 This is how Backward Compatible fix should look like
  • 48. © 2016 Magento, Inc. Page | 48 Webinar Link: http://goo.gl/awq7XK
  • 49. © 2016 Magento, Inc. Page | 49 https://t.co/HI4EF1D79n
  • 50. © 2016 Magento, Inc. Page | 50 Q & A @iminyaylo

Editor's Notes

  1. As I am a part of Community Engineering team, my main working tools became Twitter and GitHub, and IDE with code became a little bit less important.
  2. Backward compatibility is a property of a system, product, or technology that allows for interoperability with an older legacy system
  3. We promise to be backward compatible for classes and methods annotated with @api within MINOR and PATCH updates to our components. As changes are introduced, we annotate methods with @deprecated. The methods are removed only with the next MAJOR component version. 
  4. Let’s recap what we had with Magento 1 – where everything is an extension points. All the protected mess and so on. We can’t make changes in contract – all changes suppose to extend existing contract.
  5. Tilde = Significant Release Operator