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 45KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096
  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>A practical introduction to functional programming (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://maryrosecook.com/blog/post/a-practical-introduction-to-functional-programming">
  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. A practical introduction to functional programming (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://maryrosecook.com/blog/post/a-practical-introduction-to-functional-programming">Source originale du contenu</a></h3>
  445. <p>Many functional programming articles teach abstract functional techniques. That is, composition, pipelining, higher order functions. This one is different. It shows examples of imperative, unfunctional code that people write every day and translates these examples to a functional style.</p>
  446. <p>The first section of the article takes short, data transforming loops and translates them into functional maps and reduces. The second section takes longer loops, breaks them up into units and makes each unit functional. The third section takes a loop that is a long series of successive data transformations and decomposes it into a functional pipeline.</p>
  447. <p>The examples are in Python, because many people find Python easy to read. A number of the examples eschew pythonicity in order to demonstrate functional techniques common to many languages: map, reduce, pipeline.</p>
  448. <h3>A guide rope</h3>
  449. <p>When people talk about functional programming, they mention a dizzying number of “functional” characteristics. They mention immutable data<sup>1</sup>, first class functions<sup>2</sup> and tail call optimisation<sup>3</sup>. These are language features that aid functional programming. They mention mapping, reducing, pipelining, recursing, currying<sup>4</sup> and the use of higher order functions. These are programming techniques used to write functional code. They mention parallelization<sup>5</sup>, lazy evaluation<sup>6</sup> and determinism<sup>7</sup>. These are advantageous properties of functional programs.</p>
  450. <p>Ignore all that. Functional code is characterised by one thing: the absence of side effects. It doesn’t rely on data outside the current function, and it doesn’t change data that exists outside the current function. Every other “functional” thing can be derived from this property. Use it as a guide rope as you learn.</p>
  451. <p>This is an unfunctional function:</p>
  452. <pre class="prettyprint">&#13;
  453. a = 0&#13;
  454. def increment1():&#13;
  455. global a&#13;
  456. a += 1&#13;
  457. </pre>
  458. <p>This is a functional function:</p>
  459. <pre class="prettyprint">&#13;
  460. def increment2(a):&#13;
  461. return a + 1&#13;
  462. </pre>
  463. <h3>Don’t iterate over lists. Use map and reduce.</h3>
  464. <h4>Map</h4>
  465. <p>Map takes a function and a collection of items. It makes a new, empty collection, runs the function on each item in the original collection and inserts each return value into the new collection. It returns the new collection.</p>
  466. <p>This is a simple map that takes a list of names and returns a list of the lengths of those names:</p>
  467. <pre class="prettyprint">&#13;
  468. name_lengths = map(len, ["Mary", "Isla", "Sam"])&#13;
  469. &#13;
  470. print name_lengths&#13;
  471. # =&gt; [4, 4, 3]&#13;
  472. </pre>
  473. <p>This is a map that squares every number in the passed collection:</p>
  474. <pre class="prettyprint">&#13;
  475. squares = map(lambda x: x * x, [0, 1, 2, 3, 4])&#13;
  476. &#13;
  477. print squares&#13;
  478. # =&gt; [0, 1, 4, 9, 16]&#13;
  479. </pre>
  480. <p>This map doesn’t take a named function. It takes an anonymous, inlined function defined with <code>lambda</code>. The parameters of the lambda are defined to the left of the colon. The function body is defined to the right of the colon. The result of running the function body is (implicitly) returned.</p>
  481. <p>The unfunctional code below takes a list of real names and replaces them with randomly assigned code names.</p>
  482. <pre class="prettyprint">&#13;
  483. import random&#13;
  484. &#13;
  485. names = ['Mary', 'Isla', 'Sam']&#13;
  486. code_names = ['Mr. Pink', 'Mr. Orange', 'Mr. Blonde']&#13;
  487. &#13;
  488. for i in range(len(names)):&#13;
  489. names[i] = random.choice(code_names)&#13;
  490. &#13;
  491. print names&#13;
  492. # =&gt; ['Mr. Blonde', 'Mr. Blonde', 'Mr. Blonde']&#13;
  493. </pre>
  494. <p>(As you can see, this algorithm can potentially assign the same secret code name to multiple secret agents. Hopefully, this won’t be a source of confusion during the secret mission.)</p>
  495. <p>This can be rewritten as a map:</p>
  496. <pre class="prettyprint">&#13;
  497. import random&#13;
  498. &#13;
  499. names = ['Mary', 'Isla', 'Sam']&#13;
  500. &#13;
  501. secret_names = map(lambda x: random.choice(['Mr. Pink',&#13;
  502. 'Mr. Orange',&#13;
  503. 'Mr. Blonde']),&#13;
  504. names)&#13;
  505. </pre>
  506. <p><strong>Exercise 1</strong>. Try rewriting the code below as a map. It takes a list of real names and replaces them with code names produced using a more robust strategy.</p>
  507. <pre class="prettyprint">&#13;
  508. names = ['Mary', 'Isla', 'Sam']&#13;
  509. &#13;
  510. for i in range(len(names)):&#13;
  511. names[i] = hash(names[i])&#13;
  512. &#13;
  513. print names&#13;
  514. # =&gt; [6306819796133686941, 8135353348168144921, -1228887169324443034]&#13;
  515. </pre>
  516. <p>(Hopefully, the secret agents will have good memories and won’t forget each other’s secret code names during the secret mission.)</p>
  517. <p>My solution:</p>
  518. <pre class="prettyprint">&#13;
  519. names = ['Mary', 'Isla', 'Sam']&#13;
  520. &#13;
  521. secret_names = map(hash, names)&#13;
  522. </pre>
  523. <h4>Reduce</h4>
  524. <p>Reduce takes a function and a collection of items. It returns a value that is created by combining the items.</p>
  525. <p>This is a simple reduce. It returns the sum of all the items in the collection.</p>
  526. <pre class="prettyprint">&#13;
  527. sum = reduce(lambda a, x: a + x, [0, 1, 2, 3, 4])&#13;
  528. &#13;
  529. print sum&#13;
  530. # =&gt; 10&#13;
  531. </pre>
  532. <p><code>x</code> is the current item being iterated over. <code>a</code> is the accumulator. It is the value returned by the execution of the lambda on the previous item. <code>reduce()</code> walks through the items. For each one, it runs the lambda on the current <code>a</code> and <code>x</code> and returns the result as the <code>a</code> of the next iteration.</p>
  533. <p>What is <code>a</code> in the first iteration? There is no previous iteration result for it to pass along. <code>reduce()</code> uses the first item in the collection for <code>a</code> in the first iteration and starts iterating at the second item. That is, the first <code>x</code> is the second item.</p>
  534. <p>This code counts how often the word <code>'Sam'</code> appears in a list of strings:</p>
  535. <pre class="prettyprint">&#13;
  536. sentences = ['Mary read a story to Sam and Isla.',&#13;
  537. 'Isla cuddled Sam.',&#13;
  538. 'Sam chortled.']&#13;
  539. &#13;
  540. sam_count = 0&#13;
  541. for sentence in sentences:&#13;
  542. sam_count += sentence.count('Sam')&#13;
  543. &#13;
  544. print sam_count&#13;
  545. # =&gt; 3&#13;
  546. </pre>
  547. <p>This is the same code written as a reduce:</p>
  548. <pre class="prettyprint">&#13;
  549. sentences = ['Mary read a story to Sam and Isla.',&#13;
  550. 'Isla cuddled Sam.',&#13;
  551. 'Sam chortled.']&#13;
  552. &#13;
  553. sam_count = reduce(lambda a, x: a + x.count('Sam'),&#13;
  554. sentences,&#13;
  555. 0)&#13;
  556. </pre>
  557. <p>How does this code come up with its initial <code>a</code>? The starting point for the number of incidences of <code>'Sam'</code> cannot be <code>'Mary read a story to Sam and Isla.'</code> The initial accumulator is specified with the third argument to <code>reduce()</code>. This allows the use of a value of a different type from the items in the collection.</p>
  558. <p>Why are map and reduce better?</p>
  559. <p>First, they are often one-liners.</p>
  560. <p>Second, the important parts of the iteration – the collection, the operation and the return value – are always in the same places in every map and reduce.</p>
  561. <p>Third, the code in a loop may affect variables defined before it or code that runs after it. By convention, maps and reduces are functional.</p>
  562. <p>Fourth, map and reduce are elemental operations. Every time a person reads a <code>for</code> loop, they have to work through the logic line by line. There are few structural regularities they can use to create a scaffolding on which to hang their understanding of the code. In contrast, map and reduce are at once building blocks that can be combined into complex algorithms, and elements that the code reader can instantly understand and abstract in their mind. “Ah, this code is transforming each item in this collection. It’s throwing some of the transformations away. It’s combining the remainder into a single output.”</p>
  563. <p>Fifth, map and reduce have many friends that provide useful, tweaked versions of their basic behaviour. For example: <code>filter</code>, <code>all</code>, <code>any</code> and <code>find</code>.</p>
  564. <p><strong>Exercise 2</strong>. Try rewriting the code below using map, reduce and filter. Filter takes a function and a collection. It returns a collection of every item for which the function returned <code>True</code>.</p>
  565. <pre class="prettyprint">&#13;
  566. people = [{'name': 'Mary', 'height': 160},&#13;
  567. {'name': 'Isla', 'height': 80},&#13;
  568. {'name': 'Sam'}]&#13;
  569. &#13;
  570. height_total = 0&#13;
  571. height_count = 0&#13;
  572. for person in people:&#13;
  573. if 'height' in person:&#13;
  574. height_total += person['height']&#13;
  575. height_count += 1&#13;
  576. &#13;
  577. if height_count &gt; 0:&#13;
  578. average_height = height_total / height_count&#13;
  579. &#13;
  580. print average_height&#13;
  581. # =&gt; 120&#13;
  582. </pre>
  583. <p>If this seems tricky, try not thinking about the operations on the data. Think of the states the data will go through, from the list of people dictionaries to the average height. Don’t try and bundle multiple transformations together. Put each on a separate line and assign the result to a descriptively-named variable. Once the code works, condense it.</p>
  584. <p>My solution:</p>
  585. <pre class="prettyprint">&#13;
  586. people = [{'name': 'Mary', 'height': 160},&#13;
  587. {'name': 'Isla', 'height': 80},&#13;
  588. {'name': 'Sam'}]&#13;
  589. &#13;
  590. heights = map(lambda x: x['height'],&#13;
  591. filter(lambda x: 'height' in x, people))&#13;
  592. &#13;
  593. if len(heights) &gt; 0:&#13;
  594. from operator import add&#13;
  595. average_height = reduce(add, heights) / len(heights)&#13;
  596. </pre>
  597. <h3>Write declaratively, not imperatively</h3>
  598. <p>The program below runs a race between three cars. At each time step, each car may move forwards or it may stall. At each time step, the program prints out the paths of the cars so far. After five time steps, the race is over.</p>
  599. <p>This is some sample output:</p>
  600. <pre class="prettyprint">&#13;
  601. -&#13;
  602. --&#13;
  603. --&#13;
  604. &#13;
  605. --&#13;
  606. --&#13;
  607. ---&#13;
  608. &#13;
  609. ---&#13;
  610. --&#13;
  611. ---&#13;
  612. &#13;
  613. ----&#13;
  614. ---&#13;
  615. ----&#13;
  616. &#13;
  617. ----&#13;
  618. ----&#13;
  619. -----&#13;
  620. </pre>
  621. <p>This is the program:</p>
  622. <pre class="prettyprint">&#13;
  623. from random import random&#13;
  624. &#13;
  625. time = 5&#13;
  626. car_positions = [1, 1, 1]&#13;
  627. &#13;
  628. while time:&#13;
  629. # decrease time&#13;
  630. time -= 1&#13;
  631. &#13;
  632. print ''&#13;
  633. for i in range(len(car_positions)):&#13;
  634. # move car&#13;
  635. if random() &gt; 0.3:&#13;
  636. car_positions[i] += 1&#13;
  637. &#13;
  638. # draw car&#13;
  639. print '-' * car_positions[i]&#13;
  640. </pre>
  641. <p>The code is written imperatively. A functional version would be declarative. It would describe what to do, rather than how to do it.</p>
  642. <h4>Use functions</h4>
  643. <p>A program can be made more declarative by bundling pieces of the code into functions.</p>
  644. <pre class="prettyprint">&#13;
  645. from random import random&#13;
  646. &#13;
  647. def move_cars():&#13;
  648. for i, _ in enumerate(car_positions):&#13;
  649. if random() &gt; 0.3:&#13;
  650. car_positions[i] += 1&#13;
  651. &#13;
  652. def draw_car(car_position):&#13;
  653. print '-' * car_position&#13;
  654. &#13;
  655. def run_step_of_race():&#13;
  656. global time&#13;
  657. time -= 1&#13;
  658. move_cars()&#13;
  659. &#13;
  660. def draw():&#13;
  661. print ''&#13;
  662. for car_position in car_positions:&#13;
  663. draw_car(car_position)&#13;
  664. &#13;
  665. time = 5&#13;
  666. car_positions = [1, 1, 1]&#13;
  667. &#13;
  668. while time:&#13;
  669. run_step_of_race()&#13;
  670. draw()&#13;
  671. </pre>
  672. <p>To understand this program, the reader just reads the main loop. “If there is time left, run a step of the race and draw. Check the time again.” If the reader wants to understand more about what it means to run a step of the race, or draw, they can read the code in those functions.</p>
  673. <p>There are no comments any more. The code describes itself.</p>
  674. <p>Splitting code into functions is a great, low brain power way to make code more readable.</p>
  675. <p>This technique uses functions, but it uses them as sub-routines. They parcel up code. The code is not functional in the sense of the guide rope. The functions in the code use state that was not passed as arguments. They affect the code around them by changing external variables, rather than by returning values. To check what a function really does, the reader must read each line carefully. If they find an external variable, they must find its origin. They must see what other functions change that variable.</p>
  676. <h4>Remove state</h4>
  677. <p>This is a functional version of the car race code:</p>
  678. <pre class="prettyprint">&#13;
  679. from random import random&#13;
  680. &#13;
  681. def move_cars(car_positions):&#13;
  682. return map(lambda x: x + 1 if random() &gt; 0.3 else x,&#13;
  683. car_positions)&#13;
  684. &#13;
  685. def output_car(car_position):&#13;
  686. return '-' * car_position&#13;
  687. &#13;
  688. def run_step_of_race(state):&#13;
  689. return {'time': state['time'] - 1,&#13;
  690. 'car_positions': move_cars(state['car_positions'])}&#13;
  691. &#13;
  692. def draw(state):&#13;
  693. print ''&#13;
  694. print '\n'.join(map(output_car, state['car_positions']))&#13;
  695. &#13;
  696. def race(state):&#13;
  697. draw(state)&#13;
  698. if state['time']:&#13;
  699. race(run_step_of_race(state))&#13;
  700. &#13;
  701. race({'time': 5,&#13;
  702. 'car_positions': [1, 1, 1]})&#13;
  703. </pre>
  704. <p>The code is still split into functions, but the functions are functional. There are three signs of this. First, there are no longer any shared variables. <code>time</code> and <code>car_positions</code> get passed straight into <code>race()</code>. Second, functions take parameters. Third, no variables are instantiated inside functions. All data changes are done with return values. <code>race()</code> recurses<sup>3</sup> with the result of <code>run_step_of_race()</code>. Each time a step generates a new state, it is passed immediately into the next step.</p>
  705. <p>Now, here are two functions, <code>zero()</code> and <code>one()</code>:</p>
  706. <pre class="prettyprint">&#13;
  707. def zero(s):&#13;
  708. if s[0] == "0":&#13;
  709. return s[1:]&#13;
  710. &#13;
  711. def one(s):&#13;
  712. if s[0] == "1":&#13;
  713. return s[1:]&#13;
  714. </pre>
  715. <p><code>zero()</code> takes a string, <code>s</code>. If the first character is <code>'0'</code>, it returns the rest of the string. If it is not, it returns <code>None</code>, the default return value of Python functions. <code>one()</code> does the same, but for a first character of <code>'1'</code>.</p>
  716. <p>Imagine a function called <code>rule_sequence()</code>. It takes a string and a list of rule functions of the form of <code>zero()</code> and <code>one()</code>. It calls the first rule on the string. Unless <code>None</code> is returned, it takes the return value and calls the second rule on it. Unless <code>None</code> is returned, it takes the return value and calls the third rule on it. And so forth. If any rule returns <code>None</code>, <code>rule_sequence()</code> stops and returns <code>None</code>. Otherwise, it returns the return value of the final rule.</p>
  717. <p>This is some sample input and output:</p>
  718. <pre class="prettyprint">&#13;
  719. print rule_sequence('0101', [zero, one, zero])&#13;
  720. # =&gt; 1&#13;
  721. &#13;
  722. print rule_sequence('0101', [zero, zero])&#13;
  723. # =&gt; None&#13;
  724. </pre>
  725. <p>This is the imperative version of <code>rule_sequence()</code>:</p>
  726. <pre class="prettyprint">&#13;
  727. def rule_sequence(s, rules):&#13;
  728. for rule in rules:&#13;
  729. s = rule(s)&#13;
  730. if s == None:&#13;
  731. break&#13;
  732. &#13;
  733. return s&#13;
  734. </pre>
  735. <p><strong>Exercise 3</strong>. The code above uses a loop to do its work. Make it more declarative by rewriting it as a recursion.</p>
  736. <p>My solution:</p>
  737. <pre class="prettyprint">&#13;
  738. def rule_sequence(s, rules):&#13;
  739. if s == None or not rules:&#13;
  740. return s&#13;
  741. else:&#13;
  742. return rule_sequence(rules[0](s), rules[1:])&#13;
  743. </pre>
  744. <h3>Use pipelines</h3>
  745. <p>In the previous section, some imperative loops were rewritten as recursions that called out to auxiliary functions. In this section, a different type of imperative loop will be rewritten using a technique called a pipeline.</p>
  746. <p>The loop below performs transformations on dictionaries that hold the name, incorrect country of origin and active status of some bands.</p>
  747. <pre class="prettyprint">&#13;
  748. bands = [{'name': 'sunset rubdown', 'country': 'UK', 'active': False},&#13;
  749. {'name': 'women', 'country': 'Germany', 'active': False},&#13;
  750. {'name': 'a silver mt. zion', 'country': 'Spain', 'active': True}]&#13;
  751. &#13;
  752. def format_bands(bands):&#13;
  753. for band in bands:&#13;
  754. band['country'] = 'Canada'&#13;
  755. band['name'] = band['name'].replace('.', '')&#13;
  756. band['name'] = band['name'].title()&#13;
  757. &#13;
  758. format_bands(bands)&#13;
  759. &#13;
  760. print bands&#13;
  761. # =&gt; [{'name': 'Sunset Rubdown', 'active': False, 'country': 'Canada'},&#13;
  762. # {'name': 'Women', 'active': False, 'country': 'Canada' },&#13;
  763. # {'name': 'A Silver Mt Zion', 'active': True, 'country': 'Canada'}]&#13;
  764. </pre>
  765. <p>Worries are stirred by the name of the function. “format” is very vague. Upon closer inspection of the code, these worries begin to claw. Three things happen in the same loop. The <code>'country'</code> key gets set to <code>'Canada'</code>. Punctuation is removed from the band name. The band name gets capitalized. It is hard to tell what the code is intended to do and hard to tell if it does what it appears to do. The code is hard to reuse, hard to test and hard to parallelize.</p>
  766. <p>Compare it with this:</p>
  767. <pre class="prettyprint">&#13;
  768. print pipeline_each(bands, [set_canada_as_country,&#13;
  769. strip_punctuation_from_name,&#13;
  770. capitalize_names])&#13;
  771. </pre>
  772. <p>This code is easy to understand. It gives the impression that the auxiliary functions are functional because they seem to be chained together. The output from the previous one comprises the input to the next. If they are functional, they are easy to verify. They are also easy to reuse, easy to test and easy to parallelize.</p>
  773. <p>The job of <code>pipeline_each()</code> is to pass the bands, one at a time, to a transformation function, like <code>set_canada_as_country()</code>. After the function has been applied to all the bands, <code>pipeline_each()</code> bundles up the transformed bands. Then, it passes each one to the next function.</p>
  774. <p>Let’s look at the transformation functions.</p>
  775. <pre class="prettyprint">&#13;
  776. def assoc(_d, key, value):&#13;
  777. from copy import deepcopy&#13;
  778. d = deepcopy(_d)&#13;
  779. d[key] = value&#13;
  780. return d&#13;
  781. &#13;
  782. def set_canada_as_country(band):&#13;
  783. return assoc(band, 'country', "Canada")&#13;
  784. &#13;
  785. def strip_punctuation_from_name(band):&#13;
  786. return assoc(band, 'name', band['name'].replace('.', ''))&#13;
  787. &#13;
  788. def capitalize_names(band):&#13;
  789. return assoc(band, 'name', band['name'].title())&#13;
  790. </pre>
  791. <p>Each one associates a key on a band with a new value. There is no easy way to do this without mutating the original band. <code>assoc()</code> solves this problem by using <code>deepcopy()</code> to produce a copy of the passed dictionary. Each transformation function makes its modification to the copy and returns that copy.</p>
  792. <p>Everything seems fine. Band dictionary originals are protected from mutation when a key is associated with a new value. But there are two other potential mutations in the code above. In <code>strip_punctuation_from_name()</code>, the unpunctuated name is generated by calling <code>replace()</code> on the original name. In <code>capitalize_names()</code>, the capitalized name is generated by calling <code>title()</code> on the original name. If <code>replace()</code> and <code>title()</code> are not functional, <code>strip_punctuation_from_name()</code> and <code>capitalize_names()</code> are not functional.</p>
  793. <p>Fortunately, <code>replace()</code> and <code>title()</code> do not mutate the strings they operate on. This is because strings are immutable in Python. When, for example, <code>replace()</code> operates on a band name string, the original band name is copied and <code>replace()</code> is called on the copy. Phew.</p>
  794. <p>This contrast between the mutability of strings and dictionaries in Python illustrates the appeal of languages like Clojure. The programmer need never think about whether they are mutating data. They aren’t.</p>
  795. <p><strong>Exercise 4</strong>. Try and write the <code>pipeline_each</code> function. Think about the order of operations. The bands in the array are passed, one band at a time, to the first transformation function. The bands in the resulting array are passed, one band at a time, to the second transformation function. And so forth.</p>
  796. <p>My solution:</p>
  797. <pre class="prettyprint">&#13;
  798. def pipeline_each(data, fns):&#13;
  799. return reduce(lambda a, x: map(x, a),&#13;
  800. fns,&#13;
  801. data)&#13;
  802. </pre>
  803. <p>All three transformation functions boil down to making a change to a particular field on the passed band. <code>call()</code> can be used to abstract that. It takes a function to apply and the key of the value to apply it to.</p>
  804. <pre class="prettyprint">&#13;
  805. set_canada_as_country = call(lambda x: 'Canada', 'country')&#13;
  806. strip_punctuation_from_name = call(lambda x: x.replace('.', ''), 'name')&#13;
  807. capitalize_names = call(str.title, 'name')&#13;
  808. &#13;
  809. print pipeline_each(bands, [set_canada_as_country,&#13;
  810. strip_punctuation_from_name,&#13;
  811. capitalize_names])&#13;
  812. </pre>
  813. <p>Or, if we are willing to sacrifice readability for conciseness, just:</p>
  814. <pre class="prettyprint">&#13;
  815. print pipeline_each(bands, [call(lambda x: 'Canada', 'country'),&#13;
  816. call(lambda x: x.replace('.', ''), 'name'),&#13;
  817. call(str.title, 'name')])&#13;
  818. </pre>
  819. <p>The code for <code>call()</code>:</p>
  820. <pre class="prettyprint">&#13;
  821. def assoc(_d, key, value):&#13;
  822. from copy import deepcopy&#13;
  823. d = deepcopy(_d)&#13;
  824. d[key] = value&#13;
  825. return d&#13;
  826. &#13;
  827. def call(fn, key):&#13;
  828. def apply_fn(record):&#13;
  829. return assoc(record, key, fn(record.get(key)))&#13;
  830. return apply_fn&#13;
  831. </pre>
  832. <p>There is a lot going on here. Let’s take it piece by piece.</p>
  833. <p>One. <code>call()</code> is a higher order function. A higher order function takes a function as an argument, or returns a function. Or, like <code>call()</code>, it does both.</p>
  834. <p>Two. <code>apply_fn()</code> looks very similar to the three transformation functions. It takes a record (a band). It looks up the value at <code>record[key]</code>. It calls <code>fn</code> on that value. It assigns the result back to a copy of the record. It returns the copy.</p>
  835. <p>Three. <code>call()</code> does not do any actual work. <code>apply_fn()</code>, when called, will do the work. In the example of using <code>pipeline_each()</code> above, one instance of <code>apply_fn()</code> will set <code>'country'</code> to <code>'Canada'</code> on a passed band. Another instance will capitalize the name of a passed band.</p>
  836. <p>Four. When an <code>apply_fn()</code> instance is run, <code>fn</code> and <code>key</code> will not be in scope. They are neither arguments to <code>apply_fn()</code>, nor locals inside it. But they will still be accessible. When a function is defined, it saves references to the variables it closes over: those that were defined in a scope outside the function and that are used inside the function. When the function is run and its code references a variable, Python looks up the variable in the locals and in the arguments. If it doesn’t find it there, it looks in the saved references to closed over variables. This is where it will find <code>fn</code> and <code>key</code>.</p>
  837. <p>Five. There is no mention of bands in the <code>call()</code> code. That is because <code>call()</code> could be used to generate pipeline functions for any program, regardless of topic. Functional programming is partly about building up a library of generic, reusable, composable functions.</p>
  838. <p>Good job. Closures, higher order functions and variable scope all covered in the space of a few paragraphs. Have a nice glass of lemonade.</p>
  839. <p>There is one more piece of band processing to do. That is to remove everything but the name and country. <code>extract_name_and_country()</code> can pull that information out:</p>
  840. <pre class="prettyprint">&#13;
  841. def extract_name_and_country(band):&#13;
  842. plucked_band = {}&#13;
  843. plucked_band['name'] = band['name']&#13;
  844. plucked_band['country'] = band['country']&#13;
  845. return plucked_band&#13;
  846. &#13;
  847. print pipeline_each(bands, [call(lambda x: 'Canada', 'country'),&#13;
  848. call(lambda x: x.replace('.', ''), 'name'),&#13;
  849. call(str.title, 'name'),&#13;
  850. extract_name_and_country])&#13;
  851. &#13;
  852. # =&gt; [{'name': 'Sunset Rubdown', 'country': 'Canada'},&#13;
  853. # {'name': 'Women', 'country': 'Canada'},&#13;
  854. # {'name': 'A Silver Mt Zion', 'country': 'Canada'}]&#13;
  855. </pre>
  856. <p><code>extract_name_and_country()</code> could have been written as a generic function called <code>pluck()</code>. <code>pluck()</code> would be used like this:</p>
  857. <pre class="prettyprint">&#13;
  858. print pipeline_each(bands, [call(lambda x: 'Canada', 'country'),&#13;
  859. call(lambda x: x.replace('.', ''), 'name'),&#13;
  860. call(str.title, 'name'),&#13;
  861. pluck(['name', 'country'])])&#13;
  862. </pre>
  863. <p><strong>Exercise 5</strong>. <code>pluck()</code> takes a list of keys to extract from each record. Try and write it. It will need to be a higher order function.</p>
  864. <p>My solution:</p>
  865. <pre class="prettyprint">&#13;
  866. def pluck(keys):&#13;
  867. def pluck_fn(record):&#13;
  868. return reduce(lambda a, x: assoc(a, x, record[x]),&#13;
  869. keys,&#13;
  870. {})&#13;
  871. return pluck_fn&#13;
  872. </pre>
  873. <h3>What now?</h3>
  874. <p>Functional code co-exists very well with code written in other styles. The transformations in this article can be applied to any code base in any language. Try applying them to your own code.</p>
  875. <p>Think of Mary, Isla and Sam. Turn iterations of lists into maps and reduces.</p>
  876. <p>Think of the race. Break code into functions. Make those functions functional. Turn a loop that repeats a process into a recursion.</p>
  877. <p>Think of the bands. Turn a sequence of operations into a pipeline.</p>
  878. <p><br/></p>
  879. <p><sup>1</sup> An immutable piece of data is one that cannot be changed. Some languages, like Clojure, make all values immutable by default. Any “mutating” operations copy the value, change it and pass back the changed copy. This eliminates bugs that arise from a programmer’s incomplete model of the possible states their program may enter.</p>
  880. <p><sup>2</sup> Languages that support first class functions allow functions to be treated like any other value. This means they can be created, passed to functions, returned from functions and stored inside data structures.</p>
  881. <p><sup>3</sup> Tail call optimisation is a programming language feature. Each time a function recurses, a new stack frame is created. A stack frame is used to store the arguments and local values for the current function invocation. If a function recurses a large number of times, it is possible for the interpreter or compiler to run out of memory. Languages with tail call optimisation reuse the same stack frame for their entire sequence of recursive calls. Languages like Python that do not have tail call optimisation generally limit the number of times a function may recurse to some number in the thousands. In the case of the <code>race()</code> function, there are only five time steps, so it is safe.</p>
  882. <p><sup>4</sup> Currying means decomposing a function that takes multiple arguments into a function that takes the first argument and returns a function that takes the next argument, and so forth for all the arguments.</p>
  883. <p><sup>5</sup> Parallelization means running the same code concurrently without synchronization. These concurrent processes are often run on multiple processors.</p>
  884. <p><sup>6</sup> Lazy evaluation is a compiler technique that avoids running code until the result is needed.</p>
  885. <p><sup>7</sup> A process is deterministic if repetitions yield the same result every time.</p>
  886. </article>
  887. </section>
  888. <nav id="jumpto">
  889. <p>
  890. <a href="/david/blog/">Accueil du blog</a> |
  891. <a href="http://maryrosecook.com/blog/post/a-practical-introduction-to-functional-programming">Source originale</a> |
  892. <a href="/david/stream/2019/">Accueil du flux</a>
  893. </p>
  894. </nav>
  895. <footer>
  896. <div>
  897. <img src="/static/david/david-larlet-avatar.jpg" loading="lazy" class="avatar" width="200" height="200">
  898. <p>
  899. Bonjour/Hi!
  900. 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>
  901. 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>).
  902. </p>
  903. <p>
  904. 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>.
  905. </p>
  906. <p>
  907. Voici quelques articles choisis :
  908. <a href="/david/blog/2019/faire-equipe/" title="Accéder à l’article complet">Faire équipe</a>,
  909. <a href="/david/blog/2018/bivouac-automnal/" title="Accéder à l’article complet">Bivouac automnal</a>,
  910. <a href="/david/blog/2018/commodite-effondrement/" title="Accéder à l’article complet">Commodité et effondrement</a>,
  911. <a href="/david/blog/2017/donnees-communs/" title="Accéder à l’article complet">Des données aux communs</a>,
  912. <a href="/david/blog/2016/accompagner-enfant/" title="Accéder à l’article complet">Accompagner un enfant</a>,
  913. <a href="/david/blog/2016/senior-developer/" title="Accéder à l’article complet">Senior developer</a>,
  914. <a href="/david/blog/2016/illusion-sociale/" title="Accéder à l’article complet">L’illusion sociale</a>,
  915. <a href="/david/blog/2016/instantane-scopyleft/" title="Accéder à l’article complet">Instantané Scopyleft</a>,
  916. <a href="/david/blog/2016/enseigner-web/" title="Accéder à l’article complet">Enseigner le Web</a>,
  917. <a href="/david/blog/2016/simplicite-defaut/" title="Accéder à l’article complet">Simplicité par défaut</a>,
  918. <a href="/david/blog/2016/minimalisme-esthetique/" title="Accéder à l’article complet">Minimalisme et esthétique</a>,
  919. <a href="/david/blog/2014/un-web-omni-present/" title="Accéder à l’article complet">Un web omni-présent</a>,
  920. <a href="/david/blog/2014/manifeste-developpeur/" title="Accéder à l’article complet">Manifeste de développeur</a>,
  921. <a href="/david/blog/2013/confort-convivialite/" title="Accéder à l’article complet">Confort et convivialité</a>,
  922. <a href="/david/blog/2013/testament-numerique/" title="Accéder à l’article complet">Testament numérique</a>,
  923. et <a href="/david/blog/" title="Accéder aux archives">bien d’autres…</a>
  924. </p>
  925. <p>
  926. 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>.
  927. </p>
  928. <p>
  929. Je ne traque pas ta navigation mais mon
  930. <abbr title="Alwaysdata, 62 rue Tiquetonne 75002 Paris, +33.184162340">hébergeur</abbr>
  931. conserve des logs d’accès.
  932. </p>
  933. </div>
  934. </footer>
  935. <script type="text/javascript">
  936. ;(_ => {
  937. const jumper = document.getElementById('jumper')
  938. jumper.addEventListener('click', e => {
  939. e.preventDefault()
  940. const anchor = e.target.getAttribute('href')
  941. const targetEl = document.getElementById(anchor.substring(1))
  942. targetEl.scrollIntoView({behavior: 'smooth'})
  943. })
  944. })()
  945. </script>