Browse Source

Add part2

SVI 1 month ago
parent
commit
f212e369e5
2 changed files with 51 additions and 124 deletions
  1. 50 124
      doc/index.md
  2. 1 0
      doc/part02/main.md

+ 50 - 124
doc/index.md

@@ -21,138 +21,64 @@
 
 ## Благодарности
 
-Parts of the book are based on Nim’s manual [https://nim-lang.org/docs/
-manual.html] which is the work of many people over many years. I would like
-to thank everybody who made valuable contributions, such as proof-reading,
-catching spelling mistakes or pointing out mistakes or omissions in the
-documentation:
-Ivan Bobev, Juan Carlos, Federico Ceratto, Neelesh Chandola, Timothee Cour,
-Huy Doan, Ico Doornekamp, Andrea Ferretti, Jasper Jenkins, James Johnson,
-Zahary Karadjov, Avahe Kellenberger, Lorenz Krakau, Andrey Makarov,
-Chris McIntyre, Kaushal Modi, Peter Munch-Ellingsen, Oscar Nihlgård, Rory
-O’Kane, Dominik Picheta, Andrey Riabushenko, Jacek Sieka, Mathias Stearn,
-Deansher Thompson, Miran Tuhtan, Elliot Waite, Brian Wignall, Zeshen Xing,
-Danil Yarantsev, Yanis Zafirópulos.
-
-Special thanks go to Andre von Houck and Miran Tuhtan for reviewing this
-book. This book would not be as good as it is without your help.
+Parts of the book are based on Nim’s manual [https://nim-lang.org/docs/manual.html] which is the work of many people over many years. I would like to thank everybody who made valuable contributions, such as proof-reading, catching spelling mistakes or pointing out mistakes or omissions in the documentation:
+
+Ivan Bobev, Juan Carlos, Federico Ceratto, Neelesh Chandola, Timothee Cour, Huy Doan, Ico Doornekamp, Andrea Ferretti, Jasper Jenkins, James Johnson, Zahary Karadjov, Avahe Kellenberger, Lorenz Krakau, Andrey Makarov, Chris McIntyre, Kaushal Modi, Peter Munch-Ellingsen, Oscar Nihlgård, Rory O’Kane, Dominik Picheta, Andrey Riabushenko, Jacek Sieka, Mathias Stearn, Deansher Thompson, Miran Tuhtan, Elliot Waite, Brian Wignall, Zeshen Xing, Danil Yarantsev, Yanis Zafirópulos.
+
+Special thanks go to Andre von Houck and Miran Tuhtan for reviewing this book. This book would not be as good as it is without your help.
 
 I apologize to anybody that I have left out by accident.
 
 ## Preface
 
-Compiled languages are on the rise again. It’s clear why, they generally
-produce programs that have better performance over interpreted languages
-and those programs are of higher quality due to static type checking. Nim
-goes a step beyond this new wave of compiled languages, by also giving you a
-powerful macro system to express complex problems.
-Nim does not depend on any virtual machine, instead producing a binary
-that runs directly on the CPU — either with the help of an operating system
-or even without one. Every drop of performance can be squeezed out of your
-code should the need arise.
-
-Nim’s easy to use static type system catches mistakes early. The type system
-helps you ensure that a small typo will not break production and a big
-refactor is no longer scary. You don’t even type that much, type inference is
-everywhere and generics make it very comfortable to use. Unlike in dynamic
-languages, every type is known at compile time and is properly optimized for
-both run time speed and memory space.
-Meta programming and macros are really powerful and set Nim apart from
-other static compiled languages. Nim allows you to design deep and
-composable domain-specific languages with its powerful templates and
-macros.
-
-Nim offers a “pluggable” memory management system called ARC giving you
-the required control for low latency, hard real-time systems without having
-to write “low level” programs. It is good for game and embedded
-development. ARC also integrates well with custom memory management.
-Nim is a cross-platform language not tied to any operating system. It feels
-right at home on Linux, Mac and Windows, and can also be used to make
-mobile iOS and Android apps. Even on the web it can be used either as
-
-compiled to JavaScript or through WASM.
-
-For embedded programming, the size of the produced machine code is
-important — Nim also shines in this aspect. The Nim compiler prunes unused
-code thanks to its focus on static binding needing no runtime introspection
-features. Where required, Nim’s macro system can be used to provide the
-required introspection capabilities.
-
-Productivity is also improved thanks to a well designed standard library and
-a large number of third party packages. The standard library covers topics
-such as hash tables, common algorithms like sorting or computing the edit
-distance, powerful collections, wrappers around operating systems, string
-parsing, unicode and time handling, implementations for the most common
-internet protocols, math and cryptography algorithms and much more.
-Software becomes ever more complex and a modern programming language
-needs to reflect that to some extent. It cannot be “simple” anymore. Many
-features are taken for granted these days, and rightly so. They enable the
-construction of complex software much like sophisticated materials and tools
-enable the construction of skyscrapers. It follows that learning a language is
-a huge time investment. Nim rewards you with a single coherent language
-that can be used for everything and it works well on everything: It runs on
-web browsers, on virtually every operating system as well as on tiny
-embedded devices and even on GPUs. Nim’s complexity is still very
-manageable, this book tries to cover Nim completely in about 300 pages.
-Some describe Nim as a “better Python with types, macros and C’s speed”.
-The code you write is easy to understand by feeling like running pseudocode,
-thanks to its indentation-based syntax, short type names, and type inference.
-It makes people fall in love with programming again by presenting fast
-compile times, fast run times, minimal boilerplate and a comfortable
-language. But now enough of the praise, please dive in and be the judge!
-History and theory behind Nim
-Nim is a general-purpose language most inspired by Ada, Modula-3, C++,
-Python and Lisp. Its most important features are type and resource safety,
-meta programming and combining readability with syntactic convenience.
-While Nim’s primary focus is “imperative programming”, it does support:
-
-- Functional programming: Functions are first class entities and mutability
-     can be restricted.
-- Object oriented programming: Inheritance and dynamic binding are
-     supported.
-- Generic programming: Custom container types can be implemented
-     easily and efficiently.
-- Asynchronous programming: Leverage lightweight threads to support a
-     large number of clients without blocking.
-- Meta programming: Reflection over a program’s structure is supported
-     so powerful program transformations are possible. The transformations
-     are carefully restricted to what can be done at compile-time. The
-     restrictions also enforce that local reasoning about a program remains to
-     be possible: The macro construct that enables the most powerful
-     transformations cannot transform unrelated sections of the code.
-
-This is the 2nd edition of “Mastering Nim”. It describes version 2.0 of the Nim
-programming language, first released in 2023-08-01.
-Who is this for
-
-This book for people who can already program but wish to be able to
-program in Nim.
-
-This book aims to give the reader a deep understanding of how Nim is
-layered and structured. It covers how the standard library APIs work and
-how they were implemented.
+Compiled languages are on the rise again. It’s clear why, they generally produce programs that have better performance over interpreted languages and those programs are of higher quality due to static type checking. **Nim** goes a step beyond this new wave of compiled languages, by also giving you a powerful macro system to express complex problems.
+
+**Nim** does not depend on any virtual machine, instead producing a binary that runs directly on the CPU — either with the help of an operating system or even without one. Every drop of performance can be squeezed out of your code should the need arise.
+
+**Nim’s** easy to use static type system catches mistakes early. The type system helps you ensure that a small typo will not break production and a big everywhere and generics make it very comfortable to use. Unlike in dynamic  both run time speed and memory space.
+
+Meta programming and macros are really powerful and set **Nim** apart from other static compiled languages. **Nim** allows you to design deep and composable domain-specific languages with its powerful templates and macros.
+
+**Nim** offers a “pluggable” memory management system called **ARC** giving you the required control for low latency, hard real-time systems without having to write “low level” programs. It is good for game and embedded development. **ARC** also integrates well with custom memory management.
+
+**Nim** is a cross-platform language not tied to any operating system. It feels right at home on Linux, Mac and Windows, and can also be used to make mobile iOS and Android apps. Even on the web it can be used either as compiled to `JavaScript` or through **WASM**.
+
+For embedded programming, the size of the produced machine code is important — **Nim** also shines in this aspect. The **Nim** compiler prunes unused code thanks to its focus on static binding needing no runtime introspection features. Where required, **Nim’s** macro system can be used to provide the required introspection capabilities.
+
+Productivity is also improved thanks to a well designed standard library and a large number of third party packages. The standard library covers topics such as hash tables, common algorithms like sorting or computing the edit distance, powerful collections, wrappers around operating systems, string parsing, unicode and time handling, implementations for the most common internet protocols, math and cryptography algorithms and much more.
+
+Software becomes ever more complex and a modern programming language needs to reflect that to some extent. It cannot be “simple” anymore. Many features are taken for granted these days, and rightly so. They enable the construction of complex software much like sophisticated materials and tools enable the construction of skyscrapers. It follows that learning a language is a huge time investment. **Nim** rewards you with a single coherent language that can be used for everything and it works well on everything: It runs on web browsers, on virtually every operating system as well as on tiny embedded devices and even on GPUs. **Nim**’s complexity is still very manageable, this book tries to cover Nim completely in about 300 pages.
+
+Some describe **Nim** as a “better Python with types, macros and C’s speed”. The code you write is easy to understand by feeling like running pseudocode, thanks to its indentation-based syntax, short type names, and type inference. It makes people fall in love with programming again by presenting fast compile times, fast run times, minimal boilerplate and a comfortable language. But now enough of the praise, please dive in and be the judge!
+
+History and theory behind **Nim**
+
+*Nim* is a general-purpose language most inspired by **Ada**, **Modula-3**, **C++**, **Python** and **Lisp**. Its most important features are type and resource safety, meta programming and combining readability with syntactic convenience.
+
+## While **Nim**’s primary focus is “imperative programming”, it does support
+
+- Functional programming: Functions are first class entities and mutability can be restricted.
+- Object oriented programming: Inheritance and dynamic binding are supported.
+- Generic programming: Custom container types can be implemented easily and efficiently.
+- Asynchronous programming: Leverage lightweight threads to support a large number of clients without blocking.
+- Meta programming: Reflection over a program’s structure is supported so powerful program transformations are possible. The transformations are carefully restricted to what can be done at compile-time. The restrictions also enforce that local reasoning about a program remains to be possible: The macro construct that enables the most powerful transformations cannot transform unrelated sections of the code.
+
+This is the 2nd edition of “Mastering Nim”. It describes version 2.0 of the **Nim** programming language, first released in 2023-08-01.
+
+## Who is this for
+
+This book for people who can already program but wish to be able to program in **Nim**.
+
+This book aims to give the reader a deep understanding of how **Nim** is layered and structured. It covers how the standard library APIs work and how they were implemented.
 
 ## Structure of the book
 
-This book is structured as follows: Part I is an introduction to Nim via simple
+This book is structured as follows: Part I is an introduction to **Nim** via simple
 algorithms based on graphical programming.
 
-Part II is the largest part, it covers Nim in detail and in a formal language. It
-tries to convey how Nim really works and ideally you know the language
-inside out after reading it. This part originally evolved from Nim’s official
-manual but please do not think that you know it all already! It contains
-plenty of unique and novel content. Sometimes examples show how the
-features are supposed to be used or why they exist, sometimes personal
+Part II is the largest part, it covers **Nim** in detail and in a formal language. It tries to convey how **Nim** really works and ideally you know the language inside out after reading it. This part originally evolved from Nim’s official manual but please do not think that you know it all already! It contains plenty of unique and novel content. Sometimes examples show how the features are supposed to be used or why they exist, sometimes personal
 advice is provided of what to watch out for or to avoid.
-                                                                             15
-Part III focuses on Nim’s macro system. Examples are explained in detail and
-the examples were chosen to be representative of tasks where macros are an
-effective tool to improve the readability and the level of abstraction of your
-code.
-
-Part IV covers Nim’s multi-threading capabilities and memory model.
-Essential parts of Nim’s standard library are covered in the form of “cheat
-sheets”. This might seem rather superfluous in the age of the Internet but the
-online documentation does not provide the information in this concise form.
-The parts are loosely coupled and can be read independently from each
-other and in whatever order you choose.
+
+Part III focuses on **Nim**’s macro system. Examples are explained in detail and the examples were chosen to be representative of tasks where macros are an effective tool to improve the readability and the level of abstraction of your code.
+
+Part IV covers **Nim**’s multi-threading capabilities and memory model. Essential parts of **Nim**’s standard library are covered in the form of “cheat sheets”. This might seem rather superfluous in the age of the Internet but the online documentation does not provide the information in this concise form. The parts are loosely coupled and can be read independently from each other and in whatever order you choose.

+ 1 - 0
doc/part02/main.md

@@ -0,0 +1 @@
+# Часть 2. Спецификация языка