SlideShare a Scribd company logo
1 of 25
Download to read offline
OR
WHAT’S IN A NAME ?
enum ONE_FOUR_FLAG {
ONE_FOUR_FLAG_1 = 1,
ONE_FOUR_FLAG_2 = 2,
ONE_FOUR_FLAG_3 = 3,
ONE_FOUR_FLAG_4 = 4,
};
WHY INVEST TIME IN NAMING ?
• Private functions and variables
• Benefits the maintainer
• Clearer meaning, leading to less bugs
• Easier debugging
• Namespaces, classes and public functions
• Benefits all users with easier reuse
• Benefits the maintainer with easier expanding
• Removes the need for costly API renaming and prototyping
USE INTENTION REVEALING NAMES
• A proper name is better than a comment
int d; // duration of operation,
// in days
int duration_days; // of operation
bool verify(Dimentions); // within limits
bool withinLimits(Dimentions);
bool initialized(Dimentions);
AVOID DISINFORMATION
• Avoid using common CS names
s = getSize(idList); // Is this a list<> container?
int idList[100]; // Nope… confusing, I‟d say
int idArray[100]; // Same problem here
int ids[100]; // An improvement
int idGroup[100]; // better still
list<int> idList; // A proper use of “list”
• Lower case L, upper case o
int a = l;
if ( O = l )
a = O1;
else
l = 01;
AVOID DISINFORMATION
• Avoid small changes in long names
class XYZControllerForEfficientHandlingOfStrings;
…
…
…
…
class XYZControllerForEfficientParsingOfStrings;
MAKE MEANINGFUL DISTINCTION
• Avoid adding meaningless ‘noise’ words
class Product; // Informative enough
class ProductData; // „noise‟ word Data
class ProductInfo; // Same deal
class ProductShipping; // Distinctive
class ProductInventory; // Distinctive
MAKE MEANINGFUL DISTINCTION
• Same goes for object names
struct MessageA {
Header hdr;
MsgBodyA data; // Really? Doesn‟t hdr
// contain data as well?
};
struct MessageA {
Header hdr;
MsgBodyA body;
};
USE PRONOUNCEABLE NAMES
class DtaRcrdA {
private Date crtymdhms;
private Date modymdhms;
private final String pszrt = “type_A”;
…
};
class Customer {
private Date creation_timestamp;
private Date modification_timestamp;
private final String recordType = “Customer”;
…
};
USE SEARCHABLE NAMES
• A variable named ‘e’ is hard to search for
• Also 30 Class types beginning with CTRL
• However, modern IDEs and their add-ons (Visual
Assist, ReSharper) make searching much easier.
• Still, the code will be more understandable if names
stand out without the assistance of external tools
AVOID MENTAL MAPPING
• Being able to remember a lot of variable names, is
no excuse for making it hard for those that can’t …
const char url[] = “http://www.google.com/index.html”;
char * r = getUrlFilePath(url); // ah… it‟s “index.html”
…
f = fopen(r); // what was r again?
char * starterWebPageName = getUrlFilePath(url);
f = fopen(starterWebPageName); // A bit clearer, isn‟t it?
USE NOUN AND VERB PHRASES
• Combine nouns and verbs
student.setName(“Mike”); // a good option
student.changeNameTo(“Mike”); // an actual phrase
• But not too much…
String name = person.getName();
String name = person.name();
DON’T BE CUTE
void holyHandGrenade();// One down, five to go
void deleteAll();
PICK ONE WORD PER CONCEPT
• Be consistent
addressList.push_front(address);
customers.add(customer);
groceries.insert(product);
cars.append(suv);
• STL/CLR can sometimes serve as a baseline
insert // 1 or more elements, at certain
// location
push_front, push_back // 1 element, front or back
remove // remove all that match
clear // clear container from all elements
• Even if you dislike STL, remember the 1st paragraph
AVOID ENCODINGS
class Carrier {
int iFreq_MHz_;
};
class Carrier {
float iFreq_MHz_; // Not true anymore…
};
class Carrier {
int freq_MHz_;
};
class Carrier {
float freq_MHz_; // Units are sufficient info
};
SOLUTION DOMAIN NAMES
• Use when low level concepts are a must
• Because solution domain names might confuse coders,
making it harder for them to re-use the code
• Examples:
• gpioMux.setControl(3);
• vme.writeWordBE(0x0122AAAB, 15);
• receiver.writeReg(DTO_REG, freq);
COMPUTER SCIENCE NAMES
• Include all programming language constructs
• Language building blocks, algorithms, containers
• Will be more understandable to other programmers
than solution domain names
• But, better to use problem domain names, when
applicable
PROBLEM DOMAIN NAMES
• Use when computer-science names are
unclear
policy.list.find(pair.first) != policy.list.end()
policy.covers(vehicle)
bool Policy::covers(Vehicle vehicle) {
return carList_.find(vehicle.id) !=
carList_.end();
}
MAKE CONTEXT MEANINGFUL
• Don’t add redundant prefixes
// Gas Station Delux application
class GSDStation; // Try typing G and using
class GSDCustomer; // auto-complete after 30
class GSDTanker; // more of these…
namespace GSD { // Gas Station Delux
class Station;
class Customer;
class Tanker;
…
}
MAKE CONTEXT MEANINGFUL
• Use short names when possible
class BillingAddress;
class ShippingAddress; // Is it any different?
class MACAddress; // Different indeed
class Address;
class MACAddress;
Address shippingAddress, billingAddress;
MACAddress purchasedNIC;
MAKE CONTEXT MEANINGFUL
• Use longer names for clarity
for ( int i = 1; i < num; i++ ) {
meetsCriteria[i] = true;
}
for ( int i = 2; i < num / 2; ++i ) {
int j = i + i;
while (j <= num) {
meetsCriteria[j] = false;
j += i;
}
}
for ( int i = 1; i < num; ++i ) {
if (meetsCriteria[i]) {
Console.WriteLine(i + " is prime");
}
}
MAKE CONTEXT MEANINGFUL
• Use longer names for clarity
for ( int primeCandidate = 1; primeCandidate < num; primeCandidate++ ){
meetsCriteria[primeCandidate] = true;
}
for ( int factor = 2; factor < num / 2; ++factor ) {
int factorableNumber = factor + factor;
while (factorableNumber <= num) {
meetsCriteria[factorableNumber] = false;
factorableNumber += factor;
}
}
for ( int primeCandidate = 1; primeCandidate < num; ++primeCandidate ){
if (meetsCriteria[primeCandidate]) {
Console.WriteLine(primeCandidate + " is prime");
}
}
HOW TO INVEST TIME IN NAMING
 Choose a name
 Does the name capture the idea behind a function or class?
 Does the name describe what is a function supposed to do?
 Does the name avoid implying what isn’t in a function’s to-do
