SlideShare uma empresa Scribd logo
1 de 25
Let’s PHP in a better way!
Coding Recommendations.
Leekas Shep
/Leekas
1
Sneak Peek
● Coding Standards
● Coding Principles
● Design Patterns
We’ll be walking through..
.. and we’ll keep it short and sane
/Leekas
2
Hand-
Picked
Hai There..
● PHP programmer
● Working in collaboration
● Values quality codebase
● Develops scalable applications
● Most importantly, a love for coding
You can benefit the most out of this session,
if you are..
/Leekas
3
No one never ever gonna
touch my code..
Scaling and maintenance
is not even in my wildest
dreams..
And I’ve no love for
coding.. Yes, I hate my
life...
Then, you are in the
wrong place mate! Run!
Coding Standards - Hand-Picked!
● PEAR Coding Standards
● Zend Coding Standards
● PSR Coding Standards
Some of the well known and widely accepted coding standards..
/Leekas
4
PEAR Coding Standards
● One of the first proposed and
widely accepted standards
● Adheres to most of the old-
school practices
(PHP Extension and Application Repository)
/Leekas
5
Zend Coding Standards
● Follows the PEAR standards for
the most part
● No closing tag ( ?> )
● Abstract classes and Interfaces
should have postfixes in the
name - Optional in latest
standards.
/Leekas
6
PSR Coding Standards
● Published by the PHP Framework Interop Group (PHP-FIG)
● Similar to Java Specification Request for Java
(PHP Standard Recommendation)
/Leekas
7
● PSR-1 : Basic Coding Standard
● PSR-2 : Coding Style Guide
● PSR-4 : Autoloader Specifications
PSR-4 Basically deals with
namespaces and file-
directory structure
conventions..
PSR-1 : Basic Coding Standard
● Files MUST use only <?php and <?= tags.
● Files MUST use only UTF-8 without BOM for PHP
code.
● Files SHOULD either declare symbols (classes,
functions, constants, etc.) or cause side-effects
(e.g. generate output, change .ini settings, etc.)
but SHOULD NOT do both.
● Namespaces and classes MUST follow an
"autoloading" PSR: [PSR-0, PSR-4].
● Class names MUST be declared in StudlyCaps.
● Class constants MUST be declared in all upper
case with underscore separators.
● Method names MUST be declared in camelCase.
/Leekas
8
PSR-2 : Coding Style Guide
● Code MUST follow a "coding style guide" PSR [PSR-1].
● Code MUST use 4 spaces for indenting, not tabs.
● There MUST NOT be a hard limit on line length; the soft limit MUST be 120 characters;
lines SHOULD be 80 characters or less.
● There MUST be one blank line after the namespace declaration, and there MUST be one
blank line after the block of use declarations.
● Opening braces for classes MUST go on the next line, and closing braces MUST go on
the next line after the body.
● Opening braces for methods MUST go on the next line, and closing braces MUST go on
the next line after the body.
● Visibility MUST be declared on all properties and methods; abstract and final MUST be
declared before the visibility; static MUST be declared after the visibility.
● Control structure keywords MUST have one space after them; method and function calls
MUST NOT.
● Opening braces for control structures MUST go on the same line, and closing braces
MUST go on the next line after the body.
● Opening parentheses for control structures MUST NOT have a space after them, and
closing parentheses for control structures MUST NOT have a space before.
/Leekas
9
PSR-2 : Coding Style Guide
/Leekas
10
The SOLID Agile Principles
● Single Responsibility Principle
● Open/Closed Principle
● Liskov Substitution Principle
● Interface Segregation Principle
● Dependency Inversion Principle
/Leekas
11
Single Responsibility Principle
/Leekas
12
A class should have only
one reason to change.
Open/Closed Principle
/Leekas
13
Software entities
(classes, modules,
functions, etc.) should
be open for extension,
but closed for
modification.
Hmm.. Those
dependency
injection
trickies.. Luv it!
Those were the
days!
Liskov Substitution Principle
/Leekas
14
Child classes should
never break the parent
class' type definitions.
Coz,
you’ll
never
know!!
Interface Segregation Principle
/Leekas
15
The interface-segregation
principle (ISP) states that no
client should be forced to
depend on methods it does
not use.
Dependency Inversion Principle
/Leekas
16
1. High-level modules should
not depend on low-level
modules. Both should depend
on abstractions.
2. Abstractions should not
depend upon details. Details
should depend upon
abstractions.
The Dependency Inversion Principle is one
that leads or helps us respect all the other
principles.
Design Patterns - Hand-Picked!
● Strategy Pattern
● Facade Pattern
● Decorator Pattern
/Leekas
17
Strategy Pattern
/Leekas
18
● Identify an algorithm (i.e. a
behavior) that the client would
prefer to access through a "flex
point".
● Specify the signature for that
algorithm in an interface.
● Bury the alternative
implementation details in
derived classes.
● Clients of the algorithm couple
themselves to the interface.
Strategy Pattern
/Leekas
19
Facade Pattern
/Leekas
20
Facade Pattern
/Leekas
21
Decorator Pattern
/Leekas
22
Decorator Pattern
/Leekas
23
YES!!
Any questions?
Hook ‘em up!
/Leekas
24
Thank You!!
“Love your code.. Embrace your craft.. Do better..”
Leekas Shep
/Leekas
25

