SlideShare a Scribd company logo
L l o y d M o o r e , P r e s i d e n t
L l o y d @ C y b e r D a t a - R o b o t i c s . c o m
w w w . C y b e r D a t a - R o b o t i c s . c o m
Toward Less Magical
Magic Numbers
In the “dark times” we represented
constants like this:
double x = 2.718;
We eventually started calling this a “magic
number”, as it is just a number that has to
be correct for the program to work.
In time it was determined this was bad
and we added more information:
// The natural log of 1, e
const double e = 2.718281;
This is better, but for many applications it still
isn’t good enough.
Information is still missing:
 Where did this number come from?
 Why this particular precision?
 Is there a traceability requirement to the
specifications?
Even when not formally required, having more
information makes the number less magical:
// The natural log of 1, e
// Source: https://en.wikipedia.org/wiki/Natural_logarithm
// 12 decimal places required for algorithm foo()
// per requirement ABC-33920.
const double e = 2.718281828459;
But what if it is just a number that
someone made up?:
// Developer discretion
const double x = 2.718;
Then say so with some type of flag.
This will let the reader know the number
doesn’t have any particular significance!
Real World Implications:
This presentation is a result of a real world issue
from an aerospace project.
A constant had two different levels of precision
between the flight software and the IV&V
software, resulting in a failed verification.
It took minutes to find the difference and a
month to sort out value which was needed!
Questions?

More Related Content

PDF
Grounded Pointers
PPTX
ODS Data Sleuth: Tracking Down Calculated Fields in Banner
PPTX
Cpp Homework Help
PDF
26 Jo P Feb 09
DOCX
Problem 7PurposeBreak apart a complicated system.ConstantsC7C13.docx
PPS
Computers and Algorithms - What can they do and what can they not?
PDF
17 Jo P May 08
DOCX
Assignment 2 (1) (1).docx
Grounded Pointers
ODS Data Sleuth: Tracking Down Calculated Fields in Banner
Cpp Homework Help
26 Jo P Feb 09
Problem 7PurposeBreak apart a complicated system.ConstantsC7C13.docx
Computers and Algorithms - What can they do and what can they not?
17 Jo P May 08
Assignment 2 (1) (1).docx

Similar to Less Magical Numbers - A coding standard proposal (20)

PDF
Vision Algorithmics
PDF
Microcontroladores: Programación en C para microcontroladores con AVR Butterf...
DOCX
GSP 215 RANK Education Counseling -- gsp215rank.com
PDF
Networked Mathematics: NLP tools for Better Science
PDF
Scaling Rails with Ruby-prof -- Ruby Conf Kenya 2017 by Ben Hughes
DOCX
GSP 215 RANK Education Your Life--gsp215rank.com
DOCX
GSP 215 RANK Lessons in Excellence-- gsp215rank.com
DOCX
GSP 215 RANK Inspiring Innovation--gsp215rank.com
PDF
Analyzing the Blender project with PVS-Studio
PDF
I just had to check ICQ project
DOC
micro proj4.V2odt
PDF
detailed experience
PDF
The DevOps Pay Raise: Quantifying Your Value to Move Up the Ladder
PDF
Concept_of_NAN_IND_INF_DEN_Using_C++
DOC
Gsp 215 Exceptional Education / snaptutorial.com
PDF
13 Jo P Jan 08
PDF
Accord.Net: Looking for a Bug that Could Help Machines Conquer Humankind
PDF
ICSE2013
PDF
Measure camp 2021_my_journey_learning_machine_learning_the_good_the_bad_and_t...
PDF
GSP 215 RANK Education Counseling--gsp215rank.com
Vision Algorithmics
Microcontroladores: Programación en C para microcontroladores con AVR Butterf...
GSP 215 RANK Education Counseling -- gsp215rank.com
Networked Mathematics: NLP tools for Better Science
Scaling Rails with Ruby-prof -- Ruby Conf Kenya 2017 by Ben Hughes
GSP 215 RANK Education Your Life--gsp215rank.com
GSP 215 RANK Lessons in Excellence-- gsp215rank.com
GSP 215 RANK Inspiring Innovation--gsp215rank.com
Analyzing the Blender project with PVS-Studio
I just had to check ICQ project
micro proj4.V2odt
detailed experience
The DevOps Pay Raise: Quantifying Your Value to Move Up the Ladder
Concept_of_NAN_IND_INF_DEN_Using_C++
Gsp 215 Exceptional Education / snaptutorial.com
13 Jo P Jan 08
Accord.Net: Looking for a Bug that Could Help Machines Conquer Humankind
ICSE2013
Measure camp 2021_my_journey_learning_machine_learning_the_good_the_bad_and_t...
GSP 215 RANK Education Counseling--gsp215rank.com
Ad

