|
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. |
20 | 21 |
|
21 | 22 | ## Code structuring conventions |
22 | 23 |
|
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 | | - |
27 | 24 | One critical aspect of maintaining such a large codebase lies in efficient and |
28 | 25 | strategic code structuring, and continued refactoring, into small, reusable |
29 | 26 | entries. In line with this approach, we aim to factor out and encapsulate even |
30 | 27 | the tiniest bits of reusable logic or computation in their own definitions. |
31 | 28 |
|
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. |
74 | 59 |
|
75 | 60 | ## Guidelines for definitions in the agda-unimath library |
76 | 61 |
|
@@ -502,3 +487,7 @@ These guidelines are here to make everyone's coding experience more enjoyable |
502 | 487 | and productive. As always, your contributions to the agda-unimath library are |
503 | 488 | valued, and these suggestions are here to help ensure that your code is clear, |
504 | 489 | beautiful, reusable, and maintainable. Happy coding! |
| 490 | + |
| 491 | +## References |
| 492 | + |
| 493 | +{{#bibliography}} |
0 commit comments