Mais conteúdo relacionado

Mais procurados

Java generics(Under The Hood Of The Compiler) by Harmeet singh
Java generics(Under The Hood Of The Compiler) by Harmeet singhJava generics(Under The Hood Of The Compiler) by Harmeet singh
Java generics(Under The Hood Of The Compiler) by Harmeet singhHarmeet Singh(Taara)
 
(6) c sharp introduction_advanced_features_part_i
(6) c sharp introduction_advanced_features_part_i(6) c sharp introduction_advanced_features_part_i
(6) c sharp introduction_advanced_features_part_iNico Ludwig
 
Decision properties of reular languages
Decision properties of reular languagesDecision properties of reular languages
Decision properties of reular languagesSOMNATHMORE2
 
Decision properties of reular languages
Decision properties of reular languagesDecision properties of reular languages
Decision properties of reular languagesSOMNATHMORE2
 
I Know Kung Fu - Juggling Java Bytecode
I Know Kung Fu - Juggling Java BytecodeI Know Kung Fu - Juggling Java Bytecode
I Know Kung Fu - Juggling Java BytecodeAlexander Shopov
 
Single responsibility principle
Single responsibility principleSingle responsibility principle
Single responsibility principleRadu Iscu
 
Lifting The Veil - Reading Java Bytecode During Lunchtime
Lifting The Veil - Reading Java Bytecode During LunchtimeLifting The Veil - Reading Java Bytecode During Lunchtime
Lifting The Veil - Reading Java Bytecode During LunchtimeAlexander Shopov
 
Lifting The Veil - Reading Java Bytecode
Lifting The Veil - Reading Java BytecodeLifting The Veil - Reading Java Bytecode
Lifting The Veil - Reading Java BytecodeAlexander Shopov
 

Mais procurados (12)

C++ c#
C++ c#C++ c#
C++ c#
 
Finite Automata
Finite AutomataFinite Automata
Finite Automata
 
Java generics(Under The Hood Of The Compiler) by Harmeet singh
Java generics(Under The Hood Of The Compiler) by Harmeet singhJava generics(Under The Hood Of The Compiler) by Harmeet singh
Java generics(Under The Hood Of The Compiler) by Harmeet singh
 
(6) c sharp introduction_advanced_features_part_i
(6) c sharp introduction_advanced_features_part_i(6) c sharp introduction_advanced_features_part_i
(6) c sharp introduction_advanced_features_part_i
 
Decision properties of reular languages
Decision properties of reular languagesDecision properties of reular languages
Decision properties of reular languages
 
Decision properties of reular languages
Decision properties of reular languagesDecision properties of reular languages
Decision properties of reular languages
 
