SlideShare une entreprise Scribd logo
1  sur  37
Télécharger pour lire hors ligne
Magic Literals In
Pharo
Julien Delplanque, Stéphane Ducasse, and Oleksandr Zaitsev
{firstname}.{lastname}@inria.fr
Based on the paper that we published at the International
Workshop of Smalltalk Technologies (IWST’19)
• PhD Student at Inria Lille

CIFRE: Inria + Arolla

• I live and work in Lille

and come to Arolla once every two weeks

• My research is about

Machine Learning + Software Evolution

• I don’t speak French but I’m learning :)
About me
3
4
Literals in Pharo
• true and false

• nil
• Numbers: 42, -42, 4.2, 4s2, 4e2, …

• Individual characters: $a

• Strings of characters: ‘foo’

• Symbols: #foo:bar:

• Arrays of other literal constants: #(1 2 4) and #[255 0]
5
Magic Literals
6
— literals of any kind that appear in source code
without a clear explanation
Example of Magic Literals
7
Example of Magic Literals
8
what is 52?
what is 4??
Same Thing without
Magic Literals
9
Same Thing without
Magic Literals
10
aha!
Why Should We Avoid
Magic Literals?
11
1. Readability

2. Logic duplication

3. Modularity
Closer look at the literals
169,133
literals in Pharo 7
We have identified
169,133

literals
Other
Array Boolean
Symbol
String
Integer
14
RQ1: What are the most common
data types of literals?
169,133

literals
Array
Pragma
Sequence
Assignment
Return
Receiver
Argument
15
RQ2: In which part of the AST do those
literals appear?
16
Tests Non-tests
92 330
20 170
Test Non-test
60 %37 %
40 %
63 %
without

magic

literals
with

magic

literals
RQ3: Are there more literals in test
methods?
Acceptable Literals
Literals self-describing their semantics
Acceptable literals
true
false

nil
#()

#[]

{}

‘’
18
Literals directly assigned to a variable /
returned by a method
Acceptable literals
19
this is EventTypeNone
those are typical
file extensions
Literals located in a test and example
methods
Acceptable literals
20
acceptable in tests
Magic Literals
Any literal that does not fall in one of the

acceptable literal category.
22
Magic Literals
Detecting Magic Literals
Heuristic implemented as a
CodeCritic rule
24
Evaluation
Evaluation Strategy
Step 1. Select all methods from Pharo 7

Step 2. Run heuristic to find magic literals

Step 3. Select a small sample of those methods

Step 4. Manually evaluate the results
112,500
Evaluation. Step 1
We have collected
methods
from Pharo 7 image
Evaluation. Step 2
Our heuristic reported
Methods 8 986
160 147
Without 

magic literals
With 

magic literals
Evaluation. Step 2
Our heuristic reported
Literals 23 292103 514
Non-magic Magic
Evaluation. Step 3
We randomly selected
100 methods
for manual evaluation
Evaluation. Step 3
According to our heuristic,

those methods contain
243 magic

literals
Evaluation. Step 4
32
151 7418
True

Positive
False

Positive
?
243 literals
reported as magic
Evaluation. Step 4
33
True Positive example
why 2000?
Evaluation. Step 4
34
False Positive example
the meaning of
1, 2, 3 is clear
in this case -
they increment
the index
Estimated Precision
35
30 %
7 %
62 %
Conclusion
Conclusion
• First heuristic for identifying magic literals

• Implemented as code critics (lint) rule

• 62% of reported literals were actually magic

(and should be fixed)

Contenu connexe

Plus de Oleksandr Zaitsev

Cormas: Modelling for Citizens with Citizens. Building accessible and reliabl...
Cormas: Modelling for Citizens with Citizens. Building accessible and reliabl...Cormas: Modelling for Citizens with Citizens. Building accessible and reliabl...
Cormas: Modelling for Citizens with Citizens. Building accessible and reliabl...Oleksandr Zaitsev
 
Agent-Based Modelling in Pharo Using Cormas
Agent-Based Modelling in Pharo Using CormasAgent-Based Modelling in Pharo Using Cormas
Agent-Based Modelling in Pharo Using CormasOleksandr Zaitsev
 
