Skip to content

Commit 0aeeca3

Browse files
committed
Minor typographical etc. corrections to classtut.pod
1 parent 6258df8 commit 0aeeca3

File tree

1 file changed

+52
-53
lines changed

1 file changed

+52
-53
lines changed

lib/Language/classtut.pod

Lines changed: 52 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ X<|classes, encapsulation>
101101
102102
The first three lines inside the class block all declare attributes (called
103103
I<fields> or I<instance storage> in other languages). These are storage
104-
locations that every instance of a class will obtain. Just as a C<my> variable can
105-
not be accessed from the outside of its declared scope, attributes are not
104+
locations that every instance of a class will obtain. Just as a C<my> variable
105+
cannot be accessed from outside its declared scope, attributes are not
106106
accessible outside of the class. This I<encapsulation> is one of the key
107107
principles of object oriented design.
108108
@@ -154,8 +154,8 @@ having to write the method by hand. You are free instead to write your own
154154
accessor method, if at some future point you need to do something more complex
155155
than return the value.
156156
157-
Note that using the C<.> twigil has created a method that will provide with
158-
readonly access to the attribute. If instead the users of this object should be
157+
Note that using the C<.> twigil has created a method that will provide
158+
read-only access to the attribute. If instead the users of this object should be
159159
able to reset a task's completion state (perhaps to perform it again), you can
160160
change the attribute declaration:
161161
@@ -168,8 +168,8 @@ external code can modify to change the value of the attribute.
168168
169169
=head1 Static fields?
170170
171-
Perl 6 has no B<static> keyword. Anyway any class may declare anything that
172-
module can so making a scoped variable sounds like good idea.
171+
Perl 6 has no B<static> keyword. Nevertheless any class may declare anything
172+
that a module can, so making a scoped variable sounds like good idea.
173173
174174
=begin code
175175
@@ -184,31 +184,30 @@ module can so making a scoped variable sounds like good idea.
184184
185185
=end code
186186
187-
Class attributes defined by L<my> or L<our> may also be initialized while
188-
declaration but we are implementing Singleton pattern here and object must
189-
be created during first use. It is not possible to predict in 100% the moment
190-
when attribute initialization will be executed because it can be done during
191-
compilation, runtime or both especially when importing class using L<use>
192-
keyword.
187+
Class attributes defined by L<my> or L<our> may also be initialized when
188+
being declared, however we are implementing the Singleton pattern here and
189+
the object must be created during its first use. It is not 100% possible to
190+
predict the moment when attribute initialization will be executed, because
191+
it can take place during compilation, runtime or both, especially when
192+
importing the class using the L<use> keyword.
193193
194194
class HaveStaticAttr {
195195
my Foo $.foo = some_complicated_subroutine;
196196
}
197197
198-
Class attributes may also be declared with secondary sigil like object
199-
attributes that will result in generating read-only accessor if attribute
200-
is to be public.
201-
198+
Class attributes may also be declared with a secondary sigil -- in a similar
199+
manner to object attributes -- that will generate read-only accessors if the
200+
attribute is to be public.
202201
203202
=head1 Methods
204203
205204
X<|methods>
206205
X<|classes, methods>
207206
208-
While attributes give objects state, methods give objects behaviors. Ignore
209-
the C<new> method temporarily; it's a special type of method. Consider the
210-
second method, C<add-dependency>, which adds a new task to this task's
211-
dependency list.
207+
While attributes give objects state, methods give objects behaviors. Let's
208+
ignore the C<new> method temporarily; it's a special type of method.
209+
Consider the second method, C<add-dependency>, which adds a new task to a
210+
task's dependency list.
212211
213212
method add-dependency(Task $dependency) {
214213
push @!dependencies, $dependency;
@@ -222,8 +221,8 @@ the list of methods for the current class. Thus any instance of the C<Task>
222221
class can call this method with the C<.> method call operator. Second, a
223222
method places its invocant into the special variable C<self>.
224223
225-
The method itself takes the passed parameter--which must be an instance of the
226-
C<Task> class--and C<push>es it onto the invocant's C<@!dependencies>
224+
The method itself takes the passed parameter -- which must be an instance of
225+
the C<Task> class -- and C<push>es it onto the invocant's C<@!dependencies>
227226
attribute.
228227
229228
The second method contains the main logic of the dependency handler:
@@ -244,7 +243,7 @@ X<|operators, .>
244243
245244
Otherwise, the method performs all of the task's dependencies, using the C<for>
246245
construct to iterate over all of the items in the C<@!dependencies> attribute.
247-
This iteration places each item--each a C<Task> object--into the topic
246+
This iteration places each item -- each a C<Task> object -- into the topic
248247
variable, C<$_>. Using the C<.> method call operator without specifying an
249248
explicit invocant uses the current topic as the invocant. Thus the iteration
250249
construct calls the C<.perform()> method on every C<Task> object in the
@@ -275,19 +274,19 @@ X<|objects, bless>
275274
X<|bless>
276275
277276
The biggest difference between constructors in Perl 6 and constructors in
278-
languages such as C# and Java is that rather than setting up state on a somehow
279-
already magically created object, Perl 6 constructors actually create the
280-
object themselves. This easiest way to do this is by calling the L<bless>
281-
method, also inherited from L<Mu>. The C<bless> method expects a set of named parameters providing
282-
the initial values for each attribute.
277+
languages such as C# and Java is that rather than setting up state on a
278+
somehow already magically created object, Perl 6 constructors actually
279+
create the object themselves. The easiest way to do this is by calling the
280+
L<bless> method, also inherited from L<Mu>. The C<bless> method expects a
281+
set of named parameters providing the initial values for each attribute.
283282
284283
The example's constructor turns positional arguments into named arguments, so
285284
that the class can provide a nice constructor for its users. The first
286-
parameter is the callback (the thing to do to execute the task). The rest of
285+
parameter is the callback (the thing which will execute the task). The rest of
287286
the parameters are dependent C<Task> instances. The constructor captures these
288287
into the C<@dependencies> slurpy array and passes them as named parameters to
289-
C<bless> (note that C<:&callback> uses the name of the variable--minus the
290-
sigil--as the name of the parameter).
288+
C<bless> (note that C<:&callback> uses the name of the variable -- minus the
289+
sigil -- as the name of the parameter).
291290
292291
X<|BUILD>
293292
@@ -350,7 +349,7 @@ the various other dependencies in order, giving the output:
350349
Object Oriented Programming provides the concept of inheritance as one of the
351350
mechanisms to allow for code reuse. Perl 6 supports the ability for one class
352351
to inherit from one or more classes. When a class inherits from another class
353-
that informs the method dispatcher to follow the inheritance chain to look
352+
it informs the method dispatcher to follow the inheritance chain to look
354353
for a method to dispatch. This happens both for standard methods defined via
355354
the method keyword and for methods generated through other means such as
356355
attribute accessors.
@@ -365,7 +364,6 @@ improved). See L<https://github.com/perl6/book/issues/58> for discussion.
365364
method pay() {
366365
say "Here is \$$.salary";
367366
}
368-
369367
}
370368
371369
class Programmer is Employee {
@@ -393,7 +391,7 @@ defined in the Employee class as though they were from the Programmer class.
393391
$programmer.pay();
394392
=end code
395393
396-
=head2 Overriding Inherited Methods
394+
=head2 Overriding inherited methods
397395
398396
Of course, classes can override methods and attributes defined by parent
399397
classes by defining their own. The example below demonstrates the C<Baker> class
@@ -437,18 +435,20 @@ overriding the C<Cook>'s C<cook> method.
437435
Because the dispatcher will see the C<cook> method on C<Baker> before it moves up to
438436
the parent class the C<Baker>'s C<cook> method will be called.
439437
440-
As a side node, you might have wondered how passing strings to array attribute
441-
worked. Array assignment is coercive, so the assignment turn the new value
438+
As a side note, you might have wondered how passing strings to an array attribute
439+
worked. Array assignment is coercive, so the assignment turns the new value
442440
into an array. This mechanism is also used for initializing attributes.
443441
444-
=head2 Multiple Inheritance
442+
=head2 Multiple inheritance
445443
446444
As mentioned before, a class can inherit from multiple classes. When a class
447445
inherits from multiple classes the dispatcher knows to look at both classes when
448-
looking up a method to search for. As a side note, Perl 6 uses the C3
449-
algorithm to linearize the multiple inheritance hierarchies, which is a
446+
looking up a method to search for. Perl 6 uses the C3
447+
algorithm to linearize multiple inheritance hierarchies, which is a
450448
significant improvement over Perl 5's approach to handling multiple inheritance.
451449
450+
=comment isn't Perl 5 also C3 now?
451+
452452
=begin code
453453
class GeekCook is Programmer is Cook {
454454
method new( *%params ) {
@@ -468,10 +468,10 @@ significant improvement over Perl 5's approach to handling multiple inheritance.
468468
$geek.code_to_solve('P =? NP');
469469
=end code
470470
471-
Now all the methods made available by both the Programmer class and the Cook
472-
class are available from the GeekCook class.
471+
Now all the methods made available to the Programmer and the Cook
472+
classes are available from the GeekCook class.
473473
474-
While multiple inheritance is a useful concept to know and on occasion of use, it
474+
While multiple inheritance is a useful concept to know and occasionally use, it
475475
is important to understand that there are more useful OOP concepts. When
476476
reaching for multiple inheritance it is good practice to consider whether the
477477
design wouldn't be better realized by using roles, which are generally safer
@@ -482,9 +482,9 @@ names. For more information on roles see A<sec:roles>.
482482
483483
Introspection is the process of gathering information about some objects in
484484
your program, not by reading the source code, but by querying the object (or a
485-
controlling object) for some properties, like its type.
485+
controlling object) for some properties, such as its type.
486486
487-
Given an object C<$p>, and the class definitions from the previous sections,
487+
Given an object C<$o>, and the class definitions from the previous sections,
488488
we can ask it a few questions:
489489
490490
if $o ~~ Employee { say "It's an employee" };
@@ -496,7 +496,6 @@ we can ask it a few questions:
496496
497497
The output can look like this:
498498
499-
=for output
500499
It's an employee
501500
(Programmer)
502501
Programmer.new(known_languages => ["Perl", "Python", "Pascal"],
@@ -510,7 +509,7 @@ question is of class C<Employee> or one that inherits from it, but not
510509
C<GeekCook>.
511510
512511
The C<.WHAT> method returns the type object associated with the object C<$o>,
513-
which tells the exact type of C<$o>: in this case C<Programmer>.
512+
which tells us the exact type of C<$o>: in this case C<Programmer>.
514513
515514
C<$o.perl> returns a string that can be executed as Perl code, and reproduces
516515
the original object C<$o>. While this does not work perfectly in all
@@ -522,11 +521,11 @@ is very useful for debugging simple objects.
522521
523522
C<$o.^methods(:local)> produces a list of methods that can be called
524523
on C<$o>. The C<:local> named argument limits the returned methods to those
525-
defined in the C<Employee> class, and excludes the inherited methods.
524+
defined in the C<Employee> class and excludes the inherited methods.
526525
527-
The syntax of calling method with C<.^> instead of a single dot means that it
528-
is actually a method call on the I<meta class>, which is a class managing the
529-
properties of the C<Employee> class - or any other class you are interested
526+
The syntax of calling a method with C<.^> instead of a single dot means that it
527+
is actually a method call on the I<meta class>, which is a class managing the
528+
properties of the C<Employee> class -- or any other class you are interested
530529
in. This meta class enables other ways of introspection too:
531530
532531
say $o.^attributes.join(', ');
@@ -537,9 +536,9 @@ unsurprisingly returns the class name.
537536
538537
Introspection is very useful for debugging, and for learning the language
539538
and new libraries. When a function or method
540-
returns an object you don't know about, finding its type with C<.WHAT>, a
541-
construction recipe for it with C<.perl> and so on you'll get a good idea what
542-
this return value is. With C<.^methods> you can learn what you can do with it.
539+
returns an object you don't know about, finding its type with C<.WHAT>, seeing a
540+
construction recipe for it with C<.perl>, and so on, you'll get a good idea of what
541+
its return value is. With C<.^methods> you can learn what you can do with the class.
543542
544543
But there are other applications too: a routine that serializes objects to a
545544
bunch of bytes needs to know the attributes of that object, which it can find

0 commit comments

Comments
 (0)