I've taught some C++ to my nephew because he wanted to participate in the Olympiad in Informatics, the local stage.

In terms of languages I don't like, C++ is in a league of its own. E.g., the pointers, and the weird constructs, such as usage of “streams” for reading/writing file handles.

To read/write files, I told my nephew to simply mimic examples. To declare arrays, I advised him to just declare large ones, instead of bothering w/ pointers and dynamic allocation 🤷‍♂️

#cpp #programming

@alexelcu Interesting, streams are certainly cumbersome in some situations, but the one thing they have going for them is that they are very natural.

Why do you consider them weird?

@simontoth When learning programming, there can be a gap b/w understanding things and being able to do useful stuff. The larger that gap is, the more the language sucks for beginners.

Streams in C++ are OOP constructs. But more than OOP, they work based on ad-hoc polymorphism to infer an encoder/decoder from the variable used. Some types work, many don't, a guessing game for beginners. Furthermore, the operators (<<, >>) are hard to learn, versus English words (e.g., read/write/print).

@simontoth … Reading a list of integers from a file can be lower-level in Python, as you have to do some manual parsing, like reading a whole line of text, split it by some char, and then use `int` to convert those strings into integers.

It's still better for beginners as they can split complex problems into smaller problems (read, split, convert), and they don't need to cover so much of the language simply for reading a list of integers, never mind the manual memory management.

Follow

@alexelcu @simontoth

No, you write an statement that reads in each item on the line.

int I;
string s;
cin >> I >> s;

Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.