From 7e0e38bd155fab76fa3b6776f9184611d044903d Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Sun, 18 Jul 2021 17:53:37 -0400 Subject: Finish lexical scope documentation --- docs/doc/namespace.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/doc/namespace.html') diff --git a/docs/doc/namespace.html b/docs/doc/namespace.html index b8332eae..9ea2f214 100644 --- a/docs/doc/namespace.html +++ b/docs/doc/namespace.html @@ -18,7 +18,7 @@ DoThing "TODO"!

Uses

-

The features of namespaces that make them useful in BQN programming are encapsulation and mutability. But these are exactly the same features that closures provide! In fact a namespace is not much more than a closure with a name lookup system. Consequently namespaces don't really expand the basic functionality of the language, but just make it easier to use.

+

The features of namespaces that make them useful in BQN programming are encapsulation and mutability. But these are exactly the same features that closures provide! In fact a namespace is not much more than a closure with a name lookup system. Consequently namespaces don't really expand the basic functionality of the language, but just make it easier to use.

Namespaces improve encapsulation by allowing many values to be exported at once. With only one way to call them, functions and modifiers aren't such a good way to define a large part of a program. With a namespace you can define lots of things and expose exactly the ones you want to the rest of the world. For example, it's typical for files to define namespaces. A reader can see the exported values just by searching for , and if you're nice, you might declare them all at the beginning of the file. Careful use of exports can guarantee that potentially dangerous functions are used correctly: if it's only valid to call function B after function A has been called, export AB{A𝕩B𝕩} and don't export B.

Mutability means that the behavior of one namespace can change over the course of the program. Mutability is often a liability, so make sure you really need it before leaning too heavily on this property. While there's no way to tell from the outside that a particular namespace is mutable, you can tell it isn't if the source code doesn't contain , as this is the only way it can modify the variables it contains.

A namespace that makes use of mutability is essentially an object: a collection of state along with operations that act on it. Object-oriented programming is the other major use of namespaces. Contrary to the name, there's never a need to orient your programming around objects, and it's perfectly fine to use an object here or there when you need to, for instance to build a mutable queue of values.

-- cgit v1.2.3