Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1369500 Posts in 64351 Topics- by 56368 Members - Latest Member: concrete_games

November 20, 2019, 01:49:20 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Should I learn C before C++?
Pages: 1 [2]
Print
Author Topic: Should I learn C before C++?  (Read 1112 times)
fluffrabbit
Guest
« Reply #20 on: July 17, 2019, 10:44:45 PM »

Quote
If you ever thing using any of the strxxx functions or char*s as strings, you've gone too far.
Only if you plan on switching to C++. char* is a C string, and it seems to work about as well as this new-fangled string_view stuff in C++17. Why not learn the basics of a language that you have set out to learn?
Logged
Prinsessa
Level 10
*****


Ava Skoog


View Profile WWW
« Reply #21 on: July 18, 2019, 05:34:00 AM »

Even if one goes full-fledged modern C++ one will probably have to interface with C libraries or older-style C++ ones so it's always good to know how those things work too.
Logged

qMopey
Level 5
*****


View Profile WWW
« Reply #22 on: July 18, 2019, 11:25:21 AM »

Take a look at C, but don't go too deep. If you ever thing using any of the strxxx functions or char*s as strings, you've gone too far.

This is horrible advice  Facepalm
Logged
InfiniteStateMachine
Level 10
*****



View Profile WWW
« Reply #23 on: July 18, 2019, 05:36:13 PM »

I learned c++ first. It's hard to tell what changes when I was first learning would have benefit me most but I think I can say with some level of confidence that you should learn to program with c++ as a starting language.

Do you already know how to program or is this your first programming language?

OOPS I meant to say you should NOT choose c++ as your first programming language :X

Edited/Fixed my original post. My bad.

Logged

kason.xiv
Level 0
**


View Profile
« Reply #24 on: July 19, 2019, 02:22:11 PM »

...

OOPS I meant to say you should NOT choose c++ as your first programming language :X

Edited/Fixed my original post. My bad.


You really had me befuddled there for a second
Logged
Daid
Level 3
***



View Profile
« Reply #25 on: July 20, 2019, 02:56:15 AM »

Take a look at C, but don't go too deep. If you ever thing using any of the strxxx functions or char*s as strings, you've gone too far.
This is horrible advice  Facepalm
Maybe the advice comes from the fact that working with strings in C is a pain the the butt compared to using std::string. It might be a tad less efficient, but it's much less memory error prone.

I stopped counting the cases of "Person A made a 'clever' C string processing routine, Person B changed the functionality and introduced some kind of corruption because he wasn't as clever as person A. And then Person C runs into that actual bug."

Ofcourse, this is made worse with the C string functions losing their "const correctness", like:
Code:
char * strchr ( const char *, int );
So:

Code:
strchr("ABC", 'B')[0] = 'X';
printf("ABC");

Will:
  • Not compile in C++, but compiles fine in C.
  • Might crash, print "ABC" or print "AXC", depending on your compiler and target platform.
Logged

Software engineer by trade. Game development by hobby.
The Tribute Of Legends Devlog Co-op zelda.
EmptyEpsilon Free Co-op multiplayer spaceship simulator
Schrompf
Level 6
*

C++ professional, game dev sparetime


View Profile WWW
« Reply #26 on: July 21, 2019, 10:24:54 PM »

Maybe the advice comes from the fact that working with strings in C is a pain the the butt compared to using std::string. It might be a tad less efficient, but it's much less memory error prone.

I wanted to chime in that: due to small string optimization, std::string outperforms C-Strings for average tasks. The only nice thing you can do with C-Strings is to point to them, and std::string_view does that even better because it doesn't have to count every time you want to do something with its content.

On the topic: I don't think it's required to learn C before C++, but it certainly doesn't hurt. Maybe you get the basics of stack vs. heap more easily there, and you get a feel for what std::string, std::map and the like are doing under the hood.
Logged

Snake World, multiplayer worm eats stuff and grows DevLog
fluffrabbit
Guest
« Reply #27 on: July 21, 2019, 10:30:45 PM »

I don't know why, but with C++ I amass technical debt a lot quicker. I like to keep things simple. The Cave Confectioner codebase is a nightmare.
Logged
Pages: 1 [2]
Print
Jump to:  

Theme orange-lt created by panic