Elegance in Software (1) - HaPoChapoc.org/sites/default/files/Hill_Elegance_in_Software... · 2016....

24
Elegance in Software Robin Hill <[email protected]> Elegance in Software (1) file:///Users/hill/RKH_Professional/Research/PublishPresent/HaPoP3_2016_EleganceInS... 1 of 24 7/3/16, 17:44

Transcript of Elegance in Software (1) - HaPoChapoc.org/sites/default/files/Hill_Elegance_in_Software... · 2016....

Page 1: Elegance in Software (1) - HaPoChapoc.org/sites/default/files/Hill_Elegance_in_Software... · 2016. 7. 4. · This presentation used Slidy, and the current document is simply a concatenation

Elegance in SoftwareRobin Hill <[email protected]>

Elegance in Software (1) file:///Users/hill/RKH_Professional/Research/PublishPresent/HaPoP3_2016_EleganceInS...

1 of 24 7/3/16, 17:44

Page 2: Elegance in Software (1) - HaPoChapoc.org/sites/default/files/Hill_Elegance_in_Software... · 2016. 7. 4. · This presentation used Slidy, and the current document is simply a concatenation

Elegance in SoftwareThird Conference on the History and Philosophy of ProgrammingParis, 25 June 2016Robin HillDepartment of PhilosophyUniversity of [email protected]

This presentation used Slidy, and the current document is simply aconcatenation of all slides (demarcated by blue headers) into a singleHTML page. For online slides: Presenters comments and others' remarksmade during or after the talk will be added as notes.

Elegance in Software (1) file:///Users/hill/RKH_Professional/Research/PublishPresent/HaPoP3_2016_EleganceInS...

2 of 24 7/3/16, 17:44

Page 3: Elegance in Software (1) - HaPoChapoc.org/sites/default/files/Hill_Elegance_in_Software... · 2016. 7. 4. · This presentation used Slidy, and the current document is simply a concatenation

How This Came AboutTo broaden the subject matter of the philosophy of computer science, I posedthis question in one or two seminars:

What makes a program elegant?

Elegance in Software (1) file:///Users/hill/RKH_Professional/Research/PublishPresent/HaPoP3_2016_EleganceInS...

3 of 24 7/3/16, 17:44

Page 4: Elegance in Software (1) - HaPoChapoc.org/sites/default/files/Hill_Elegance_in_Software... · 2016. 7. 4. · This presentation used Slidy, and the current document is simply a concatenation

How This Came AboutTo broaden the subject matter of the philosophy of computer science, I posedthis question in one or two seminars:

What makes a program elegant?

And then I started to ponder that question myself.Culminating in this abstract:

Elegance in software rests on not only efficiency, but otherfeatures that reflect the notion in other creative endeavors, butdiffers in emphasis on its "fit" to the task.

Elegance in Software (1) file:///Users/hill/RKH_Professional/Research/PublishPresent/HaPoP3_2016_EleganceInS...

4 of 24 7/3/16, 17:44

Page 5: Elegance in Software (1) - HaPoChapoc.org/sites/default/files/Hill_Elegance_in_Software... · 2016. 7. 4. · This presentation used Slidy, and the current document is simply a concatenation

AssumptionsWe are assuming that:

Professional computer programmers call some programs elegant.1.

Elegance in Software (1) file:///Users/hill/RKH_Professional/Research/PublishPresent/HaPoP3_2016_EleganceInS...

5 of 24 7/3/16, 17:44

Page 6: Elegance in Software (1) - HaPoChapoc.org/sites/default/files/Hill_Elegance_in_Software... · 2016. 7. 4. · This presentation used Slidy, and the current document is simply a concatenation

AssumptionsWe are assuming that:

Professional computer programmers call some programs elegant.1. Professional programmers generally agree which programs areelegant.

2.

Remark: This assumption is debatable under serious examination.

Elegance in Software (1) file:///Users/hill/RKH_Professional/Research/PublishPresent/HaPoP3_2016_EleganceInS...

6 of 24 7/3/16, 17:44

Page 7: Elegance in Software (1) - HaPoChapoc.org/sites/default/files/Hill_Elegance_in_Software... · 2016. 7. 4. · This presentation used Slidy, and the current document is simply a concatenation

AssumptionsWe are assuming that:

Professional computer programmers call some programs elegant.1. Professional programmers generally agree which programs areelegant.

2.

Professional programmers find it difficult to articulate comprehensivereasons.

3.

Elegance in Software (1) file:///Users/hill/RKH_Professional/Research/PublishPresent/HaPoP3_2016_EleganceInS...

7 of 24 7/3/16, 17:44