AI for Software Engineering:
Research & Innovation
AI for Software Engineering:
Research & InnovationAI for Software Engineering:
Research & Innovation
AI for Software Engineering:
Research & InnovationOleksandr Zaitsev
 
How Libraries Evolve. A Survey of Two Industrial Companies and an Open-Source...
How Libraries Evolve. A Survey of Two Industrial Companies and an Open-Source...How Libraries Evolve. A Survey of Two Industrial Companies and an Open-Source...
How Libraries Evolve. A Survey of Two Industrial Companies and an Open-Source...Oleksandr Zaitsev
 
Data Mining-based Tools to Support Library Update. PhD Defence of Oleksandr Z...
Data Mining-based Tools to Support Library Update. PhD Defence of Oleksandr Z...Data Mining-based Tools to Support Library Update. PhD Defence of Oleksandr Z...
Data Mining-based Tools to Support Library Update. PhD Defence of Oleksandr Z...Oleksandr Zaitsev
 
How Fast is AI in Pharo? Benchmarking Linear Regression
How Fast is AI in Pharo? Benchmarking Linear RegressionHow Fast is AI in Pharo? Benchmarking Linear Regression
How Fast is AI in Pharo? Benchmarking Linear RegressionOleksandr Zaitsev
 
DepMiner: Automatic Recommendation of Transformation Rules for Method Depreca...
DepMiner: Automatic Recommendation of Transformation Rules for Method Depreca...DepMiner: Automatic Recommendation of Transformation Rules for Method Depreca...
DepMiner: Automatic Recommendation of Transformation Rules for Method Depreca...Oleksandr Zaitsev
 
Suggesting Descriptive Method Names: An Exploratory Study of Two Machine Lear...
Suggesting Descriptive Method Names: An Exploratory Study of Two Machine Lear...Suggesting Descriptive Method Names: An Exploratory Study of Two Machine Lear...
Suggesting Descriptive Method Names: An Exploratory Study of Two Machine Lear...Oleksandr Zaitsev
 
Machine Learning-based Tools to Support Library Update
Machine Learning-based Tools to Support Library UpdateMachine Learning-based Tools to Support Library Update
Machine Learning-based Tools to Support Library UpdateOleksandr Zaitsev
 
Introduction to Git Version Control System
Introduction to Git Version Control SystemIntroduction to Git Version Control System
Introduction to Git Version Control SystemOleksandr Zaitsev
 
Aspects of software naturalness through the generation of IdentifierNames
Aspects of software naturalness through the generation of IdentifierNamesAspects of software naturalness through the generation of IdentifierNames
Aspects of software naturalness through the generation of IdentifierNamesOleksandr Zaitsev
 

Plus de Oleksandr Zaitsev (16)

Cormas: Modelling for Citizens with Citizens. Building accessible and reliabl...
Cormas: Modelling for Citizens with Citizens. Building accessible and reliabl...Cormas: Modelling for Citizens with Citizens. Building accessible and reliabl...
Cormas: Modelling for Citizens with Citizens. Building accessible and reliabl...
 
Cormas RMoD
Cormas RMoDCormas RMoD
Cormas RMoD
 
Cirad Parcours
Cirad ParcoursCirad Parcours
Cirad Parcours
 
Cirad Concours
Cirad ConcoursCirad Concours
Cirad Concours
 
Agent-Based Modelling in Pharo Using Cormas
Agent-Based Modelling in Pharo Using CormasAgent-Based Modelling in Pharo Using Cormas
Agent-Based Modelling in Pharo Using Cormas
 
AI for Software Engineering:
Research & Innovation
AI for Software Engineering:
Research & InnovationAI for Software Engineering:
Research & Innovation
AI for Software Engineering:
Research & Innovation
 
How Libraries Evolve. A Survey of Two Industrial Companies and an Open-Source...
How Libraries Evolve. A Survey of Two Industrial Companies and an Open-Source...How Libraries Evolve. A Survey of Two Industrial Companies and an Open-Source...
How Libraries Evolve. A Survey of Two Industrial Companies and an Open-Source...
 
