SlideShare une entreprise Scribd logo
1  sur  2
Télécharger pour lire hors ligne
One of the hardest things in software development
is naming. Naming of products, of paradigms and of
parts of your code. The reason naming is both hard
and important is because it is an act of communication;
without good names your code might as well be
written in, well, code.
©totallyPic/Shutterstock
By Kevlin Henney
EXCEPTIONAL
NAMING
48
We often adopt conventions to make
some aspects of naming easier, but
while such consistency is often a good
thing, some practices are flawed from
the outset. Although having a com-
mon vocabulary of concepts is useful
across a codebase, the basis of the
consistency must be useful other-
wise it's just noise and can become
homeopathic: programmers make
names longer by adding more words
but end up diluting the meaning of
their code with every Factory/Man-
ager/Object/Controller/Aggregate/
Value they add.
 
One such ritual common to both the
.NET and the Java worlds is adding
the suffix Exception to a class to
denote that its instances are excep-
tions. Exceptions are privileged in the
language, meaning that they appear in
specific and compiler-enforced places
in your code: in a throw, in a catch and,
in the case of the Java, in a throws list.
By definition things that appear in
these places can only be exceptions;
the reader already knows they are
exceptions, so there's nothing more
to add.
 
Of course, there is also the definition
of the exception class. That a class is
an exception should be obvious either
by its parentage or by its name. The
name should represent whatever the
problem is, and should do so directly
and precisely.To add Exception to the
end is either redundant — so remove it
— or an indication of a poor name — so
rename it. Consider, for example, the
following core Java exception classes:
 
ClassNotFoundException
EnumConstantNotPresentException
IllegalArgumentException
IllegalAccessException
IndexOutOfBoundsException
NegativeArraySizeException
NoSuchMethodException
TypeNotPresentException
UnsupportedOperationException
 
Dropping the Exception suffix gives
the following names:
 
ClassNotFound
EnumConstantNotPresent
IllegalArgument
IllegalAccess
IndexOutOfBounds
NegativeArraySize
NoSuchMethod
TypeNotPresent
UnsupportedOperation
 
These names are more concise and
perfectly descriptive. There is no
question that these are exceptions.
 
OK, but what about the following, also
from the core Java exception classes?
 
ArithmeticException
ArrayStoreException
ClassCastException
InstantiationException
NullPointerException
SecurityException
 
Dropping the Exception suffix results
in the following:
 
Arithmetic
ArrayStore
ClassCast
Instantiation
NullPointer
Security
 
Hmm, not so good. But is that a prob-
lem with dropping the Exception suf-
fix?Oraproblemrevealedbydropping
it? Let's try renaming these classes
to the exceptions they actually rep-
resent:
 
IntegerDivisionByZero
IllegalArrayElementType
CastToNonSubclass
ClassCannotBeInstantiated
NullDereferenced
SecurityViolation
 
These names are both accurate and
precise, representing the actual
exception condition without resorting
tonoisewords.Isitanexceptionthata
reference (or rather, a pointer) is null?
Not at all: the exception is only thrown
when a null is dereferenced, such as
having a method called through it.
Is security an exception? Not at all:
a security violation is what is being
signalled. Of particular interest is
renaming ArithmeticException  to
IntegerDivisionByZero, which clari-
fies something many Java program-
mers are unaware of!
 
Just as you don't tag your verbs with
Verb or your nouns with Noun when
you write or speak, there is little rea-
son — and many reasons not to — tag
Exception onto the end of an exception
class's name. In many cases it can be
considered a code smell rather than
a practice to follow, and can deprive
programmers of the opportunity to
choose a better name. The possible
exception to this rule? The general
class that indicates that its descend-
ants are exceptions: Exception. But
thenagain,that'snotasuffix:that'sthe
whole of its name and the concept that
it represents, so perhaps there are no
exceptions on Exception naming.
49
Kevlin is an independent
consultant and trainer based
in the UK. His development
interests are in patterns,
programming, practice and
process. He has been a columnist
for various magazines and web
sites, including Better Software,
The Register, Application
Development Advisor, Java
Report and the C/C++ Users
Journal. Kevlin is co-author
of A Pattern Language for
Distributed Computing and
On Patterns and Pattern
Languages, two volumes in
the Pattern-Oriented Software
Architecture series. He is also
editor of the 97 Things Every
Programmer Should Know site
and book.

