Archive

Posts Tagged ‘readability’

Information content of expressions

December 11th, 2009 Derek-Jones No comments

Software developers read source code to obtain information. How might the information content of source code be quantified?

Both of the following functions assign the same value to x and if that is the only information a reader of that code is interested in, then the information content of both assignment statements could be said to be the same.

int foo(void)
{
x = 5;
...
}
 
int bar(void)
{
x = 2 + 3;
...

A reader seeking deeper understanding of the above code would ask why the value 5 is built from two values in bar. One reason might be that the author of the function wanted to explicitly call out background information about how the value 5 was derived (this is often done using symbolic names, but the use of literals themselves is sometimes encountered). Perhaps the author of foo did not see the need to expose this information or perhaps the shared value is purely coincidental.

If the two representations denote the same quantity doesn’t the second have a greater information content for a reader seeking deeper understanding?

In the following example:

... x + y & z ...
 
...
 
... num_red + num_white & lower_bits ...

an experienced developer with a knowledge of English is likely to interpret the expression as adding the number of occurrences of two quantities and using bit-wise AND to extract the lower bits. For some readers the second expression has a higher information content. Would use of the names number_of_red further increase the information content?

In the following example the first expression has not added any information that was not already present in the first expression above (except perhaps that the author was not certain of the precedence or perhaps did not expect subsequent readers to be certain).

... ( x + y ) & z ...
 
...
 
... x + ( y & z ) ...

The second expression uses parenthesis to achieve an operand/operator binding that is different from the default. Has this changed the information content of the expression?

There is experimental evidence that developers extract information from the names of variables to help them make decisions about operator precedence. To me the name all_32_bits_one suggests a sequence of bits and I would expect such a representation to be associated with the bit-wise AND operator, not binary plus. With no knowledge of the relative precedence of the two operators in the following expression the name of the middle operand would cause me to misinterpret the code. Does this change the information content of the expression? Does knowledge of the experimental evidence and the correct operator precedence change the information content (i.e., there is a potential fault in the code because the author may have assumed the incorrect precedence)?

... num_red + all_32_bits_one & sign_bit ...

There is experimental evidence that people use the amount of whitespace appearing between operands and their operators to visually highlight operator precedence

The relative quantities of whitespace used in the following two expressions appear to tell very different stories. Do the two expressions have a different information content?

... x  +  y & z ...
 
...
 
... x + y  &  z ...

The idea of measuring the information content of source code is very enticing. However, an accurate measure requires knowledge of the kind of information a reader is trying to obtain and of information that already exists in their brain.

Another question is the easy with which information can be extracted from code. Something that might be labeled as readability, except that readability has connotations of there being an abundant supply of information to extract.

Readability, an experimental view

January 20th, 2009 Derek-Jones No comments

Readability is an attribute that source code is often claimed to have, but what is it? While people are happy to use the term they have great difficulty in defining exactly what it is (I will eventually get around discussing my own own views in post). Ray Buse took a very simply approach to answering this question, he asked lots of people (to be exact 120 students) to rate short snippets of code and analysed the results. Like all good researchers he made his data available to others. This posting discusses my thoughts on the expected results and some analysis of the results.

The subjects were first, second, third year undergraduates and postgraduates. I would not expect first year students to know anything and for their results to be essentially random. Over the years, as they gain more experience, I would expect individual views on what constitutes readability to stabilize. The input from friends, teachers, books and web pages might be expected to create some degree of agreement between different students’ view of what constitutes readability. I’m not saying that this common view is correct or bears any relationship to views held by other groups of people, only that there might be some degree of convergence within a group of people studying together.

Readability is not something that students can be expected to have explicitly studied (I’m assuming that it plays an insignificant part in any course marks), so their knowledge of it is implicit. Some students will enjoy writing code and spends lots of time doing it while (many) others will not.

Separating out the data by year the results for first year students look like a normal distribution with a slight bulge on one side (created using plot(density(1_to_5_rating_data)) in R).

First year

year by year this bulge turns (second year):

Second year

into a hillock (final year):

Final year

It is tempting to interpret these results as the majority of students assigning an essentially random rating, with a slight positive bias, for the readability of each snippet, with a growing number of more experienced students assigning less than average rating to some snippets.

Do the student’s view converge to a common opinion on readability? The answers appears to be No. An analysis of the final year data using Fleiss’s Kappa shows that there is virtually no agreement between students ratings. In fact every Interrater Reliability and Agreement function I tried said the same thing. Some cluster analysis might enable me to locate students holding similar views.

In an email exchange with Ray Buse I learned that the postgraduate students had a relatively wide range of computing expertise, so I did not analyse their results.

I wish I had thought of this approach to measuring readability. Its simplicity makes it amenable for use in a wide range of experimental situations. The one change I would make is that I would explicitly create the snippets to have certain properties, rather than randomly extracting them from existing source.

FireStats icon Powered by FireStatsdiscount propecia online

buy propecia where

best propecia prices

levitra mail order

levitra viagra online

buy cialis online uk

levitra presciptions online

discount levitra online us

cialis alternative

cheap discount levitra

generic viagra from china

buy pfizer viagra online

cheapest propecia uk

buy cheap generic propecia

generic cialis soft tabs

best levitra prices

cialis cost

original brand cialis

buy online propecia

buy cialis once daily

canadian pharmacy

buy propecia in the uk

buy cialis online canada

buy levitra now

buy viagra in canada

levitra prices

dosage levitra

online pharmacy propecia sale

5 mg original brand cialis

online ordering propecia

cialis philippines

cialis 5 mg italia

brand viagra over the net

best viagra

buy cialis usa

cialis 30 mg

lowest cost levitra

levitra next day delivery

levitra vs viagra

cheapest prices on propecia

canadian pharmacy viagra

cheap cialis soft

levitra in india

bestellen levitra online

online viagra levitra cialis

5 mg cialis

buy viagra

buy viagra germany canadian meds

cialis usa

cialis no prescription

levitra discount

index

cheap levitra online

canadian healthcare pharmacy

best prices for propecia

cialis dose

cialis for women

cialis price in canada

canadian pharmacy viagra legal

buying cialis online

cialis alternative

buy cialis in usa

buying online propecia

cialis soft tablets

female viagra

lowest price on non generic levitra

cialis online without prescription

buy discount viagra

buy propecia and proscar

one day delivery cialis

buying cialis soft tabs 100 mg

cialis 5 mg

buy propecia uk

canadian women viagra

chip cialis

generic cialis next day shipping

cheap propecia online

overnight canadian viagra

brand name cialis overnight

cialis generic

cialis dose

buy branded viagra

generic prescriptions propecia

online generic cialis 100 mg

canadian healthcare

cialis vs levitra

cialis from mexico

cialis daily dosing cost

buy cheap generic levitra

lowest price propecia

buy propecia now

online pharmacy propecia

buy cialis on line

buy cialis professional

canada online pharmacy propecia

cialis online

discount propecia propecia

levitra vardenafil

buy now online propecia

buy viagra pills

buying viagra with no prescription

canada cheap propecia

online levitra

buy cialis on line

cheapest price propecia cheap

cialis dosage

canadian drug viagra soft

best price generic propecia

levitra mg

cheap propecia order online

canadian cialis

get viagra fast

ordering propecia online

how much to buy viagra in pounds

canadian healthcare cialis

cheap cialis fast delivery time

levitra online no prescription

buy prescription propecia

generic cialis next day delivery

cialis in canada

generic viagra

cheapest propecia online

cheapest prices on viagra

levitra vs cialis

levitra cheap

buy cialis without a prescription

canadian healthcare

buying propecia online

does generic cialis work

levitra 20mg

canadian healthcare viagra sales

buy levitra in europe

buy cheap propecia

cialis soft tabs

cialis generic 100 mg

cheapest prices for viagra

index

cialis discounts

generic propecia finasteride

ordering cialis gel

buy levitra low price

canada viagra

canadian viagra 50mg

buy viagra online canada

buy cialis in canada

cialis discounts

buy cialis online uk

levitra in canada

best price cialis

buy cialis professional

cialis daily in canada

cialis on line pricing in canada

how to get cialis no prescription

buy propecia and proscar

best deal for propecia

canadian healthcare cialis

brand name cialis

buy fast propecia

cialis canadian cost

buy cialis online without prescription

buy cialis cannada

cheapest prices on propecia

5 mg cialis canada

cialis daily

cialis quick shipment

buying generic propecia

cialis generic 100 mg

best price levitra

buy cheap online propecia

cialis germany

buy propecia in canada

cheap levitra without prescription

buying online propecia

buy generic viagra india rx

low cost levitra

cialis buy overnight

cialis canada illegal buy

buying viagra in canada

canadian healthcare viagra

buy canada levitra

cialis headaches

cialis by women

how much to buy viagra in pounds

cheap viagra online

cialis women

cialis arterial fibrillation

buy cialis online

levitra viagra cialis

levitra canadian

buy cialis online uk

brand viagra professional

buy pfizer viagra in canada

cialis brand

buy online prescription propecia

how much does cialis cost

cialis and ketoconazole

best propecia prices

levitra canada prescription

cialis dosage mg

cialis cost

ordering viagra overnight delivery

combine cialis and levitra

cialis cheap us pharmacy

canadian viagra generic

buy xenical propecia

daily cialis

fda levitra

buy propecia international pharmacy

canada meds viagra

how to get cialis

buy propecia canada

cialis brand only

cialis overnight

cost of cialis

buy propecia no prescription

how much is viagra

levitra lowest price

buy generic levitra

buy cialis on line

canadian generic viagra online

5mg propecia

cialis fast

cialis quick shipment

cialis 100 mg

discount levitra rx

buy propecia online prescription

cialis online without prescription

cialis price 100 mg

canada viagra pharmacies scam

order usa viagra online

cialis india

getting cialis from canada

buy propecia online cheap pharmacy

indian cialis canada

herbal viagra

cialis dosage

cialis brand name

cialis daily canada

about cialis

cialis angioplasty

non pescription cialis

cheapest propecia in uk

best price propecia

cialis professional 20 mg

cialis price in canada

generic viagra in canada

mail online order propecia

can i order viagra from the chemist

canadian viagra india

buying generic cialis mexico rx