Asynchronous PHP. Myth? Reality!
Asynchronous PHP. Myth? Reality!Asynchronous PHP. Myth? Reality!
Asynchronous PHP. Myth? Reality!
 
I Know Kung Fu - Juggling Java Bytecode
I Know Kung Fu - Juggling Java BytecodeI Know Kung Fu - Juggling Java Bytecode
I Know Kung Fu - Juggling Java Bytecode
 
Single responsibility principle
Single responsibility principleSingle responsibility principle
Single responsibility principle
 
Lifting The Veil - Reading Java Bytecode During Lunchtime
Lifting The Veil - Reading Java Bytecode During LunchtimeLifting The Veil - Reading Java Bytecode During Lunchtime
Lifting The Veil - Reading Java Bytecode During Lunchtime
 
Lifting The Veil - Reading Java Bytecode
Lifting The Veil - Reading Java BytecodeLifting The Veil - Reading Java Bytecode
Lifting The Veil - Reading Java Bytecode
 
Python decision making
Python   decision makingPython   decision making
Python decision making
 

Semelhante a Let's PHP in a better way! - Coding Recommendations.

Software Craftmanship - Cours Polytech
Software Craftmanship - Cours PolytechSoftware Craftmanship - Cours Polytech
Software Craftmanship - Cours Polytechyannick grenzinger
 
Psr 2 coding style guide - Tidepool Labs
Psr 2   coding style guide - Tidepool LabsPsr 2   coding style guide - Tidepool Labs
Psr 2 coding style guide - Tidepool LabsHarutyun Abgaryan
 
Solid principles
Solid principlesSolid principles
Solid principlesNhan Nguyen
 
Clean Code - Part 2
Clean Code - Part 2Clean Code - Part 2
Clean Code - Part 2Knoldus Inc.
 
JDT embraces lambda expressions
JDT embraces lambda expressionsJDT embraces lambda expressions
JDT embraces lambda expressionsEclipse Day India
 
PHP Standards Recommendations - PHP-FIG
PHP Standards Recommendations - PHP-FIGPHP Standards Recommendations - PHP-FIG
PHP Standards Recommendations - PHP-FIGAkshay Khale
 
Principled And Clean Coding
Principled And Clean CodingPrincipled And Clean Coding
Principled And Clean CodingMetin Ogurlu
 
Basics of writing clean code
Basics of writing clean codeBasics of writing clean code
Basics of writing clean codeKnoldus Inc.
 
FRONTEND BOOTCAMP Session 2.pptx
FRONTEND BOOTCAMP Session 2.pptxFRONTEND BOOTCAMP Session 2.pptx
FRONTEND BOOTCAMP Session 2.pptxEhtesham46
 
(3) c sharp introduction_basics_part_ii
(3) c sharp introduction_basics_part_ii(3) c sharp introduction_basics_part_ii
(3) c sharp introduction_basics_part_iiNico Ludwig
 
Web development basics (Part-4)
Web development basics (Part-4)Web development basics (Part-4)
Web development basics (Part-4)Rajat Pratap Singh
 
C STANDARDS (C17).pptx
C STANDARDS (C17).pptxC STANDARDS (C17).pptx
C STANDARDS (C17).pptxSKUP1
 
C STANDARDS (C17) (1).pptx
C STANDARDS (C17) (1).pptxC STANDARDS (C17) (1).pptx
C STANDARDS (C17) (1).pptxSKUP ACADEMY
 
C STANDARDS (C17) (1).pptx
C STANDARDS (C17) (1).pptxC STANDARDS (C17) (1).pptx
C STANDARDS (C17) (1).pptxSKUP ACADEMY
 
C STANDARDS (C17).pptx
C STANDARDS (C17).pptxC STANDARDS (C17).pptx
C STANDARDS (C17).pptxLECO9
 
Psr - php standards recommendations
Psr - php standards recommendationsPsr - php standards recommendations
Psr - php standards recommendationsHà Anh Sơn
 
New c sharp3_features_(linq)_part_ii
New c sharp3_features_(linq)_part_iiNew c sharp3_features_(linq)_part_ii
New c sharp3_features_(linq)_part_iiNico Ludwig
 

