>

Programming Best Practices

  • sparedes
  • Topic Author
  • Visitor
  • Visitor
16 Jan 2018 22:40 #357842 by sparedes


You should do your best to adhere to common programming best practices to reduce the amount of bugs and improve the quality and maintainability of your extensions. The following list of best practices addresses commonly reported issues found in third party extensions.

Follow a set of coding standards

Coding standards are a set of guidelines that describe how code should be written. These standards define coding practices that determine the style of the code. Whether you are a solo developer or part of a team, following a set of coding standards will help make your code consistent and maintainable.

Magento’s Coding Standards are based on the following:
• Zend Coding standards
• PSR2
• PSR4
W88

To help you stick to coding standards, we recommend using the customer service m88 tool.

Write and utilize re-usable code

Avoid using redundant or duplicate code, which can be hard to maintain. Instead of copying and pasting the same code throughout application, create a single class or method and reference it when needed. As a general rule of thumb, be sure to reuse code as much as possible to save yourself from the online baccarat malaysia costs of duplication.

The code you write should be small, focused, and provides a generic solution. This will let you re-use these pieces again in future development.

Design your code to be replaceable
Designing and writing your code to be replaceable is just as important as making it re-usable. Having a replaceable design means your code is modular and loosely coupled, therefore allowing easy updates and improvements in the future.
It is common practice to replace parts of your codebase with newer and better pieces as bugs are found or newer strategies become available. Writing replaceable code in your codebase makes this practice easier and more efficient.

Avoid creating helper classes
Helper or utility classes are classes filled with static methods that do not quite fit anywhere else. These classes are considered an antipattern and go against the principles of object oriented programming. If you have ClassA and a ClassAHelper with static functions that work on ClassA, you should consider refactoring those functions into ClassA.

A helper class that functions as a catch-all for random methods breaks the single responsibility principle because it is an attempt to solve multiple problems in a single class. You should refactor your code and move those functions into the appropriate classes they work on.

Be consistent with case and naming conventions
You should be consistent in your naming conventions for files, folder names, Classes, and Methods. Following standard conventions will make your code look professional and easy to read.

Not following this practice is a code standards violation and impacts your extension’s readability and maintainability.

Composition over inheritance
Class inheritance is the object-oriented programming concept that allows code reuse and extending of the behavior of a base class. This was favored for Magento 1 development.

Object composition is the programming concept of combining class objects and data types to create a more complex class. The classes and data types are used together to produce a desired functionality.

For Magento 2 extension development, we encourage the use of object composition over class inheritance. Using composition over inheritance makes your extension easier to maintain when class changes occur and update when new features need to be implemented.

Please Log in or Create an account to join the conversation.

Time to create page: 0.163 seconds
Monicae(11.09.2025, 18:03)(18:03)0
RylandLol... Hetmyer. Fell agonizingly short of his century! Just 91 more he needed!(08.09.2025, 06:53)(06:53)0
RylandThe progress of the PPP government should not be judged by the dissenting voices of a few, but by the tangible benefits it has brought to everyone.(02.09.2025, 18:51)(18:51)0
Warren2 firefighters battling Washington state wildfire arrested by Border Patrol(29.08.2025, 11:51)(11:51)0
SalvadorPresident Ali hints at possible Christmas cash grant(27.08.2025, 13:36)(13:36)0
Sierrahi(27.08.2025, 13:07)(13:07)0
SergioWhat food could you eat every day of the week because you love it so much?(25.08.2025, 14:41)(14:41)0
KingsleyIsrael strikes a Gaza hospital twice, killing at least 20, including journalists and rescuers(25.08.2025, 12:27)(12:27)0
KingsleyShubman Gill returns to India's T20I squad as vice-captain for Asia Cup(20.08.2025, 13:54)(13:54)0
KingstonCanada's government forced Air Canada and its striking flight attendants back to work and into arbitration Saturday after a work stoppage stranded more than 100,000 travelers around the world.(16.08.2025, 19:08)(19:08)0
KingsleyGovernment papers found in an Alaskan hotel reveal new details of Trump-Putin summit(16.08.2025, 18:59)(18:59)0
LawrenceI'm confused how a cemetery can raise its funeral prices and blame it on the cost of living. ?(15.08.2025, 08:03)(08:03)0
LawrenceNext up West Indies play Nepal in a 3 match series (T20i), starting on the 27th Sept.(13.08.2025, 14:49)(14:49)0
JayleeFor the first time since 1991, we have won a bilateral series v Pakistan!??

What a win!?
(12.08.2025, 17:57)(17:57)0
LawrenceI think if the Japanese take up cricket seriously they will be really good at it ?? ??(11.08.2025, 19:40)(19:40)0
LillieTo the man who united West Indies like no other, remembering Sir Frank Worrell on his birth anniversary ??