list?
 Does the name capture all the responsibilities a class has?
 Does the name exclude tasks not required of the class?
 Does the name make unit-test code clearer?
 Ask co-worker to review the name
 If you got a single “No”, reiterate the above points
WHY INVEST TIME IN NAMING ?
• Private functions and variables
• Benefits the maintainer
• Clearer meaning, leading to less bugs
• Easier debugging
• Namespaces, classes and public functions
• Benefits all users with easier reuse
• Benefits the maintainer with easier expanding
• Removes the need for costly API renaming and prototyping
REMEMBER !!!
• Even if you don’t remember anything else from this
presentation…
Invest time in naming
WORK BASED ON
• The power of names, Glenn Vanderburg
• C# Coding Style Guide, Mike Kruger
• The poetry of function naming, Stephen Wolfram
blog
• https://class.stanford.edu/c4x/Engineering/CS144/a
sset/Naming.pdf

More Related Content

What's hot

Clean code and refactoring
Clean code and refactoringClean code and refactoring
Clean code and refactoringYuriy Gerasimov
 
Compiler Construction | Lecture 8 | Type Constraints
Compiler Construction | Lecture 8 | Type ConstraintsCompiler Construction | Lecture 8 | Type Constraints
Compiler Construction | Lecture 8 | Type ConstraintsEelco Visser
 
