Saturday, July 07, 2012

Types and Bugs

There are certain discussions in our biz that are so played out they provoke instant boredom upon encounter. A major one is the old dynamic vs. static skirmish, recently resurfaced in a blog post by Evan Farrer. Which is a shame as the post is quite interesting, describing his results transliterating well-tested code in a dynamic language to a static language to see if the type system found any bugs. Which it did.

The full-length paper is a great read as well. He describes his translation methodology and gives some detail on each bug found. At first it may seem the author could be stacking the odds towards the static language as the translation was manually done by himself, but I found his description of the process pretty convincing of its fairness. The choice of Python as a source language probably helped given the pythonic inclination towards straightforward code that avoids sophisticated abstraction and metaprogramming mechanisms.

But the real meat of the paper is in the description of the bugs he found. Upon a not particularly discriminating reading, a clear pattern jumped out. Most of the bugs fell into one of two categories:
  • Assuming that a variable always references a valid value when it can contain a null value. 
  • Referencing constructs that no longer exist in the source.
The first category is also the largest, comprising several places where the original code could be coerced into letting a variable be set to a null value, usually by just leaving it uninitialized, and a subsequent call would attempt to derefence it assuming it contained a valid value. Haskell's type system avoids the problem as it  simply doesn't have any notion of null. Code that has to deal with optional values must do it trough algebraic data types.

How the second category of bug comes about is easy to guess from the projects histories: some method or variable was present but changed, perhaps it was renamed or subsumed, and not all references were updated to reflect the change. Even pervasive unit tests can't hope to catch these kinds of regressions, as the problem is found on the integration between units of code; the units themselves are just fine. A type system helps when the change affects the signature of the referenced construct, which is often but not always.

If the study's findings are generalizable and my observations are correct, these are the main takeaways:
  • If you have a type system at your service, it's prudent to structure code such that behavior-breaking changes are reflected on the types.
  • End-to-end integration tests are a necessary complement to both a suite of unit tests and a type system. In my experience how far should these tests stray off the happy path is a difficult engineering trade-off.
  • If your type system allows nulls — such as Java's, for instance — its role in bug prevention is greatly diminished. The proportion of null-dereference bugs on the analysed code bases helps to makes it clear just how big a mistake it is to allow nulls in a programming language. 

29 comments:

Zhou Haoyang said...

Why watch for a period of time suddenly go fast, travel time is not stable? Automatic mechanical watches with shockpro of omega replica ability, but if the impact Too large, such as vigorously waving wrist, the impact will make spring up together, to watch too fast or even shut down; more impact will let out of hublot replica watch hairspring,Damping device off, the speed of the needle dislocation, which is fatal for the speed control system. Often suffer from great impact, will make winding efficiency, even failure.What is the "luminous table"? And what is the difference between the electroluminessent table Commonly known as the "luminous table" refers to the nail on the hands or word coated with fluorescent powder, in the dark or light visible hand nail hand Table. There is also a kind of luminous watch is in the middle of 90s appeared to make the entire surface of the fluorescent light. The difference between the two is as follows: 1.luminous watch by Absorption of natural light energy, while the power of yha-travel-insurance the electric meter can be relied on the battery. 2.luminous watch the "glow" light is visible only in the dark, but as long as the electric fluorescent table The corresponding according to the system at any time can shine. 3 light emitting time luminous watch by absorption time and light intensity limit, the electric battery power limit by fluorescence.

vigneswaran said...

There are lots of information about Selenium Testing have spread around the web automate, but this is a unique one according to me.
Selenium Training in Chennai

Xiang Nan said...

When I took possession of the Rolex Submariner,a couple things jumped out at me. First, and this is always nice to find, it had its original Origina Replica Breitling Twinlock crown (Triplocks came later at around the 3M serial number). So many 1:1 Replica Rolex Watches have lost their original crowns to Triplocks along the way,In a weird twist of irony, the Omega Watches Robert-Jan wrote about from this year’s Baselworld contained a Cyclops for the first time in its history. Hermes handbags , in its self-pronounced desire to push innovation.

Ammu said...

Great post.

Thanks,
Lakshmi,
Best Angular Training Institute in Chennai

Pankaj Singh said...

Thank you much for this tutorial; this is an informative and valuable blog. Visit for
Offshore Anonymous Hosting

alex said...

I play a lot and win, what are you capable of? best online casino games with us Play, win or be defeated.

service care said...

Alot of blogs I see these days don't really provide anything that I'm interested in, but I'm most definitely interested in this one. Just thought that I would post and let you know. Nice! thank you so much! Thank you for sharing.
samsung service centres in chennai
samsung mobile service center in velachery
samsung mobile service center in porur

jaya devan said...

