summaryrefslogtreecommitdiffstats
path: root/2021/talks/form.md
blob: 9128c8b334f8a7ac4b9d77218a74ad48dac3465e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
[[!meta title="Old McCarthy Had a Form"]]
[[!meta copyright="Copyright © 2021 Ian Eure"]]
[[!inline pages="internal(2021/info/form-nav)" raw="yes"]]

<!-- You can manually edit this file to update the abstract, add links, etc. --->


# Old McCarthy Had a Form
Ian Eure



Name Pronunciation: (EE-un YOU-r)

Pronouns: he/him/his

Preferred contact info: ian@retrospec.tv / ieure on Libera

[[!inline pages="internal(2021/info/form-schedule)" raw="yes"]]

Most practical languages are multi-paradigm, offering several
abstractions for the programmer.  But did you know that Emacs Lisp
comes with a powerful system for object-oriented programming? Join me
for a discussion of EIEIO, and learn how it can help you write more
modular, flexible Emacs Lisp.

# Discussion

IRC nick: ieure

-   Q2: AFAIK, EIEIO is generally slower than, e.g. cl-defstructs.  When
    do you think EIEIO is not suitable for performance reasons?
    -   A: I agree with Dmitry: first make it work, then make it fast. 
        I don't think there's a blanket reason not to use EIEIO, but
        definitely profile if you're using it in a performance-critical
        context.  EXWM is one project that uses EIEIO extensively and
        seems to perform well, so I don't think it's off-limits for
        performance-critical code.
-   Q3: Do you have any tips about introspection?  e.g. IIRC there's an
    EIEIO introspection facility, though it may be somewhat primitive.
    -   A: It is somewhat primitive, but seems to work okay
        (<https://www.gnu.org/software/emacs/manual/html_node/eieio/Introspection.html)>. 
        I haven't found a need for anything fancier (yet).
-   Q4: Have you used any of the EIEIO-related serialization tools? 
    IIRC there are some limitations with regard to printable/readable
    values.
    -   A: I haven't had call for this, but
        <https://www.gnu.org/software/emacs/manual/html_mono/eieio.html#eieio_002dpersistent>
        is the mechanism (for anyone wondering)
-   Q5: I did not get how generic functions can work with non class
    objects
    -   A: Dynamic dispatch is very powerful!
-   Q6:So with that Emacs is on pair with Smalltalk development
    environments now (?)
    -   A: Not very familiar
-   Q7: Most of what you presented can be done without `defclass`. 
    AFAICT, the only exception is *multiple* inheritance (since
    `cl-defstruct` also supports single inheritance via `:include`).
    -   A: Yes, you can mix and match structs/objects or any other
        type.  You need classes if you want the EIEIO customization
        editing facility or MI.  I think also `initialize-instance` is
        class-only, so you need classes if you have to do some kinds of
        complex (cross-slot) initializtaion.

- I didn't know that custom.el works with EIEIO that way, very nice
- Dang Ian. What a talk, great demos.
- Wow, that's a great talk.
- Great talk. So with that Emacs is on pair with Smalltalk development environments now
- For reference, transient.el, which we all know and love as the engine that drives the magit interface, is written via EIEIO afaik.
- I reckon I should look more into it, I've always avoided it because I was afraid it wouldn't be /quite as nice/ as CLOS or GOOPS.
  - ieure: It's missing a few things (most documented in the manual: https://www.gnu.org/software/emacs/manual/html_mono/eieio.html#CLOS-compatibility), but it's solid and worth using.
    - Yeah when transient.el first came out I was impressed by how naturally it worked as part of that abstraction.
- ieure: EIEIO all the things!  I had to cut it, but you can use dynamic dispatch based on major-mode, like: (cl-defmethod whatever ((mode (derived-mode python-mode)))) and then (whatever major-mode).

- Also really nice for things like 'window-system.  I really like when callsites are clean and not cluttered with conditionals.
- Can eieio do regexp dispatch? 
  - ieure: Not currently, but it's possible to add.
  - okay, so I don't need to feel too bad about coding up my own vtable for those then
  - ieure: This is the thing that implements (thing (eql :whatever)) specialization, should be a good starting point if you want (thing (string-match-p "^foo")): <https://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/emacs-lisp/cl-generic.el#n1164>
  - thanks for the pointer, but I think I have some more pressing cl-defgeneric reimplementations to make before I touch that
  - ieure: Extremely fair.  One thing I didn't get to touch on is that you can extend generic functions from anywhere.  So you don't have to patch up cl-generic.el, you can define a new method for a generic function defined anywhere, in any file.  Which rules.
-  This is not a question: Brilliant title for the presentation. :)

Links:

-  <https://www.gnu.org/software/emacs/manual/html_mono/eieio.html>
# Outline

-  What is EIEIO?
-  Why OOP?
-  The CLOS Model
    -  Classes
    -  Generic Functions
    -  Methods
    -  Specialization
    -  Method Qualifiers
    -  Multiple Inheritance
    -  Nice Properties
-  Practical Examples
    -  Encapsulation
        -  Example: `transmission.el`
    -  Abstraction
        -  Example: `sql.el`
    -  Extensibility
        -  Example: comint
-  Conclusion


[[!inline pages="internal(2021/captions/form)" raw="yes"]]

[[!inline pages="internal(2021/info/form-nav)" raw="yes"]]