Coding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean CodeCoding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean CodeGanesh Samarthyam
 
Creating Domain Specific Languages in Python
Creating Domain Specific Languages in PythonCreating Domain Specific Languages in Python
Creating Domain Specific Languages in PythonSiddhi
 
Compiler Construction | Lecture 5 | Transformation by Term Rewriting
Compiler Construction | Lecture 5 | Transformation by Term RewritingCompiler Construction | Lecture 5 | Transformation by Term Rewriting
Compiler Construction | Lecture 5 | Transformation by Term RewritingEelco Visser
 
Let's build a parser!
Let's build a parser!Let's build a parser!
Let's build a parser!Boy Baukema
 
Declarative Type System Specification with Statix
Declarative Type System Specification with StatixDeclarative Type System Specification with Statix
Declarative Type System Specification with StatixEelco Visser
 
Lecture 22
Lecture 22Lecture 22
Lecture 22rhshriva
 
CS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | ParsingCS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | ParsingEelco Visser
 
CS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term RewritingCS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term RewritingEelco Visser
 
Fantastic DSL in Python
Fantastic DSL in PythonFantastic DSL in Python
Fantastic DSL in Pythonkwatch
 
Applying Compiler Techniques to Iterate At Blazing Speed
Applying Compiler Techniques to Iterate At Blazing SpeedApplying Compiler Techniques to Iterate At Blazing Speed
Applying Compiler Techniques to Iterate At Blazing SpeedPascal-Louis Perez
 
R. herves. clean code (theme)2
R. herves. clean code (theme)2R. herves. clean code (theme)2
R. herves. clean code (theme)2saber tabatabaee
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applicationschartjes
 

What's hot (20)

Clean code and refactoring
Clean code and refactoringClean code and refactoring
Clean code and refactoring
 
Compiler Construction | Lecture 8 | Type Constraints
Compiler Construction | Lecture 8 | Type ConstraintsCompiler Construction | Lecture 8 | Type Constraints
Compiler Construction | Lecture 8 | Type Constraints
 
Coding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean CodeCoding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean Code
 
Creating Domain Specific Languages in Python
Creating Domain Specific Languages in PythonCreating Domain Specific Languages in Python
Creating Domain Specific Languages in Python
 
Effective PHP. Part 4
Effective PHP. Part 4Effective PHP. Part 4
Effective PHP. Part 4
 
Compiler Construction | Lecture 5 | Transformation by Term Rewriting
Compiler Construction | Lecture 5 | Transformation by Term RewritingCompiler Construction | Lecture 5 | Transformation by Term Rewriting
Compiler Construction | Lecture 5 | Transformation by Term Rewriting
 
Let's build a parser!
Let's build a parser!Let's build a parser!
Let's build a parser!
 
Effective PHP. Part 6
Effective PHP. Part 6Effective PHP. Part 6
Effective PHP. Part 6
 
Declarative Type System Specification with Statix
Declarative Type System Specification with StatixDeclarative Type System Specification with Statix
Declarative Type System Specification with Statix
 
Lecture 22
Lecture 22Lecture 22
Lecture 22
 
CS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | ParsingCS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | Parsing
 
Effective PHP. Part 5
Effective PHP. Part 5Effective PHP. Part 5
Effective PHP. Part 5
 
CS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term RewritingCS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term Rewriting
 
Fantastic DSL in Python
Fantastic DSL in PythonFantastic DSL in Python
Fantastic DSL in Python
 
Trie Data Structure
Trie Data StructureTrie Data Structure
Trie Data Structure
 
Applying Compiler Techniques to Iterate At Blazing Speed
Applying Compiler Techniques to Iterate At Blazing SpeedApplying Compiler Techniques to Iterate At Blazing Speed
Applying Compiler Techniques to Iterate At Blazing Speed
 
R. herves. clean code (theme)2
R. herves. clean code (theme)2R. herves. clean code (theme)2
R. herves. clean code (theme)2
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applications
 
Effective PHP. Part 2
Effective PHP. Part 2Effective PHP. Part 2
Effective PHP. Part 2
 
