SlideShare una empresa de Scribd logo
1 de 21
Descargar para leer sin conexión
Best Practices
   Naming Conventions

Mariano Wahlmann
Greatly inspired in the contents of...




                           &

 ISBN-13: 978-0596001735       ISBN-13: 978-0131655492
“Always code as if the person who will maintain
your code is a maniac serial killer that knows
where you live”



●   Software Engineers spend most of their
    time reading code NOT writing it!
●   Code is the only complete, accurate
    and updated documentation
●   Easy to read code has fewer bugs
sub attr {
   $_ = (caller(0))[3];
   s/.*://; @_ > 1 ? $_[0]->{$_} = $_[1] : $_[0]->{$_}
}




                         vs
sub attr {
   my $self = shift;
   $self->{attr} = shift if(@_ );
   return $self->{attr};
}
Namespaces
Guideline
        namespace → Noun [ :: Adjective ]*

Begin package's names with an uppercase, if compound
words are used each word must be capitalized, also
when using acronyms each letter must be capitalized


                                                       Good
package XML::Simple;
package Car::Electric;
Package Devel::NYTProf;
package Moose;


                                                        Bad
package Hotel::Inventory::HotelInventory;
package Big::House;
Package Rich::People;
package Html::tag;
Guideline
Avoid names that relate to implementation details,
there might be special cases where you don't want to
do that such as packages that provide bindings to an
specific library


                                                       Good
package Plane::Jet;
package Dog::Beagle;
Package XML::LibXML;
package Gtk2;


                                                        Bad