Page 8: Elegance in Software (1) - HaPoChapoc.org/sites/default/files/Hill_Elegance_in_Software... · 2016. 7. 4. · This presentation used Slidy, and the current document is simply a concatenation

StipulationsArtifacts are unnatural.

We consider elegance to be a property exclusively of artifacts rather thannatural objects. A study of the elegance of natural objects would be adifferent (but also interesting) endeavor.

We deal only with the qualitative measures of elegance.Formal or mathematical measures may serve a purpose, but are deferred.

Programs are not distinguished from algorithms.We will equivocate on whether the objects under study are programs oralgorithms, or abstract data types, although those distinctions areimportant.

Comment: In fact, we should defer formal or mathematical measures untilwe have a firm grip on our intuitive concept of elegance in software.

Elegance in Software (1) file:///Users/hill/RKH_Professional/Research/PublishPresent/HaPoP3_2016_EleganceInS...

8 of 24 7/3/16, 17:44

Page 9: Elegance in Software (1) - HaPoChapoc.org/sites/default/files/Hill_Elegance_in_Software... · 2016. 7. 4. · This presentation used Slidy, and the current document is simply a concatenation

The Ready AnswerOne feature of elegance, mentioned in disparate contexts, seems universal:EfficiencyAn elegant design artifact is sleek and spare in its utility. An elegant programin minimally gratuitous.

Comment: For elucidation, we will compare program and design artifactsthroughout.

Elegance in Software (1) file:///Users/hill/RKH_Professional/Research/PublishPresent/HaPoP3_2016_EleganceInS...

9 of 24 7/3/16, 17:44

Page 10: Elegance in Software (1) - HaPoChapoc.org/sites/default/files/Hill_Elegance_in_Software... · 2016. 7. 4. · This presentation used Slidy, and the current document is simply a concatenation

Example: SortingTo sort a set of numbers (no duplicates) in a given integer range, we have awell-known set of tools: Heap Sort, Bubble Sort, Merge Sort, Selection Sort,and so forth.

Input Data18, 1003, 834, 9, 50, 4672, 501, 46, 93, 201, 887, and maybe a hundred more(unique) values.We can compare these and arrange them in order relative to each other, in anindexed array.

Table 1. Intermediate Stage

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 … 45 46 47 48 19 50 51 …

9 46 1003 50 201 4672 835 887 501 18 50 …

Comment: This is how Selection Sort would proceed-- find the smallestand append.

Elegance in Software (1) file:///Users/hill/RKH_Professional/Research/PublishPresent/HaPoP3_2016_EleganceInS...

10 of 24 7/3/16, 17:44

Page 11: Elegance in Software (1) - HaPoChapoc.org/sites/default/files/Hill_Elegance_in_Software... · 2016. 7. 4. · This presentation used Slidy, and the current document is simply a concatenation

Example, continued: Bitmap SortOR we can grasp that the range of possible values can be easily set up:

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 … 45 46 47 48 19 50 51 …

… …

And that we can look at each datum once, recording its presence:

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 … 45 46 47 48 19 50 51 …

t t … t t …

Then we can generate the answer by performing a simple operation-- outputof the index of each "t."9 18 46 50 93 …

Elegance in Software (1) file:///Users/hill/RKH_Professional/Research/PublishPresent/HaPoP3_2016_EleganceInS...

11 of 24 7/3/16, 17:44

Page 12: Elegance in Software (1) - HaPoChapoc.org/sites/default/files/Hill_Elegance_in_Software... · 2016. 7. 4. · This presentation used Slidy, and the current document is simply a concatenation

Bitmap Sort is More ElegantClaim: Bitmap Sort, program or algorithm, is more elegeant.But why is this? Recall:EfficiencyBut what are other features that might distinguish program artifacts?

Elegance in Software (1) file:///Users/hill/RKH_Professional/Research/PublishPresent/HaPoP3_2016_EleganceInS...

12 of 24 7/3/16, 17:44

Page 13: Elegance in Software (1) - HaPoChapoc.org/sites/default/files/Hill_Elegance_in_Software... · 2016. 7. 4. · This presentation used Slidy, and the current document is simply a concatenation

Artifacts: DifferencesBut first, note that program and design artifacts exhibit significantdifferences.

SafetyYet programs become less elegant as they get better---“better” in terms ofverification, type conformity, error-checking, and so forth---because theyacquire more code extraneous to the core function.

OrnamentationYet artifacts of design may be praised via descriptions opposed to elegance:``fancy," ``intricate", ``ornate"

So some facets of program elegance are not shared by other artifacts, andsome features of elegance of other artifacts do not hold for programs.

Elegance in Software (1) file:///Users/hill/RKH_Professional/Research/PublishPresent/HaPoP3_2016_EleganceInS...