C Programming Project
C Programming ProjectC Programming Project
C Programming Project
 

Viewers also liked

อุปกรณ์เชื่อมต่อคอมพิวเตอร์
อุปกรณ์เชื่อมต่อคอมพิวเตอร์อุปกรณ์เชื่อมต่อคอมพิวเตอร์
อุปกรณ์เชื่อมต่อคอมพิวเตอร์jaeoidanaya
 
Cristinatassin.ppt
Cristinatassin.pptCristinatassin.ppt
Cristinatassin.pptcristassin
 
Economics Tuition Singapore
Economics Tuition SingaporeEconomics Tuition Singapore
Economics Tuition SingaporeEcons Tutor
 
บริการต่างๆบนอินเทอร์เน็ต
บริการต่างๆบนอินเทอร์เน็ตบริการต่างๆบนอินเทอร์เน็ต
บริการต่างๆบนอินเทอร์เน็ตYingYung
 
Motors major classification
Motors  major classificationMotors  major classification
Motors major classificationsiddhusitthan
 
Why should you drink more water?
Why should you drink more water?Why should you drink more water?
Why should you drink more water?Heatwave LLC
 
الشيخ سعود بن صقر القاسمي
الشيخ سعود بن صقر القاسميالشيخ سعود بن صقر القاسمي
الشيخ سعود بن صقر القاسميneildruker
 
Amax family training march2014
Amax family training march2014Amax family training march2014
Amax family training march2014ID Idd
 
the final abstract of our major project for the award of the degree of bachel...
the final abstract of our major project for the award of the degree of bachel...the final abstract of our major project for the award of the degree of bachel...
the final abstract of our major project for the award of the degree of bachel...Sourav Lahiri
 
Optimal design of a hyperboloidal cooling tower
Optimal design of a hyperboloidal cooling towerOptimal design of a hyperboloidal cooling tower
Optimal design of a hyperboloidal cooling towerSourav Lahiri
 
The formation of mountains
The formation of mountainsThe formation of mountains
The formation of mountainsMsCCostello
 
Tears of Ganga..case study
Tears of Ganga..case studyTears of Ganga..case study
Tears of Ganga..case studySourav Lahiri
 

Viewers also liked (14)

อุปกรณ์เชื่อมต่อคอมพิวเตอร์
อุปกรณ์เชื่อมต่อคอมพิวเตอร์อุปกรณ์เชื่อมต่อคอมพิวเตอร์
อุปกรณ์เชื่อมต่อคอมพิวเตอร์
 
Cristinatassin.ppt
Cristinatassin.pptCristinatassin.ppt
Cristinatassin.ppt
 
Economics Tuition Singapore
Economics Tuition SingaporeEconomics Tuition Singapore
Economics Tuition Singapore
 
บริการต่างๆบนอินเทอร์เน็ต
บริการต่างๆบนอินเทอร์เน็ตบริการต่างๆบนอินเทอร์เน็ต
บริการต่างๆบนอินเทอร์เน็ต
 
Motors major classification
Motors  major classificationMotors  major classification
Motors major classification
 
Why should you drink more water?
Why should you drink more water?Why should you drink more water?
Why should you drink more water?
 
الشيخ سعود بن صقر القاسمي
الشيخ سعود بن صقر القاسميالشيخ سعود بن صقر القاسمي
الشيخ سعود بن صقر القاسمي
 
Amax family training march2014
Amax family training march2014Amax family training march2014
Amax family training march2014
 
the final abstract of our major project for the award of the degree of bachel...
the final abstract of our major project for the award of the degree of bachel...the final abstract of our major project for the award of the degree of bachel...
the final abstract of our major project for the award of the degree of bachel...
 
Optimal design of a hyperboloidal cooling tower
Optimal design of a hyperboloidal cooling towerOptimal design of a hyperboloidal cooling tower
Optimal design of a hyperboloidal cooling tower
 
Hemorragia en el embarazo
Hemorragia en el embarazo Hemorragia en el embarazo
Hemorragia en el embarazo
 
Rural marketing
Rural marketingRural marketing
Rural marketing
 