Data Mining-based Tools to Support Library Update. PhD Defence of Oleksandr Z...
Data Mining-based Tools to Support Library Update. PhD Defence of Oleksandr Z...Data Mining-based Tools to Support Library Update. PhD Defence of Oleksandr Z...
Data Mining-based Tools to Support Library Update. PhD Defence of Oleksandr Z...
 
PolyMath (ESUG 2022)
PolyMath (ESUG 2022)PolyMath (ESUG 2022)
PolyMath (ESUG 2022)
 
How Fast is AI in Pharo? Benchmarking Linear Regression
How Fast is AI in Pharo? Benchmarking Linear RegressionHow Fast is AI in Pharo? Benchmarking Linear Regression
How Fast is AI in Pharo? Benchmarking Linear Regression
 
DepMiner: Automatic Recommendation of Transformation Rules for Method Depreca...
DepMiner: Automatic Recommendation of Transformation Rules for Method Depreca...DepMiner: Automatic Recommendation of Transformation Rules for Method Depreca...
DepMiner: Automatic Recommendation of Transformation Rules for Method Depreca...
 
Suggesting Descriptive Method Names: An Exploratory Study of Two Machine Lear...
Suggesting Descriptive Method Names: An Exploratory Study of Two Machine Lear...Suggesting Descriptive Method Names: An Exploratory Study of Two Machine Lear...
Suggesting Descriptive Method Names: An Exploratory Study of Two Machine Lear...
 
Machine Learning-based Tools to Support Library Update
Machine Learning-based Tools to Support Library UpdateMachine Learning-based Tools to Support Library Update
Machine Learning-based Tools to Support Library Update
 
Introduction to Git Version Control System
Introduction to Git Version Control SystemIntroduction to Git Version Control System
Introduction to Git Version Control System
 
PhD Roadmap
PhD RoadmapPhD Roadmap
PhD Roadmap
 
Aspects of software naturalness through the generation of IdentifierNames
Aspects of software naturalness through the generation of IdentifierNamesAspects of software naturalness through the generation of IdentifierNames
Aspects of software naturalness through the generation of IdentifierNames
 

Dernier

9999266834 Call Girls In Noida Sector 22 (Delhi) Call Girl Service
9999266834 Call Girls In Noida Sector 22 (Delhi) Call Girl Service9999266834 Call Girls In Noida Sector 22 (Delhi) Call Girl Service
9999266834 Call Girls In Noida Sector 22 (Delhi) Call Girl Servicenishacall1
 
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...Sérgio Sacani
 
Botany 4th semester series (krishna).pdf
Botany 4th semester series (krishna).pdfBotany 4th semester series (krishna).pdf
Botany 4th semester series (krishna).pdfSumit Kumar yadav
 
Zoology 4th semester series (krishna).pdf
Zoology 4th semester series (krishna).pdfZoology 4th semester series (krishna).pdf
Zoology 4th semester series (krishna).pdfSumit Kumar yadav
 
Proteomics: types, protein profiling steps etc.
Proteomics: types, protein profiling steps etc.Proteomics: types, protein profiling steps etc.
Proteomics: types, protein profiling steps etc.Silpa
 
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdfPests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdfPirithiRaju
 
GBSN - Biochemistry (Unit 1)
GBSN - Biochemistry (Unit 1)GBSN - Biochemistry (Unit 1)
GBSN - Biochemistry (Unit 1)Areesha Ahmad
 
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...Lokesh Kothari
 
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 60009654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000Sapana Sha
 
Formation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disksFormation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disksSérgio Sacani
 
Forensic Biology & Its biological significance.pdf
Forensic Biology & Its biological significance.pdfForensic Biology & Its biological significance.pdf
Forensic Biology & Its biological significance.pdfrohankumarsinghrore1
 
FAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
FAIRSpectra - Enabling the FAIRification of Spectroscopy and SpectrometryFAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
FAIRSpectra - Enabling the FAIRification of Spectroscopy and SpectrometryAlex Henderson
 
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.Nitya salvi
 
Justdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts Service
Justdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts ServiceJustdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts Service
Justdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts Servicemonikaservice1
 