Contenu connexe

Tendances

Coding standards for java
Coding standards for javaCoding standards for java
Coding standards for javamaheshm1206
 
Standards For Java Coding
Standards For Java CodingStandards For Java Coding
Standards For Java CodingRahul Bhutkar
 
WordCamp US: Clean Code
WordCamp US: Clean CodeWordCamp US: Clean Code
WordCamp US: Clean Codemtoppa
 
Mark asoi ppt
Mark asoi pptMark asoi ppt
Mark asoi pptmark-asoi
 
Standard coding practices
Standard coding practicesStandard coding practices
Standard coding practicesAnilkumar Patil
 
Listen and look at your PHP code
Listen and look at your PHP codeListen and look at your PHP code
Listen and look at your PHP codeGabriele Santini
 
Clean Code summary
Clean Code summaryClean Code summary
Clean Code summaryJan de Vries
 
Java ocjp level_2
Java ocjp level_2Java ocjp level_2
Java ocjp level_2Sayed Ahmed
 
Another Tale of Two Patterns
Another Tale of Two PatternsAnother Tale of Two Patterns
Another Tale of Two PatternsKevlin Henney
 
Creating Clean Code with AOP
Creating Clean Code with AOPCreating Clean Code with AOP
Creating Clean Code with AOPRobert Lemke
 
Expressive And Modular Predicate Dispatch In Java
Expressive And Modular Predicate Dispatch In JavaExpressive And Modular Predicate Dispatch In Java
Expressive And Modular Predicate Dispatch In JavaDr Anjan Krishnamurthy
 
Systematic error management - we ported rudder to zio
Systematic error management - we ported rudder to zioSystematic error management - we ported rudder to zio
Systematic error management - we ported rudder to ziofanf42
 
Journey's diary developing a framework using tdd
Journey's diary   developing a framework using tddJourney's diary   developing a framework using tdd
Journey's diary developing a framework using tddeduardomg23
 
Clean code: meaningful Name
Clean code: meaningful NameClean code: meaningful Name
Clean code: meaningful Namenahid035
 
Desenvolvendo um Framework com TDD - Um Diário de Bordo - Agile Trends 2014
Desenvolvendo um Framework com TDD - Um Diário de Bordo - Agile Trends 2014Desenvolvendo um Framework com TDD - Um Diário de Bordo - Agile Trends 2014
Desenvolvendo um Framework com TDD - Um Diário de Bordo - Agile Trends 2014eduardomg23
 

Tendances (20)

Opposites Attract
Opposites AttractOpposites Attract
Opposites Attract
 
Coding standards for java
Coding standards for javaCoding standards for java
Coding standards for java
 
Standards For Java Coding
Standards For Java CodingStandards For Java Coding
Standards For Java Coding
 
Bb Tequila Coding Style (Draft)
Bb Tequila Coding Style (Draft)Bb Tequila Coding Style (Draft)
Bb Tequila Coding Style (Draft)
 
Cursus phpunit
Cursus phpunitCursus phpunit
Cursus phpunit
 
WordCamp US: Clean Code
WordCamp US: Clean CodeWordCamp US: Clean Code
WordCamp US: Clean Code
 
Mark asoi ppt
Mark asoi pptMark asoi ppt
Mark asoi ppt
 
Standard coding practices
Standard coding practicesStandard coding practices
Standard coding practices
 
Codings Standards
Codings StandardsCodings Standards
Codings Standards
 
Listen and look at your PHP code
Listen and look at your PHP codeListen and look at your PHP code
Listen and look at your PHP code
 
Clean Code summary
Clean Code summaryClean Code summary
Clean Code summary
 
Java ocjp level_2
Java ocjp level_2Java ocjp level_2
Java ocjp level_2
 
Another Tale of Two Patterns
Another Tale of Two PatternsAnother Tale of Two Patterns
Another Tale of Two Patterns
 
Creating Clean Code with AOP
Creating Clean Code with AOPCreating Clean Code with AOP
Creating Clean Code with AOP
 
Expressive And Modular Predicate Dispatch In Java
Expressive And Modular Predicate Dispatch In JavaExpressive And Modular Predicate Dispatch In Java
Expressive And Modular Predicate Dispatch In Java
 
