C++ Logo

std-proposals

Advanced search

Re: Making C++ easier for new students

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Wed, 4 Aug 2021 22:50:09 -0400
On Wed, Aug 4, 2021 at 8:51 PM Bill Kerney via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> Rust issues aside, there's two emails I would like to respond to.
>
> >In my personal opinion C++ will never get good in this areas. Reason is that C++ standardization has very limited resources and they are mostly spent on making language better for professional developers. For example there was proposal for sane main() arguments, that never made it into the standard.
>
> That's more or less what I'm talking about here. I think the recent revisions have been focused on professionals. But a language's long term growth depends on new people being trained in it to replace the old programmers who are retiring.
>
> I'm not so pessimistic about C++ that I think we should just abandon ship for Rust or Python or whatever. There's some low-hanging fruit that would make life a lot easier for people and make people like C++ more when they learn it.
>
> >Some of these things are not language questions but operating system questions.
>
> Well, specifically I'm talking about the C++ standard library, which sits above OS syscalls exactly in order to make them safer and easier to use. As Bjarne put it a couple years back at CppCon, a standard library should make common tasks easy. Handling input is a very common task, and the current implementation in std only makes it easy to do it wrong.
>
> I think it would be nice for input to just, you know, work. Is there any real objection to doing input like this?
>
> int x = read();

Yes, that's possible. It'd require a return value which uses a
template conversion operator to do some kind of input reading, so that
it knows what type to read.

Also, it totally doesn't work if you do `auto x = read();`. What's
worse is that this will *compile*, but fail to work when you use `x`
with a likely confusing error message.

But even if you could, what happens when you need to do more complex
reading, like formatted reading?

One of the big problems in teaching anything is to transition from
using crutches to actually walking. If you hide all of the details
from a user and give them some basic input tool like that, eventually,
they're going to out-grow it. Then what?

std::cin isn't great, but it does *scale* (kinda). It handles simple
cases and more complex cases using basically the same API. So a user
who knows how to read an integer can more easily read an integer
that's a hexadecimal value. Your `read` function is good for simple
stuff, but it doesn't scale at all.

Received on 2021-08-04 21:50:25