Skip to content

Commit f91c62d

Browse files
authored
Merge pull request #1260 from pat-rogers/master
Enhance the Cons section to say this is as type-safe as streams can be.
2 parents 69e7be6 + 588e8e7 commit f91c62d

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

content/courses/ada-in-practice/chapters/streams_api_flexibility.rst

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ to send and receive more complex data types. If so, how can the device driver
1818
support them?
1919

2020
We certainly don't want the clients to do unchecked conversions everywhere.
21-
That's error-prone, because it prevents the compiler from checking the usage,
21+
That's error-prone, it prevents the compiler from checking the usage,
2222
and makes clients responsible for what should be an internal implementation
2323
detail.
2424

@@ -608,19 +608,22 @@ Limited types do not support the stream I/O attributes by default, but
608608
developers can define them. Note that this is not a problem for the
609609
generic-based approach, because we declared the generic formal type as
610610
:ada:`limited` and wouldn't need to do anything within the generic that would
611-
contradict that.
612-
The client's generic actual type can then be either a limited type or not.
611+
contradict that. The client's generic actual type can then be either a limited
612+
type or not.
613613

614614
When multiple types are being sent and received, the sender and receiver must
615615
be coordinated so that the next value consumed from the stream is of the type
616616
expected by the receiver. For example, the next value in the stream might have
617617
been written by the sender as a floating-point value, via
618618
:ada:`Float'Write (...)`. The receiver must use :ada:`Float'Read(...)` to
619619
consume that value from the stream. Arguably, this is not really a *con*
620-
because it's true for any stream when multiple types are involved. It's even
621-
true across programming languages |mdash| see
620+
because it's true for any stream when multiple types are involved. Even if we
621+
used the generic-based approach, developers could instantiate the generic multiple
622+
times with different types and send their values via the same port. With streams this
623+
approach is as type-safe as it can be.
624+
However, see
622625
:ref:`Note #2 <Ada_In_Practice_Using Streams_Note_Generic_Dispatching_Constructor>`
623-
below.
626+
below for a possible mitigation.
624627

625628

626629
Relationship With Other Idioms

0 commit comments

Comments
 (0)