Systematic error management - we ported rudder to zio
Systematic error management - we ported rudder to zioSystematic error management - we ported rudder to zio
Systematic error management - we ported rudder to zio
 
Switch case looping
Switch case loopingSwitch case looping
Switch case looping
 
Journey's diary developing a framework using tdd
Journey's diary   developing a framework using tddJourney's diary   developing a framework using tdd
Journey's diary developing a framework using tdd
 
Clean code: meaningful Name
Clean code: meaningful NameClean code: meaningful Name
Clean code: meaningful Name
 
Desenvolvendo um Framework com TDD - Um Diário de Bordo - Agile Trends 2014
Desenvolvendo um Framework com TDD - Um Diário de Bordo - Agile Trends 2014Desenvolvendo um Framework com TDD - Um Diário de Bordo - Agile Trends 2014
Desenvolvendo um Framework com TDD - Um Diário de Bordo - Agile Trends 2014
 

En vedette

Stringing Things Along
Stringing Things AlongStringing Things Along
Stringing Things AlongKevlin Henney
 
Promoting Polymorphism
Promoting PolymorphismPromoting Polymorphism
Promoting PolymorphismKevlin Henney
 
Collections for States
Collections for StatesCollections for States
Collections for StatesKevlin Henney
 
Worse Is Better, for Better or for Worse
Worse Is Better, for Better or for WorseWorse Is Better, for Better or for Worse
Worse Is Better, for Better or for WorseKevlin Henney
 
10 Celebrities You Didn't Know Studied Accounting
10 Celebrities You Didn't Know Studied Accounting10 Celebrities You Didn't Know Studied Accounting
10 Celebrities You Didn't Know Studied AccountingAccounting4Free
 
Anatomy of a methodology
Anatomy of a methodologyAnatomy of a methodology
Anatomy of a methodologySaumya Ganguly
 
Press Briefing Slides on the budget and economic outlook 2015 to 2025
Press Briefing Slides on the budget and economic outlook 2015 to 2025Press Briefing Slides on the budget and economic outlook 2015 to 2025
Press Briefing Slides on the budget and economic outlook 2015 to 2025Congressional Budget Office
 
Habitual behaviour(unit 1)
Habitual behaviour(unit 1)Habitual behaviour(unit 1)
Habitual behaviour(unit 1)Hamed Hashemian
 
Why FPGA
Why FPGAWhy FPGA
Why FPGAProFAX
 
совладельцы. сособственники
совладельцы. сособственникисовладельцы. сособственники
совладельцы. сособственникиSychev.n
 
How to start a blog step-by-step guide
How to start a blog   step-by-step guideHow to start a blog   step-by-step guide
How to start a blog step-by-step guideKaran Labra
 
ХӨС семинар 10
ХӨС семинар 10ХӨС семинар 10
ХӨС семинар 10Usukhuu Galaa
 

En vedette (20)

One Careful Owner
One Careful OwnerOne Careful Owner
One Careful Owner
 
Stringing Things Along
Stringing Things AlongStringing Things Along
Stringing Things Along
 
Promoting Polymorphism
Promoting PolymorphismPromoting Polymorphism
Promoting Polymorphism
 
The Perfect Couple
The Perfect CoupleThe Perfect Couple
The Perfect Couple
 
Collections for States
Collections for StatesCollections for States
Collections for States
 
Worse Is Better, for Better or for Worse
Worse Is Better, for Better or for WorseWorse Is Better, for Better or for Worse
Worse Is Better, for Better or for Worse
 
Inside Requirements
Inside RequirementsInside Requirements
Inside Requirements
 
Substitutability
SubstitutabilitySubstitutability
Substitutability
 
Bound and Checked
Bound and CheckedBound and Checked
Bound and Checked
 
10 Celebrities You Didn't Know Studied Accounting
10 Celebrities You Didn't Know Studied Accounting10 Celebrities You Didn't Know Studied Accounting
10 Celebrities You Didn't Know Studied Accounting
 
Anatomy of a methodology
Anatomy of a methodologyAnatomy of a methodology
Anatomy of a methodology
 
Press Briefing Slides on the budget and economic outlook 2015 to 2025
Press Briefing Slides on the budget and economic outlook 2015 to 2025Press Briefing Slides on the budget and economic outlook 2015 to 2025
Press Briefing Slides on the budget and economic outlook 2015 to 2025
 