The formation of mountains
The formation of mountainsThe formation of mountains
The formation of mountains
 
Tears of Ganga..case study
Tears of Ganga..case studyTears of Ganga..case study
Tears of Ganga..case study
 

Similar to What's in a name

Naming Standards, Clean Code
Naming Standards, Clean CodeNaming Standards, Clean Code
Naming Standards, Clean CodeCleanestCode
 
Presentacion clean code
Presentacion clean codePresentacion clean code
Presentacion clean codeIBM
 
Oop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiOop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiMuhammed Thanveer M
 
OOP Is More Than Cars and Dogs
OOP Is More Than Cars and DogsOOP Is More Than Cars and Dogs
OOP Is More Than Cars and DogsChris Tankersley
 
Addressing Scenario
Addressing ScenarioAddressing Scenario
Addressing ScenarioTara Hardin
 
SOLID, DRY, SLAP design principles
SOLID, DRY, SLAP design principlesSOLID, DRY, SLAP design principles
SOLID, DRY, SLAP design principlesSergey Karpushin
 
Writing High Quality Code in C#
Writing High Quality Code in C#Writing High Quality Code in C#
Writing High Quality Code in C#Svetlin Nakov
 
Jeremiah Caballero - Introduction of Clean Code
Jeremiah Caballero - Introduction of Clean CodeJeremiah Caballero - Introduction of Clean Code
Jeremiah Caballero - Introduction of Clean CodeAwesome Ars Academia
 
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptxINTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptxDeepasCSE
 
Practices For Becoming A Better Programmer
Practices For Becoming A Better ProgrammerPractices For Becoming A Better Programmer
Practices For Becoming A Better ProgrammerSrikanth Shreenivas
 
The art of readable code (ch1~ch4)
The art of readable code (ch1~ch4)The art of readable code (ch1~ch4)
The art of readable code (ch1~ch4)Ki Sung Bae
 
The art of readable code (ch1~ch4)
The art of readable code (ch1~ch4)The art of readable code (ch1~ch4)
The art of readable code (ch1~ch4)Ki Sung Bae
 

Similar to What's in a name (20)

Naming Standards, Clean Code
Naming Standards, Clean CodeNaming Standards, Clean Code
Naming Standards, Clean Code
 
Coding Guidelines in CPP
Coding Guidelines in CPPCoding Guidelines in CPP
Coding Guidelines in CPP
 
Clean code
Clean codeClean code
Clean code
 
Clean code
Clean codeClean code
Clean code
 
Clean Code
Clean CodeClean Code
Clean Code
 
C++ tutorials
C++ tutorialsC++ tutorials
C++ tutorials
 
Presentacion clean code
Presentacion clean codePresentacion clean code
Presentacion clean code
 
Clean code
Clean codeClean code
Clean code
 
Oop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiOop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer Melayi
 
OOP Is More Than Cars and Dogs
OOP Is More Than Cars and DogsOOP Is More Than Cars and Dogs
OOP Is More Than Cars and Dogs
 
Addressing Scenario
Addressing ScenarioAddressing Scenario
Addressing Scenario
 
Clean Code
Clean CodeClean Code
Clean Code
 
SOLID, DRY, SLAP design principles
SOLID, DRY, SLAP design principlesSOLID, DRY, SLAP design principles
SOLID, DRY, SLAP design principles
 
Writing High Quality Code in C#
Writing High Quality Code in C#Writing High Quality Code in C#
Writing High Quality Code in C#
 
Jeremiah Caballero - Introduction of Clean Code
Jeremiah Caballero - Introduction of Clean CodeJeremiah Caballero - Introduction of Clean Code
Jeremiah Caballero - Introduction of Clean Code
 
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptxINTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
 
Practices For Becoming A Better Programmer
Practices For Becoming A Better ProgrammerPractices For Becoming A Better Programmer
Practices For Becoming A Better Programmer
 
The art of readable code (ch1~ch4)
The art of readable code (ch1~ch4)The art of readable code (ch1~ch4)
The art of readable code (ch1~ch4)
 