module for grade 9 for distance learning
module for grade 9 for distance learningmodule for grade 9 for distance learning
module for grade 9 for distance learninglevieagacer
 
Chemistry 4th semester series (krishna).pdf
Chemistry 4th semester series (krishna).pdfChemistry 4th semester series (krishna).pdf
Chemistry 4th semester series (krishna).pdfSumit Kumar yadav
 
Chemical Tests; flame test, positive and negative ions test Edexcel Internati...
Chemical Tests; flame test, positive and negative ions test Edexcel Internati...Chemical Tests; flame test, positive and negative ions test Edexcel Internati...
Chemical Tests; flame test, positive and negative ions test Edexcel Internati...ssuser79fe74
 
Vip profile Call Girls In Lonavala 9748763073 For Genuine Sex Service At Just...
Vip profile Call Girls In Lonavala 9748763073 For Genuine Sex Service At Just...Vip profile Call Girls In Lonavala 9748763073 For Genuine Sex Service At Just...
Vip profile Call Girls In Lonavala 9748763073 For Genuine Sex Service At Just...Monika Rani
 
Botany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdfBotany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdfSumit Kumar yadav
 

Dernier (20)

9999266834 Call Girls In Noida Sector 22 (Delhi) Call Girl Service
9999266834 Call Girls In Noida Sector 22 (Delhi) Call Girl Service9999266834 Call Girls In Noida Sector 22 (Delhi) Call Girl Service
9999266834 Call Girls In Noida Sector 22 (Delhi) Call Girl Service
 
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
 
Botany 4th semester series (krishna).pdf
Botany 4th semester series (krishna).pdfBotany 4th semester series (krishna).pdf
Botany 4th semester series (krishna).pdf
 
Zoology 4th semester series (krishna).pdf
Zoology 4th semester series (krishna).pdfZoology 4th semester series (krishna).pdf
Zoology 4th semester series (krishna).pdf
 
Proteomics: types, protein profiling steps etc.
Proteomics: types, protein profiling steps etc.Proteomics: types, protein profiling steps etc.
Proteomics: types, protein profiling steps etc.
 
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdfPests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
 
GBSN - Biochemistry (Unit 1)
GBSN - Biochemistry (Unit 1)GBSN - Biochemistry (Unit 1)
GBSN - Biochemistry (Unit 1)
 
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
 
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 60009654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
 
Formation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disksFormation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disks
 
Forensic Biology & Its biological significance.pdf
Forensic Biology & Its biological significance.pdfForensic Biology & Its biological significance.pdf
Forensic Biology & Its biological significance.pdf
 
FAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
FAIRSpectra - Enabling the FAIRification of Spectroscopy and SpectrometryFAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
FAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
 
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
 
Justdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts Service
Justdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts ServiceJustdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts Service
Justdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts Service
 
module for grade 9 for distance learning
module for grade 9 for distance learningmodule for grade 9 for distance learning
module for grade 9 for distance learning
 
Chemistry 4th semester series (krishna).pdf
Chemistry 4th semester series (krishna).pdfChemistry 4th semester series (krishna).pdf
Chemistry 4th semester series (krishna).pdf
 
Chemical Tests; flame test, positive and negative ions test Edexcel Internati...
Chemical Tests; flame test, positive and negative ions test Edexcel Internati...Chemical Tests; flame test, positive and negative ions test Edexcel Internati...
Chemical Tests; flame test, positive and negative ions test Edexcel Internati...
 
Vip profile Call Girls In Lonavala 9748763073 For Genuine Sex Service At Just...
Vip profile Call Girls In Lonavala 9748763073 For Genuine Sex Service At Just...Vip profile Call Girls In Lonavala 9748763073 For Genuine Sex Service At Just...
Vip profile Call Girls In Lonavala 9748763073 For Genuine Sex Service At Just...
 
Botany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdfBotany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdf
 
CELL -Structural and Functional unit of life.pdf
CELL -Structural and Functional unit of life.pdfCELL -Structural and Functional unit of life.pdf
CELL -Structural and Functional unit of life.pdf
 

Magic Literals in Pharo