Letter of application
Letter of applicationLetter of application
Letter of application
 
Habitual behaviour(unit 1)
Habitual behaviour(unit 1)Habitual behaviour(unit 1)
Habitual behaviour(unit 1)
 
Informal letter
Informal letterInformal letter
Informal letter
 
Why FPGA
Why FPGAWhy FPGA
Why FPGA
 
совладельцы. сособственники
совладельцы. сособственникисовладельцы. сособственники
совладельцы. сособственники
 
How to start a blog step-by-step guide
How to start a blog   step-by-step guideHow to start a blog   step-by-step guide
How to start a blog step-by-step guide
 
Section 3
Section 3Section 3
Section 3
 
ХӨС семинар 10
ХӨС семинар 10ХӨС семинар 10
ХӨС семинар 10
 

Similaire à Exceptional Naming

OCA Java SE 8 Exam Chapter 1 Java Building Blocks
OCA Java SE 8 Exam Chapter 1 Java Building BlocksOCA Java SE 8 Exam Chapter 1 Java Building Blocks
OCA Java SE 8 Exam Chapter 1 Java Building Blocksİbrahim Kürce
 
Back-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real WorldBack-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real WorldDavid McCarter
 
Back-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real WorldBack-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real WorldDavid McCarter
 
Java Faqs useful for freshers and experienced
Java Faqs useful for freshers and experiencedJava Faqs useful for freshers and experienced
Java Faqs useful for freshers and experiencedyearninginjava
 
Intro Java Rev010
Intro Java Rev010Intro Java Rev010
Intro Java Rev010Rich Helton
 
Top 371 java fa qs useful for freshers and experienced
Top 371 java fa qs useful for freshers and experiencedTop 371 java fa qs useful for freshers and experienced
Top 371 java fa qs useful for freshers and experiencedGaurav Maheshwari
 
How To Tidy Up Your Test Code
How To Tidy Up Your Test CodeHow To Tidy Up Your Test Code
How To Tidy Up Your Test CodeRock Interview
 
C# coding standards, good programming principles & refactoring
C# coding standards, good programming principles & refactoringC# coding standards, good programming principles & refactoring
C# coding standards, good programming principles & refactoringEyob Lube
 
Classes and Objects
Classes and ObjectsClasses and Objects
Classes and Objectsvmadan89
 
Creativity vs Best Practices
Creativity vs Best PracticesCreativity vs Best Practices
Creativity vs Best PracticesSupun Dissanayake
 
Exception handler
Exception handler Exception handler
Exception handler dishni
 
Bt0074 oops with java2
Bt0074 oops with java2Bt0074 oops with java2
Bt0074 oops with java2Techglyphs
 
Java for Mainframers
Java for MainframersJava for Mainframers
Java for MainframersRich Helton
 
Framework Design Guidelines
Framework Design GuidelinesFramework Design Guidelines
Framework Design GuidelinesMohamed Meligy
 
Learn C# programming - Interfaces & Namespaces
Learn C# programming - Interfaces & NamespacesLearn C# programming - Interfaces & Namespaces
Learn C# programming - Interfaces & NamespacesEng Teong Cheah
 

Similaire à Exceptional Naming (20)

Java & J2EE Coding Conventions
Java & J2EE Coding ConventionsJava & J2EE Coding Conventions
Java & J2EE Coding Conventions
 
OCA Java SE 8 Exam Chapter 1 Java Building Blocks
OCA Java SE 8 Exam Chapter 1 Java Building BlocksOCA Java SE 8 Exam Chapter 1 Java Building Blocks
OCA Java SE 8 Exam Chapter 1 Java Building Blocks
 
Back-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real WorldBack-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real World
 
Back-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real WorldBack-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real World
 
DAY_1.1.pptx
DAY_1.1.pptxDAY_1.1.pptx
DAY_1.1.pptx
 
Java Faqs useful for freshers and experienced
Java Faqs useful for freshers and experiencedJava Faqs useful for freshers and experienced
Java Faqs useful for freshers and experienced
 
Intro Java Rev010
Intro Java Rev010Intro Java Rev010
Intro Java Rev010
 
Top 371 java fa qs useful for freshers and experienced
Top 371 java fa qs useful for freshers and experiencedTop 371 java fa qs useful for freshers and experienced
Top 371 java fa qs useful for freshers and experienced
 