More from LloydMoore (15)

PPTX
Free / Open Source C++ Static Analysis Tools
PPTX
Chosing The Right Language for your project
PDF
Cuda Without a Phd - A practical guick start
PPTX
Debugging Intermittent Issues - A How To
PPTX
Successful Software Projects - What you need to consider
PPTX
A Slice Of Rust - A quick look at the Rust programming language
PPTX
What Have We Lost - A look at some historical techniques
PPTX
Raspberry pi robotics
PPTX
High Reliabilty Systems
PPTX
Real Time Debugging - What to do when a breakpoint just won't do
PPT
PSoC USB HID
PPT
Using PSoC Creator
PPT
Using the Cypress PSoC Processor
PPT
C for Microcontrollers
PPTX
Starting Raspberry Pi
Free / Open Source C++ Static Analysis Tools
Chosing The Right Language for your project
Cuda Without a Phd - A practical guick start
Debugging Intermittent Issues - A How To
Successful Software Projects - What you need to consider
A Slice Of Rust - A quick look at the Rust programming language
What Have We Lost - A look at some historical techniques
Raspberry pi robotics
High Reliabilty Systems
Real Time Debugging - What to do when a breakpoint just won't do
PSoC USB HID
Using PSoC Creator
Using the Cypress PSoC Processor
C for Microcontrollers
Starting Raspberry Pi
Ad

Recently uploaded (20)

PPTX
OOP with Java - Java Introduction (Basics)
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
UNIT 4 Total Quality Management .pptx
PDF
PPT on Performance Review to get promotions
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPT
Mechanical Engineering MATERIALS Selection
PDF
composite construction of structures.pdf
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPTX
web development for engineering and engineering
PPT
Project quality management in manufacturing
OOP with Java - Java Introduction (Basics)
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
UNIT 4 Total Quality Management .pptx
PPT on Performance Review to get promotions
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Mechanical Engineering MATERIALS Selection
composite construction of structures.pdf
CYBER-CRIMES AND SECURITY A guide to understanding
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Operating System & Kernel Study Guide-1 - converted.pdf
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Automation-in-Manufacturing-Chapter-Introduction.pdf
web development for engineering and engineering
Project quality management in manufacturing

Less Magical Numbers - A coding standard proposal

  • 1. L l o y d M o o r e , P r e s i d e n t L l o y d @ C y b e r D a t a - R o b o t i c s . c o m w w w . C y b e r D a t a - R o b o t i c s . c o m Toward Less Magical Magic Numbers
  • 2. In the “dark times” we represented constants like this: double x = 2.718; We eventually started calling this a “magic number”, as it is just a number that has to be correct for the program to work.
  • 3. In time it was determined this was bad and we added more information: // The natural log of 1, e const double e = 2.718281; This is better, but for many applications it still isn’t good enough. Information is still missing:  Where did this number come from?  Why this particular precision?  Is there a traceability requirement to the specifications?
  • 4. Even when not formally required, having more information makes the number less magical: // The natural log of 1, e // Source: https://en.wikipedia.org/wiki/Natural_logarithm // 12 decimal places required for algorithm foo() // per requirement ABC-33920. const double e = 2.718281828459;
  • 5. But what if it is just a number that someone made up?: // Developer discretion const double x = 2.718; Then say so with some type of flag. This will let the reader know the number doesn’t have any particular significance!
  • 6. Real World Implications: This presentation is a result of a real world issue from an aerospace project. A constant had two different levels of precision between the flight software and the IV&V software, resulting in a failed verification. It took minutes to find the difference and a month to sort out value which was needed!