A place to cache linked articles (think custom and personal wayback machine)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.html 67KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167
  1. <!doctype html><!-- This is a valid HTML5 document. -->
  2. <!-- Screen readers, SEO, extensions and so on. -->
  3. <html lang=fr>
  4. <!-- Has to be within the first 1024 bytes, hence before the <title>
  5. See: https://www.w3.org/TR/2012/CR-html5-20121217/document-metadata.html#charset -->
  6. <meta charset=utf-8>
  7. <!-- Why no `X-UA-Compatible` meta: https://stackoverflow.com/a/6771584 -->
  8. <!-- The viewport meta is quite crowded and we are responsible for that.
  9. See: https://codepen.io/tigt/post/meta-viewport-for-2015 -->
  10. <meta name=viewport content="width=device-width,minimum-scale=1,initial-scale=1,shrink-to-fit=no">
  11. <!-- Required to make a valid HTML5 document. -->
  12. <title>Interfaces - The Most Important Software Engineering Concept (archive) — David Larlet</title>
  13. <!-- Generated from https://realfavicongenerator.net/ such a mess. -->
  14. <link rel="apple-touch-icon" sizes="180x180" href="/static/david/icons/apple-touch-icon.png">
  15. <link rel="icon" type="image/png" sizes="32x32" href="/static/david/icons/favicon-32x32.png">
  16. <link rel="icon" type="image/png" sizes="16x16" href="/static/david/icons/favicon-16x16.png">
  17. <link rel="manifest" href="/manifest.json">
  18. <link rel="mask-icon" href="/static/david/icons/safari-pinned-tab.svg" color="#5bbad5">
  19. <link rel="shortcut icon" href="/static/david/icons/favicon.ico">
  20. <meta name="apple-mobile-web-app-title" content="David Larlet">
  21. <meta name="application-name" content="David Larlet">
  22. <meta name="msapplication-TileColor" content="#da532c">
  23. <meta name="msapplication-config" content="/static/david/icons/browserconfig.xml">
  24. <meta name="theme-color" content="#f0f0ea">
  25. <!-- That good ol' feed, subscribe :p. -->
  26. <link rel=alternate type="application/atom+xml" title=Feed href="/david/log/">
  27. <meta name="robots" content="noindex, nofollow">
  28. <meta content="origin-when-cross-origin" name="referrer">
  29. <!-- Canonical URL for SEO purposes -->
  30. <link rel="canonical" href="http://blog.robertelder.org/interfaces-most-important-software-engineering-concept/">
  31. <style>
  32. /* http://meyerweb.com/eric/tools/css/reset/ */
  33. html, body, div, span,
  34. h1, h2, h3, h4, h5, h6, p, blockquote, pre,
  35. a, abbr, address, big, cite, code,
  36. del, dfn, em, img, ins,
  37. small, strike, strong, tt, var,
  38. dl, dt, dd, ol, ul, li,
  39. fieldset, form, label, legend,
  40. table, caption, tbody, tfoot, thead, tr, th, td,
  41. article, aside, canvas, details, embed,
  42. figure, figcaption, footer, header, hgroup,
  43. menu, nav, output, ruby, section, summary,
  44. time, mark, audio, video {
  45. margin: 0;
  46. padding: 0;
  47. border: 0;
  48. font-size: 100%;
  49. font: inherit;
  50. vertical-align: baseline;
  51. }
  52. /* HTML5 display-role reset for older browsers */
  53. article, aside, details, figcaption, figure,
  54. footer, header, hgroup, menu, nav, section { display: block; }
  55. body { line-height: 1; }
  56. blockquote, q { quotes: none; }
  57. blockquote:before, blockquote:after,
  58. q:before, q:after {
  59. content: '';
  60. content: none;
  61. }
  62. table {
  63. border-collapse: collapse;
  64. border-spacing: 0;
  65. }
  66. /* http://practicaltypography.com/equity.html */
  67. /* https://calendar.perfplanet.com/2016/no-font-face-bulletproof-syntax/ */
  68. /* https://www.filamentgroup.com/lab/js-web-fonts.html */
  69. @font-face {
  70. font-family: 'EquityTextB';
  71. src: url('/static/david/css/fonts/Equity-Text-B-Regular-webfont.woff2') format('woff2'),
  72. url('/static/david/css/fonts/Equity-Text-B-Regular-webfont.woff') format('woff');
  73. font-weight: 300;
  74. font-style: normal;
  75. font-display: swap;
  76. }
  77. @font-face {
  78. font-family: 'EquityTextB';
  79. src: url('/static/david/css/fonts/Equity-Text-B-Italic-webfont.woff2') format('woff2'),
  80. url('/static/david/css/fonts/Equity-Text-B-Italic-webfont.woff') format('woff');
  81. font-weight: 300;
  82. font-style: italic;
  83. font-display: swap;
  84. }
  85. @font-face {
  86. font-family: 'EquityTextB';
  87. src: url('/static/david/css/fonts/Equity-Text-B-Bold-webfont.woff2') format('woff2'),
  88. url('/static/david/css/fonts/Equity-Text-B-Bold-webfont.woff') format('woff');
  89. font-weight: 700;
  90. font-style: normal;
  91. font-display: swap;
  92. }
  93. @font-face {
  94. font-family: 'ConcourseT3';
  95. src: url('/static/david/css/fonts/concourse_t3_regular-webfont-20190806.woff2') format('woff2'),
  96. url('/static/david/css/fonts/concourse_t3_regular-webfont-20190806.woff') format('woff');
  97. font-weight: 300;
  98. font-style: normal;
  99. font-display: swap;
  100. }
  101. /* http://practice.typekit.com/lesson/caring-about-opentype-features/ */
  102. body {
  103. /* http://www.cssfontstack.com/ Palatino 99% Win 86% Mac */
  104. font-family: "EquityTextB", Palatino, serif;
  105. background-color: #f0f0ea;
  106. color: #07486c;
  107. font-kerning: normal;
  108. -moz-osx-font-smoothing: grayscale;
  109. -webkit-font-smoothing: subpixel-antialiased;
  110. text-rendering: optimizeLegibility;
  111. font-variant-ligatures: common-ligatures contextual;
  112. font-feature-settings: "kern", "liga", "clig", "calt";
  113. }
  114. pre, code, kbd, samp, var, tt {
  115. font-family: 'TriplicateT4c', monospace;
  116. }
  117. em {
  118. font-style: italic;
  119. color: #323a45;
  120. }
  121. strong {
  122. font-weight: bold;
  123. color: black;
  124. }
  125. nav {
  126. background-color: #323a45;
  127. color: #f0f0ea;
  128. display: flex;
  129. justify-content: space-around;
  130. padding: 1rem .5rem;
  131. }
  132. nav:last-child {
  133. border-bottom: 1vh solid #2d7474;
  134. }
  135. nav a {
  136. color: #f0f0ea;
  137. }
  138. nav abbr {
  139. border-bottom: 1px dotted white;
  140. }
  141. h1 {
  142. border-top: 1vh solid #2d7474;
  143. border-bottom: .2vh dotted #2d7474;
  144. background-color: #e3e1e1;
  145. color: #323a45;
  146. text-align: center;
  147. padding: 5rem 0 4rem 0;
  148. width: 100%;
  149. font-family: 'ConcourseT3';
  150. display: flex;
  151. flex-direction: column;
  152. }
  153. h1.single {
  154. padding-bottom: 10rem;
  155. }
  156. h1 span {
  157. position: absolute;
  158. top: 1vh;
  159. left: 20%;
  160. line-height: 0;
  161. }
  162. h1 span a {
  163. line-height: 1.7;
  164. padding: 1rem 1.2rem .6rem 1.2rem;
  165. border-radius: 0 0 6% 6%;
  166. background: #2d7474;
  167. font-size: 1.3rem;
  168. color: white;
  169. text-decoration: none;
  170. }
  171. h2 {
  172. margin: 4rem 0 1rem;
  173. border-top: .2vh solid #2d7474;
  174. padding-top: 1vh;
  175. }
  176. h3 {
  177. text-align: center;
  178. margin: 3rem 0 .75em;
  179. }
  180. hr {
  181. height: .4rem;
  182. width: .4rem;
  183. border-radius: .4rem;
  184. background: #07486c;
  185. margin: 2.5rem auto;
  186. }
  187. time {
  188. display: bloc;
  189. margin-left: 0 !important;
  190. }
  191. ul, ol {
  192. margin: 2rem;
  193. }
  194. ul {
  195. list-style-type: square;
  196. }
  197. a {
  198. text-decoration-skip-ink: auto;
  199. text-decoration-thickness: 0.05em;
  200. text-underline-offset: 0.09em;
  201. }
  202. article {
  203. max-width: 50rem;
  204. display: flex;
  205. flex-direction: column;
  206. margin: 2rem auto;
  207. }
  208. article.single {
  209. border-top: .2vh dotted #2d7474;
  210. margin: -6rem auto 1rem auto;
  211. background: #f0f0ea;
  212. padding: 2rem;
  213. }
  214. article p:last-child {
  215. margin-bottom: 1rem;
  216. }
  217. p {
  218. padding: 0 .5rem;
  219. margin-left: 3rem;
  220. }
  221. p + p,
  222. figure + p {
  223. margin-top: 2rem;
  224. }
  225. blockquote {
  226. background-color: #e3e1e1;
  227. border-left: .5vw solid #2d7474;
  228. display: flex;
  229. flex-direction: column;
  230. align-items: center;
  231. padding: 1rem;
  232. margin: 1.5rem;
  233. }
  234. blockquote cite {
  235. font-style: italic;
  236. }
  237. blockquote p {
  238. margin-left: 0;
  239. }
  240. figure {
  241. border-top: .2vh solid #2d7474;
  242. background-color: #e3e1e1;
  243. text-align: center;
  244. padding: 1.5rem 0;
  245. margin: 1rem 0 0;
  246. font-size: 1.5rem;
  247. width: 100%;
  248. }
  249. figure img {
  250. max-width: 250px;
  251. max-height: 250px;
  252. border: .5vw solid #323a45;
  253. padding: 1px;
  254. }
  255. figcaption {
  256. padding: 1rem;
  257. line-height: 1.4;
  258. }
  259. aside {
  260. display: flex;
  261. flex-direction: column;
  262. background-color: #e3e1e1;
  263. padding: 1rem 0;
  264. border-bottom: .2vh solid #07486c;
  265. }
  266. aside p {
  267. max-width: 50rem;
  268. margin: 0 auto;
  269. }
  270. /* https://fvsch.com/code/css-locks/ */
  271. p, li, pre, code, kbd, samp, var, tt, time, details, figcaption {
  272. font-size: 1rem;
  273. line-height: calc( 1.5em + 0.2 * 1rem );
  274. }
  275. h1 {
  276. font-size: 1.9rem;
  277. line-height: calc( 1.2em + 0.2 * 1rem );
  278. }
  279. h2 {
  280. font-size: 1.6rem;
  281. line-height: calc( 1.3em + 0.2 * 1rem );
  282. }
  283. h3 {
  284. font-size: 1.35rem;
  285. line-height: calc( 1.4em + 0.2 * 1rem );
  286. }
  287. @media (min-width: 20em) {
  288. /* The (100vw - 20rem) / (50 - 20) part
  289. resolves to 0-1rem, depending on the
  290. viewport width (between 20em and 50em). */
  291. p, li, pre, code, kbd, samp, var, tt, time, details, figcaption {
  292. font-size: calc( 1rem + .6 * (100vw - 20rem) / (50 - 20) );
  293. line-height: calc( 1.5em + 0.2 * (100vw - 50rem) / (20 - 50) );
  294. margin-left: 0;
  295. }
  296. h1 {
  297. font-size: calc( 1.9rem + 1.5 * (100vw - 20rem) / (50 - 20) );
  298. line-height: calc( 1.2em + 0.2 * (100vw - 50rem) / (20 - 50) );
  299. }
  300. h2 {
  301. font-size: calc( 1.5rem + 1.5 * (100vw - 20rem) / (50 - 20) );
  302. line-height: calc( 1.3em + 0.2 * (100vw - 50rem) / (20 - 50) );
  303. }
  304. h3 {
  305. font-size: calc( 1.35rem + 1.5 * (100vw - 20rem) / (50 - 20) );
  306. line-height: calc( 1.4em + 0.2 * (100vw - 50rem) / (20 - 50) );
  307. }
  308. }
  309. @media (min-width: 50em) {
  310. /* The right part of the addition *must* be a
  311. rem value. In this example we *could* change
  312. the whole declaration to font-size:2.5rem,
  313. but if our baseline value was not expressed
  314. in rem we would have to use calc. */
  315. p, li, pre, code, kbd, samp, var, tt, time, details, figcaption {
  316. font-size: calc( 1rem + .6 * 1rem );
  317. line-height: 1.5em;
  318. }
  319. p, li, pre, details {
  320. margin-left: 3rem;
  321. }
  322. h1 {
  323. font-size: calc( 1.9rem + 1.5 * 1rem );
  324. line-height: 1.2em;
  325. }
  326. h2 {
  327. font-size: calc( 1.5rem + 1.5 * 1rem );
  328. line-height: 1.3em;
  329. }
  330. h3 {
  331. font-size: calc( 1.35rem + 1.5 * 1rem );
  332. line-height: 1.4em;
  333. }
  334. figure img {
  335. max-width: 500px;
  336. max-height: 500px;
  337. }
  338. }
  339. figure.unsquared {
  340. margin-bottom: 1.5rem;
  341. }
  342. figure.unsquared img {
  343. height: inherit;
  344. }
  345. @media print {
  346. body { font-size: 100%; }
  347. a:after { content: " (" attr(href) ")"; }
  348. a, a:link, a:visited, a:after {
  349. text-decoration: underline;
  350. text-shadow: none !important;
  351. background-image: none !important;
  352. background: white;
  353. color: black;
  354. }
  355. abbr[title] { border-bottom: 0; }
  356. abbr[title]:after { content: " (" attr(title) ")"; }
  357. img { page-break-inside: avoid; }
  358. @page { margin: 2cm .5cm; }
  359. h1, h2, h3 { page-break-after: avoid; }
  360. p3 { orphans: 3; widows: 3; }
  361. img {
  362. max-width: 250px !important;
  363. max-height: 250px !important;
  364. }
  365. nav, aside { display: none; }
  366. }
  367. ul.with_columns {
  368. column-count: 1;
  369. }
  370. @media (min-width: 20em) {
  371. ul.with_columns {
  372. column-count: 2;
  373. }
  374. }
  375. @media (min-width: 50em) {
  376. ul.with_columns {
  377. column-count: 3;
  378. }
  379. }
  380. ul.with_two_columns {
  381. column-count: 1;
  382. }
  383. @media (min-width: 20em) {
  384. ul.with_two_columns {
  385. column-count: 1;
  386. }
  387. }
  388. @media (min-width: 50em) {
  389. ul.with_two_columns {
  390. column-count: 2;
  391. }
  392. }
  393. .gallery {
  394. display: flex;
  395. flex-wrap: wrap;
  396. justify-content: space-around;
  397. }
  398. .gallery figure img {
  399. margin-left: 1rem;
  400. margin-right: 1rem;
  401. }
  402. .gallery figure figcaption {
  403. font-family: 'ConcourseT3'
  404. }
  405. footer {
  406. font-family: 'ConcourseT3';
  407. display: flex;
  408. flex-direction: column;
  409. border-top: 3px solid white;
  410. padding: 4rem 0;
  411. background-color: #07486c;
  412. color: white;
  413. }
  414. footer > * {
  415. max-width: 50rem;
  416. margin: 0 auto;
  417. }
  418. footer a {
  419. color: #f1c40f;
  420. }
  421. footer .avatar {
  422. width: 200px;
  423. height: 200px;
  424. border-radius: 50%;
  425. float: left;
  426. -webkit-shape-outside: circle();
  427. shape-outside: circle();
  428. margin-right: 2rem;
  429. padding: 2px 5px 5px 2px;
  430. background: white;
  431. border-left: 1px solid #f1c40f;
  432. border-top: 1px solid #f1c40f;
  433. border-right: 5px solid #f1c40f;
  434. border-bottom: 5px solid #f1c40f;
  435. }
  436. </style>
  437. <h1>
  438. <span><a id="jumper" href="#jumpto" title="Un peu perdu ?">?</a></span>
  439. Interfaces - The Most Important Software Engineering Concept (archive)
  440. <time>Pour la pérennité des contenus liés. Non-indexé, retrait sur simple email.</time>
  441. </h1>
  442. <section>
  443. <article>
  444. <h3><a href="http://blog.robertelder.org/interfaces-most-important-software-engineering-concept/">Source originale du contenu</a></h3>
  445. <h1>Synopsis</h1>
  446. <p>     An interface can be thought of as a contract between the system and the environment.  In a computer program, the 'system' is the function or module in question, and the 'environment' is the rest of the project.  The interface formally describes what can pass between the system and the environment.  An 'implementation' can be defined as the system minus the interface.  Interfaces in languages like Haskell can be extremely specific, or very non-specific like in Python.  The types of interfaces used can affect the amount of technical debt that is created (a mathematical formula is provided), and programmer productivity.  A method for quantifying and comparing interfaces is proposed.  Based on these comparisons, you can make a number of observations about the way a language or tool is used.</p>
  447. <p>     Read the comment thread on <a href="https://news.ycombinator.com/item?id=11180030">Hacker News</a>.</p>
  448. <h1>Overview</h1>
  449. <p>     The most important concept in software engineering is the concept of an <strong>interface</strong>.  This article is not about interfaces in <em>Java</em>, it is about interfaces in software design, and to a lesser extent, interfaces <em>anywhere in the universe</em>.  There are many other important concepts used in software development, but I would argue that many of them actually end up relating back to why interfaces are so important.  In this article, I will discuss:</p>
  450. <h1 id="what-is-an-interface">What is an Interface?</h1>
  451. <p>     In university we learned of a couple succinct definitions for what an interface is that I really like:</p>
  452. <p class="obvious">An interface is <strong>a contract between the system and the environment.</strong></p>
  453. <p>     or alternatively</p>
  454. <p class="obvious">An interface is <strong>the intersection between the system and the environment.</strong></p>
  455. <p>
  456. <span>Interface = System ∩ Environment</span>
  457. </p>
  458. <p><img src="https://s3.amazonaws.com/re-software-images/interface-intersection.gif" alt="Interface: Intersection between system and environment"/></p>
  459. <p>     The intersection definition fits well when the 'system' is actually a physical object.  The above definitions are very abstract, so let's go directly to a specific example of someone typing on a keyboard:</p>
  460. <table>
  461. <tr>
  462. <td>
  463. <img src="https://s3.amazonaws.com/re-software-images/hands.jpg" alt="Hands typing on keyboard."/>
  464. </td>
  465. <td>
  466. <img src="https://s3.amazonaws.com/re-software-images/example-interface.jpg" alt="Hands typing on keyboard overlayed with interface."/>
  467. </td>
  468. </tr>
  469. </table>
  470. <p>     In the above example, the system represents the laptop computer as a whole, the environment is the person's hands (and any nearby cats that like to step on keyboards).  The interface, therefore, must any part of the interaction between the hands and the computer that is not exclusively attributable to one or the other, but can only be attributed to both.  Normally we think of hands and keyboards as being distinctly separate, so the precise boundary of the interface in this case is up for philosophical debate.  It is up to the reader to decide whether they consider the entire keyboard, or just the individual atoms that come in contact with the fingers or keyboard to be part of the interface.  You might be wondering how this example can relate to the definition of an interface as a contract: The "contract" in this case is the convention that we all spent much effort learning back when we had to program our brains with all the muscle memory to know where all the keys are.  There are also more subtle aspects to the contract, like the fact that pressing a key and holding it down has a different meaning than pressing it quickly and releasing.</p>
  471. <p>     This is a nice bit of philosophy, but what does it have to do with writing software?  Well, interfaces in programming are all around us, even if you're not aware of it.  If you're a Java programmer you explicitly name them for what they are, but they also exist in other languages like C.  Let's consider the interface of the function 'add_numbers' in the following example:</p>
  472. <pre>
  473. <code class="c">
  474. unsigned int add_numbers(unsigned int, unsigned int);
  475. void other_function(void){
  476. add_numbers(3,4);
  477. }
  478. unsigned int add_numbers(unsigned int a, unsigned int b){
  479. return a + b;
  480. }
  481. int main(void){
  482. add_numbers(9,99);
  483. return 0;
  484. }
  485. </code>
  486. </pre>
  487. <p>     Let's apply the same highlighting technique to describe the environment, the 'add_numbers' system, and the interface:</p>
  488. <p>     In the above illustrations, the 'system' in question consists of the 'add_numbers' function.  You would be correct to say that the main method, or the 'other_function' method could also be considered an individual system, however for simplicity the images above have considered the 'add_numbers' function as a system in isolation.  It would also be reasonable to consider the invocations of the 'add_numbers' function to be part of the interface too.  Note that we've added a fourth idea: an 'Implementation'.  It is difficult to discuss interfaces without making reference to implementations, so let's go ahead and try to formally define what an implementation is:</p>
  489. <p class="obvious">An implementation is <strong>the system minus the interface</strong>:</p>
  490. <p>
  491. <span>Implementation = System ∖ Interface</span>
  492. <br/>
  493. <span>Implementation = System ∖ (System ∩ Environment)</span>
  494. </p>
  495. <p><img src="https://s3.amazonaws.com/re-software-images/implementation-intersection.gif" alt="Implementation"/></p>
  496. <p>     Please note that I've never actually heard of (or don't remember) anyone else defining an implementation this way, but it seems like such an irresistible extension of the set based definition of an interface and it has a couple other benefits I'll discuss shortly.  If you're a poor student studying for an exam, your professor will probably have never heard of this definition.  I also wouldn't be surprised if this definition was in conflict with some Object Oriented Programming taxonomy, but even it does, I don't plan to change it.  Let those crazy OOP people change their textbooks to match my definition.</p>
  497. <p>     Defining implementations this way leads us to other reasonable conclusions: When we talk about interfaces on physical systems, we typically think of the 'system implementation' as the entire physical object, and it would be unnatural to consider the 'real' system implementation to exclude the buttons, screens or any other physical part.  This pushes us to consider the interface to include as little as possible of the physical system, and represent more of a convention.  It is almost as if an interface were just a set of promises, guarantees, or some kind of ... <strong>CONTRACT BETWEEN THE SYSTEM AND THE ENVIRONMENT!</strong></p>
  498. <h1 id="interface-as-contract">An Interface as a Contract</h1>
  499. <p>     Let's consider the interface to the function 'add_numbers' in the previous example as a contract, and see what it guarantees:</p>
  500. <ul>
  501. <li>'add_numbers' is a function that exists.</li>
  502. <li>'add_numbers' takes exactly two parameters, both of which are 'unsigned int's.</li>
  503. <li>'add_numbers' returns exactly one 'unsigned int'.</li>
  504. </ul>
  505. <p>     The interface for this function does not say anything about
  506. <br/>
  507. </p>
  508. <ul>
  509. <li>Whether 'add_numbers' will ever halt.</li>
  510. <li>The asymptotic run-time complexity of 'add_numbers'.</li>
  511. <li>The quantity of free memory required to run 'add_numbers'.</li>
  512. <li>What the implementation of 'unsigned int' really is.</li>
  513. <li>Side effects (like allocating memory, and modifying global variables)</li>
  514. </ul>
  515. <p>     The interface to 'add_numbers' described above is known as a function 'prototype', and in earlier versions of K&amp;R C, there was a weaker form of describing interfaces:</p>
  516. <pre>
  517. <code class="c">
  518. unsigned int add_numbers();
  519. </code>
  520. </pre>
  521. <p>     Defining an interface as a "contract" is very convenient for programming since most programming tasks simply amount to defining and requiring sets of axioms. Post-conditions, and pre-conditions are all guarantees about certain properties or behaviour.  Before two parties engage in doing business together, they ought to have a contract prepared.  The contract spells out what the deliverables are, how much money is paid, and when.  Other topics like early termination, indemnification, expenses are all lain out in advance.  When the contract is breached, a court or an arbitrator can resolve the situation, but if you forget to define something in the contract, then unexpected surprises are more likely.  In a computer program we have the same thing: Modules and functions specify what they want, and (sometimes) what they will return.  A breach of this contract will result in a compile error, a run-time error, program fault, build system or linter failure or even your manager yelling at you.  I would go so far as to say that the concept of defining an interface as a "contract" is not even metaphorical.  It really is the same concept as a business contract, even thought a business contract is typically not as detailed.</p>
  522. <h1 id="patents-and-copyright">Patents, Copyright and Interfaces</h1>
  523. <p>     This section does not consist of legal advice and may even be in contradiction with existing law, all statements herein are the opinions of the author.</p>
  524. <p>     In the previous section, I stated that I would consider an interface to <em>literally</em> be a 'business contract' between two entities, and I emphasized that I don't consider this to be a metaphor.  I believe this interpretation is one that appeals to the concerns of both computer scientists and also to legal professionals who aim to protect creative works.</p>
  525. <p>     Should an interface be patentable?  Using the definition included in this article, that an interface is a contract between the system and the environment, I do not believe that interfaces should be patentable, and so far the existing case law seems to agree with me.  Keep in mind, however, that the word 'interface' is very generic, and is often used in a way that is different than how I have defined it in this article.  </p>
  526. <p>     Should an interface be copyrightable?  Using the definition included in this article, that an interface is a contract between the system and the environment, I do believe that the "Source Code" of an interface should be copyrightable.  Furthermore, the copyrightable aspects of an interface should extend no further than the point just before they begin to cover the aspects of an interface that make interfaces so special.   The copyright should cover only the medium (source code or handwritten copy), but not the guarantees or constraints.  If any guarantees or constraints of the interface become inseparable from any part of the medium, then those parts of the medium should be disqualified from copyrightability.  I'll propose a simple test that could be applied to determine if something is <strong>not</strong> copyrightable:</p>
  527. <p class="obvious">If you consider a set of attributes of an interface that you'd like to consider copyrightable, given any conceivable third-party piece of software that successfully uses the interface in question in any way, it should always be possible to build some drop-in replacement that declares and implements the same interface and is successfully used by the third-party software without any modification to the third-party software, and without infringing any copyrights.  If every possible drop-in replacement would cause infringement or require that the third-party software be modified or regress in functionality, then the chosen set of copyrightable attributes are too aggressive must be reduced.</p>
  528. <p>     I believe the above test would be appropriate to test for patentability as well.  Note that this test would only determine if something is <strong>not</strong> copyrightable or patentable.  It would say nothing about conclusively determining whether it <em>is</em> copyrightable or patentable.  Finally, the above test is just my opinion, don't confuse it with actual law.</p>
  529. <p>     An important thing to point out in relation to the above test, is that any criteria that could be considered part of the interface in one language, may not be part of the interface in another language.  For example, in Java the order in which functions are declared does not affect program execution.  If you were tempted to casually say 'the order of functions in the file never matters', then you would be incorrect if you consider the following python program:</p>
  530. <pre>
  531. <code class="python">
  532. def foo():
  533. print("asdf")
  534. def foo(abc):
  535. print(abc)
  536. foo("lol")
  537. </code>
  538. </pre>
  539. <p>     Giving consideration to the legal aspects of interfaces prompted me to go back and take a look at the famous <a href="http://www.potomaclaw.com/oracle-v-google-copyrightability-apis/">Oracle Vs. Google</a> case.  The provided link includes details of the case that would be interesting to software developers, so that's what I'll draw on for my analysis.  In summary, based on what I see, I can't find a reason to disagree with the outcome in favour of Oracle.  That's not to say that I support it, since the publicly available case details that I can find are fairly sparse.</p>
  540. <p>     I think the concern among most software developers was that the outcome of the case might set a precedent that would allow copyright or patents to cover parts of interfaces that would cause the above test I proposed to fail.</p>
  541. <p>     The outcome of the case rested on the district court's finding that 'the "structure, sequence and organization" of an API was copyrightable.'  As I mentioned above, I don't think there is a problem with this, as long as the definition of "structure, sequence and organization" does not cause the above test to fail.  Here are a few quotes from the linked article that are key:</p>
  542. <p>     "The district court concluded that 'there is only one way to write' the declarations to interface with Java. If true, the use of identical declarations would not be copyrightable. However, except for three of the API packages, Google did not dispute the fact that it could have written its own API packages to access the Java language." and finally "Google conceded that it copied the declarations verbatim."</p>
  543. <p>     It would seem that the district court made the right decision in concluding that the intrinsically unique properties of an interface are not copyrightable, but Google also admitted to copying declarations 'verbatim'.  If 'verbatim' can be take to include literal copy and pasting, that includes non-functional aspects like white space, and spelling mistakes in comments, then I think it would be very reasonable to consider this as copyright infringement.  The non-copyrightability of an interface does not need to prevent an individual artistic expression of an interface from being copyrighted.</p>
  544. <p>     My knowledge of this case only comes from what I can read online, but it would appear to me that Google created verbatim copies of Java source code which happened to include interfaces.  Google themselves appears to have been been of the opinion that their use of Java required licensing, because prior to 2010 Google pursued licensing deals with Sun to license the use of Java.  After Sun was acquired by Oracle, the licensing negotiations fell through.  The fact that Google was pursuing licensing deals that didn't come to fruition, but continued using 'verbatim' copies of code doesn't seem to help their case.  I suspect that Google's lawyers may have known they had a weak case, and so they attempted to use a defense related to the very legitimate claim that interfaces should not be copyrighted, and hoped that the source code representation of an interface, and the more philosophical concept would become conflated, allowing them to win the case.</p>
  545. <h1 id="what-is-module-or-abstraction">What is a 'Module' or 'Abstraction'?</h1>
  546. <p>     When I think about a 'Module' this is what I picture in my mind:</p>
  547. <p><img src="https://s3.amazonaws.com/re-software-images/shape-sorter.jpg" alt="Module"/></p>
  548. <p>     The reason I think this representation applies so well is because it clearly emphasizes the importance of the boundary of the module, and how it interfaces with the rest of its environment.  Furthermore, the interface of the cube above imposes very strong constraints about how the external world can interact with what is inside.  You can't go around the interface, so if you want to interact with it, you must do so through the means it exposes to you.  Finally, there is nothing in the cube, but we actually don't care, because it's not what's on the inside that counts (sorry cube), it's the interface that is exposed to the world.</p>
  549. <p>     Another example I really like is that of a cell and its membrane:  Features on the cell surface like transport and receptor proteins only permit certain things in the extra-cellular matrix to influence what happens inside the cytoplasm according to very specific rules:</p>
  550. <p><img src="https://s3.amazonaws.com/re-software-images/cell-membrane.gif" alt="Cell Membrane"/></p>
  551. <p>     In the context of this article, I will refer to 'modules' and 'abstractions' as if they were the same concept.  The dictionary definition of these words is certainly not the same, and even between programming languages these concepts have different meanings.  The key properties I'm interested in are that both of them can be though of as a 'system' as we've been using the term in this article: Abstractions and modules can be thought of as something consisting of an interface, and an implementation.  You could think of an individual function in C as a module, a 'module' in Python, a class or package in Java.  Anything that has some kind of externally presented interface, and some 'hidden' implementation.  Note that the 'hiddenness' of the implementation can be imposed by the rules of the language, or even just by convention of the programmer.</p>
  552. <h1 id="what-is-abstraction-leak">Abstraction Leaks</h1>
  553. <p>     As far as I can tell, the idea of an abstraction leak can be traced back to <a href="http://www.joelonsoftware.com/articles/LeakyAbstractions.html">an essay by Joel Spolsky</a>.  There are a few good examples of specific abstraction leaks in the essay, but I'd like to add one of my own: The concept of a 'map' is very common in programming, and represents a data structure consisting of key and value pairs.  An important constraint that the map guarantees is that all map keys must be unique: Trying to write a new value to a given key either results in an error, or overwriting the previous value for that key.  The result is never to have duplicate keys.  An extremely common programer requirement is to want to iterate over all the keys of the map.  Since ordering of keys is not necessarily a guarantee maps provide, you might wonder what order the keys will be in when you iterate over them?  Well, the ordering is not defined, because the map interface does not provide any guarantee of ordering.  Therefore, any ordering is considered acceptable, but in practice the keys are likely to be sorted in some way.  Why would they be sorted?  Well, sorting happens to be an efficient way of organizing the data.  It can make things like checking for pre-existing keys easier.</p>
  554. <p>     Iterating over sorted data can produce very different results than iterating over random data.  For example, if you're trying to find the minimum number in a list:</p>
  555. <pre>
  556. <code class="c">
  557. min = null;
  558. list = map.getMapKeys();
  559. for (item in list){
  560. if ( min == null ){
  561. min = item
  562. }else if (item &lt; min){
  563. min = min; /* This line has a bug */
  564. }
  565. }
  566. </code>
  567. </pre>
  568. <p>     The 'else if' branch will never execute if your data is sorted in ascending order, and even if you do randomised input testing, your program will never uncover the problem with this line.  This is a huge problem, because if you swap the map implementation out for another one that doesn't return sorted keys, then your code is suddenly going to start running the buggy code path.  At this point, you've complete forgotten about this code, and it is hidden inside a huge monolithic project.</p>
  569. <p>     I'm going to propose my own definition of an <strong>abstraction leak</strong> for use later in this article:</p>
  570. <p class="obvious">An abstraction leak exists when it is possible for an implementation to affect the environment in a way that was not agreed upon in the interface.</p>
  571. <p>     Using this definition, it would seem that nearly <em>every</em> abstraction is leaky, because specifying every environmental effect in the interface is only practical in the most rigorous mathematical systems.  For physical systems, you could probably also make a connection to <a href="https://en.wikipedia.org/wiki/G%C3%B6del%27s_incompleteness_theorems">Gödel's incompleteness theorems</a> here.  The idea that most abstractions are leaky is not unfounded since that is essentially what Joel Spolsky implies with his 'The Law of Leaky Abstractions':</p>
  572. <p class="obvious">"All non-trivial abstractions, to some degree, are leaky."</p>
  573. <p>     Well if every abstraction is leaky why bother talking about it?  Problems only occur when a part of the environment begins to rely on one of these unspecified environmental effects that originated from the system in question.  These are the problematic abstraction leaks that everybody talks about.</p>
  574. <p>     This has far-reaching consequences, not only for casual bugs but also in the security domain.  There is one well-known phrase related to the security of physical systems, where unintended effects from the system leak into the environment in a way that compromises its security: A <a href="https://en.wikipedia.org/wiki/Side-channel_attack">Side-channel attack</a>.  Combining this with the claim that all abstractions are leaky would give the following conclusion:</p>
  575. <p class="obvious">Every physical implementation of a cryptosystem is vulnerable to a side-channel attack.</p>
  576. <p>     Given what we've discussed above, it is not unreasonable to extend this idea to include not only physical implementations, but also emulated ones as well.</p>
  577. <h1 id="quantifying-and-comparing">Quantifying and Comparing Interfaces</h1>
  578. <p>     As we saw above, interfaces in C specify things like the return type, and the number of parameters that can be passed into a function.  But what do interfaces in Python specify?  Note that I'm using the term 'interface' in a way that is consistent with this article, which is likely more general than any literature you've read before on 'interfaces' in Python.</p>
  579. <pre>
  580. <code class="python">
  581. def add_numbers(a,b):
  582. return a + b
  583. print(add_numbers(3,1))
  584. print(add_numbers("abc","def"))
  585. </code>
  586. </pre>
  587. <p>     In Python you don't have to specify the types on the interface to a function.  This has the benefit of making the function easier to define and invoke because there is less information to specify, and the disadvantage of less constraints that can be checked ahead of time (to detect possible programming errors).</p>
  588. <p>     I think there is something to be said about comparing and quantifying the different characteristics of an interface in terms of how many ways you can send information through them.  This could be done for a specific interface, but also from the perspective of all interfaces that can be specified in a given programming language.  It may also be useful for comparing the safety of specific interfaces within the same language.  For the 'add_numbers' example in C, let's consider how much information we can send both through, and around the interface through abstraction leaks:</p>
  589. <table class="characteristic-compare">
  590. <tr>
  591. <td class="compare-side" valign="top">
  592. <h2 class="compare-header">Information Through C Interface</h2>
  593. <table class="characteristic-description">
  594. <tr>
  595. <th><h3>Characteristic Description</h3></th>
  596. <th><h3>Number of Possible States</h3></th>
  597. </tr>
  598. <tr>
  599. <td>Parameter 1 Type</td>
  600. <td>1 (unsigned int)</td>
  601. </tr>
  602. <tr>
  603. <td>Parameter 2 Type</td>
  604. <td>1 (unsigned int)</td>
  605. </tr>
  606. <tr>
  607. <td>Return Value Type</td>
  608. <td>1 (unsigned int)</td>
  609. </tr>
  610. <tr>
  611. <td>Parameter 1 Value</td>
  612. <td>2^(# bits in 'unsigned int')</td>
  613. </tr>
  614. <tr>
  615. <td>Parameter 2 Value</td>
  616. <td>2^(# bits in 'unsigned int')</td>
  617. </tr>
  618. <tr>
  619. <td>Return Value</td>
  620. <td>2^(# bits in 'unsigned int')</td>
  621. </tr>
  622. </table>
  623. </td>
  624. <td class="compare-side" valign="top">
  625. <h2 class="compare-header">Information Around C Interface</h2>
  626. <table class="characteristic-description">
  627. <tr>
  628. <th><h3>Characteristic Description</h3></th>
  629. <th><h3>Number of Possible States</h3></th>
  630. </tr>
  631. <tr>
  632. <td>Global Variable States</td>
  633. <td>(# global variables) * (# global variable states)</td>
  634. </tr>
  635. <tr>
  636. <td>Filesystem</td>
  637. <td># filesystem states</td>
  638. </tr>
  639. <tr>
  640. <td>CPU Time Taken</td>
  641. <td>Unbounded</td>
  642. </tr>
  643. <tr>
  644. <td>Heap State</td>
  645. <td># heap states</td>
  646. </tr>
  647. <tr>
  648. <td>Many Others...</td>
  649. <td>...</td>
  650. </tr>
  651. </table>
  652. </td>
  653. </tr>
  654. </table>
  655. <p>     And these are the number of things that can be communicated through the python interface to 'add_numbers'</p>
  656. <table class="characteristic-compare">
  657. <tr>
  658. <td class="compare-side" valign="top">
  659. <h2 class="compare-header">Information Through Python Interface</h2>
  660. <table class="characteristic-description">
  661. <tr>
  662. <th><h3>Characteristic Description</h3></th>
  663. <th><h3>Number of Possible States</h3></th>
  664. </tr>
  665. <tr>
  666. <td>Parameter 1 Type</td>
  667. <td>practically infinite</td>
  668. </tr>
  669. <tr>
  670. <td>Parameter 2 Type</td>
  671. <td>practically infinite</td>
  672. </tr>
  673. <tr>
  674. <td>Return Value Type</td>
  675. <td>practically infinite</td>
  676. </tr>
  677. <tr>
  678. <td>Parameter 1 Value</td>
  679. <td>practically infinite</td>
  680. </tr>
  681. <tr>
  682. <td>Parameter 2 Value</td>
  683. <td>practically infinite</td>
  684. </tr>
  685. <tr>
  686. <td>Return Value</td>
  687. <td>practically infinite</td>
  688. </tr>
  689. </table>
  690. </td>
  691. <td class="compare-side" valign="top">
  692. <h2 class="compare-header">Information Around Python Interface</h2>
  693. <table class="characteristic-description">
  694. <tr>
  695. <th><h3>Characteristic Description</h3></th>
  696. <th><h3>Number of Possible States</h3></th>
  697. </tr>
  698. <tr>
  699. <td>Global Variable States</td>
  700. <td>(# global variables) * (# global variable states)</td>
  701. </tr>
  702. <tr>
  703. <td>Filesystem</td>
  704. <td># filesystem states</td>
  705. </tr>
  706. <tr>
  707. <td>CPU Time Taken</td>
  708. <td>Unbounded</td>
  709. </tr>
  710. <tr>
  711. <td>Heap State</td>
  712. <td># heap states</td>
  713. </tr>
  714. <tr>
  715. <td>Many Others...</td>
  716. <td>...</td>
  717. </tr>
  718. </table>
  719. </td>
  720. </tr>
  721. </table>
  722. <p>     Now if you take a look at the types of interfaces we can describe in Haskell (Thanks to <a href="https://github.com/hudon">James Hudon</a> for reviewing this, since I barely know any Haskell):</p>
  723. <pre>
  724. <code class="python">
  725. add_numbers :: Int &gt; Int -&gt; Int
  726. add_numbers 3 4 = 7
  727. main = print (add_numbers 3 4)
  728. </code>
  729. </pre>
  730. <p>     With the above Haskell code, the interface 'add_numbers' can accept the following information:</p>
  731. <table class="characteristic-compare">
  732. <tr>
  733. <td class="compare-side" valign="top">
  734. <h2 class="compare-header">Information Through Haskell Interface</h2>
  735. <table class="characteristic-description">
  736. <tr>
  737. <th><h3>Characteristic Description</h3></th>
  738. <th><h3>Number of Possible States</h3></th>
  739. </tr>
  740. <tr>
  741. <td>Parameter 1 Type</td>
  742. <td>1 (Int)</td>
  743. </tr>
  744. <tr>
  745. <td>Parameter 2 Type</td>
  746. <td>1 (Int)</td>
  747. </tr>
  748. <tr>
  749. <td>Return Value Type</td>
  750. <td>1 (Int)</td>
  751. </tr>
  752. <tr>
  753. <td>Parameter 1 Value</td>
  754. <td>1 (the value 3)</td>
  755. </tr>
  756. <tr>
  757. <td>Parameter 2 Value</td>
  758. <td>1 (the value 4)</td>
  759. </tr>
  760. <tr>
  761. <td>Return Value</td>
  762. <td>at least 2^30[<a href="https://en.wikibooks.org/wiki/Haskell/A_Miscellany_of_Types">1</a>]</td>
  763. </tr>
  764. </table>
  765. </td>
  766. <td class="compare-side" valign="top">
  767. <h2 class="compare-header">Information Around Haskell Interface</h2>
  768. <table class="characteristic-description">
  769. <tr>
  770. <th><h3>Characteristic Description</h3></th>
  771. <th><h3>Number of Possible States</h3></th>
  772. </tr>
  773. <tr>
  774. <td>CPU Time Taken</td>
  775. <td>Unbounded</td>
  776. </tr>
  777. <tr>
  778. <td>CPU/Memory Cache effects</td>
  779. <td>Unbounded</td>
  780. </tr>
  781. <tr>
  782. <td>Possibly Others...</td>
  783. <td>...</td>
  784. </tr>
  785. </table>
  786. </td>
  787. </tr>
  788. </table>
  789. <p>     For a specific interface in a given language, you can quantify a couple different things:</p>
  790. <ul>
  791. <li>The number of unique ways you can communicate information through the interface</li>
  792. <li>The number of unique ways you can communicate information around the interface through abstraction leaks</li>
  793. </ul>
  794. <p>     From the perspective of programming languages you can also make observations about</p>
  795. <ul>
  796. <li>How restrictive the language lets you be about how much or how little information goes through an interface</li>
  797. <li>What tools the language provides you with for preventing communication around the interface.</li>
  798. </ul>
  799. <p>     If you extend the same type of analysis to other interfaces, like for example graphical user interface where you can change directories:</p>
  800. <p><img src="https://s3.amazonaws.com/re-software-images/folders.jpg" alt="Interface: Intersection between system and environment"/></p>
  801. <table class="characteristic-compare">
  802. <tr>
  803. <td class="compare-side" valign="top">
  804. <h2 class="compare-header">Information Through GUI</h2>
  805. <table class="characteristic-description">
  806. <tr>
  807. <th><h3>Characteristic Description</h3></th>
  808. <th><h3>Number of Possible States</h3></th>
  809. </tr>
  810. <tr>
  811. <td>Click On Folder 1</td>
  812. <td># of pixels Folder 1 takes on screen * number of clicks</td>
  813. </tr>
  814. <tr>
  815. <td>Click On Folder 2</td>
  816. <td># of pixels Folder 2 takes on screen * number of clicks</td>
  817. </tr>
  818. <tr>
  819. <td>Hover On Folder 1</td>
  820. <td># of pixels Folder 1 takes on screen</td>
  821. </tr>
  822. <tr>
  823. <td>Hover On Folder 2</td>
  824. <td># of pixels Folder 2 takes on screen</td>
  825. </tr>
  826. <tr>
  827. <td>Time between hover/click events</td>
  828. <td>Infinite</td>
  829. </tr>
  830. <tr>
  831. <td>Common Keyboard events</td>
  832. <td># common key combinations</td>
  833. </tr>
  834. <tr>
  835. <td>GUI Screen Area</td>
  836. <td># Pixels used for GUI display</td>
  837. </tr>
  838. </table>
  839. </td>
  840. <td class="compare-side" valign="top">
  841. <h2 class="compare-header">Information Around GUI</h2>
  842. <table class="characteristic-description">
  843. <tr>
  844. <th><h3>Characteristic Description</h3></th>
  845. <th><h3>Number of Possible States</h3></th>
  846. </tr>
  847. <tr>
  848. <td>Hidden UI features</td>
  849. <td>Unlimited</td>
  850. </tr>
  851. <tr>
  852. <td>Non-standard keyboard shortcuts</td>
  853. <td># of pixels Button 2 takes on screen</td>
  854. </tr>
  855. <tr>
  856. <td>Other unexpected UI features</td>
  857. <td>...</td>
  858. </tr>
  859. </table>
  860. </td>
  861. </tr>
  862. </table>
  863. <p>     And if you review the same task of changing directories performed on the command line using 'cd':</p>
  864. <table class="characteristic-compare">
  865. <tr>
  866. <td class="compare-side" valign="top">
  867. <h2 class="compare-header">Information Through GUI</h2>
  868. <table class="characteristic-description">
  869. <tr>
  870. <th><h3>Characteristic Description</h3></th>
  871. <th><h3>Number of Possible States</h3></th>
  872. </tr>
  873. <tr>
  874. <td>Number of possible directories typed</td>
  875. <td>Unlimited</td>
  876. </tr>
  877. </table>
  878. </td>
  879. <td class="compare-side" valign="top">
  880. <h2 class="compare-header">Information Around GUI</h2>
  881. <table class="characteristic-description">
  882. <tr>
  883. <th><h3>Characteristic Description</h3></th>
  884. <th><h3>Number of Possible States</h3></th>
  885. </tr>
  886. <tr>
  887. <td>Environment Variables</td>
  888. <td>Unlimited</td>
  889. </tr>
  890. </table>
  891. </td>
  892. </tr>
  893. </table>
  894. <p>     For the information sent through GUIs and the command line, there is actually another piece of data that I didn't include in the above tables:  The amount of noise in the signal.  If you consider how hard it is to exactly repeat a sequence of keyboard strokes (key by key) versus a sequence of mouse movements (pixel by pixel), you'll note that there is always way more error in the data you get from a mouse movement or click versus a keyboard stroke.  GUIs compensate for this by making the semantics they accept more non-specific.  Can you imagine if the clickable area on "OK" and "Cancel" buttons was only 1 pixel wide?  In addition, this analysis can get even more complex when you consider how the error rates change for differently abled individuals.</p>
  895. <p>     Now that I've reviewed one possible way to quantifying and comparing interfaces, I'll make a few extrapolations from these examples and my own personal experience:</p>
  896. <ul>
  897. <li>Human beings tend to prefer interfaces that aren't very specific about the information they accept, especially when they are unfamiliar with that interface</li>
  898. <li>Interfaces that aren't very specific about what information they accept are prone to being misused.</li>
  899. <li>Catch-all interfaces that accept large amounts of information are seen as powerful, but are often misused.</li>
  900. <li>Humans tend to communicate information around an interface when communication becomes tedious.</li>
  901. <li>Communicating around an interface through abstraction leaks is very prone to undesirable surprises.</li>
  902. </ul>
  903. <h1 id="leaky-and-specific-interfaces">Leaky and Specific Interfaces</h1>
  904. <p>     I'm going to make a lot of observations based on the analysis in the previous section, so I'll define a couple terms for the sake of clarity:</p>
  905. <p class="obvious">A <strong>Leaky</strong> interface exists when the interface is prone to being ignored during any communication between the system and the environment.</p>
  906. <p class="obvious">An interface is <strong>Specific</strong> if is has a relatively small number of possible inputs and outputs.</p>
  907. <p>     For more details on <strong>Leaky</strong> interfaces, consult the section on <a href="#what-is-abstraction-leak">abstraction leaks</a>.  A good example of what I mean by a <strong>Specific</strong> interface would be piecewise defined functions, defined only for a very small number of inputs.</p>
  908. <p>     If you can meaningfully quantify how 'leaky', or 'specific' interfaces are, I think it is worth defining a spectrum where interfaces that are very specific and non-leaky are on one end, and non-specific and leaky interfaces are on the other:</p>
  909. <p><img src="https://s3.amazonaws.com/re-software-images/interface-spectrum.gif" alt="Interface Spectrum"/></p>
  910. <p>     There are probably reasonable arguments to move any of the items in the spectrum above either more to the right, or the left, but you get the idea.  Note that you could probably split this up into two spectrums:  One for how much the interfaces allow for 'leaky' abstractions, and one for how specific the interfaces are, although in general these two concepts seem to be correlated.  Another correlation that I would propose based on my experience is that 'errors' that come from tools on the "Non User Friendly" end of this spectrum are less frequent, and when they do happen, they are more likely to be caused by failures in <a href="https://en.wikipedia.org/wiki/Software_verification_and_validation">validation</a>.  For the "User Friendly" end of the spectrum, errors are more frequent, and more likely to be <a href="https://en.wikipedia.org/wiki/Software_verification_and_validation">verification</a> errors.</p>
  911. <h1 id="complexity-of-technical-debt">The Asymptotic Complexity of Technical Debt</h1>
  912. <p>     I'm going to start this section with a claim:</p>
  913. <p class="obvious">The majority of technical debt in a project originates from an inappropriate reliance on abstraction leaks, or a reliance on extremely non-specific interface contracts that have difficult to foresee consequences.</p>
  914. <p>     When a project starts there are only one or two modules, and the amount of work you need to do to specify a good interface contract is O(1). If you design a bad interface, the amount of technical debt you will create is O(1) too, so there is not much payoff to taking the time to get the interface contract right.  But as the number of modules increases linearly, the worst-case number of inter-module communications increases according to O(N^2).  Therefore, if you make bad interface contracts, the worse case number of invocations to these bad interface contracts will scale according to N^2 (if every module talks to every other module.).</p>
  915. <p><img src="https://s3.amazonaws.com/re-software-images/technical-debt.gif" alt="Technical Debt"/></p>
  916. <p>     In the above graph, you can see that it is initially less work to avoid creating well-defined interfaces, however, this advantage is quickly overtaken because of the fact that inter-module communication problems will occur at a rate that is polynomial in the number of modules, whereas the work required to create good interface specifications is linear in the number of modules.  The polynomial cost comes from considering the handshake problem where in a worst case, every module communicates with every other module.  Obviously, the average project will have communication requirements that scale at a rate of less than O(n^2), but it will definitely be more than O(n).  There is also another factor that deceivingly shifts the rapid increase off into the future:  The human memory.  When you first start out, even if you have 20 modules, you can probably keep in your head what all of them do, so vague function names and esoteric conventions are all the contracts that you need.  Once the project gets large enough that you forget these, or you bring in someone else, the polynomial cost always dominates.</p>
  917. <h1 id="why-still-command-line">Why do People Still Use the Command Line?</h1>
  918. <p>     When you ask this question, people generally give a few different answers, none of which are what I consider to be the most important:</p>
  919. <ul>
  920. <li>It is very powerful and flexible.</li>
  921. <li>The command line uses less resources.</li>
  922. <li>Using the command line gives you more understanding about how things work under the hood.</li>
  923. </ul>
  924. <p>     The most important reason why we still use the command line is <strong>AUTOMATION</strong>!  It is difficult to overestimate the productivity gain you get by automating tasks.  If I need to launch a cluster of 100 servers, are you going to log into each server and manually install your software stack by clicking on a bunch of GUIs?  Even if you want to automate the task of clicking on the GUIs, you'd need some kind of file storage that remembers how and where to click on things.  Some sort of file full of flexible... commands.</p>
  925. <p>     Another general relationship I'll make with the <a href="#quantifying-and-comparing">section on quantifying and comparing interfaces</a>, is that even though we could automate things through automated clicks and screen grabbers, this type of communication is designed for humans, and thus it exposes a very non-specific interface that does not allow you to be very precise.  The result is that your automatic clicker is very likely to get stuck on a screen because a window moved when it didn't expect it to, or perhaps a colour or font changed.  There are too many variables with a GUI.  With the command line, everything is much more precise, and you communicate everything through a very narrow unforgiving interface, which is why many humans don't like it but other computer programs do.</p>
  926. <p>     There are of course, situations where the imprecise communication of a GUI is a virtue.  For example, when doing graphic art work you generally don't care about specifying every individual pixel shade and colour, but you do want <em>something</em> to be specified for every pixel.  In this situation the noise from any motions of your hand as you move the cursor actually become meaningful informational content for the final product.</p>
  927. <h1 id="choosing-a-language">Choosing the Right Language</h1>
  928. <p>     If you read the section on <a href="#complexity-of-technical-debt">the asymptotic complexity of technical debt</a> you might come away with the impression that you should always start a project in a language with very specific interface contracts, like Haskell or Java.  That is not at all the message I want to convey.  If you're making a decision about what language to use for a particular project, I think this question is likely to help:</p>
  929. <p class="obvious">How likely is it that the requirements for the project will change?</p>
  930. <p>     If you're starting a business, the answer is almost certainly going to be 'very likely', especially if you're building a small product from scratch and you're still establishing product market fit.  If you already know exactly what the requirements are, for example, if you're building a compiler, or something based on an international standard, then you'd probably answer 'not very likely'.</p>
  931. <p>     If you answered 'very likely' to this question, then you would probably want to go with a language that doesn't cause you to waste a lot of time specifying interface contracts, because they will likely work against you when the requirements change.  After all, the goal at this stage isn't to get the perfect implementation of the requirements, it is to get the perfect requirements so you can <em>start</em> the final implementation.  An exception to this would be if your MVP actually consists of a huge system that is likely to have hundreds of modules.  If there are already many people involved in building the software then good interface contracts will be necessary to prevent them from stepping on each others toes.</p>
  932. <p>     If you answered 'not very likely' to this question, then you should probably start off with a language that has very strong interface contracts.  It will be more work to get started, but it will also be less work to add new features on day number 1523.  The only exception, would be if you're writing something small (say a few hundred lines).</p>
  933. <p>     Back in the day there was much discussion about how Twitter started out using Ruby on Rails, and then later encountered a number of scaling issues because of this.  They later switched to using Scala.  Some would probably claim that this represented a failure, and that the right decision was to pick Scala all along.  I don't believe this is true.  The idea of Twitter itself is extremely simple, so with a number of potential competitors their initial primary goal was to gain enough market share to be dominant.  They needed to grow as fast as possible at all costs.  This meant iterating on features as fast as possible to figure out what product people actually want them to build.  The scaling issues are not a symptom of failure, but a symptom of success.  The vision for what the 'product' of Twitter actually was articulated, all that was left was to build it.  From the perspective of developers, this is a nirvana like situation that every programmer dreams about, but never experiences:  When your boss says "Re-write this crappy code from scratch in your favourite language in whatever way you want so that it is easier to work on later."  Re-writing something from scratch when you have a weaker reference implementation is not as much work as figuring out what product you actually need build to start a rocket ship company.  Unfortunately, most companies only see this type of switch as an unnecessary cost meant to scratch a programmer's obsessive itch, and waste a lot of time trying to scale something that just wasn't meant to scale.</p>
  934. <h1 id="why-python-is-popular">Why is Python So Popular?</h1>
  935. <p>     In the section on <a href="#leaky-and-specific-interfaces">leaky and specific interfaces</a>, I discussed how you can classify interfaces according to how prone they are to abstraction leaks, and how specific the interface definitions can be.  I also pointed out the fact that languages that are considered more 'user friendly' and 'productive' are often the ones that on the highly leaky, and non-specific end of this spectrum.</p>
  936. <p>     I claim that the reason Python is so popular is because it is an excellent introductory language due to its extremely lean interface contracts.  This is also the same reason that Python becomes difficult to maintain as the size of a project increases.</p>
  937. <p>     Python is also very popular in the scientific community, and for people experimenting with numerical computation.  The very nature of experimentation requires that you constantly iterate on the design of what you're building, and for this reason more specific interfaces would slow down the experimentation process.</p>
  938. <h1 id="why-does-enterprise-use-java">Why is Enterprise Software Usually Java/C++?</h1>
  939. <p>     I claim that the reason is exactly the opposite reason as in the previous section on 'Why Python is So Popular?'.  In the section on <a href="#leaky-and-specific-interfaces">leaky and specific interfaces</a>, I discussed the tradeoffs related to different types of interfaces.  Interfaces in Java and C++ fall more on the specific end of the spectrum than those found in other languages like Python or Ruby.  C++ and Java still can be leaky, and of course there are even more specific languages like Haskell, but Java and C++ seem to strike a balance between scalabilty, user friendliness, and iteration time.  These languages also provide the programmer with flexibility in how leaky they would like their interfaces to be as a matter of project convention.  An example would be how you can make variables or functions private, public, or protected, depending depending on the needs of the project.</p>
  940. <h1 id="how-to-cut-corners">How to Cut Corners Efficiently</h1>
  941. <p>     If there is one thing you should take away from this article, it is this: If you have to cut corners in your project, do it inside the <em>implementation</em>, and wrap a <strong>very good</strong> interface around it.  You might be thinking that if the implementation is bad enough, then the problems in that implementation can leak to other parts of your system, but they shouldn't!  If they do, I would call that bad interface design!  For the sake of clarity, I'll explicitly list out what I mean my 'interfaces' here:</p>
  942. <ul>
  943. <li>Function Protoypes</li>
  944. <li>Java 'Interfaces'</li>
  945. <li>Public Class Methods</li>
  946. <li>Public Member Variables</li>
  947. <li>Header (.h) files in C/C++.</li>
  948. <li>RESTful API endpoints</li>
  949. <li>URL Routing</li>
  950. <li>Publicly visible aspects of 'Modules' or 'Packages'</li>
  951. <li>Database Schema (DDL)</li>
  952. <li>Many Others...</li>
  953. </ul>
  954. <h1 id="conclusion">Conclusion</h1>
  955. <p>     As you can see, the concept of an 'interface' is an incredibly important one with a variety of far reaching consequences.  There are legal consequences, productivity consequences, and a number of very philosophical connections you can make to other aspects of system design.  Ask any experienced programmer what they think about interfaces and you're likely to get an earful.</p>
  956. <p>     A final thanks to <a href="https://github.com/hudon">James Hudon</a> who provided some feedback and corrections to this article.</p>
  957. </article>
  958. </section>
  959. <nav id="jumpto">
  960. <p>
  961. <a href="/david/blog/">Accueil du blog</a> |
  962. <a href="http://blog.robertelder.org/interfaces-most-important-software-engineering-concept/">Source originale</a> |
  963. <a href="/david/stream/2019/">Accueil du flux</a>
  964. </p>
  965. </nav>
  966. <footer>
  967. <div>
  968. <img src="/static/david/david-larlet-avatar.jpg" loading="lazy" class="avatar" width="200" height="200">
  969. <p>
  970. Bonjour/Hi!
  971. Je suis <a href="/david/" title="Profil public">David&nbsp;Larlet</a>, je vis actuellement à Montréal et j’alimente cet espace depuis 15 ans. <br>
  972. Si tu as apprécié cette lecture, n’hésite pas à poursuivre ton exploration. Par exemple via les <a href="/david/blog/" title="Expériences bienveillantes">réflexions bimestrielles</a>, la <a href="/david/stream/2019/" title="Pensées (dés)articulées">veille hebdomadaire</a> ou en t’abonnant au <a href="/david/log/" title="S’abonner aux publications via RSS">flux RSS</a> (<a href="/david/blog/2019/flux-rss/" title="Tiens c’est quoi un flux RSS ?">so 2005</a>).
  973. </p>
  974. <p>
  975. Je m’intéresse à la place que je peux avoir dans ce monde. En tant qu’humain, en tant que membre d’une famille et en tant qu’associé d’une coopérative. De temps en temps, je fais aussi des <a href="https://github.com/davidbgk" title="Principalement sur Github mais aussi ailleurs">trucs techniques</a>. Et encore plus rarement, <a href="/david/talks/" title="En ce moment je laisse plutôt la place aux autres">j’en parle</a>.
  976. </p>
  977. <p>
  978. Voici quelques articles choisis :
  979. <a href="/david/blog/2019/faire-equipe/" title="Accéder à l’article complet">Faire équipe</a>,
  980. <a href="/david/blog/2018/bivouac-automnal/" title="Accéder à l’article complet">Bivouac automnal</a>,
  981. <a href="/david/blog/2018/commodite-effondrement/" title="Accéder à l’article complet">Commodité et effondrement</a>,
  982. <a href="/david/blog/2017/donnees-communs/" title="Accéder à l’article complet">Des données aux communs</a>,
  983. <a href="/david/blog/2016/accompagner-enfant/" title="Accéder à l’article complet">Accompagner un enfant</a>,
  984. <a href="/david/blog/2016/senior-developer/" title="Accéder à l’article complet">Senior developer</a>,
  985. <a href="/david/blog/2016/illusion-sociale/" title="Accéder à l’article complet">L’illusion sociale</a>,
  986. <a href="/david/blog/2016/instantane-scopyleft/" title="Accéder à l’article complet">Instantané Scopyleft</a>,
  987. <a href="/david/blog/2016/enseigner-web/" title="Accéder à l’article complet">Enseigner le Web</a>,
  988. <a href="/david/blog/2016/simplicite-defaut/" title="Accéder à l’article complet">Simplicité par défaut</a>,
  989. <a href="/david/blog/2016/minimalisme-esthetique/" title="Accéder à l’article complet">Minimalisme et esthétique</a>,
  990. <a href="/david/blog/2014/un-web-omni-present/" title="Accéder à l’article complet">Un web omni-présent</a>,
  991. <a href="/david/blog/2014/manifeste-developpeur/" title="Accéder à l’article complet">Manifeste de développeur</a>,
  992. <a href="/david/blog/2013/confort-convivialite/" title="Accéder à l’article complet">Confort et convivialité</a>,
  993. <a href="/david/blog/2013/testament-numerique/" title="Accéder à l’article complet">Testament numérique</a>,
  994. et <a href="/david/blog/" title="Accéder aux archives">bien d’autres…</a>
  995. </p>
  996. <p>
  997. On peut <a href="mailto:david%40larlet.fr" title="Envoyer un courriel">échanger par courriel</a>. Si éventuellement tu souhaites que l’on travaille ensemble, tu devrais commencer par consulter le <a href="http://larlet.com">profil dédié à mon activité professionnelle</a> et/ou contacter directement <a href="http://scopyleft.fr/">scopyleft</a>, la <abbr title="Société coopérative et participative">SCOP</abbr> dont je fais partie depuis six ans. Je recommande au préalable de lire <a href="/david/blog/2018/cout-site/" title="Attention ce qui va suivre peut vous choquer">combien coûte un site</a> et pourquoi je suis plutôt favorable à une <a href="/david/pro/devis/" title="Discutons-en !">non-demande de devis</a>.
  998. </p>
  999. <p>
  1000. Je ne traque pas ta navigation mais mon
  1001. <abbr title="Alwaysdata, 62 rue Tiquetonne 75002 Paris, +33.184162340">hébergeur</abbr>
  1002. conserve des logs d’accès.
  1003. </p>
  1004. </div>
  1005. </footer>
  1006. <script type="text/javascript">
  1007. ;(_ => {
  1008. const jumper = document.getElementById('jumper')
  1009. jumper.addEventListener('click', e => {
  1010. e.preventDefault()
  1011. const anchor = e.target.getAttribute('href')
  1012. const targetEl = document.getElementById(anchor.substring(1))
  1013. targetEl.scrollIntoView({behavior: 'smooth'})
  1014. })
  1015. })()
  1016. </script>