A place to cache linked articles (think custom and personal wayback machine)
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062
  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>Promises: All The Wrong Ways (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="https://blog.getify.com/promises-wrong-ways/">
  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. Promises: All The Wrong Ways (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="https://blog.getify.com/promises-wrong-ways/">Source originale du contenu</a></h3>
  445. <p>If you’re not well-versed on JavaScript Promises yet, I urge you to <a href="https://blog.getify.com/promises-part-1/">read up</a> on <a href="https://github.com/getify/You-Dont-Know-JS/blob/master/async%20&amp;%20performance/ch3.md">them</a> before diving into this article.</p>
  446. <p>Promises are the <em>promise</em> of a vastly improved asynchrony over our previous primitives (notably: callbacks). By abstracting a potentially future value so that it can be treated as time-independent — we don’t have to care if the value is still pending or already finalized — we remove <strong>time</strong> from our concerns, making our programs far easier to reason about.</p>
  447. <p>But I’m not writing to convince you to use promises. Nor am I writing to convince you <em>not</em> to use them. I simply want to call out some ways promises are being used in the wild that I think miss the point, muddy up your code, and dilute the benefits of using them in the first place.</p>
  448. <h3 id="false-start">False Start</h3>
  449. <p>You use some lib that has a function called <code>foo()</code>, and supposedly when you call it, you get a promise back. But… exactly what flavor of promise is it? Your app uses Bluebird promises because you love those extra API methods, but do you know what kind of promise this other <code>foo()</code> function is going to give you? Are you even sure it’s a reliably Promises/A+ compliant promise?</p>
  450. <p>How much can you really trust that the promise you’re getting is the promise you think you’re getting? And what if you are using different libraries that each have their own flavor of promises returned? How are you managing the mixing of all these promises in your code?</p>
  451. <p>The plain fact, which is inconvenient and troubling, is this: this code is a bad anti-pattern:</p>
  452. <pre class="code">
  453. foo()
  454. .then( nextStep )
  455. ..
  456. </pre>
  457. <p>You need to normalize the promise you’re receiving back to make sure it’s a legitimate promise and of the flavor you assume.</p>
  458. <p>Fortunately, this is relatively easy, if not a teeny bit tedious. Use <code>Promise.resolve(..)</code> — or whatever the equivalent is for your promise library of choice — to normalize the returned value into a promise you recognize and trust:</p>
  459. <pre class="code">
  460. Promise.resolve( foo() )
  461. .then( nextStep )
  462. ..
  463. </pre>
  464. <p>If <code>foo()</code> returns a promise that is the same as you are expecting, it’ll pass through <code>Promise.resolve(..)</code> untouched. Otherwise, it’ll be adapted so that the return of <code>Promise.resolve(..)</code> <em>is</em> a promise you recognize and trust.</p>
  465. <p>But wait… does that mean we have to wrap every single promise we get? Eh, not exactly.</p>
  466. <p>The <code>then(..)</code> method automatically does this same sort of normalizing on any return value it receives back from either the fulfillment or rejection handlers.</p>
  467. <pre class="code">
  468. Promise.resolve( foo() )
  469. .then( bar )
  470. .then( lastStep );
  471. </pre>
  472. <p>Even if <code>bar()</code> produces a different kind of promise, that promise is subsumed by <code>then(..)</code> — the <code>then(..)</code> that comes from the kind of promise we want, via <code>Promise.resolve(..)</code> — meaning that the normalization is automatically implied as we’d want.</p>
  473. <p>So it’s really only the beginning of the promise chain that we need to be more careful with. We need to make sure to normalize all first-of-chain promises, just in case.</p>
  474. <h4 id="start-delays">Start Delays</h4>
  475. <p>Speaking of the start of a promise chain, another mistake that’s often made is adding unnecessary promise resolution steps. For example:</p>
  476. <pre class="code">
  477. Promise.resolve()
  478. .then( firstStep );
  479. </pre>
  480. <p>Why would we do this? The first reason is that it automatically normalizes <code>firstStep()</code>‘s returned value/promise, as just described. The second we’ll cover in the next section.</p>
  481. <p>But instead of calling <code>firstStep()</code> right away, here it’ll be delayed until the end of the event-loop tick. Is that really a big deal? Usually not, but when you do this over and over again, those delays <em>can</em> add up.</p>
  482. <p>Don’t put an extra empty tick at the beginning of your promise chain. Just start the chain right away.</p>
  483. <p>And while we’re discussing it, don’t do this either:</p>
  484. <pre class="code">
  485. new Promise( function(resolve,reject){
  486. firstStep()
  487. .then( resolve, reject );
  488. } )
  489. ..
  490. </pre>
  491. <p>You may think that’d be obnoxious and obviously bad, but it’s more common than you’d realize and really shouldn’t be done.</p>
  492. <h4 id="failing-to-start">Failing To Start</h4>
  493. <p>What if there’s any case where <code>firstStep()</code> being called could result directly in a synchronous exception — not a rejected promise?</p>
  494. <p>Most people think such method behavior shouldn’t ever be designed — indeed, many would call such a function an anti-pattern in and of itself — but this post isn’t about bad patterns with API design, it’s about bad practices with using the promises you get.</p>
  495. <p>The fact is, some functions of this sort do exist. If you have to deal with one, you’re probably going to want trap such an exception and turn it into a promise rejection that can be dealt with in the normalized promise chain.</p>
  496. <p>You might consider doing something manual like this:</p>
  497. <pre class="code">
  498. var p;
  499. try {
  500. p = Promise.resolve( firstStep() );
  501. }
  502. catch (err) {
  503. p = Promise.reject( err );
  504. }
  505. p
  506. .then( .. )
  507. ..
  508. </pre>
  509. <p>We not only normalize the return value to the desired promise flavor with <code>Promise.resolve(..)</code>, but the <code>try..catch</code> also normalizes any caught exception into the rejection. That’s effective, but ugly, and this code’s verbosity doesn’t actually contribute to easier understanding, IMO.</p>
  510. <p>This concern is where two earlier-mentioned patterns probably originated from:</p>
  511. <pre class="code">
  512. Promise.resolve()
  513. .then( firstStep )
  514. ..
  515. // and:
  516. new Promise( function(resolve,reject){
  517. firstStep()
  518. .then( resolve, reject );
  519. } )
  520. ..
  521. </pre>
  522. <p>In both cases, if <code>firstStep()</code> results in an exception, it will automatically be caught by the Promise machinery, and turned into a promise rejection that the rest of the chain can articulate handling for.</p>
  523. <p>But I think a cleaner way of doing this is to use an <a href="https://blog.getify.com/not-awaiting-1/"><code>async function</code></a>, specifically in its <code>=&gt;</code> arrow-function IIFE form:</p>
  524. <pre class="code">
  525. async _=&gt;firstStep()()
  526. .then( .. )
  527. ..
  528. </pre>
  529. <p><strong>Note:</strong> <code>async function</code>s are a proposed addition to the JS standard, but have not officially landed. They are experimentally implemented in several major browsers, but as with all recent JS changes, you’ll likely be transpiling them, which is fully supported by Babel and others.</p>
  530. <p>The <code>async function</code> normalizes whatever comes back from the <code>firstStep()</code> function call into a promise, including catching any exception and turning it into a promise rejection.</p>
  531. <p>The small caveat here, different from using <code>Promise.resolve(..)</code> manually, is that the promise coming back from an <code>async function</code> is going to be a built-in native Promise, not some custom extended flavor. Use an additional <code>Promise.resolve(..)</code> or equivalent to cast it into a promise you’re happy with.</p>
  532. <h3 id="deconstruction">Deconstruction</h3>
  533. <p>When you construct a promise manually, the initialization function you pass to the constructor receives the capabilities for resolving that promise:</p>
  534. <pre class="code">
  535. var pr = new Promise( function init(resolve,reject){
  536. // call `resolve()` to fulfill the promise
  537. // or call `reject()` to reject it
  538. } );
  539. </pre>
  540. <p>By convention, we usually call those functions <code>resolve()</code> and <code>reject()</code>.</p>
  541. <p>Back before the standard for promises was finalized, there was a notion of these two capabilities — referred to collectively at the time as the <strong>deferred</strong> — being separately created from the promise they controlled.</p>
  542. <p>Imagine creating a promise more like this:</p>
  543. <pre class="code">
  544. var [ pr, def ] = new Promise();
  545. // call `def.resolve()` to fulfill the promise
  546. // or call `def.reject()` to reject it
  547. </pre>
  548. <p><strong>Note:</strong> FYI: <code>[pr,def] = ..</code> is utilizing the new <a href="https://github.com/getify/You-Dont-Know-JS/blob/master/es6%20&amp;%20beyond/ch2.md#destructuring">ES6 destructuring syntax</a>, specifically <strong>array destructuring</strong>.</p>
  549. <p>Having the promise and the deferred separated can seem quite useful in certain cases if the code that is doing this construction needs to transfer the resolution capabilities (deferred) to one part of the code and the observation capabilities (the promise) to another.</p>
  550. <p>For example:</p>
  551. <pre class="code">
  552. var [ pr, def ] = new Promise();
  553. // later:
  554. setupEvent( def.resolve, def.reject );
  555. // even later:
  556. handleEvent( pr );
  557. </pre>
  558. <p>Essentially, this approach treates a promise like a single-value event conduit. One part of the app holds the “write end” of the pipe, the <strong>deferred</strong>. Another part of the app holds the “read end”, the promise.</p>
  559. <p>Though the Promise API doesn’t work like this, it is possible to emulate, by <strong>extracting the resolution capabilities</strong>:</p>
  560. <pre class="code">
  561. function makePromise() {
  562. var def = {};
  563. var pr = new Promise( function init(resolve,reject){
  564. def.resolve = resolve;
  565. def.reject = reject;
  566. } );
  567. return [ pr, def ];
  568. }
  569. var [ pr, def ] = makePromise();
  570. </pre>
  571. <p>As you can see, we extract the <code>resolve()</code> and <code>reject()</code> capabilities from the promise initialization function storing them on <code>def</code>, then return both <code>pr</code> and <code>def</code> to the calling code.</p>
  572. <p>Undeniably, there are cases where this is quite convenient. I’ve done this many times myself.</p>
  573. <p>But I will assert that it’s an anti-pattern and that you should try to avoid it. At a minimum, if you have to do so, you should be hiding that kind of trick inside the plumbing of a library, not exposing the deferred and promise separately at the top level of logic in your application.</p>
  574. <p>If you agree with me that promise resolution extraction smells a little hackish, it’s because IMO we’re abusing a promise to act like a different kind of abstraction (that is already more well understood).</p>
  575. <h4 id="abstractions-for-value-communication">Abstractions For Value Communication</h4>
  576. <p>One way to envision this alternate, more well-suited abstraction is as an Event Emitter:</p>
  577. <pre class="code">
  578. var evt = new EventEmitter();
  579. // later:
  580. setupEvent( evt );
  581. // even later:
  582. handleEvent( evt );
  583. </pre>
  584. <p>Inside <code>setupEvent(..)</code>, we use <code>evt</code> to call <code>evt.emit(..)</code> to set an event of some name, and optionally pass along any data with that event. Inside <code>handleEvent(..)</code>, we call something like <code>evt.once(..)</code> to set up a single-occurring event listener for that pre-agreed event name.</p>
  585. <p>Either with promises (as shown earlier) or these Event Emitter events, we use a <strong>push</strong> model for communicating the value at the appropriate future time.</p>
  586. <p>But another way to abstract this problem is with a <strong>pull</strong> model. In other words, instead of the producer pushing the value once it’s ready, the consumer pulls the value when it’s ready to handle it.</p>
  587. <p>In my <a href="https://github.com/getify/asynquence">asynquence</a> library, I have an abstraction called “iterable sequences”, which is basically like an queue. You can add new handlers to the queue by calling <code>then(..)</code>, and then iterate through the queue using the standard <code>next()</code> iterator interface.</p>
  588. <p>For example:</p>
  589. <pre class="code">
  590. var isq = ASQ.iterable();
  591. isq
  592. .then( function(val){
  593. return val * 2;
  594. } )
  595. .then( function(val){
  596. return !!val;
  597. } )
  598. .then( function(val){
  599. return val.toUpperCase();
  600. } );
  601. isq.next( 21 ); // { value: 42, done: false }
  602. isq.next( false ); // { value: true, done: false }
  603. isq.next( "hello" ); // { value: "HELLO", done: false }
  604. isq.next(); // { done: true }
  605. </pre>
  606. <p>An <em>iterable sequence</em> is a different kind of abstraction that encapsulates both the resolution and observation capabilities into a single interface. We pass around that single abstraction wrapper instead of splitting up the promise and the deferred.</p>
  607. <p><strong>Note:</strong> By the way, that’s similar in nature to <a href="http://reactivex.io/documentation/subject.html"><em>Observable Subject</em>s</a>.</p>
  608. <p>Aside from custom library abstractions, we can use already built-in parts of JavaScript to create a <strong>pull</strong> abstraction directly. A generator can create a producer iterator:</p>
  609. <pre class="code">
  610. function *setupProducer() {
  611. var pr = new Promise(function(resolve,reject){
  612. setupEvent( resolve, reject );
  613. });
  614. yield pr;
  615. }
  616. var producer = setupProducer();
  617. </pre>
  618. <p>What’s going on here? We want an iterator that when we call <code>next()</code> on it, we’ll get back a value. But when we pull it, that value might not be ready yet. So instead, we yield a promise for that single next value that the producer will eventually produce. So the consumer is <strong>pulling</strong> (iterating) out each <strong>push</strong> instance (promise).</p>
  619. <p>Why is that different from the earlier promise capability extraction I called an anti-pattern? Because we’re not tracking the promise and its paired deferred separately at the top level of logic; we’ve hidden those as implementation details inside the <code>setupProducer()</code> generator.</p>
  620. <p>What we instead pass around is the wrapper around this capability: <code>producer</code>, which is an iterator. That’s a better abstraction that makes code easier to reason about. Tracking promises and their deferred capabilities separately is much harder to reason about in complex applications.</p>
  621. <p><strong>Note:</strong> The other advantage, though hard to see in this snippet, is that our generator/iterator could produce a new promise for each pull request, so we can use this conduit for communicating multiple values, instead of just once when there’s only a single promise involved. We get a new promise for each value.</p>
  622. <p>Here’s how we later <strong>pull</strong> a value:</p>
  623. <pre class="code">
  624. var pr = producer.next();
  625. pr.then( function(value){
  626. // ..
  627. } );
  628. </pre>
  629. <p>We call <code>next()</code> on our <code>producer</code> iterator, and we get out a promise, that we can then listen to.</p>
  630. <p>By the way, this notion of a generator that produces promises is not my own invention. There’s currently <a href="https://github.com/tc39/proposal-async-iteration#asynchronous-iterators-for-ecmascript">a proposal to add a new primitive</a> to JavaScript called an “async generator”. It basically does what I just sketched out: it gives an iterator that returns a new promise each time it is <code>next()</code> iterated.</p>
  631. <p>These various abstractions are far better suited for modeling the transmission of a value asynchronously from one part of the application to another. Promises have to be twisted and contorted to serve that purpose.</p>
  632. <p>Don’t do it just because you <em>can</em> do it. Promises shouldn’t be used that way, at least not visibly to your main application code.</p>
  633. <h3 id="promise-side-effects">Promise Side-Effects</h3>
  634. <p>Promises are, at their most core, a model for values. The fact that we use functions with the Promise API as the vehicle for unwrapping those values is an unfortunate temptation trap we can too easily fall into.</p>
  635. <p>Functional programming practices implore us to rely on value immutability for easier to reason about code, as well as using functions without side-effects (aka, pure). But it’s all too common that promises are used in very non-FP-friendly ways. Specifically, it’s far too common to either create or rely on side-effects with the functions passed to promise methods.</p>
  636. <p>The first kind of common side-effect is relative sequencing between multiple promises.</p>
  637. <p>Consider:</p>
  638. <pre class="code">
  639. firstStep()
  640. .then( secondStep )
  641. .then( function(){
  642. console.log( "two" );
  643. } );
  644. firstStep()
  645. .then( function(){
  646. console.log( "one" );
  647. } );
  648. </pre>
  649. <p>What order do you think those two console messages are printed? Almost certainly in “one”, “two” order, right? Almost. It’s actually possible that the second invocation of the <code>firstStep()</code> function will produce a promise that isn’t resolved until after the <code>secondStep()</code> promise is finished, resulting in “two”, “one” order.</p>
  650. <p>If you author code like this, what you’re saying is, “I believe I can predict the relative ordering of asynchronous activity, and rely on that for my application.” Unfortunately, you’re the only one; noone else who reads your code will be able to do so to the same effective extent. 🙁</p>
  651. <p>Another example:</p>
  652. <pre class="code">
  653. Promise.resolve().then( function(){
  654. console.log( "two" );
  655. } );
  656. console.log( "one" );
  657. </pre>
  658. <p>The console here will always print “one”, “two”, because we’re taking advantage of our knowledge that a <code>then(..)</code> handler will always be run asynchronously.</p>
  659. <p>By “run asynchronously”, we mean strictly after the current synchronous execution context, but we don’t actually mean on the next tick of the event loop, like with a <code>setTimeout(..0)</code> type of asynchrony:</p>
  660. <pre class="code">
  661. setTimeout( function(){
  662. console.log( "three" );
  663. }, 0 );
  664. Promise.resolve().then( function(){
  665. console.log( "two" );
  666. } );
  667. console.log( "one" );
  668. </pre>
  669. <p>In a conforming/native implementation, this snippet will always print “one”, “two”, “three”, because the “two” console message function is on the microtask queue to be run at the end of the snippet (after the “one” console message), but the <code>setTimeout(..0)</code> schedules the “three” message on the next event loop tick.</p>
  670. <p>As intrictate as this situation is, I’ve seen plenty of code that <strong>relies on</strong> the relative sequencing of these types of actions, even with multiple promises:</p>
  671. <pre class="code">
  672. Promise.resolve().then( function(){
  673. console.log( "one" );
  674. } );
  675. Promise.resolve().then( function(){
  676. console.log( "two" );
  677. } );
  678. </pre>
  679. <p>The specification doesn’t explicitly require “one”, “two” sequencing here. However, in practice, it’ll probably happen that way, because there will probably only be one internal microtask queue that those two separate <code>then(..)</code> actions are scheduled onto, in first-come-first-served order.</p>
  680. <p>While you might be able to rely on this as an implementation detail, I think these kinds of tricks are an absolutely terrible idea.</p>
  681. <p>If there’s some dependency between the actions, then express it directly — do <strong>not</strong> rely on perceived behaviors or async microtask processing. Even if the code “works”, you’ve written <strong>entirely un-reason-able code</strong>, as future readers will almost certainly not be able to intuit those same implied sequencing relationships.</p>
  682. <p>Inter-promise sequencing may or may not be guaranteed in any given scenario, but one thing that <em>is</em> guaranteed is that relying on this behavior makes your code worse. Don’t do it!</p>
  683. <h4 id="construction-sequencing">Construction Sequencing</h4>
  684. <p>Another place where this sequencing side-effects thing is often seen is with the <code>Promise(..)</code> constructor.</p>
  685. <p>The idea is to take advantage of the knowledge that the initialization function you pass in is <strong>synchronously</strong> executed, even though the other parts of the Promise API (like the handlers you pass to <code>then(..)</code>) execute those functions <strong>asynchronously</strong>.</p>
  686. <p>We already saw this illustrated earlier when we discussed the capability extraction.</p>
  687. <p>For example:</p>
  688. <pre class="code">
  689. var fn;
  690. var pr = new Promise( function init(resolve){
  691. fn = resolve;
  692. } );
  693. fn( 42 );
  694. </pre>
  695. <p>We <em>know</em> we can call <code>fn()</code> right away because we know the <code>init(..)</code> function is executed synchronously by the Promise constructor.</p>
  696. <p>I’m asserting that this is a <strong>bad idea</strong> to exploit this sort of semantic in your normal application code alongside other <code>then(..)</code> function calls, since those are always asynchronous. Having both sync and async behaviors mixed together makes the code harder to understand.</p>
  697. <p>The above snippet is equivalent to just:</p>
  698. <pre class="code">
  699. var pr = Promise.resolve( 42 );
  700. </pre>
  701. <p>I’m not saying to avoid the Promise constructor. But don’t use it as a synchronous side-effect producing function — specifically, relying on the sequencing of the side effects — if you can at all avoid it.</p>
  702. <h4 id="scopes">Scopes</h4>
  703. <p>Another pattern that seems to crop up is the sharing of values across scopes via side-effects, to get around the fact that promises only model/fulfill single values.</p>
  704. <p>Consider:</p>
  705. <pre class="code">
  706. function getOrderDetails(orderID) {
  707. var _order;
  708. return db.find( "orders", orderID )
  709. .then( function(order){
  710. _order = order;
  711. return db.find( "customers", order.customerID )
  712. } )
  713. .then( function(customer){
  714. _order.customer = customer;
  715. return _order;
  716. } );
  717. }
  718. </pre>
  719. <p>What’s going on here? We first make a <code>db.find("orders" ..)</code> call, which gives us the <code>order</code>. We not only need that to get <code>order.customerID</code> for the <code>db.find("customers" ..)</code> call, but we’ll also need <code>order</code> for the final result of our <code>getOrderDetails(..)</code> operation.</p>
  720. <p>But the second <code>then(..)</code> will receive the result of the <code>db.find("customers" ..)</code> call, which will not pass along the <code>order</code> value as part of its result. So, it seems we have to save it somewhere, which we choose to do with an outer <code>_order</code> variable that’s shared across scopes. When the second <code>then(..)</code> handler runs, <code>_order</code> will still be available for us to use.</p>
  721. <p>Don’t kid yourself: <strong>this is side-effect programming</strong>. <code>_order</code> is a side-effect of the first <code>then(..)</code>. We are crippled by the limitations of the Promise API mechanics and can’t share the state with the next step, so we just stick that state in an outer scope to share it.</p>
  722. <p>This is a bad idea. I don’t care how many times you’ve done this or how acceptable you think it is. <strong>It’s an anti-pattern code smell</strong>. Stop programming side-effects with your promises. It makes your code harder to reason about.</p>
  723. <p>I know how allergic many developers seem to be with respect to nesting, but the more appropriate way to handle this case is to nest the second <code>then(..)</code> in the scope where <code>order</code> still exists, as shown here:</p>
  724. <pre class="code">
  725. function getOrderDetails(orderID) {
  726. return db.find( "orders", orderID )
  727. .then( function(order){
  728. return db.find( "customers", order.customerID )
  729. // nested `then()` instead of flattened to outer chain,
  730. // so that we still have lexical scope access to `order`
  731. .then( function(customer){
  732. order.customer = customer;
  733. return order;
  734. } );
  735. } );
  736. }
  737. </pre>
  738. <p>Normally, nesting promise <code>then(..)</code>s is a bad idea, and even goes by the name “promise hell”.</p>
  739. <p>But in these cases where multiple values need to be available (in scope), a flattened vertical promise chain necessitates the worser evil of side-effects. Promise nesting is the better choice.</p>
  740. <h3 id="promise-chainitis">Promise Chain’itis</h3>
  741. <p>A promise models a value that may still be pending. The purpose is to factor time out of the picture so that you only have to think about the value and what you need to do with it — not the <em>time</em> you have to wait until it’s ready.</p>
  742. <p>The problem is that the mechanics of how promises work in JS means that the finalizing of a value is observable — you can tell when it happens. Though you shouldn’t be thinking about time, promises let you still think about time if you want to, and many people do it too much.</p>
  743. <p>The most obvious way we use our knowledge of when a promise resolves is to use this observation as a step in a flow control. For example:</p>
  744. <pre class="code">
  745. firstStep()
  746. .then( secondStep )
  747. .then( thirdStep );
  748. </pre>
  749. <p>Here, what we’re saying with the promise chain is that we want to delay the execution of the <code>secondStep()</code> function until after <code>firstStep()</code> has finished. You’ll notice that nothing here makes it obvious that we’re using a promise as a placeholder for a <em>future value</em>. Instead, we’re using promises kind of like event handlers to let us know when each step finishes.</p>
  750. <p>I used to be enormously excited about promise chains as flow control. But the longer I’ve programmed with promises, the more I’ve realized that long promise chains are actually a bad smell. I’ve almost come to the point where I’d say there should only ever be one <code>then(..)</code> in the chain. Using promise chains as a way to express flow control is a poor idea.</p>
  751. <p>Yes, yes, I know that <strong>literally almost everybody is doing this</strong>. Doesn’t matter, they’re all wrong.</p>
  752. <p>So, what should we do to express our multi-step flow control? Go back to nested callbacks? No.</p>
  753. <p>Use the <strong>synchronous-async pattern</strong>. If you’re not familiar, I’ve talked about this pattern in detail in several places, including:</p>
  754. <p>To boil this down, using either generators (with a runner), or <code>async function</code>s, we get the ability to express fundamentally asynchronous code in a synchronous fashion. This sync semantic works not only for success flow control but also error handling (ie, <code>try..catch</code>).</p>
  755. <p>Here’s how the previous promise-chain flow control code should be written:</p>
  756. <pre class="code">
  757. async function main() {
  758. await firstStep();
  759. await secondStep();
  760. await thirdStep();
  761. }
  762. // or:
  763. function *main() {
  764. yield firstStep();
  765. yield secondStep();
  766. yield thirdStep();
  767. }
  768. </pre>
  769. <p>We’re still relying on the fact that each step returns a promise, and we’re still waiting on each promise to resolve before moving onto the next step.</p>
  770. <p>Unfortunately, with these examples we’re missing not only articulation of the result values but also of any error handling. A bit more of a realistic example:</p>
  771. <pre class="code">
  772. async function main() {
  773. try {
  774. var val1 = await firstStep();
  775. var val2 = await secondStep( val1 );
  776. var val3 = await thirdStep( val1, val2 );
  777. console.log( "Final: ", val3 );
  778. }
  779. catch (err) {
  780. console.error( err );
  781. }
  782. }
  783. </pre>
  784. <p>This example clearly illustrates how we are using synchronous code semantics to express the async flow control (success and exception).</p>
  785. <p>Under the covers, something similar to the earlier chain, but not the same, is happening. <code>firstStep()</code> produces a promise, which is then <code>await</code>ed. That means, hidden from view, the engine puts a <code>then(..)</code> on it and waits for it to finish before resuming the paused <code>main()</code> function. It also unwraps the promise’s fulfillment value and gives it back so we can assign it to <code>val1</code>.</p>
  786. <p>When the <code>await</code> is called on the promise from the <code>secondStep(..)</code> call, it’s performing a <code>then(..)</code> against <em>that</em> promise, <strong>not</strong> the one that came from the <code>then(..)</code> called on the first. And so on.</p>
  787. <p>It may seem like pointless nuance, but that’s not the same thing as chaining one <code>then(..)</code> after another. It’s treating, explicitly, each step as a separate promise/<code>then(..)</code> pair.</p>
  788. <p>Conceptually that’s a much cleaner and easier to understand process than what happens when promises are chained multiple times. If you’ve ever tried to understand just how a promise chain is wired up, or explain it to someone else, you’ll know it’s not so simple. I won’t belabor those details here, but I’ve <a href="https://blog.getify.com/promises-part-5/#the-chains-that-bind-us">previously explained it in more detail</a> if you care to dig into it.</p>
  789. <p>The sync-async pattern above wipes away any of that unnecessary complexity. It also conveniently hides the <code>then(..)</code> calling altogether, because truthfully, that part is a wart. The <code>then(..)</code> on a promise is an unfortunate but necessary component of the Promise API design that was settled on for JS.</p>
  790. <p>I assert that, for the most part, we should try not to ever call <code>then(..)</code> explicitly. As much as possible, that should stay hidden as an implementation detail.</p>
  791. <p>Calling <code>then(..)</code> on a promise is a <strong>code smell and anti-pattern</strong>.</p>
  792. <p>I’m sure you’ve heard the admonition of “use the right tool for the job.” To put a slight twist on that, here the problem is more about using a tool inappropriately. It’s like if you held a hammer in your teeth and tried to drive in a nail. A hammer is better used if held in your hand.</p>
  793. <p>Instead of using the promise API for expressing async flow control, we should only use promises for what they’re good for: modeling future values in a time independent way. Sure, promises <em>can</em> be chained together. No, <strong>you shouldn’t be doing that</strong>. Let libraries and engines do the plumbing for you.</p>
  794. <p>There’s a better tool for the job of expressing flow control: the sync-async pattern of generators+promises or <code>async function</code>s.</p>
  795. <h3 id="summary">Summary</h3>
  796. <p>Summing up, using promises outside of the main notion of modeling a future value independent of time is probably wandering towards anti-patterns.</p>
  797. <p>Promises are powerful and transformative, but I urge you to take a step back and re-examine how you’re relying on them. They are best as a value/composition mechanism. Use them as such and stay away from all the wrong ways.</p>
  798. </article>
  799. </section>
  800. <nav id="jumpto">
  801. <p>
  802. <a href="/david/blog/">Accueil du blog</a> |
  803. <a href="https://blog.getify.com/promises-wrong-ways/">Source originale</a> |
  804. <a href="/david/stream/2019/">Accueil du flux</a>
  805. </p>
  806. </nav>
  807. <footer>
  808. <div>
  809. <img src="/static/david/david-larlet-avatar.jpg" loading="lazy" class="avatar" width="200" height="200">
  810. <p>
  811. Bonjour/Hi!
  812. 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>
  813. 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>).
  814. </p>
  815. <p>
  816. 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>.
  817. </p>
  818. <p>
  819. Voici quelques articles choisis :
  820. <a href="/david/blog/2019/faire-equipe/" title="Accéder à l’article complet">Faire équipe</a>,
  821. <a href="/david/blog/2018/bivouac-automnal/" title="Accéder à l’article complet">Bivouac automnal</a>,
  822. <a href="/david/blog/2018/commodite-effondrement/" title="Accéder à l’article complet">Commodité et effondrement</a>,
  823. <a href="/david/blog/2017/donnees-communs/" title="Accéder à l’article complet">Des données aux communs</a>,
  824. <a href="/david/blog/2016/accompagner-enfant/" title="Accéder à l’article complet">Accompagner un enfant</a>,
  825. <a href="/david/blog/2016/senior-developer/" title="Accéder à l’article complet">Senior developer</a>,
  826. <a href="/david/blog/2016/illusion-sociale/" title="Accéder à l’article complet">L’illusion sociale</a>,
  827. <a href="/david/blog/2016/instantane-scopyleft/" title="Accéder à l’article complet">Instantané Scopyleft</a>,
  828. <a href="/david/blog/2016/enseigner-web/" title="Accéder à l’article complet">Enseigner le Web</a>,
  829. <a href="/david/blog/2016/simplicite-defaut/" title="Accéder à l’article complet">Simplicité par défaut</a>,
  830. <a href="/david/blog/2016/minimalisme-esthetique/" title="Accéder à l’article complet">Minimalisme et esthétique</a>,
  831. <a href="/david/blog/2014/un-web-omni-present/" title="Accéder à l’article complet">Un web omni-présent</a>,
  832. <a href="/david/blog/2014/manifeste-developpeur/" title="Accéder à l’article complet">Manifeste de développeur</a>,
  833. <a href="/david/blog/2013/confort-convivialite/" title="Accéder à l’article complet">Confort et convivialité</a>,
  834. <a href="/david/blog/2013/testament-numerique/" title="Accéder à l’article complet">Testament numérique</a>,
  835. et <a href="/david/blog/" title="Accéder aux archives">bien d’autres…</a>
  836. </p>
  837. <p>
  838. 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>.
  839. </p>
  840. <p>
  841. Je ne traque pas ta navigation mais mon
  842. <abbr title="Alwaysdata, 62 rue Tiquetonne 75002 Paris, +33.184162340">hébergeur</abbr>
  843. conserve des logs d’accès.
  844. </p>
  845. </div>
  846. </footer>
  847. <script type="text/javascript">
  848. ;(_ => {
  849. const jumper = document.getElementById('jumper')
  850. jumper.addEventListener('click', e => {
  851. e.preventDefault()
  852. const anchor = e.target.getAttribute('href')
  853. const targetEl = document.getElementById(anchor.substring(1))
  854. targetEl.scrollIntoView({behavior: 'smooth'})
  855. })
  856. })()
  857. </script>