Semelhante a Let's PHP in a better way! - Coding Recommendations. (20)

Software Craftmanship - Cours Polytech
Software Craftmanship - Cours PolytechSoftware Craftmanship - Cours Polytech
Software Craftmanship - Cours Polytech
 
Psr 2 coding style guide - Tidepool Labs
Psr 2   coding style guide - Tidepool LabsPsr 2   coding style guide - Tidepool Labs
Psr 2 coding style guide - Tidepool Labs
 
Solid principles
Solid principlesSolid principles
Solid principles
 
Solid principles
Solid principlesSolid principles
Solid principles
 
Clean Code - Part 2
Clean Code - Part 2Clean Code - Part 2
Clean Code - Part 2
 
JDT embraces lambda expressions
JDT embraces lambda expressionsJDT embraces lambda expressions
JDT embraces lambda expressions
 
PHP Standards Recommendations - PHP-FIG
PHP Standards Recommendations - PHP-FIGPHP Standards Recommendations - PHP-FIG
PHP Standards Recommendations - PHP-FIG
 
Principled And Clean Coding
Principled And Clean CodingPrincipled And Clean Coding
Principled And Clean Coding
 
Solid principes
Solid principesSolid principes
Solid principes
 
Basics of writing clean code
Basics of writing clean codeBasics of writing clean code
Basics of writing clean code
 
FRONTEND BOOTCAMP Session 2.pptx
FRONTEND BOOTCAMP Session 2.pptxFRONTEND BOOTCAMP Session 2.pptx
FRONTEND BOOTCAMP Session 2.pptx
 
(3) c sharp introduction_basics_part_ii
(3) c sharp introduction_basics_part_ii(3) c sharp introduction_basics_part_ii
(3) c sharp introduction_basics_part_ii
 
Web development basics (Part-4)
Web development basics (Part-4)Web development basics (Part-4)
Web development basics (Part-4)
 
C STANDARDS (C17).pptx
C STANDARDS (C17).pptxC STANDARDS (C17).pptx
C STANDARDS (C17).pptx
 
C STANDARDS (C17) (1).pptx
C STANDARDS (C17) (1).pptxC STANDARDS (C17) (1).pptx
C STANDARDS (C17) (1).pptx
 
C STANDARDS (C17) (1).pptx
C STANDARDS (C17) (1).pptxC STANDARDS (C17) (1).pptx
C STANDARDS (C17) (1).pptx
 
C STANDARDS (C17).pptx
C STANDARDS (C17).pptxC STANDARDS (C17).pptx
C STANDARDS (C17).pptx
 
Coding conventions
Coding conventionsCoding conventions
Coding conventions
 
Psr - php standards recommendations
Psr - php standards recommendationsPsr - php standards recommendations
Psr - php standards recommendations
 
New c sharp3_features_(linq)_part_ii
New c sharp3_features_(linq)_part_iiNew c sharp3_features_(linq)_part_ii
New c sharp3_features_(linq)_part_ii
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 

Último (20)

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 