package XML::SAXServiceParser;
package People::CachedList;
Package Moose::People;
package HTTP::LWPAgent;
Subroutines or Methods
Guideline
routine ➝ imperative_verb [ _ adjective ]? _ noun _ preposition
        | imperative_verb [ _ adjective ]? _ noun _ participle
        | imperative_verb [ _ adjective ]? _ noun
 Pick function and method names that describe what
 they do and not how they do it


                                                            Good
 $list->is_empty;
 sub calculate_net_rate {
 sub get_record {
 sub build_profile_using {


                                                             Bad
 $date->ok;
 sub end_tag {
 $file->backup;
 sub using {
Guideline
Begin subroutine or method names with is_ or has_ if
they return a boolean, there might be special cases
where you don't want to do that


                                                       Good
$element->is_valid;
$node->has_children;
$hotel->room_available_for(@dates);
$list->contains($element);


                                                        Bad
$date->valid;
$record->bad_record;
$list->list_empty;
$process->running;
Guideline
Prefix “internal use only” subroutines or “Private”
methods with an underscore


                                                      Good
$self->_build_list;
$self->_calculate_price;
$self->_store($element);
$self->_initialize(@_);



                                                       Bad
sub internal_method {
sub private_function {
Guideline
Use nouns for subroutines or methods which return a
specific object or value


                                                      Good
$car->engine;
$face->mouth;
$list->next_item;
$person->name;


                                                       Bad
$car->get_engine;
$list->item;
$plane->retrieve_model;
$dog->leg;
Guideline
Use imperative for subroutines or methods that
performs an action


                                                     Good
$car->start_engine;
$face->smile;
$list->remove_all;
$person->clone;


                                                      Bad
$car->engine;
$face->happy;
$list->clear;
$person->new_instance;
Variables
Guideline
            Variable ➝ [ adjective _ ]* noun
Use lowercase for variables and if compound words are
use separate each word with underscore


                                                    Good
my $name = 'Doe';
my $first_name = 'John';
my $total_price = $net_rate + $taxes
my $next_node;


                                                        Bad
my $name_first;
my $name_last;
my $node;
my $sum;
Guideline
Name arrays in plural and hashes in singular



                                                   Good
my @errors;
my %author_of;
my @brands;
my %config;


                                                    Bad
my @record;
my %authors;
my %places;
my @user;
Guideline
lookup_variable ➝ [ adjective _ ]* noun _ preposition
Adding a preposition to the end of lookup variables
make names more readable


                                                      Good
my @sales_for;
print “$sales_for[$month]n”;
my %title_of;
print “$title_of{$book}n”;


                                                        Bad
my @sales;
print “$sales[$index]n”;
my %titles;
print “$titles{$isbn}n”;
Common
Guideline
Avoid ambiguous abbreviations or names, is preferable
to use short full names. If you have to abbreviate
use well-accepted abbreviations


                                                    Good
my $io_stream;
my $tcp_sock;
my $udp_socket;
sub gmt_timestamp {


                                                        Bad
my $left;
my $tcp_st;
my @e;
sub g_tmstmp {
Guideline
Use named constants, using the constant pragma. For
named constants use uppercase



                                                      Good
use constant PI => 3.14;
my $area = PI * $radius**2 ;
use constant BASE_URL => 'http://a.com';
my $home_url = “${BASE_URL}/home”;


                                                       Bad
my $area = 3.14 * $radius**2;
my $base_url = 'http://a.com';
my $home_url = 'http://a.com/home';
if ( $#results < 50 ) {
Source: http://xkcd.org




                          Thank You!

Más contenido relacionado

La actualidad más candente

Web app development_php_04
Web app development_php_04Web app development_php_04
Web app development_php_04Hassen Poreya
 
Creating "Secure" PHP Applications, Part 1, Explicit Code & QA
Creating "Secure" PHP Applications, Part 1, Explicit Code & QACreating "Secure" PHP Applications, Part 1, Explicit Code & QA
Creating "Secure" PHP Applications, Part 1, Explicit Code & QAarchwisp
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisIan Macali
 
Benchmarking Perl (Chicago UniForum 2006)
Benchmarking Perl (Chicago UniForum 2006)Benchmarking Perl (Chicago UniForum 2006)
Benchmarking Perl (Chicago UniForum 2006)brian d foy
 
Drupal 8: Forms
Drupal 8: FormsDrupal 8: Forms
Drupal 8: Formsdrubb
 
06 Php Mysql Connect Query
06 Php Mysql Connect Query06 Php Mysql Connect Query
06 Php Mysql Connect QueryGeshan Manandhar
 
Let's write secure Drupal code! - Drupal Camp Poland 2019
Let's write secure Drupal code! - Drupal Camp Poland 2019Let's write secure Drupal code! - Drupal Camp Poland 2019
Let's write secure Drupal code! - Drupal Camp Poland 2019Balázs Tatár
 
Let's write secure Drupal code! - DrupalCamp Oslo, 2018
Let's write secure Drupal code! - DrupalCamp Oslo, 2018Let's write secure Drupal code! - DrupalCamp Oslo, 2018
Let's write secure Drupal code! - DrupalCamp Oslo, 2018Balázs Tatár
 
07 Php Mysql Update Delete
07 Php Mysql Update Delete07 Php Mysql Update Delete
07 Php Mysql Update DeleteGeshan Manandhar
 
Your code sucks, let's fix it (CakeFest2012)
Your code sucks, let's fix it (CakeFest2012)Your code sucks, let's fix it (CakeFest2012)
Your code sucks, let's fix it (CakeFest2012)Rafael Dohms
 
8時間耐久CakePHP2 勉強会
8時間耐久CakePHP2 勉強会8時間耐久CakePHP2 勉強会
8時間耐久CakePHP2 勉強会Yusuke Ando
 
Drupal 8: Entities
Drupal 8: EntitiesDrupal 8: Entities
Drupal 8: Entitiesdrubb
 
Dependency injection in Drupal 8
Dependency injection in Drupal 8Dependency injection in Drupal 8
Dependency injection in Drupal 8Alexei Gorobets
 
Drupal Lightning FAPI Jumpstart
Drupal Lightning FAPI JumpstartDrupal Lightning FAPI Jumpstart
Drupal Lightning FAPI Jumpstartguestfd47e4c7
 
Oop php 5
Oop php 5Oop php 5
Oop php 5phpubl
 
Zend Framework 2 : Dependency Injection
Zend Framework 2 : Dependency InjectionZend Framework 2 : Dependency Injection
Zend Framework 2 : Dependency InjectionAbdul Malik Ikhsan
 
Drupal 8: Routing & More
Drupal 8: Routing & MoreDrupal 8: Routing & More
Drupal 8: Routing & Moredrubb
 
Extending Zend Framework
Extending Zend FrameworkExtending Zend Framework
Extending Zend FrameworkPHPBelgium
 

La actualidad más candente (20)

Web app development_php_04
Web app development_php_04Web app development_php_04
Web app development_php_04
 
Creating "Secure" PHP Applications, Part 1, Explicit Code & QA
Creating "Secure" PHP Applications, Part 1, Explicit Code & QACreating "Secure" PHP Applications, Part 1, Explicit Code & QA
Creating "Secure" PHP Applications, Part 1, Explicit Code & QA
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
 
Benchmarking Perl (Chicago UniForum 2006)
Benchmarking Perl (Chicago UniForum 2006)Benchmarking Perl (Chicago UniForum 2006)
Benchmarking Perl (Chicago UniForum 2006)
 
Drupal 8: Forms
Drupal 8: FormsDrupal 8: Forms
Drupal 8: Forms
 
06 Php Mysql Connect Query
06 Php Mysql Connect Query06 Php Mysql Connect Query
06 Php Mysql Connect Query
 
Let's write secure Drupal code! - Drupal Camp Poland 2019
Let's write secure Drupal code! - Drupal Camp Poland 2019Let's write secure Drupal code! - Drupal Camp Poland 2019
Let's write secure Drupal code! - Drupal Camp Poland 2019
 
Let's write secure Drupal code! - DrupalCamp Oslo, 2018
Let's write secure Drupal code! - DrupalCamp Oslo, 2018Let's write secure Drupal code! - DrupalCamp Oslo, 2018
Let's write secure Drupal code! - DrupalCamp Oslo, 2018
 
Smarty
SmartySmarty
Smarty
 
07 Php Mysql Update Delete
07 Php Mysql Update Delete07 Php Mysql Update Delete
07 Php Mysql Update Delete
 
Your code sucks, let's fix it (CakeFest2012)
Your code sucks, let's fix it (CakeFest2012)Your code sucks, let's fix it (CakeFest2012)
Your code sucks, let's fix it (CakeFest2012)
 
8時間耐久CakePHP2 勉強会
8時間耐久CakePHP2 勉強会8時間耐久CakePHP2 勉強会
8時間耐久CakePHP2 勉強会
 
Drupal 8: Entities
Drupal 8: EntitiesDrupal 8: Entities
Drupal 8: Entities
 
Haml
HamlHaml
Haml
 
Dependency injection in Drupal 8
Dependency injection in Drupal 8Dependency injection in Drupal 8
Dependency injection in Drupal 8
 
Drupal Lightning FAPI Jumpstart
Drupal Lightning FAPI JumpstartDrupal Lightning FAPI Jumpstart
Drupal Lightning FAPI Jumpstart
 
Oop php 5
Oop php 5Oop php 5
Oop php 5
 
Zend Framework 2 : Dependency Injection
Zend Framework 2 : Dependency InjectionZend Framework 2 : Dependency Injection
Zend Framework 2 : Dependency Injection
 
Drupal 8: Routing & More
Drupal 8: Routing & MoreDrupal 8: Routing & More
Drupal 8: Routing & More
 
Extending Zend Framework
Extending Zend FrameworkExtending Zend Framework
Extending Zend Framework
 

Similar a Best practices naming conventions

Introduction to Perl - Day 2
Introduction to Perl - Day 2Introduction to Perl - Day 2
Introduction to Perl - Day 2Dave Cross
 
Intermediate Perl
Intermediate PerlIntermediate Perl
Intermediate PerlDave Cross
 
Improving Dev Assistant
Improving Dev AssistantImproving Dev Assistant
Improving Dev AssistantDave Cross
 
Beginning Perl
Beginning PerlBeginning Perl
Beginning PerlDave Cross
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Kang-min Liu
 
Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)brian d foy
 
Learning Perl 6
Learning Perl 6 Learning Perl 6
Learning Perl 6 brian d foy
 
I, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 OverlordsI, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 Overlordsheumann
 
LPW: Beginners Perl
LPW: Beginners PerlLPW: Beginners Perl
LPW: Beginners PerlDave Cross
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to PerlDave Cross
 
Utility Modules That You Should Know About
Utility Modules That You Should Know AboutUtility Modules That You Should Know About
Utility Modules That You Should Know Aboutjoshua.mcadams
 
What's New in Perl? v5.10 - v5.16
What's New in Perl?  v5.10 - v5.16What's New in Perl?  v5.10 - v5.16
What's New in Perl? v5.10 - v5.16Ricardo Signes
 
Introduction to Perl - Day 1
Introduction to Perl - Day 1Introduction to Perl - Day 1
Introduction to Perl - Day 1Dave Cross
 
Tutorial perl programming basic eng ver
Tutorial perl programming basic eng verTutorial perl programming basic eng ver
Tutorial perl programming basic eng verQrembiezs Intruder
 
Programming in perl style
Programming in perl styleProgramming in perl style
Programming in perl styleBo Hua Yang
 

Similar a Best practices naming conventions (20)

Introduction to Perl - Day 2
Introduction to Perl - Day 2Introduction to Perl - Day 2
Introduction to Perl - Day 2
 
Intermediate Perl
Intermediate PerlIntermediate Perl
Intermediate Perl
 
Improving Dev Assistant
Improving Dev AssistantImproving Dev Assistant
Improving Dev Assistant
 
Perl Introduction
Perl IntroductionPerl Introduction
Perl Introduction
 
Beginning Perl
Beginning PerlBeginning Perl
Beginning Perl
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)
 
Learning Perl 6
Learning Perl 6 Learning Perl 6
Learning Perl 6
 
Cleancode
CleancodeCleancode
Cleancode
 
I, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 OverlordsI, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 Overlords
 
Subroutines
SubroutinesSubroutines
Subroutines
 
LPW: Beginners Perl
LPW: Beginners PerlLPW: Beginners Perl
LPW: Beginners Perl
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Utility Modules That You Should Know About
Utility Modules That You Should Know AboutUtility Modules That You Should Know About
Utility Modules That You Should Know About
 
What's New in Perl? v5.10 - v5.16
What's New in Perl?  v5.10 - v5.16What's New in Perl?  v5.10 - v5.16
What's New in Perl? v5.10 - v5.16
 
Introduction to Perl - Day 1
Introduction to Perl - Day 1Introduction to Perl - Day 1
Introduction to Perl - Day 1
 
Tutorial perl programming basic eng ver
Tutorial perl programming basic eng verTutorial perl programming basic eng ver
Tutorial perl programming basic eng ver
 
Programming in perl style
Programming in perl styleProgramming in perl style
Programming in perl style
 
Perl Presentation
Perl PresentationPerl Presentation
Perl Presentation
 
Introduction to perl_lists
Introduction to perl_listsIntroduction to perl_lists
Introduction to perl_lists
 

Último

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
🐬 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
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 

Último (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

Best practices naming conventions

  • 1. Best Practices Naming Conventions Mariano Wahlmann
  • 2. Greatly inspired in the contents of... & ISBN-13: 978-0596001735 ISBN-13: 978-0131655492
  • 3. “Always code as if the person who will maintain your code is a maniac serial killer that knows where you live” ● Software Engineers spend most of their time reading code NOT writing it! ● Code is the only complete, accurate and updated documentation ● Easy to read code has fewer bugs
  • 4. sub attr { $_ = (caller(0))[3]; s/.*://; @_ > 1 ? $_[0]->{$_} = $_[1] : $_[0]->{$_} } vs sub attr { my $self = shift; $self->{attr} = shift if(@_ ); return $self->{attr}; }
  • 6. Guideline namespace → Noun [ :: Adjective ]* Begin package's names with an uppercase, if compound words are used each word must be capitalized, also when using acronyms each letter must be capitalized Good package XML::Simple; package Car::Electric; Package Devel::NYTProf; package Moose; Bad package Hotel::Inventory::HotelInventory; package Big::House; Package Rich::People; package Html::tag;
  • 7. Guideline Avoid names that relate to implementation details, there might be special cases where you don't want to do that such as packages that provide bindings to an specific library Good package Plane::Jet; package Dog::Beagle; Package XML::LibXML; package Gtk2; Bad package XML::SAXServiceParser; package People::CachedList; Package Moose::People; package HTTP::LWPAgent;
  • 9. Guideline routine ➝ imperative_verb [ _ adjective ]? _ noun _ preposition | imperative_verb [ _ adjective ]? _ noun _ participle | imperative_verb [ _ adjective ]? _ noun Pick function and method names that describe what they do and not how they do it Good $list->is_empty; sub calculate_net_rate { sub get_record { sub build_profile_using { Bad $date->ok; sub end_tag { $file->backup; sub using {
  • 10. Guideline Begin subroutine or method names with is_ or has_ if they return a boolean, there might be special cases where you don't want to do that Good $element->is_valid; $node->has_children; $hotel->room_available_for(@dates); $list->contains($element); Bad $date->valid; $record->bad_record; $list->list_empty; $process->running;
  • 11. Guideline Prefix “internal use only” subroutines or “Private” methods with an underscore Good $self->_build_list; $self->_calculate_price; $self->_store($element); $self->_initialize(@_); Bad sub internal_method { sub private_function {
  • 12. Guideline Use nouns for subroutines or methods which return a specific object or value Good $car->engine; $face->mouth; $list->next_item; $person->name; Bad $car->get_engine; $list->item; $plane->retrieve_model; $dog->leg;
  • 13. Guideline Use imperative for subroutines or methods that performs an action Good $car->start_engine; $face->smile; $list->remove_all; $person->clone; Bad $car->engine; $face->happy; $list->clear; $person->new_instance;
  • 15. Guideline Variable ➝ [ adjective _ ]* noun Use lowercase for variables and if compound words are use separate each word with underscore Good my $name = 'Doe'; my $first_name = 'John'; my $total_price = $net_rate + $taxes my $next_node; Bad my $name_first; my $name_last; my $node; my $sum;
  • 16. Guideline Name arrays in plural and hashes in singular Good my @errors; my %author_of; my @brands; my %config; Bad my @record; my %authors; my %places; my @user;
  • 17. Guideline lookup_variable ➝ [ adjective _ ]* noun _ preposition Adding a preposition to the end of lookup variables make names more readable Good my @sales_for; print “$sales_for[$month]n”; my %title_of; print “$title_of{$book}n”; Bad my @sales; print “$sales[$index]n”; my %titles; print “$titles{$isbn}n”;
  • 19. Guideline Avoid ambiguous abbreviations or names, is preferable to use short full names. If you have to abbreviate use well-accepted abbreviations Good my $io_stream; my $tcp_sock; my $udp_socket; sub gmt_timestamp { Bad my $left; my $tcp_st; my @e; sub g_tmstmp {
  • 20. Guideline Use named constants, using the constant pragma. For named constants use uppercase Good use constant PI => 3.14; my $area = PI * $radius**2 ; use constant BASE_URL => 'http://a.com'; my $home_url = “${BASE_URL}/home”; Bad my $area = 3.14 * $radius**2; my $base_url = 'http://a.com'; my $home_url = 'http://a.com/home'; if ( $#results < 50 ) {