#RoyalsFamily
(02.08.2025, 16:32)(16:32)0
RobertIt looks like another whitewash is in the making for West Indies.(01.08.2025, 09:13)(09:13)0
ChristinaThe ICC should remove the West Indies from participating in International Cricket ?
No Cricketing Nation should be embarrassed.
(01.08.2025, 06:39)(06:39)0
JayleeToll-free travel across Wismar, Berbice, Demerara bridges from midnight!(31.07.2025, 20:24)(20:24)0
JayleeAnother party accuses WIN of being duplicitous, stealing its ideas(31.07.2025, 20:24)(20:24)0
ChristinaI get the feeling that the players don't wish to play for Sammy(26.07.2025, 09:20)(09:20)0
QuintinSad day?? Lol. How many T20I matches russell played regularly for wi cricket? Even in the last T20 series tour in eng he was in the squad but he played only 1 match out of 3. Lol sad day(19.07.2025, 19:44)(19:44)0
ChristinaIt is time for a full evaluation and accountability to the people of this region for the disastrous batting performance of the West Indies Cricket Team. We cannot disregard what all of us witnessed and endured in the last three test matches. This is not about our players, administrators, or any individual; it is an entire system that is failing, and together, all of us must fix it now. This cannot continue into another series; we must not allow it to.(15.07.2025, 15:52)(15:52)0
ChristinaOnce again for the 5th consecutive times . West Indies has bowled out Australia(the #1 team )
within 90 overs.
Again under 300 runs
(13.07.2025, 08:10)(08:10)0
ChristinaWiaan Mulder declaring with himself being 367 not out, is beyond commendable and sportsmanship. Tho many questions will be asked.(07.07.2025, 10:06)(10:06)0
IngridHow bad are the West Indies ?
Their batting is absolutely abysmal
(06.07.2025, 16:36)(16:36)0
QuintinMexican boxer Julio César Chávez Jr. arrested by ICE for deportation, federal officials say(03.07.2025, 19:05)(19:05)0
QuintinKraigg Brathwaite reaches 100 Tests: 'I was in total disbelief that I could score a hundred for West Indies'(03.07.2025, 18:52)(18:52)0
LoganBad performance by west indies(28.06.2025, 06:48)(06:48)0
QuintinMasai Ujiri fired as Raptors president and vice chairman after 13 years with franchise(27.06.2025, 17:50)(17:50)0
LoganAustralia 180 all out(26.06.2025, 06:45)(06:45)0
Logan99 for 3(25.06.2025, 13:21)(13:21)0
LoganShammar 2 wickets(25.06.2025, 12:13)(12:13)0
Logan65 for 3 at lunch(25.06.2025, 12:12)(12:12)0
WendyDid you know 160 years ago, Texans moved to Brazil to start a Confederate colony with Slavery, after #Juneteenth? ?(24.06.2025, 09:55)(09:55)0
WendyGood morning(24.06.2025, 09:29)(09:29)0
MelodyVaughan 'staggered' by England's bowl-first decision as India dominate at Headingley(20.06.2025, 19:19)(19:19)0
chairmanPPP/C is UNSTOPPABLE….
So all de small parties coming together to try beat the PPP/C
Guyanese don’t be fooled
Vote for Peace Progress and Prosperity.
(19.06.2025, 07:51)(07:51)0
PeytonCOACH SAMMY TO MISS IRELAND T20Is(05.06.2025, 18:49)(18:49)0
ketchimJune 1st 2ndODI : replace the 4 guys on the bench : Evin Lewis, John Campbell, Shamar Joseph and Jediah Blades !(31.05.2025, 15:09)(15:09)0
chairmanHuge defeat(29.05.2025, 19:07)(19:07)0
chairmanMatthew Forde you beauty. I didn't even realise he averages almost 40 in FC. And he is only 23 yrs old.(23.05.2025, 20:05)(20:05)0
chairmanWelcome to Guyana - Hakeem Olajuwon, also known as "The Dream,"
A storied career:

- 2x NBA Champion (1994, 1995)
- 2x NBA Finals MVP (1994, 1995)
- 12x NBA All-Star
- 12x All-NBA Team selection
- 9x NBA All-Defensive First Team
- NBA MVP (1994)
- NBA Defensive Player of the Year (1994)
- NBA Rookie of the Year (1984)
- Inducted into the Naismith Memorial Basketball Hall of Fame in 2008

One of the greatest players in NBA history.
(23.05.2025, 10:05)(10:05)0
chairmanI would like to see every house in Essequibo has a Guyana ?? Flag
and possibly the Rest of Guyana ??
(19.05.2025, 06:38)(06:38)0
PeytonSevere weather leaves at least 27 dead, including 18 in Kentucky(17.05.2025, 18:46)(18:46)0
chairmanCongratulations to the newly appointed Roston Chase as West Indies Test captain.
Does he have any captain/ leadership experience?
Your thoughts:
(16.05.2025, 19:23)(19:23)0
TalonDozens of white South Africans arrive in US under Trump refugee plan(12.05.2025, 19:57)(19:57)0
BryantRomario Shepherd hits the FATEST FIFTY for any batter in RCB colours!
Second fastest fifty in the history of the IPL.
(03.05.2025, 15:16)(15:16)0
JamisonTrump celebrates the Super Bowl champ Eagles at White House(30.04.2025, 18:26)(18:26)0
JamisonUNC’s Belichick defends Hudson as ‘doing her job’ after interjecting during CBS interview(30.04.2025, 18:25)(18:25)0
Esme
Go to top