Let's PHP in a better way! - Coding Recommendations.

  • 1. Let’s PHP in a better way! Coding Recommendations. Leekas Shep /Leekas 1
  • 2. Sneak Peek ● Coding Standards ● Coding Principles ● Design Patterns We’ll be walking through.. .. and we’ll keep it short and sane /Leekas 2 Hand- Picked
  • 3. Hai There.. ● PHP programmer ● Working in collaboration ● Values quality codebase ● Develops scalable applications ● Most importantly, a love for coding You can benefit the most out of this session, if you are.. /Leekas 3 No one never ever gonna touch my code.. Scaling and maintenance is not even in my wildest dreams.. And I’ve no love for coding.. Yes, I hate my life... Then, you are in the wrong place mate! Run!
  • 4. Coding Standards - Hand-Picked! ● PEAR Coding Standards ● Zend Coding Standards ● PSR Coding Standards Some of the well known and widely accepted coding standards.. /Leekas 4
  • 5. PEAR Coding Standards ● One of the first proposed and widely accepted standards ● Adheres to most of the old- school practices (PHP Extension and Application Repository) /Leekas 5
  • 6. Zend Coding Standards ● Follows the PEAR standards for the most part ● No closing tag ( ?> ) ● Abstract classes and Interfaces should have postfixes in the name - Optional in latest standards. /Leekas 6
  • 7. PSR Coding Standards ● Published by the PHP Framework Interop Group (PHP-FIG) ● Similar to Java Specification Request for Java (PHP Standard Recommendation) /Leekas 7 ● PSR-1 : Basic Coding Standard ● PSR-2 : Coding Style Guide ● PSR-4 : Autoloader Specifications PSR-4 Basically deals with namespaces and file- directory structure conventions..
  • 8. PSR-1 : Basic Coding Standard ● Files MUST use only <?php and <?= tags. ● Files MUST use only UTF-8 without BOM for PHP code. ● Files SHOULD either declare symbols (classes, functions, constants, etc.) or cause side-effects (e.g. generate output, change .ini settings, etc.) but SHOULD NOT do both. ● Namespaces and classes MUST follow an "autoloading" PSR: [PSR-0, PSR-4]. ● Class names MUST be declared in StudlyCaps. ● Class constants MUST be declared in all upper case with underscore separators. ● Method names MUST be declared in camelCase. /Leekas 8
  • 9. PSR-2 : Coding Style Guide ● Code MUST follow a "coding style guide" PSR [PSR-1]. ● Code MUST use 4 spaces for indenting, not tabs. ● There MUST NOT be a hard limit on line length; the soft limit MUST be 120 characters; lines SHOULD be 80 characters or less. ● There MUST be one blank line after the namespace declaration, and there MUST be one blank line after the block of use declarations. ● Opening braces for classes MUST go on the next line, and closing braces MUST go on the next line after the body. ● Opening braces for methods MUST go on the next line, and closing braces MUST go on the next line after the body. ● Visibility MUST be declared on all properties and methods; abstract and final MUST be declared before the visibility; static MUST be declared after the visibility. ● Control structure keywords MUST have one space after them; method and function calls MUST NOT. ● Opening braces for control structures MUST go on the same line, and closing braces MUST go on the next line after the body. ● Opening parentheses for control structures MUST NOT have a space after them, and closing parentheses for control structures MUST NOT have a space before. /Leekas 9
  • 10. PSR-2 : Coding Style Guide /Leekas 10
  • 11. The SOLID Agile Principles ● Single Responsibility Principle ● Open/Closed Principle ● Liskov Substitution Principle ● Interface Segregation Principle ● Dependency Inversion Principle /Leekas 11
  • 12. Single Responsibility Principle /Leekas 12 A class should have only one reason to change.
  • 13. Open/Closed Principle /Leekas 13 Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification. Hmm.. Those dependency injection trickies.. Luv it! Those were the days!
  • 14. Liskov Substitution Principle /Leekas 14 Child classes should never break the parent class' type definitions. Coz, you’ll never know!!
  • 15. Interface Segregation Principle /Leekas 15 The interface-segregation principle (ISP) states that no client should be forced to depend on methods it does not use.
  • 16. Dependency Inversion Principle /Leekas 16 1. High-level modules should not depend on low-level modules. Both should depend on abstractions. 2. Abstractions should not depend upon details. Details should depend upon abstractions. The Dependency Inversion Principle is one that leads or helps us respect all the other principles.
  • 17. Design Patterns - Hand-Picked! ● Strategy Pattern ● Facade Pattern ● Decorator Pattern /Leekas 17
  • 18. Strategy Pattern /Leekas 18 ● Identify an algorithm (i.e. a behavior) that the client would prefer to access through a "flex point". ● Specify the signature for that algorithm in an interface. ● Bury the alternative implementation details in derived classes. ● Clients of the algorithm couple themselves to the interface.
  • 25. Thank You!! “Love your code.. Embrace your craft.. Do better..” Leekas Shep /Leekas 25