Date: Sat, 7 Aug 2021 11:42:27 +0300
I'll make specific comments rather than address the general issue -
which is a valid concern.
On 03/08/2021 9:05, Bill Kerney via Std-Proposals wrote:
> 1. How do I do non-blocking I/O? (Sometimes phrased like, "How do I
> read an arrow key?")
I don't believe this is supposed to be trivial or succinct in a
general-purpose programming language, as opposed to, say, a gaming or UI
app engine. I also doubt it is relevant to students beginning to learn a
language (though perhaps I'm missing something).
> 2. How do I recover from errors in input?
Well, this is actually not so terrible, in the sense that cin'ing into a
type which doesn't match the input doesn't get you stuck: It sets the
result variable to 0 or some other value, and sets the failbit. You can
then recover with clearing the failbit; however, clearing the input
buffer is not trivial.
Here's a post about this exact question:
https://hackingcpp.com/cpp/recipe/istream_recover_from_errors.html
Now, with your read() method - it's not clear what exactly should happen
if some invalid characters are given on the input.
Another alternative is suggesting people use istream::getline() and
parse, if they want to handle failures. It's a bit of challenge for
absolute newbies, but it's a surmountable one, so it can be a motivator
rather than a demotivator: If you want to impress your friends in class
by being able to handle errors, you could do XYZ.
> 3. How do I display graphics on the screen?
You may want to read the discussion of this point in a (relatively)
recent paper about 2D graphics in the standard library, from 2018:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1062r0.html
they essentially argue that this should be easily available as a
package, but not as part of the standard.
> 4. How do I do colored text?
> 5. How do I read a mouse click?
> 6. How do I play a sound?
Same question/argument as in the above: Does it make sense for this to
be in the standard, or for there to be an education-focused,
ease-of-use-focused, library for these things?
> 7. How do I send data over the internet?
So, here you could possibly cheat, without a proper library, by using
system(), and in it doing something like scp, or sending email and such.
You would explain that would not work on any possible system, and isn't
part of C++, but if your students are also learning to use the command
shell, it might not be terrible to do this. I would strive to avoid
students using for multiple things or routinely.
> 8. How do I split a string?
See this StackOverflow question:
https://stackoverflow.com/q/14265581/1593077
Is it really too hard to get students to write something like this:
auto start = 0;
auto end = str.find(delim);
while (end != std::string::npos)
{
do_stuff_like_putting_in_a_container(
str.substr(start, end - start));
start = end + delim.length();
end = str.find(delim, start);
}
? Now, sure, this doesn't use ranges, nor <algorithm>, and the choice of
types is not ideal so it's not the most elegant thing in the world. But
is it that bad? Note that there is no use of C-style strings, nor other
memory-unsafe operations, since we're limiting ourselves to string's
methods.
> I've written solutions to 1, 2, 4, and somewhat to 5.
Maybe the thing to do is to get more people in C++ education aware of
your, or others', efforts on this. Perhaps there could be a common
"training wheels library", which is not in the standard, but is
well-known enough that educators will likely know about it and use it,
and students would be able to have it on their system as one of the OS
distribution packages, or something which comes with their IDE or what-not.
which is a valid concern.
On 03/08/2021 9:05, Bill Kerney via Std-Proposals wrote:
> 1. How do I do non-blocking I/O? (Sometimes phrased like, "How do I
> read an arrow key?")
I don't believe this is supposed to be trivial or succinct in a
general-purpose programming language, as opposed to, say, a gaming or UI
app engine. I also doubt it is relevant to students beginning to learn a
language (though perhaps I'm missing something).
> 2. How do I recover from errors in input?
Well, this is actually not so terrible, in the sense that cin'ing into a
type which doesn't match the input doesn't get you stuck: It sets the
result variable to 0 or some other value, and sets the failbit. You can
then recover with clearing the failbit; however, clearing the input
buffer is not trivial.
Here's a post about this exact question:
https://hackingcpp.com/cpp/recipe/istream_recover_from_errors.html
Now, with your read() method - it's not clear what exactly should happen
if some invalid characters are given on the input.
Another alternative is suggesting people use istream::getline() and
parse, if they want to handle failures. It's a bit of challenge for
absolute newbies, but it's a surmountable one, so it can be a motivator
rather than a demotivator: If you want to impress your friends in class
by being able to handle errors, you could do XYZ.
> 3. How do I display graphics on the screen?
You may want to read the discussion of this point in a (relatively)
recent paper about 2D graphics in the standard library, from 2018:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1062r0.html
they essentially argue that this should be easily available as a
package, but not as part of the standard.
> 4. How do I do colored text?
> 5. How do I read a mouse click?
> 6. How do I play a sound?
Same question/argument as in the above: Does it make sense for this to
be in the standard, or for there to be an education-focused,
ease-of-use-focused, library for these things?
> 7. How do I send data over the internet?
So, here you could possibly cheat, without a proper library, by using
system(), and in it doing something like scp, or sending email and such.
You would explain that would not work on any possible system, and isn't
part of C++, but if your students are also learning to use the command
shell, it might not be terrible to do this. I would strive to avoid
students using for multiple things or routinely.
> 8. How do I split a string?
See this StackOverflow question:
https://stackoverflow.com/q/14265581/1593077
Is it really too hard to get students to write something like this:
auto start = 0;
auto end = str.find(delim);
while (end != std::string::npos)
{
do_stuff_like_putting_in_a_container(
str.substr(start, end - start));
start = end + delim.length();
end = str.find(delim, start);
}
? Now, sure, this doesn't use ranges, nor <algorithm>, and the choice of
types is not ideal so it's not the most elegant thing in the world. But
is it that bad? Note that there is no use of C-style strings, nor other
memory-unsafe operations, since we're limiting ourselves to string's
methods.
> I've written solutions to 1, 2, 4, and somewhat to 5.
Maybe the thing to do is to get more people in C++ education aware of
your, or others', efforts on this. Perhaps there could be a common
"training wheels library", which is not in the standard, but is
well-known enough that educators will likely know about it and use it,
and students would be able to have it on their system as one of the OS
distribution packages, or something which comes with their IDE or what-not.
Received on 2021-08-07 03:42:35