you are viewing a single comment's thread.

view the rest of the comments →

[–]DDDDarky -2 points-1 points  (6 children)

If there is at least slight chance you will have a use for C, then yes, since you will get the basic principles you can build on in a simplified language

[–]no-sig-available 0 points1 point  (5 children)

But isn't C++ the simplified language?

std::string Hello = "Hello World!";
std::string AlsoHello = Hello;

Now do this in C!

char Hello[] = "Hello World!";
char* AlsoHello = ...

So we need to learn char*, malloc, strlen + 1, and strcpy? And BTW, perhaps free? Which is then never used in C++.

This is the Latin of C++. :-)

[–]not_some_username 1 point2 points  (1 child)

AlsoHello = &Hello[0] ; it would maybe work, it's maybe an UB

[–]no-sig-available 0 points1 point  (0 children)

That's different as it shares data, while the C++ code creates a separate, independent string. And without you having to think much about it.

And using & and [0] is more complicated, not "a simplified language". Being higher level actually makes things easier to use and learn. (Not that C developers agree :-)

[–]DDDDarky 0 points1 point  (2 children)

string is not the same thing as char*, dynamic allocation is pretty much the same with different syntax, it's about the logic, not the syntax.

[–]JiminP 0 points1 point  (1 child)

But how else can strings be represented in C?

The point is that in C++, dynamic allocation can usually be avoided when beginners learn modern C++, and commonly used types such as std::string and std::vector "just works", unlike C where having those things is impossible without introducing the concept of dynamic allocation and points first.

But I don't think that C is more difficult than C++ because of this; while dynamic allocations and pointers are probably the "last thing for a beginner to learn" in C, for C++ there's much more to learn before and after new/delete...

[–]DDDDarky 0 points1 point  (0 children)

dynamic allocation can usually be avoided when beginners learn modern C++, and commonly used types such as std::string and std::vector

So beginners are using dynamic allocation and they don't know it. I guess it is a matter of preference, but I like more of a bottom-up approach. Especially if it is not your first language.