13 of 24 7/3/16, 17:44

Page 14: Elegance in Software (1) - HaPoChapoc.org/sites/default/files/Hill_Elegance_in_Software... · 2016. 7. 4. · This presentation used Slidy, and the current document is simply a concatenation

Aspects of EleganceSuggestions for other aspects of elegance in program artifacts:

Minimality (Efficiency)AccomplishmentModestyRevelation

Comment: These criteria were developed only by musing about it.

Elegance in Software (1) file:///Users/hill/RKH_Professional/Research/PublishPresent/HaPoP3_2016_EleganceInS...

14 of 24 7/3/16, 17:44

Page 15: Elegance in Software (1) - HaPoChapoc.org/sites/default/files/Hill_Elegance_in_Software... · 2016. 7. 4. · This presentation used Slidy, and the current document is simply a concatenation

Aspects of EleganceSuggestions for other aspects of elegance in program artifacts:

Minimality (Efficiency)AccomplishmentModestyRevelation

As we consider some characteristics of efficiency, let’s ask what would be theopposite of each.

Comment: The contrasts may help illuminate the characteristics ofelegance.

Elegance in Software (1) file:///Users/hill/RKH_Professional/Research/PublishPresent/HaPoP3_2016_EleganceInS...

15 of 24 7/3/16, 17:44

Page 16: Elegance in Software (1) - HaPoChapoc.org/sites/default/files/Hill_Elegance_in_Software... · 2016. 7. 4. · This presentation used Slidy, and the current document is simply a concatenation

Aspects of Elegance: MinimalityAn elegant artifact does not use resoures unnecessarily (efficiency), includingad hoc solutions. An elegant program is concise rather than brief, respectingits quality standards.The Salginatobel bridge by Maillart is an analog in design artifacts.

What would be the opposite in design? Cluttered

What would be the opposite in a program? CruftyPhoto from the website of Jim Wood, http://personal.strath.ac.uk/j.wood/Biomimetics/

Remark: Study of mathematical beauty must be consulted.

Elegance in Software (1) file:///Users/hill/RKH_Professional/Research/PublishPresent/HaPoP3_2016_EleganceInS...

16 of 24 7/3/16, 17:44

Page 17: Elegance in Software (1) - HaPoChapoc.org/sites/default/files/Hill_Elegance_in_Software... · 2016. 7. 4. · This presentation used Slidy, and the current document is simply a concatenation

Aspects of Elegance: AccomplishmentWe can safely say that a program that does not work, in whatever sense of"work" applies, is not elegant.

The lemon juicer of Phillippe Starck is an analog.

"Starck has imbued what was a perfectly adequate kitchen drawerfiller with aspirational desirability, indications of intellectualmeaning and a mythical lack of juicing prowess."

The Independent 2010— Michael Czerwinski of London's Design Museum

What would be the opposite in design? Flawed

What would be the opposite in a program? BuggyPhoto by Niklas Morberg - originally posted to Flickr as Juicy Salif - 78/365, CC BY-SA 2.0,

https://commons.wikimedia.org/w/index.php?curid=6042687

Elegance in Software (1) file:///Users/hill/RKH_Professional/Research/PublishPresent/HaPoP3_2016_EleganceInS...

17 of 24 7/3/16, 17:44

Page 18: Elegance in Software (1) - HaPoChapoc.org/sites/default/files/Hill_Elegance_in_Software... · 2016. 7. 4. · This presentation used Slidy, and the current document is simply a concatenation

Aspects of Elegance: ModestyProgrammers show a regrettable tendency to write terse and baffling code.In C, we can write a loop control structure like this: while(i=0;i<10;i++)

Or like this: while(i<10; i++)

Or like this: while(i++ < 10)

But this last is a virtuoso performance rather than a helpful demonstration.

Elegance is present "whenever a work of architecture… has themodesty not to draw attention to the difficulties it hassurmounted."

— Allain De Botton 2006

What would be the opposite in design? Ostentatious

What would be the opposite in a program? Showing off

Comment: This embraces Thompson's suggestion to throw code away.

Elegance in Software (1) file:///Users/hill/RKH_Professional/Research/PublishPresent/HaPoP3_2016_EleganceInS...

18 of 24 7/3/16, 17:44

Page 19: Elegance in Software (1) - HaPoChapoc.org/sites/default/files/Hill_Elegance_in_Software... · 2016. 7. 4. · This presentation used Slidy, and the current document is simply a concatenation

Aspects of Elegance: RevelationAn elegant artifact shows us something new about its nature, or rather, showsus something that we recognize as true. It exposes some aspect of the essenceof the object.Bitmap Sort: Integers are already ordinal, so can be arranged by theirpresence.Boyer-Moore String Search: Strings are just as distinct when viewed backwardas when viewed forward.What would be the opposite in design? Shallow

