Skip to main content
gamedev.net
🔒 Locked

anyone start with c++ as their first language?

Started by fusion1 49 replies 13k views
Original Post
fusion1
fusion1
So, i have been reading much on the internet that c++ is not a good idea to start with, however i wondered if people had tried c++ as their first language anyway(including myself). I was wondering from these sources of which i have read whether you believe this is the case as well.

As a side question, what language did you do after c++(in terms of learn)?

Thank you for your time
Cornstalks
Cornstalks
rolleyes.gif this is just going to end in a holy war, you know. If you really want to know why people say C++ isn't a good language for beginners, start with Washu's quizzes. I've never, ever met anyone who can correctly answer all the questions without cheating, including industry experts. And they're not even complicated questions.

That, and tell me the bug in this program:
[spoiler]

#include <iostream>
#include <string>

int main()
{
std::string str = "Hello world!";
const char* helloWorld = str.c_str();

str = "How are you on this fine day?";
const char* question = str.c_str();

std::cout << helloWorld << "\n" << question << "\n";
}

[/spoiler]

You might be able to tell me, but it's little nuances like this that can cause beginners to start with some bad habits.

But whatever, it's not the end of the world. You can start with C++. It's your choice. It's not going to stop you from progressing in CS. You and I might have different opinions on what might be more effective for a beginner, but honestly, it's really not that big of a deal.

I started with Basic (DarkBASIC, to be exact), then went to C++, then Java, then C#. I primarily develop in C++ at work, school, and home hobby stuff though.
fusion1
fusion1
redefining the str variable, i may be wrong. But i dont cheat
Antheus
Antheus
Yes, many have.

Next question.
ApochPiQ
ApochPiQ
How many languages do you know? How long have you been programming? Can you answer the quiz linked above?

My point here is just that you probably are under-qualified to be disagreeing with the opinions of highly experienced, highly knowledgeable subject matter experts who say C++ is a bad language to begin with.

Also, one data point (i.e. you) does not invalidate the overarching advice, even if you are actually good enough to disagree with the conventional wisdom (which I'm skeptical about, frankly).
way2lazy2care
way2lazy2care
Whether or not you can is irrelevant. Tons of people have and will start with C++. The real debate is over whether it is the most useful language to start with in large part because the number of concepts required to teach how to program (ie. non-syntax specific programming concepts) is very large in C++. What's worse is that starting in C++ without an understanding of the previously mentioned concepts can cause you to pick up very bad habits if nobody is making sure you're doing everything correctly.

edit: I say this knowing I am not a C++ expert. Those are just the reasons I wouldn't want to learn it first.
Luckless
Luckless
C++ was the first programming language I tried to learn way back in High School. The end result was learning to be a piss poor programmer with exceptionally low productivity when I worked on projects. Learned Java in university in far less time, and was able to focus more on actually solving the problem at hand rather than trying to work out what the language was actually doing. Then was introduced to C and low level assembly at the same time I started learning Python. Things made sense, things were easy, productivity soared, and I haven't looked back from Python with C as needed.


Really, it doesn't matter what you start with, as long as you start. Some languages, such as Python, let you move forward with greater ease, and cost you far less of your hair.
Old Username: Talroth
If your signature on a web forum takes up more space than your average post, then you are doing things wrong.
GeneralQuery
GeneralQuery
I started with C++. However, that was over 15 years ago. The landscape has changed considerably since then and I certainly wouldn't choose it as a starting point if I had to somehow start over again. I think the reason why beginners who start with c++ think that it's not as bad as everyone says is because they're thinking in terms if syntax. The syntax is no more difficult than, say, c#, java etc but that is not where the "gotchas" lie, they lie in other mire subtle, nuanced areas that can and will cause unproductively and frustration for the inexperienced. Energy is better spent on more productive areas rather than esoteric logical bugs that you'll pull your hair out over. If you haven't sussed cornstalk's example, compile the code and attempt to find the answer by debugging. Then ask yourself whether or not it was a productive use of your time.
fusion1
fusion1
i actually started with c++ anyway, i did find it rather difficult. I think may have unintended for the message come across as it did and i do not and probably never will , i have studied c++ for a few months and i just wanted to know if anyone was in the same position as i was at some point. I definitely am to under qualified to disagree with these people, but it was down to my personal preference at the time of starting. I wanted to study this because i saw a large amount of software made for it, so i jumped in.it may have been a bad move (as GeneralQuery mentioned) as i spent most of the time on my larger projects tearing my hair out at bugs that i couldn't find.

it was merely personal preference from what i have learned. i think i will re word the post

thank you for your time
fusion1
fusion1
i suppose it was rather stupid to put this topic up in the first place considering some of the response
fusion1
fusion1
I'm sorry if I accidentally started a flame war, but I have never been a member of a forum before
Servant of the Lord
Servant of the Lord
I started with C++ as my first language. I'm glad I did, but I wouldn't recommend it to others - even if I decided to take a masochistic route for my first language, there are languages available that make it easier to become a programmer and in less time.
I know C++ well enough to work on my own projects, but I'd be pretty delusional if I think I fully understand it - there are far too many 'gotchas', and many minor features that you never normally encounter in day-to-day coding.
SimonForsman
SimonForsman

redefining the str variable, i may be wrong. But i dont cheat


There is nothing wrong with reassigning a non constant std:string. (str is only defined once)
The problem i think (I'm probably wrong aswell) is with the c_str method returning a const char pointer to an internal buffer (it doesn't copy the buffer), both char * helloworld and char * question stores a pointer to the buffer used by str.

There are afaik 2 possible things that can happen:
1) when str is reassigned it allocates a new buffer and freeing the one pointed to by char *helloworld( char* helloworld will then point at what is effectivly garbage that can be overwritten at any time)
2) str reuses the old buffer (or reallocates it without changing its starting position), the data pointed to by helloworld will be overwritten and both the char * variables will point to the exact same text.