The art of readable code (ch1~ch4)
The art of readable code (ch1~ch4)The art of readable code (ch1~ch4)
The art of readable code (ch1~ch4)
 
Introduction to mysql part 3
Introduction to mysql part 3Introduction to mysql part 3
Introduction to mysql part 3
 

Recently uploaded

What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?Watsoo Telematics
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsMehedi Hasan Shohan
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
buds n tech IT solutions
buds n  tech IT                solutionsbuds n  tech IT                solutions
buds n tech IT solutionsmonugehlot87
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 

Recently uploaded (20)

What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software Solutions
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
buds n tech IT solutions
buds n  tech IT                solutionsbuds n  tech IT                solutions
buds n tech IT solutions
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 

What's in a name

  • 1. OR WHAT’S IN A NAME ? enum ONE_FOUR_FLAG { ONE_FOUR_FLAG_1 = 1, ONE_FOUR_FLAG_2 = 2, ONE_FOUR_FLAG_3 = 3, ONE_FOUR_FLAG_4 = 4, };
  • 2. WHY INVEST TIME IN NAMING ? • Private functions and variables • Benefits the maintainer • Clearer meaning, leading to less bugs • Easier debugging • Namespaces, classes and public functions • Benefits all users with easier reuse • Benefits the maintainer with easier expanding • Removes the need for costly API renaming and prototyping
  • 3. USE INTENTION REVEALING NAMES • A proper name is better than a comment int d; // duration of operation, // in days int duration_days; // of operation bool verify(Dimentions); // within limits bool withinLimits(Dimentions); bool initialized(Dimentions);
  • 4. AVOID DISINFORMATION • Avoid using common CS names s = getSize(idList); // Is this a list<> container? int idList[100]; // Nope… confusing, I‟d say int idArray[100]; // Same problem here int ids[100]; // An improvement int idGroup[100]; // better still list<int> idList; // A proper use of “list” • Lower case L, upper case o int a = l; if ( O = l ) a = O1; else l = 01;
  • 5. AVOID DISINFORMATION • Avoid small changes in long names class XYZControllerForEfficientHandlingOfStrings; … … … … class XYZControllerForEfficientParsingOfStrings;
  • 6. MAKE MEANINGFUL DISTINCTION • Avoid adding meaningless ‘noise’ words class Product; // Informative enough class ProductData; // „noise‟ word Data class ProductInfo; // Same deal class ProductShipping; // Distinctive class ProductInventory; // Distinctive
  • 7. MAKE MEANINGFUL DISTINCTION • Same goes for object names struct MessageA { Header hdr; MsgBodyA data; // Really? Doesn‟t hdr // contain data as well? }; struct MessageA { Header hdr; MsgBodyA body; };
  • 8. USE PRONOUNCEABLE NAMES class DtaRcrdA { private Date crtymdhms; private Date modymdhms; private final String pszrt = “type_A”; … }; class Customer { private Date creation_timestamp; private Date modification_timestamp; private final String recordType = “Customer”; … };
  • 9. USE SEARCHABLE NAMES • A variable named ‘e’ is hard to search for • Also 30 Class types beginning with CTRL • However, modern IDEs and their add-ons (Visual Assist, ReSharper) make searching much easier. • Still, the code will be more understandable if names stand out without the assistance of external tools
  • 10. AVOID MENTAL MAPPING • Being able to remember a lot of variable names, is no excuse for making it hard for those that can’t … const char url[] = “http://www.google.com/index.html”; char * r = getUrlFilePath(url); // ah… it‟s “index.html” … f = fopen(r); // what was r again? char * starterWebPageName = getUrlFilePath(url); f = fopen(starterWebPageName); // A bit clearer, isn‟t it?
  • 11. USE NOUN AND VERB PHRASES • Combine nouns and verbs student.setName(“Mike”); // a good option student.changeNameTo(“Mike”); // an actual phrase • But not too much… String name = person.getName(); String name = person.name();
  • 12. DON’T BE CUTE void holyHandGrenade();// One down, five to go void deleteAll();
  • 13. PICK ONE WORD PER CONCEPT • Be consistent addressList.push_front(address); customers.add(customer); groceries.insert(product); cars.append(suv); • STL/CLR can sometimes serve as a baseline insert // 1 or more elements, at certain // location push_front, push_back // 1 element, front or back remove // remove all that match clear // clear container from all elements • Even if you dislike STL, remember the 1st paragraph
  • 14. AVOID ENCODINGS class Carrier { int iFreq_MHz_; }; class Carrier { float iFreq_MHz_; // Not true anymore… }; class Carrier { int freq_MHz_; }; class Carrier { float freq_MHz_; // Units are sufficient info };
  • 15. SOLUTION DOMAIN NAMES • Use when low level concepts are a must • Because solution domain names might confuse coders, making it harder for them to re-use the code • Examples: • gpioMux.setControl(3); • vme.writeWordBE(0x0122AAAB, 15); • receiver.writeReg(DTO_REG, freq);
  • 16. COMPUTER SCIENCE NAMES • Include all programming language constructs • Language building blocks, algorithms, containers • Will be more understandable to other programmers than solution domain names • But, better to use problem domain names, when applicable
  • 17. PROBLEM DOMAIN NAMES • Use when computer-science names are unclear policy.list.find(pair.first) != policy.list.end() policy.covers(vehicle) bool Policy::covers(Vehicle vehicle) { return carList_.find(vehicle.id) != carList_.end(); }
  • 18. MAKE CONTEXT MEANINGFUL • Don’t add redundant prefixes // Gas Station Delux application class GSDStation; // Try typing G and using class GSDCustomer; // auto-complete after 30 class GSDTanker; // more of these… namespace GSD { // Gas Station Delux class Station; class Customer; class Tanker; … }
  • 19. MAKE CONTEXT MEANINGFUL • Use short names when possible class BillingAddress; class ShippingAddress; // Is it any different? class MACAddress; // Different indeed class Address; class MACAddress; Address shippingAddress, billingAddress; MACAddress purchasedNIC;
  • 20. MAKE CONTEXT MEANINGFUL • Use longer names for clarity for ( int i = 1; i < num; i++ ) { meetsCriteria[i] = true; } for ( int i = 2; i < num / 2; ++i ) { int j = i + i; while (j <= num) { meetsCriteria[j] = false; j += i; } } for ( int i = 1; i < num; ++i ) { if (meetsCriteria[i]) { Console.WriteLine(i + " is prime"); } }
  • 21. MAKE CONTEXT MEANINGFUL • Use longer names for clarity for ( int primeCandidate = 1; primeCandidate < num; primeCandidate++ ){ meetsCriteria[primeCandidate] = true; } for ( int factor = 2; factor < num / 2; ++factor ) { int factorableNumber = factor + factor; while (factorableNumber <= num) { meetsCriteria[factorableNumber] = false; factorableNumber += factor; } } for ( int primeCandidate = 1; primeCandidate < num; ++primeCandidate ){ if (meetsCriteria[primeCandidate]) { Console.WriteLine(primeCandidate + " is prime"); } }
  • 22. HOW TO INVEST TIME IN NAMING  Choose a name  Does the name capture the idea behind a function or class?  Does the name describe what is a function supposed to do?  Does the name avoid implying what isn’t in a function’s to-do list?  Does the name capture all the responsibilities a class has?  Does the name exclude tasks not required of the class?  Does the name make unit-test code clearer?  Ask co-worker to review the name  If you got a single “No”, reiterate the above points
  • 23. WHY INVEST TIME IN NAMING ? • Private functions and variables • Benefits the maintainer • Clearer meaning, leading to less bugs • Easier debugging • Namespaces, classes and public functions • Benefits all users with easier reuse • Benefits the maintainer with easier expanding • Removes the need for costly API renaming and prototyping
  • 24. REMEMBER !!! • Even if you don’t remember anything else from this presentation… Invest time in naming
  • 25. WORK BASED ON • The power of names, Glenn Vanderburg • C# Coding Style Guide, Mike Kruger • The poetry of function naming, Stephen Wolfram blog • https://class.stanford.edu/c4x/Engineering/CS144/a sset/Naming.pdf