Skip to content

Commit c5b32ae

Browse files
mark-summerfieldKristofferC
authored andcommitted
Minor English fixes in constructors.md (#29338)
(cherry picked from commit 94aa39b)
1 parent ea37169 commit c5b32ae

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

doc/src/manual/constructors.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ julia> foo.baz
2222
```
2323

2424
For many types, forming new objects by binding their field values together is all that is ever
25-
needed to create instances. There are, however, cases where more functionality is required when
25+
needed to create instances. However, in some cases more functionality is required when
2626
creating composite objects. Sometimes invariants must be enforced, either by checking arguments
2727
or by transforming them. [Recursive data structures](https://en.wikipedia.org/wiki/Recursion_%28computer_science%29#Recursive_data_structures_.28structural_recursion.29),
2828
especially those that may be self-referential, often cannot be constructed cleanly without first
@@ -34,7 +34,7 @@ addresses all of these cases and more.
3434
[^1]:
3535
Nomenclature: while the term "constructor" generally refers to the entire function which constructs
3636
objects of a type, it is common to abuse terminology slightly and refer to specific constructor
37-
methods as "constructors". In such situations, it is generally clear from context that the term
37+
methods as "constructors". In such situations, it is generally clear from the context that the term
3838
is used to mean "constructor method" rather than "constructor function", especially as it is often
3939
used in the sense of singling out a particular method of the constructor from all of the others.
4040

@@ -77,7 +77,7 @@ While outer constructor methods succeed in addressing the problem of providing a
7777
methods for constructing objects, they fail to address the other two use cases mentioned in the
7878
introduction of this chapter: enforcing invariants, and allowing construction of self-referential
7979
objects. For these problems, one needs *inner* constructor methods. An inner constructor method
80-
is much like an outer constructor method, with two differences:
80+
is like an outer constructor method, except for two differences:
8181

8282
1. It is declared inside the block of a type declaration, rather than outside of it like normal methods.
8383
2. It has access to a special locally existent function called [`new`](@ref) that creates objects of the
@@ -110,7 +110,7 @@ Stacktrace:
110110
```
111111

112112
If the type were declared `mutable`, you could reach in and directly change the field values to
113-
violate this invariant, but messing around with an object's internals uninvited is considered poor form.
113+
violate this invariant. Of course, messing around with an object's internals uninvited is bad practice.
114114
You (or someone else) can also provide additional outer constructor methods at any later point, but
115115
once a type is declared, there is no way to add more inner constructor methods. Since outer constructor
116116
methods can only create objects by calling other constructor methods, ultimately, some inner constructor
@@ -160,7 +160,7 @@ julia> T2(1.0)
160160
T2(1)
161161
```
162162

163-
It is considered good form to provide as few inner constructor methods as possible: only those
163+
It is good practice to provide as few inner constructor methods as possible: only those
164164
taking all arguments explicitly and enforcing essential error checking and transformation. Additional
165165
convenience constructor methods, supplying default values or auxiliary transformations, should
166166
be provided as outer constructors that call the inner constructors to do the heavy lifting. This
@@ -194,8 +194,8 @@ value for the `obj` field of another instance, such as, for example, itself.
194194
To allow for the creation of incompletely initialized objects, Julia allows the [`new`](@ref) function
195195
to be called with fewer than the number of fields that the type has, returning an object with
196196
the unspecified fields uninitialized. The inner constructor method can then use the incomplete
197-
object, finishing its initialization before returning it. Here, for example, we take another crack
198-
at defining the `SelfReferential` type, with a zero-argument inner constructor returning instances
197+
object, finishing its initialization before returning it. Here, for example, is another attempt
198+
at defining the `SelfReferential` type, this time using a zero-argument inner constructor returning instances
199199
having `obj` fields pointing to themselves:
200200

201201
```jldoctest selfrefer2
@@ -222,11 +222,11 @@ true
222222
```
223223

224224
Although it is generally a good idea to return a fully initialized object from an inner constructor,
225-
incompletely initialized objects can be returned:
225+
it is possible to return incompletely initialized objects:
226226

227227
```jldoctest incomplete
228228
julia> mutable struct Incomplete
229-
xx
229+
data
230230
Incomplete() = new()
231231
end
232232
@@ -237,7 +237,7 @@ While you are allowed to create objects with uninitialized fields, any access to
237237
reference is an immediate error:
238238

239239
```jldoctest incomplete
240-
julia> z.xx
240+
julia> z.data
241241
ERROR: UndefRefError: access to undefined reference
242242
```
243243

@@ -263,13 +263,13 @@ You can pass incomplete objects to other functions from inner constructors to de
263263

264264
```jldoctest
265265
julia> mutable struct Lazy
266-
xx
266+
data
267267
Lazy(v) = complete_me(new(), v)
268268
end
269269
```
270270

271271
As with incomplete objects returned from constructors, if `complete_me` or any of its callees
272-
try to access the `xx` field of the `Lazy` object before it has been initialized, an error will
272+
try to access the `data` field of the `Lazy` object before it has been initialized, an error will
273273
be thrown immediately.
274274

275275
## Parametric Constructors
@@ -513,8 +513,8 @@ it is short, self-contained, and implements an entire basic Julia type.
513513
As we have seen, a typical parametric type has inner constructors that are called when type parameters
514514
are known; e.g. they apply to `Point{Int}` but not to `Point`. Optionally, outer constructors
515515
that determine type parameters automatically can be added, for example constructing a `Point{Int}`
516-
from the call `Point(1,2)`. Outer constructors call inner constructors to do the core work of
517-
making an instance. However, in some cases one would rather not provide inner constructors, so
516+
from the call `Point(1,2)`. Outer constructors call inner constructors to actually
517+
make instances. However, in some cases one would rather not provide inner constructors, so
518518
that specific type parameters cannot be requested manually.
519519

520520
For example, say we define a type that stores a vector along with an accurate representation of

0 commit comments

Comments
 (0)