Skip to content

Commit f6d69af

Browse files
authored
Editing coding style (#1950)
It seems that a couple of years ago the maintainers had a bit of fun with ChatGPT to help them write the guidelines of the library. Some of these gpt-isms are quite embarrassing. With this pull request, I hope to correct some past mistakes.
1 parent 15e6ccb commit f6d69af

2 files changed

Lines changed: 67 additions & 65 deletions

File tree

docs/CODINGSTYLE.md

Lines changed: 54 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,61 @@
1-
# The agda-unimath library style guide
2-
3-
The agda-unimath library is an ever-expanding encyclopedia of formalized
4-
mathematics from a univalent point of view. The library's corresponding website
5-
serves as an extensive platform, presenting our work in a structured,
6-
encyclopedia-like format.
7-
8-
The coding and style conventions we've established aren't simply rules; they're
9-
tools for us to shape and nurture this resource. They ensure that the formalized
10-
definitions are clean and focused, and ready for reuse across the library,
11-
thereby weaving each contribution into a bigger tapestry.
12-
13-
Conceptual clarity and readability are the core values of our formalization
14-
project. This style guide aims to help contributors write code that is both
15-
functional and understandable, as well as easily maintainable. Please reach out
16-
to us if you have any questions or remarks about the agda-unimath style, or need
17-
any help getting started with your formalization project. Our code, and also
18-
this guide, are open to refinement to best support our community and the
19-
project's goals.
1+
# The agda-unimath library coding style guide
2+
3+
The agda-unimath library is an ever-expanding library of formalized mathematics
4+
from a univalent point of view. Agda-unimath stands as the largest library of
5+
formalized mathematics in the Agda proof assistant, covering a broad range of
6+
mathematical subjects. The library's corresponding website displays the
7+
formalization pages in a markdown book, with over 3000 separate pages as of
8+
May 2026.
9+
10+
In this coding style guide we will outline some of the design principles of
11+
these pages. The purpose of these principles is to create a clean framework
12+
through which we present our work, and to ensure good maintainability and
13+
reusability of the code. A core value of our formalization project is conceptual
14+
clarity and readability. We hope that with this style guide, we are able to help
15+
new contributors write code that is both functional and understandable, as well
16+
as easily maintainable.
17+
18+
Please reach out to us on [Discord](https://discord.gg/Zp2e8hYsuX) if you have
19+
any questions or remarks about the agda-unimath style, or need any help getting
20+
started with your formalization project.
2021

2122
## Code structuring conventions
2223

23-
The agda-unimath library is a comprehensive collection of formalized mathematics
24-
spanning a broad range of subjects. All fields of mathematics are inherently
25-
interlinked, which we leverage in our formalization process.
26-
2724
One critical aspect of maintaining such a large codebase lies in efficient and
2825
strategic code structuring, and continued refactoring, into small, reusable
2926
entries. In line with this approach, we aim to factor out and encapsulate even
3027
the tiniest bits of reusable logic or computation in their own definitions.
3128

32-
Here are the benefits of this approach:
33-
34-
- **Simplicity**: Breaking down complex structures into smaller ones simplifies
35-
the overall codebase, making it more accessible to new contributors.
36-
37-
- **Reusability**: Once a particular logic or computation is formalized, it can
38-
be reused in multiple places, thereby avoiding redundancy and promoting
39-
efficiency.
40-
41-
- **Cleanliness**: By separating reusable logic from proof constructions, we
42-
keep our proofs clean and focus only on the essential parts of the argument.
43-
44-
- **Demonstrability**: Well-structured code serves as a practical guide on how
45-
to use prior parts of the library in the current setting or in new
46-
definitions.
47-
48-
- **Maintainability**: When logic is broken down into separate, reusable pieces,
49-
it becomes easier to manage and maintain the codebase. Constructions that are
50-
broken down into small definitions are much easier to understand. This also
51-
makes the project more scalable.
52-
53-
- **Reliability**: While formally verified code is guaranteed to be "correct" in
54-
terms of its internal logic, it doesn't necessarily ensure that a mathematical
55-
concept is accurately modeled within Agda. By proving properties, reusing
56-
existing implementations in manners that mirror the expectations of
57-
mathematicians, and by tightly integrating them with the rest of the library,
58-
we create more opportunities to use and confirm the fidelity of these
59-
implementations. This process bolsters confidence in their correctness and the
60-
overall reliability of the library.
61-
62-
In essence, our code structuring conventions are guided by the goal of ensuring
63-
that our code remains as conceptually clear and as understandable as possible.
64-
Finally, a maintainable codebase is a welcoming codebase. By ensuring that the
65-
agda-unimath code is easy to understand and navigate, new contributors can more
66-
readily participate in the project. This is crucial for the growth and dynamism
67-
of the agda-unimath community. It allows a diverse group of developers, each
68-
with their unique skills and perspectives, to contribute to the project's
69-
ongoing success.
70-
71-
So, in particular, refactoring isn't just about "cleaning up" the code; it's a
72-
strategic endeavor to ensure the longevity, vitality, and success of the
73-
agda-unimath project.
29+
### Small entries with simple structure
30+
31+
In the agda-unimath library, we have some, but very few long entries. Indeed, it
32+
has been remarked upon that most of our code looks like boiler-plate code. This
33+
is by design. By breaking down entries into small and simple entries, we make
34+
the library easier to maintain in several ways: Faster compilation; cleaner
35+
appearance; the code will break less, or less severely, if definitions are
36+
changed. Moreover, by factoring parts out of a proof or construction, they
37+
become elements of the recorded knowledge base of agda-unimath.
38+
39+
Other obvious benefits of refactoring your code into small parts is that these
40+
parts thereby become reusable across the library. Work that is properly
41+
refactored is more easily understood and used by others, which is ultimately
42+
what it's all about!
43+
44+
### Representation independence
45+
46+
Most of our concepts are introduced along with a "user interface", which
47+
consists of entries that specify and determine the basic use cases of the
48+
concept. This way, our code itself serves as a practical guide on how it can be
49+
used later in new definitions. Furthermore, later code that correctly uses the
50+
interface of a concept don't depend on the specific implementations of its
51+
dependencies, which makes them conceptually a lot cleaner, and more robust to
52+
change. John C. Reynolds explained the benefits of representation independence
53+
more fully in {{#cite Reynolds1974}}.
54+
55+
In essence, our code structuring conventions are designed and practiced with the
56+
goal of making the library as conceptually clear and understandable as possible.
57+
Finally, we hope that with the coding practices outlined here, you'll find our
58+
codebase welcoming and pleasant to work with.
7459

7560
## Guidelines for definitions in the agda-unimath library
7661

@@ -502,3 +487,7 @@ These guidelines are here to make everyone's coding experience more enjoyable
502487
and productive. As always, your contributions to the agda-unimath library are
503488
valued, and these suggestions are here to help ensure that your code is clear,
504489
beautiful, reusable, and maintainable. Happy coding!
490+
491+
## References
492+
493+
{{#bibliography}}

references.bib

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,19 @@ @phdthesis{Qui16
909909
langid = {english},
910910
}
911911

912+
@inproceedings{Reynolds1974,
913+
title = {Towards a theory of type structure},
914+
author = {Reynolds, John C.},
915+
year = 1974,
916+
booktitle = {Programming Symposium: Proceedings Colloque sur la Programmation, Paris, April 9--11, 1974},
917+
publisher = {Springer},
918+
series = {Lecture Notes in Computer Science},
919+
volume = 19,
920+
pages = {408--425},
921+
doi = {10.1007/3-540-06859-7_148},
922+
editor = {Robinet, B.},
923+
}
924+
912925
@online{Rezk10HomotopyToposes,
913926
title = {Toposes and homotopy toposes},
914927
author = {Rezk, Charles},

0 commit comments

Comments
 (0)