Indeed, OOP using "tricky methods" is a major problem. 😆

[Excerpt from an introductory textbook on computer science.]

#programming #education

This gem a couple of paragraphs later on OOP:

"This approach has magically brought about an evolution in the software world."

Magic. 😆

A couple of pages later, listing characteristics of C++:

I suppose this definition also serves to illustrate recursion. 😀

It's amazing (and sad) how many books and people claim/believe that the terms "literal" and "constant" are interchangeable in programming.

A rather interesting first C++ program. 😢

[From an actual CS intro textbook. No surprise, it doesn't compile in any compliant C++ compiler in any version of C++, all the way back to C++98: https://godbolt.org/z/x4Kc3x8sh]

[Of course, void main works in MSVC but "iostream.h" and unqualified cout?]

#cpp #cplusplus #textbook #introduction

Compiler Explorer - C++

void main() { cout<<"This is first C++ program"; }

Not surprised to see the claim that "C++ is a superset of C" in this book.

Also, C++ programmers should know they're a privileged bunch.

#cpp #cplusplus #teaching

Words fail me, and my worry for students grows. 😢

#cpp #cplusplus #teaching #pointers

Ah yes, we can use the exit function to end a program. I just wasn't expecting to find it discussed in a textbook for a CS intro course, that too about 20% of the way in. 🤦‍♂️

[FWIW, I don't recall ever using the exit function in all my programming.]

#cpp #cplusplus

I don't quite get why intro C++ courses teach arrays, 2-dimensional arrays no less.

In the same vein, why teach null-terminated strings (beyond literals)? They have so many pitfalls that even the authors can't keep things straight. 😢

#cpp #cplusplus #arrays #cstring

Ahem. A C++ void function *must not* include a return statement.

#cpp #cplusplus #teaching #functions

EDIT: please see the reply from @glloyd and my reply to that. I apologize for, in being brief, suggesting that a void function cannot at all have a return statement.
https://elk.zone/fosstodon.org/@glloyd/110299354968932782

Gareth Lloyd (He/him) (@glloyd@fosstodon.org)

@smurthys@hachyderm.io Not quite, return is implicit when flowing off the end of a non-coroutine function with a cv void return type. Also consider early exit. https://eel.is/c++draft/stmt.return

Fosstodon

"Teaching C++ is easy. After all, I know C."

Also, that reason to declare functions: 🤦‍♂️

#cpp #cplusplus #teaching #functions

"You keep using that word "template" in unfortunately incorrect/confusing ways." 😢

#cpp #cplusplus #teaching

At this point, I mean why not just go with this imperative on structs? 🤦‍♂️

#cpp #cplusplus #teaching

Sure, if by "declaration", you mean "instantiation".

#cpp #cplusplus #teaching #structs

I wasn't going to mention the endl issue because most C++ books have that issue. On that front, this book briefly gave me hope that it distinguishes between '\n' and endl, but alas that lasted only two pages.

The book uses \n for newline exactly once, then mentions endl, and it's all endl from then on. 😢

#cpp #cplusplus #teaching

For context, the aforementioned textbook for an intro CS course 👆 was first published in 2014 and revised in 2018.

#cpp #cplusplus #teaching

@smurthys maybe thinking of
typedef struct foo {} foo;
@PeterSommerlad Not even remotely. The book goes nowhere near that sophistication.

@smurthys

Not quite, return is implicit when flowing off the end of a non-coroutine function with a cv void return type. Also consider early exit.

https://eel.is/c++draft/stmt.return

[stmt.return]

@glloyd I omitted describing a rather tedious section of the book which made my point valid but the phrasing in my post is incomplete with respect to the specific situation.

I now see that without that tedious context, my post says that a return statement cannot at all be used in a void function, and of course that is incorrect. 🫣

PS: I edited OP to link to your reply.

@smurthys No worries, I've done that so many times.

For brevity, omitting context, then in isolation it appears foolish.

@smurthys I don't teach arrays (only for experts and then to hide them deeply)
@smurthys may be I should finally restart AND finish my C++ textbook. My problem was time and always being overtaken by new standard revisions
@smurthys I was teaching it for UNIX system call trainings in the 1980s. also because shell scripts tend to use exit to set an error status
@smurthys I'm beginning to suspect it's not a great book.

@shiide Now imagine: This is *the* required book and material must be taught strictly from this book. Plus, students' answers to exam questions must match what this book says. 😢

I'm not making this up.

@smurthys Namespaces are overrated!
Turbo/Borland C++ is still haunting us today 😢
@smurthys such an 1989 feeling. at least no endl
Sean Murthy (@smurthys@hachyderm.io)

Attached: 3 images I wasn't going to mention the endl issue because most C++ books have that issue, but this book briefly gave me hope that it distinguishes between '\n' and endl, but alas that lasted only two pages. The book uses \n for newline exactly once, then mentions endl, and it's all endl from then on. 😢 #cpp #cplusplus #teaching

Hachyderm.io
@smurthys i need to clean myself out after having seen just 2 additional excerpts. any barf bag ready.
@smurthys reads like someone with very bad C knowledge attempting to write a C++ book on C++ from mid 1980s (Turbo-C++ 1.0?)
@smurthys This was in my C++ book from 1997. Nobody should be using a book that says this in the past quarter century.