Really awesome blog. Your blog is really useful for me
Regards,
Best Selenium Training Institute in Chennai | Selenium Course in Chennai

luckys said...

whatsapp groups

luckys said...

1movies

luckys said...

gomovies

whatsapp plus said...

mobile whatsapp groups

whatsapp plus said...

mobile whatsapp groups

Admin said...

dtc bus app
dtc bus
dtc bus app download
dtc bus pass
dtc bus route
dtc bus route app
dtc bus app download

Admin said...

dtc bus app
dtc bus
dtc bus app download
dtc bus pass
dtc bus route
dtc bus route app
dtc bus app download

Admin said...

funny WiFi names
cool WiFi names
claver WiFi names
cool and claver WiFi names
funny WiFi names list
Good wifi names
wifi names 2020
Disney wifi names
wifi name for gamers
bollywood movies funny WiFi names

shivam said...

Flying Shift - Packers & Movers in Bhopal

easylearn said...

Hi,
Good job & thank you very much for the new information, i learned something new. Very well written. It was sooo good to read and usefull to improve knowledge. Who want to learn this information most helpful. One who wanted to learn this technology IT employees will always suggest you take python training in pune. Because python course in pune is one of the best that one can do while choosing the course.

Abhishek rajpoot said...

WhatsApp Status Video Download :WhatsApp introduced the status feature in 2015, in which we can share images, videos, and gifs as our story for 24 hours. Before this feature, WhatsApp had only text status option in which we can write our bio, but the new status feature is different. The story or status disappears after 24 hours and can’t be archived as still in WhatsApp.

Boy attitude status video download for whatsApp
Boy attitude status video download
Boy attitude status video download

Most romantic status video download for whatsApp
Sad video status download
Most Romantic status video download

video status download for whatsApp


we have latest & best collection of video status download for whatsapp

khushboo said...

The registrations and auditions for the Bigg Boss 13 are going to start soon. The official list of contestants is not yet announced by the officials. That will be announced by the makers on the inaugural day which is 15 the of September. bigg boss 13 contestants name list with photo Though a few rumored names are coming up as the expected celebrity contestants of the year. They are Nia Sharma, Raghav Juyal, Punit Pathak, Divyanka Tripathi, Garima Chaurasia, Ridhima Pandit, Aditya Narayan, Jasmin Bhasin, Zain Imam, Bhuvan Bam, Chetna Pande, Krystle D’Souza, and Devoleena Bhattacharjee. This year too, the show will be back with a new theme and the star host, Salman Khan. Though the theme is not declared yet officially. Stay tuned with us to know more about the show Bigg Boss 13.

gokul said...

Thanks for this informative blog
Top 5 Data science training in chennai
Data science training in chennai
Data science training in velachery
Data science training in OMR
Best Data science training in chennai
Data science training course content
Data science certification in chennai
Data science courses in chennai
Data science training institute in chennai
Data science online course
Data science with python training in chennai
Data science with R training in chennai

Vijiaajith said...

Very nice
freeinplanttrainingcourseforECEstudents
internship-in-chennai-for-bsc
inplant-training-for-automobile-engineering-students
freeinplanttrainingfor-ECEstudents-in-chennai
internship-for-cse-students-in-bsnl
application-for-industrial-training

Vijiaajith said...

nice
interview-

questions/aptitude/permutation-and-

combination/how-many-groups-of-6-persons-can-be-

formed


tutorials/oracle/or

acle-delete


technology/chrom

e-flags-complete-guide-enhance-browsing-

experience/


interview-

questions/aptitude/time-and-work/a-alone-can-do-1-

4-of-the-work-in-2-days


interview-

questions/programming/recursion-and-

iteration/integer-a-40-b-35-c-20-d-10-comment-about-

the-output-of-the-following-two-statements


Admin said...

WhatsApp group links

MIUI theme

Admin said...

Dr Driving is one of the my favourite game ever and today I am going to share Dr Driving Mod Apk
https://www.drdrivingmodapk.xyz/

Nicolay said...

Nice article

Bulletproof Domain Registration

Vijiaajith said...

how to hack flipkart payment
react native developer resume
group selector css
chemistry interview questions
sample complaint letter to bank for wrong transaction

Vijiaajith said...

javascript int max value
passage writing in fiserv
vijay invested rs.50,000 partly at 10% and partly at 15%. his total income after a year was rs.7000. how much did he invest at the rate of 10%?
residue on ignition
the simple interest earned on a certain amount is double the money

mary Brown said...

Great Article. Thank you for sharing! Really an awesome post for every one.
Project Centers in Chennai

JavaScript Training in Chennai

Final Year Project Domains for IT

JavaScript Training in Chennai