The problem with this is that the program will compile and run happily as if nothing was wrong, it can even produce the correct result when you test it but fail or crash when one of your customers run it or when you add more code to the application (having your application break because of an old bug when you add new code is never fun as it becomes quite difficult to figure out where exactly the bug is)
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!
Cornstalks
Cornstalks

[quote name='fusion1' timestamp='1334678420' post='4932170']
redefining the str variable, i may be wrong. But i dont cheat

*snip*
[/quote]
That is correct, yes. The pointer returned by [font=courier new,courier,monospace]c_str()[/font] is only valid until the next non-const member function of the [font=courier new,courier,monospace]std::string[/font] is called. So in the second assignment, [font=courier new,courier,monospace]helloWorld[/font] becomes an invalid pointer, but it is used in the last line, which results in undefined behavior (at which point anything can happen, from "Hello world!" being printed out, to the program crashing, to a black hole opening up and swallowing us all).
way2lazy2care
way2lazy2care

I'm sorry if I accidentally started a flame war, but I have never been a member of a forum before

If you think this is a flame war, then it shows that you haven't been a member of a forum before ;)

This is probably the most civil programming language discussion I've seen.
Hodgman
Hodgman
I started with C++ as my first language. I'm glad I did, but I wouldn't recommend it to others
+1 biggrin.png
laztrezort
laztrezort

[quote name='fusion1' timestamp='1334694196' post='4932274']
I'm sorry if I accidentally started a flame war, but I have never been a member of a forum before

If you think this is a flame war, then it shows that you haven't been a member of a forum before ;)

This is probably the most civil programming language discussion I've seen.
[/quote]

Give it one more page smile.png
AoS
AoS
I started out with javascript and html, yes yes html is only a markup language, then i worked with php and also sql with mysql. I would say that PHP having very similar syntax to c++ helped a lot. I was already proficient in my braces and such.

I would say that ideally you would have a high level language with identical syntax to whatever end lower level language you wanted to learn as far as the higher level language went. You would move down a list of languages that added progressively more low level stuff as you advanced, and you could follow that line down as low as you wanted to go without having to learn drastically new syntax. Obviously this is never going to happen and many people do fine without it.

I will say that I despised basic after starting with php. Typing out the syntax drove me insane. So verbose.

I can do at least the first washu quiz easily enough. I am not the best c++ programmer in the world though. So don't take my opinion too seriously. I also hate python, I am not a fan of white space. Does not make things easier for me personally.
Washu
Washu
I started out... a long time ago.

I started with BASIC. I've never actually hit any limitations on the usage of BASIC, to be honest. The only reason I moved on from it was plain old curiosity. Heck, you could access IO instructions with BASIC and communicate directly with low level hardware using it. From there I moved on to DEBUG.COM. Yeah. You may remember that if you used DOS. DEBUG.COM was, and perhaps still is, the single best piece of software I've ever used.

From there I moved on to C and C++... oh about 20 years ago? No, longer than that now... it's been a while. Of course, C++ wasn't even standardized back then. But we had compilers for it. If you think the C++ environment today is hard... you have NO IDEA how bad it was. Lets see, that was Microsoft C++ Compiler 2.0 I think? It was a while ago. From there I moved on to Visual C++ 2.0 on Windows 3.11. EXCITING! Writing those HUGE MODE applications. Fascinating thing "HUGE MODE", its not actually HUGE but due to the architecture of the x86 real mode platform it allowed you to run quite large applications... slowly.

Hmm, what happened next? I think it was Microsoft Visual C++ 4... Ahh yes, my first 32 bit compiler. On Windows 95 of all things! My, those were fun days. MFC was huge and buggy, much like today. ATL didn't even exist yet. COM was kicking about, and harder to use than a 747 is to fly by a novice. Oh, and the joys of Win32 programming. Then I moved on up in the world! To Visual C++ 6. Such fun was had with that compiler. It was a mainstay of the windows development world for nearly 6 YEARS. So on and so forth it goes.

Along the way, of course, I picked up many other languages though.. like batch file scripting, shell scripting (linux), python, perl... Heck, I've even done FORTRAN and PASCAL development for some clients. Oh, and can't forget PICK... ahh yes PICK.

You know, its funny, but picking up languages is kind of a habit of mine anymore. Its not hard once you're past the first three or four languages.

I can do at least the first washu quiz easily enough. I am not the best c++ programmer in the world though.

You know, its funny you say that... I would like you to go ahead and post your answers here. Try not to cheat and look at the answers I've already posted though. I've met lots and lots and lots of C++ programmers. Some with novice level experience and some with decades under their belts... and most cannot answer my quiz questions correctly without cheating.
In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.
Tribad
Tribad
@washu:
Thats sounds like my own way of programming language usage.

I started with BASIC on a Wang-System 2200 with a 4kByte magnetic core memory, I had to search for the english word. After that 6502 Assembler on a Apple IIe. And than around 1984 PASCAL on a HP-3000/68. After that I started with C on a HP-UX 5 HP9000/550.
Even PCs have been around at this time it needed until 1988 before I did some programming on a AT clone with 20MHz and a MS-DOS 3.3, I think.
Then I moved on to MS-C compiler 5.0 and the most modern update C/C++ 6.0 compiler.
After that I mostly did programming in C++. So because of all the things I did before it was an easy step but I had no chance of doing it in another order. C++ does not exist as I started programming.
I would say that it probably is not a question what language to learn first. I think it is more important to understand a language. Than it is easy to use it.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.