Skip to content

Commit fc41f3d

Browse files
committed
flattened sections in other paradigms chapter
Signed-off-by: Konstantin Läufer <laufer@cs.luc.edu>
1 parent 92d469b commit fc41f3d

1 file changed

Lines changed: 21 additions & 24 deletions

File tree

source/75-otherparadigms.rst

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,30 @@ Dataflow programming models programs as a directed graph of the data flowing bet
159159
result = add(tf.constant(2), tf.constant(3))
160160
print(result) # tf.Tensor(5, shape=(), dtype=int32)
161161
162-
Other Paradigms
163-
~~~~~~~~~~~~~~~
164162
165-
There are several other paradigms worth noting:
163+
Event-driven Programming
164+
~~~~~~~~~~~~~~~~~~~~~~~~
165+
166+
Event-driven programming drives computation through events (user interactions, messages, timers) and callbacks. It is the dominant model in UI frameworks and server-side I/O (Node.js):
167+
168+
.. code-block:: javascript
169+
170+
// Node.js HTTP server: execution is driven by incoming request events
171+
const http = require('http');
172+
const server = http.createServer((req, res) => {
173+
res.end('Hello, world!');
174+
});
175+
server.listen(3000);
176+
177+
// Browser: UI event drives a callback
178+
document.querySelector('button')
179+
.addEventListener('click', () => alert('Button clicked!'));
180+
181+
Event-driven programming is closely related to the reactive paradigm (see above), with the key difference that reactive programming typically provides composable operators (``map``, ``filter``, ``merge``) over streams of events, whereas plain event-driven code uses ad-hoc callbacks.
182+
166183

167184
Constraint Programming
168-
``````````````````````
185+
~~~~~~~~~~~~~~~~~~~~~~
169186

170187
Constraint programming extends logic programming by allowing variables to be constrained over a domain (e.g., integers, reals, finite sets) and using specialised solvers to find solutions. SWI-Prolog's ``clpfd`` library is a widely used constraint solver:
171188

@@ -184,23 +201,3 @@ Constraint programming extends logic programming by allowing variables to be con
184201
% X = 1, Y = 9 ; X = 2, Y = 8 ; ...
185202
186203
See also the discussion of Prolog and backtracking in :doc:`/70-logic`.
187-
188-
Event-driven Programming
189-
````````````````````````
190-
191-
Event-driven programming drives computation through events (user interactions, messages, timers) and callbacks. It is the dominant model in UI frameworks and server-side I/O (Node.js):
192-
193-
.. code-block:: javascript
194-
195-
// Node.js HTTP server: execution is driven by incoming request events
196-
const http = require('http');
197-
const server = http.createServer((req, res) => {
198-
res.end('Hello, world!');
199-
});
200-
server.listen(3000);
201-
202-
// Browser: UI event drives a callback
203-
document.querySelector('button')
204-
.addEventListener('click', () => alert('Button clicked!'));
205-
206-
Event-driven programming is closely related to the reactive paradigm (see above), with the key difference that reactive programming typically provides composable operators (``map``, ``filter``, ``merge``) over streams of events, whereas plain event-driven code uses ad-hoc callbacks.

0 commit comments

Comments
 (0)