Suga java training_with_footer
Suga java training_with_footerSuga java training_with_footer
Suga java training_with_footer
 
How To Tidy Up Your Test Code
How To Tidy Up Your Test CodeHow To Tidy Up Your Test Code
How To Tidy Up Your Test Code
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
 
Viva file
Viva fileViva file
Viva file
 
C# coding standards, good programming principles & refactoring
C# coding standards, good programming principles & refactoringC# coding standards, good programming principles & refactoring
C# coding standards, good programming principles & refactoring
 
Classes and Objects
Classes and ObjectsClasses and Objects
Classes and Objects
 
Creativity vs Best Practices
Creativity vs Best PracticesCreativity vs Best Practices
Creativity vs Best Practices
 
Exception handler
Exception handler Exception handler
Exception handler
 
Bt0074 oops with java2
Bt0074 oops with java2Bt0074 oops with java2
Bt0074 oops with java2
 
Java for Mainframers
Java for MainframersJava for Mainframers
Java for Mainframers
 
Framework Design Guidelines
Framework Design GuidelinesFramework Design Guidelines
Framework Design Guidelines
 
Learn C# programming - Interfaces & Namespaces
Learn C# programming - Interfaces & NamespacesLearn C# programming - Interfaces & Namespaces
Learn C# programming - Interfaces & Namespaces
 

Plus de Kevlin Henney

The Case for Technical Excellence
The Case for Technical ExcellenceThe Case for Technical Excellence
The Case for Technical ExcellenceKevlin Henney
 
Empirical Development
Empirical DevelopmentEmpirical Development
Empirical DevelopmentKevlin Henney
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that LetterKevlin Henney
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that LetterKevlin Henney
 
Solid Deconstruction
Solid DeconstructionSolid Deconstruction
Solid DeconstructionKevlin Henney
 
Procedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went AwayProcedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went AwayKevlin Henney
 
Structure and Interpretation of Test Cases
Structure and Interpretation of Test CasesStructure and Interpretation of Test Cases
Structure and Interpretation of Test CasesKevlin Henney
 
Refactoring to Immutability
Refactoring to ImmutabilityRefactoring to Immutability
Refactoring to ImmutabilityKevlin Henney
 
Turning Development Outside-In
Turning Development Outside-InTurning Development Outside-In
Turning Development Outside-InKevlin Henney
 
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...Kevlin Henney
 
Thinking Outside the Synchronisation Quadrant
Thinking Outside the Synchronisation QuadrantThinking Outside the Synchronisation Quadrant
Thinking Outside the Synchronisation QuadrantKevlin Henney
 
The Error of Our Ways
The Error of Our WaysThe Error of Our Ways
The Error of Our WaysKevlin Henney
 

Plus de Kevlin Henney (20)

Program with GUTs
Program with GUTsProgram with GUTs
Program with GUTs
 
The Case for Technical Excellence
The Case for Technical ExcellenceThe Case for Technical Excellence
The Case for Technical Excellence
 
Empirical Development
Empirical DevelopmentEmpirical Development
Empirical Development
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that Letter
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that Letter
 
Solid Deconstruction
Solid DeconstructionSolid Deconstruction
Solid Deconstruction
 
Get Kata
Get KataGet Kata
Get Kata
 
Procedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went AwayProcedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went Away
 
Structure and Interpretation of Test Cases
Structure and Interpretation of Test CasesStructure and Interpretation of Test Cases
Structure and Interpretation of Test Cases
 
Agility ≠ Speed
Agility ≠ SpeedAgility ≠ Speed
Agility ≠ Speed
 
Refactoring to Immutability
Refactoring to ImmutabilityRefactoring to Immutability
Refactoring to Immutability
 
Old Is the New New
Old Is the New NewOld Is the New New
Old Is the New New
 
Turning Development Outside-In
Turning Development Outside-InTurning Development Outside-In
Turning Development Outside-In
 
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
 
Thinking Outside the Synchronisation Quadrant
Thinking Outside the Synchronisation QuadrantThinking Outside the Synchronisation Quadrant
Thinking Outside the Synchronisation Quadrant
 
Code as Risk
Code as RiskCode as Risk
Code as Risk
 