What would be the opposite in a program? Standard

Post-Talk Remark: Yet a proof may be admired to the degree that it showsnothing new.

Elegance in Software (1) file:///Users/hill/RKH_Professional/Research/PublishPresent/HaPoP3_2016_EleganceInS...

19 of 24 7/3/16, 17:44

Page 20: Elegance in Software (1) - HaPoChapoc.org/sites/default/files/Hill_Elegance_in_Software... · 2016. 7. 4. · This presentation used Slidy, and the current document is simply a concatenation

FitCan these be integrated into "fit"?The artifact fulfills (accomplishment and revelation) but does notoutstrip (efficiency and modesty) our hopes and expectations.The view implies strong influence of background and context, conferred bythe experience of the programmer.Both LISP and relational databases-- manifest in the derived programs-- havethe virtue of a pervasive structure or paradigm (which pose a challenge andinspire loyalty). Is that "fit"?

"We must feel that the simplicity it displays has been hard won,that it flows from the resolution of a demanding technical ornatural predicament."

— De Botton 2006

Comment: Elegance grows out of a tension between ease and difficulty.

Elegance in Software (1) file:///Users/hill/RKH_Professional/Research/PublishPresent/HaPoP3_2016_EleganceInS...

20 of 24 7/3/16, 17:44

Page 21: Elegance in Software (1) - HaPoChapoc.org/sites/default/files/Hill_Elegance_in_Software... · 2016. 7. 4. · This presentation used Slidy, and the current document is simply a concatenation

Open QuestionsCan these artifacts be elegant?

Operating systems? Does an operating system lackaccomplishment in the sense of a clean finish?

a.

Calendar systems? Does a calendar system lack the uniformdata organization necessary to efficiency?

b.

Data Structures? Does a data structure have the efficiency andaccomplishment for elegance?

c.

1.

Comment: Operating systems are built under expedience; is that alwaysopposed to elegance?

Elegance in Software (1) file:///Users/hill/RKH_Professional/Research/PublishPresent/HaPoP3_2016_EleganceInS...

21 of 24 7/3/16, 17:44

Page 22: Elegance in Software (1) - HaPoChapoc.org/sites/default/files/Hill_Elegance_in_Software... · 2016. 7. 4. · This presentation used Slidy, and the current document is simply a concatenation

Open QuestionsCan these artifacts be elegant?

Operating systems? Does an operating system lackaccomplishment in the sense of a clean finish?

a.

Calendar systems? Does a calendar system lack the uniformdata organization necessary to efficiency?

b.

Data Structures? Does a data structure have the efficiency andaccomplishment for elegance?

c.

1.

Can elegance be detected by the compiler or loader or control unit?2. Can elegance by expressed mathematically, as in KolmogorovComplexity?

3.

Comment: Can elegance in a program go "all the way down," through thecompiler and assembler, so that elegant source code does not incur an uglycost at lower levers?

Elegance in Software (1) file:///Users/hill/RKH_Professional/Research/PublishPresent/HaPoP3_2016_EleganceInS...

22 of 24 7/3/16, 17:44

Page 23: Elegance in Software (1) - HaPoChapoc.org/sites/default/files/Hill_Elegance_in_Software... · 2016. 7. 4. · This presentation used Slidy, and the current document is simply a concatenation

ConclusionA program creates tension in its recognition of a challenge, often a difficultone. A program resolves tension in its satisfaction of the challenge.Our four characteristics of elegance:

MinimalityAccomplishmentModestyRevelation

Can be captured by the (less than elegant) term "fit," calling for striving andstruggle, such as De Botton attributes to elegant architecture.

Comment: Which criteria (these or others) are aspects of the process, andwhich, of the artifact itself?

Elegance in Software (1) file:///Users/hill/RKH_Professional/Research/PublishPresent/HaPoP3_2016_EleganceInS...

23 of 24 7/3/16, 17:44

Page 24: Elegance in Software (1) - HaPoChapoc.org/sites/default/files/Hill_Elegance_in_Software... · 2016. 7. 4. · This presentation used Slidy, and the current document is simply a concatenation

DiscussionThank you for your attention. Questions?

Robin HillThe author welcomes comments at any [email protected]

Comment: Other aspects of elegance might be:Consistency-- of semantics or instruction format, for instanceResourcefulness-- using the tools at hand in novel ways

Elegance in Software (1) file:///Users/hill/RKH_Professional/Research/PublishPresent/HaPoP3_2016_EleganceInS...

24 of 24 7/3/16, 17:44