Skip to content

Commit c0e9561

Browse files
author
doyougnu
committed
prelim: fix poor domain modeling, intro section
fixes: haskellfoundation#77
1 parent 1c90e2c commit c0e9561

File tree

1 file changed

+48
-30
lines changed

1 file changed

+48
-30
lines changed

src/Preliminaries/what_makes_fast_hs.rst

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ The Programs of Consistent Lethargy
44
===================================
55

66
We'll begin by showing small bite sized programs that demonstrate a particular
7-
way Haskell programs slow down. We call these programs *canonical* programs
7+
way Haskell programs can slow down. We call these programs *canonical* programs
88
because each program is the smallest example of a kind of slow down. A reader
9-
should come away from this section with an understanding of the ways a
10-
Haskell program slows down. For each slow down topic we provide a sister
11-
12-
9+
should come away from this section with an understanding of the ways a Haskell
10+
program slows down. This chapter is just to small tour; for each slow down topic
11+
we provide a sister chapter that explores the topic in more detail.
1312

1413
.. _canonical-inlining:
1514

@@ -69,7 +68,6 @@ particulars of GHC's inliner, in the chapter dedicated to :ref:`Inlining
6968
<Inlining Chapter>`.
7069

7170

72-
7371
.. _canonical-fusion:
7472

7573
Fusion
@@ -239,6 +237,7 @@ This pragma instructs GHC to store the contents of ``Int`` directly in the
239237
``Counter`` constructor, rather than storing a pointer to an ``Int`` on the heap
240238
in the constructor. We'll return to these fixes in the :ref:`Unboxing` chapter.
241239

240+
242241
.. _canonical-closure-alloc:
243242

244243
Excessive Closure Allocation
@@ -364,19 +363,39 @@ What is Poor Domain Modeling
364363
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
365364

366365
Poor domain modeling is a catch all phrase for constructing a program that has a
367-
high impedance to the problem domain. The problem domain dictates the
368-
computation that the program must do; it requires specific actions that abide by
369-
specific invariants, if those actions are hard to express, and those invariants
370-
hard to abide by, then you have a high impedance between the problem domain and
371-
the program domain. Obviously this is problem specific and we cannot provide a
372-
canonical example, instead we'll provide a set of guidelines to describe when
373-
you know you have high impedance and how to fix it.
366+
high impedance to the problem domain. The problem domain is the abstract domain
367+
that dictates the computation that the program must do, the logical sequence of
368+
steps it must take and the invariants it must uphold. The program domain is the
369+
implementation, it is the code that is tasked with performing the computation
370+
and upholding the invariants in the problem domain. This is a one-to-many
371+
relationship; for any given problem domain there are many possible
372+
implementations.
373+
374+
For example, imagine our task is to implement a program that sorts some data. We
375+
can list the concepts, invariants and properties this problem domain specifies:
376+
the domain has the concepts of a datum; which is a single unit of information, a
377+
partial order on that data; there are many sequences of data, but for a given
378+
set of data only two sequences have the property sorted, a datum must have an
379+
ordinal property; or else we would not be able to sort, and the sorted
380+
invariant; that defines what the property sorted means: for a sort from low to
381+
high, a given datum that is less than another datum must precede the greater
382+
datum in the output sequence. Note that every possible implementation must
383+
somehow represent and abide by these ideas for the program to be considered
384+
correct and for the implementation to be considered an implementation at all.
385+
386+
Therefore poor domain modeling occurs when the implementation makes it difficult
387+
to express the computation, properties and invariants required by the problem
388+
domain. If this is the case then we say there is a high impedance between the
389+
problem domain and the program domain. Obviously this is problem specific and we
390+
cannot provide a canonical example, instead we'll provide a set of guidelines to
391+
describe when you know you have high impedance and how to fix it.
374392

375393

376394
How do I know if I have Poor Domain Modeling
377395
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
378396

379-
Unfortunately, this is more art than science. Classic indications are:
397+
Unfortunately, this is more art than science. Classic indications in Haskell
398+
are all instances of the implementation doing more work than is necessary:
380399

381400

382401
Overuse of Data.List
@@ -398,27 +417,26 @@ entire list in order to produce a result:
398417
#. any kind of indexing
399418

400419
Recall that lists in Haskell are streams; not treating them as such creates
401-
impedance between the problem domain and your program in addition to
402-
degrading runtime performance (and easily creating a quadratic time program).
403-
However, small temporary lists holding single digits of elements are fine
404-
because they take less time to construct and traverse than a more complicated
405-
data structure.
420+
impedance between the problem domain and your program in addition to degrading
421+
runtime performance (and easily creating a quadratic time program). However,
422+
small temporary lists holding single digits of elements are fine because they
423+
take less time to construct and traverse than more complicated data structures.
406424

407425
Functions in your Program Domain do not Easily Compose to have Meaning in your Problem Domain
408426
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
409427

410428
Composition and composability is one of the most valuable properties code can
411-
have. It is key to modularity, key to reuse, is easier to test, is easier to
412-
understand and often produces more compact code. When the functions in your
413-
program domain do not easily compose you'll often find yourself constantly
414-
packing, unpacking, and repacking domain elements just to get anything done.
415-
You'll be forced to reach into the *implementation* of objects in your program
416-
domain in order to express meaning in your problem domain, rather than
417-
expressing that meaning through functions.
418-
419-
When the program domain lacks composability functions will become overly large
420-
and overly concerned with implementation details; *that* is high impedence
421-
expressing itself in the program domain.
429+
have. It is key to modularity, key to reuse, creates code that is easier to
430+
test, is easier to understand and is often more compact code. When the functions
431+
in your program domain do not easily compose you'll often find yourself
432+
constantly packing, unpacking, and repacking domain elements just to get
433+
anything done. You'll be forced to reach into the *implementation* of objects in
434+
your program domain in order to express meaning in your problem domain, rather
435+
than expressing that meaning through functions.
436+
437+
When the program domain lacks composability, functions will become overly large
438+
and overly concerned with implementation details; *that* is high impedance
439+
expressing itself in the implementation.
422440

423441
.. todo::
424442
Need example as case study see `#20 <https://github.com/input-output-hk/hs-opt-handbook.github.io/issues/20>`_

0 commit comments

Comments
 (0)