Software Is Details
Software Is DetailsSoftware Is Details
Software Is Details
 
Game of Sprints
Game of SprintsGame of Sprints
Game of Sprints
 
Good Code
Good CodeGood Code
Good Code
 
The Error of Our Ways
The Error of Our WaysThe Error of Our Ways
The Error of Our Ways
 

Dernier

5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...kalichargn70th171
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfryanfarris8
 

Dernier (20)

5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 

Exceptional Naming

  • 1. One of the hardest things in software development is naming. Naming of products, of paradigms and of parts of your code. The reason naming is both hard and important is because it is an act of communication; without good names your code might as well be written in, well, code. ©totallyPic/Shutterstock By Kevlin Henney EXCEPTIONAL NAMING 48
  • 2. We often adopt conventions to make some aspects of naming easier, but while such consistency is often a good thing, some practices are flawed from the outset. Although having a com- mon vocabulary of concepts is useful across a codebase, the basis of the consistency must be useful other- wise it's just noise and can become homeopathic: programmers make names longer by adding more words but end up diluting the meaning of their code with every Factory/Man- ager/Object/Controller/Aggregate/ Value they add.   One such ritual common to both the .NET and the Java worlds is adding the suffix Exception to a class to denote that its instances are excep- tions. Exceptions are privileged in the language, meaning that they appear in specific and compiler-enforced places in your code: in a throw, in a catch and, in the case of the Java, in a throws list. By definition things that appear in these places can only be exceptions; the reader already knows they are exceptions, so there's nothing more to add.   Of course, there is also the definition of the exception class. That a class is an exception should be obvious either by its parentage or by its name. The name should represent whatever the problem is, and should do so directly and precisely.To add Exception to the end is either redundant — so remove it — or an indication of a poor name — so rename it. Consider, for example, the following core Java exception classes:   ClassNotFoundException EnumConstantNotPresentException IllegalArgumentException IllegalAccessException IndexOutOfBoundsException NegativeArraySizeException NoSuchMethodException TypeNotPresentException UnsupportedOperationException   Dropping the Exception suffix gives the following names:   ClassNotFound EnumConstantNotPresent IllegalArgument IllegalAccess IndexOutOfBounds NegativeArraySize NoSuchMethod TypeNotPresent UnsupportedOperation   These names are more concise and perfectly descriptive. There is no question that these are exceptions.   OK, but what about the following, also from the core Java exception classes?   ArithmeticException ArrayStoreException ClassCastException InstantiationException NullPointerException SecurityException   Dropping the Exception suffix results in the following:   Arithmetic ArrayStore ClassCast Instantiation NullPointer Security   Hmm, not so good. But is that a prob- lem with dropping the Exception suf- fix?Oraproblemrevealedbydropping it? Let's try renaming these classes to the exceptions they actually rep- resent:   IntegerDivisionByZero IllegalArrayElementType CastToNonSubclass ClassCannotBeInstantiated NullDereferenced SecurityViolation   These names are both accurate and precise, representing the actual exception condition without resorting tonoisewords.Isitanexceptionthata reference (or rather, a pointer) is null? Not at all: the exception is only thrown when a null is dereferenced, such as having a method called through it. Is security an exception? Not at all: a security violation is what is being signalled. Of particular interest is renaming ArithmeticException  to IntegerDivisionByZero, which clari- fies something many Java program- mers are unaware of!   Just as you don't tag your verbs with Verb or your nouns with Noun when you write or speak, there is little rea- son — and many reasons not to — tag Exception onto the end of an exception class's name. In many cases it can be considered a code smell rather than a practice to follow, and can deprive programmers of the opportunity to choose a better name. The possible exception to this rule? The general class that indicates that its descend- ants are exceptions: Exception. But thenagain,that'snotasuffix:that'sthe whole of its name and the concept that it represents, so perhaps there are no exceptions on Exception naming. 49 Kevlin is an independent consultant and trainer based in the UK. His development interests are in patterns, programming, practice and process. He has been a columnist for various magazines and web sites, including Better Software, The Register, Application Development Advisor, Java Report and the C/C++ Users Journal. Kevlin is co-author of A Pattern Language for Distributed Computing and On Patterns and Pattern Languages, two volumes in the Pattern-Oriented Software Architecture series. He is also editor of the 97 Things Every Programmer Should Know site and book.