Advertisement

anyone start with c++ as their first language?

Started by April 17, 2012 03:24 PM
49 comments, last by Stroppy Katamari 12 years, 5 months ago

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.
I agree C++ isn't a good choice for beginners, but I'm not sure it's for this reason. I mean, do you consider C a bad choice too? Wouldn't the risk of memory access and deletion problems occur there too? Not to mention that on C, you have to deal with strings as just arrays of chars, where as at least on C++ you don't have to (your example is rather contrived, in that you could just cout the string directly).

I start 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.[/quote]I started with BASIC too, though I think suggesting that as a good first language is also controversial :)

http://erebusrpg.sourceforge.net/ - Erebus, Open Source RPG for Windows/Linux/Android
http://conquests.sourceforge.net/ - Conquests, Open Source Civ-like Game for Windows/Linux


[quote name='Cornstalks' timestamp='1334677178' post='4932164']
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.
I agree C++ isn't a good choice for beginners, but I'm not sure it's for this reason. I mean, do you consider C a bad choice too? Wouldn't the risk of memory access and deletion problems occur there too? Not to mention that on C, you have to deal with strings as just arrays of chars, where as at least on C++ you don't have to (your example is rather contrived, in that you could just cout the string directly).[/quote]
Personally, I'd advise against C as a starting language too. I'd say it's slightly better than C++ for beginners though (C++ adds more complexity), but again, this is just my personal opinion.

And yes, the example is slightly contrived, although I did actually try storing strings as char* in an array from std::strings as a beginner, and when I changed the std::strings my array of char* went to junk. I wouldn't ever suggest doing this in real life, but let's be honest: beginners do a lot of things you probably shouldn't do in real life (I know I certainly did, at least).


I start 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.
I started with BASIC too, though I think suggesting that as a good first language is also controversial smile.png
[/quote]
Oh, I was certainly not suggesting it as a starting language smile.png He just asked what languages people learned after C++, so I gave my short history in learning languages. I did notice at typo though when you quoted it: I meant to say "started" not "start," and I think that could have made it sound like I was suggesting BASIC.
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]
Advertisement
I started with C++, and I don't think it was particularly difficult. Of course, difficulty is relative.

Learning C++ felt quite painless, although it did take several years. What I think was a deciding factor is that the expectations were way different back then. There were no Crysises around, and I was tackling it at my own pace without any rush to reach a particular level or a goal. Learning C++ felt a cool and "hacker"-like geeky thing and I didn't really know about alternatives then. This was somewhere around 1996 with Borland Turbo C++ 3.1.
I started with C++. Actually, I started with C, but I moved onto C++ way too early.

I think there is a lot of worthwhile stuff to learn from C++, but learning it as a first language gives you too much at once. If you start with C++, you have to learn simultenously how to do low level coding, and how to do high-level organising your code into objects, figuring out how they will interact, etc (OOP).

Learning python at first is good, because you can learn to do the OOP, without having to worry about the low level details so much, because python takes care of it for you.

Alternatively, learning C at first is good, because you can focus on the low level details without worrying about how your code is going to fit together. You still have to find a way of making it work, but being a bit messy with your code seems easier if you don't have to organize it into objects. With C, it seems like you can improvise the structure much more easily as you go along, where as with C++, you have to think about it.

That's assuming you use C++ for it's object orientated facilities, but then, that's pretty much the main reason to use it. But if you don't see the point in having object orientated facilities, if you don't really FEEL the NEED for them, then they are just going to take up mental space, and get in the way of thinking about what you're coding.

This is just my experience, though. If somebody said this to me when I started out, I would have avoided loads of problems.
I started with C++, because that's what my college taught its CS1 and CS2 courses in. I think whoever mentioned the point on syntax being the easy part hit the nail on the head. I got through learning individual 'gotchas' from other, more experienced resources (including this forum, woot). Having used many other languages since, the only things I'm particularly appreciative of from working in C++ is:

1) Experience with C++. Always nice to have on a resume
2) Experience working with raw pointers and memory management.

If you (roughly) know what you're doing, the language doesn't get in your way with higher-level programming guards, which is convenient some of the time, and disastrous in other instances. But for 90-ish% of programming tasks, there are many better or easier languages to work in.

All of this prefaced, of course, with "this is just my opinion".

Hazard Pay :: FPS/RTS in SharpDX (gathering dust, retained for... historical purposes)
DeviantArt :: Because right-brain needs love too (also pretty neglected these days)

I started with BASIC on an Atari 1200, then moved to QBASIC on DOS 6. Very shortly after that I moved to Borland Turbo C++ and DJGPP.

BASIC taught me imperative programming. C++ mainly just taught me how to debug (and how). When C# came out, I switched to it and learned OOP and functional styles "for real".

I would recommend using C++ for a few years if you have a burning desire to become truly badass at debugging, but not for anything else.

(edit) Oh yeah, C and C++ are also really good at forcing you to learn how to use third party source, libraries, makefiles, compiler settings, etc.
Advertisement
Here's my feelings on this...

I basically learned programming in college, and they taught C first and then C++. I remember having a real hard time dealing with concepts like pointers, memory allocation, making data structures like linked lists, etc. But I think learning it gave me an edge over a lot of people. It just gives you a more intimate understanding of how things actually work "inside" your computer, and even if you wind up coding in C# or something else where you don't need to worry about pointers and memory addresses...that knowledge will help you.

That said, I'm not sure if I would have successfully learned C or C++ as my first languages without the pressure of a university grade on me and the resources of the university to help. It really can be frustrating at times. In the end, I would say give it a shot if you want, but if you find yourself struggling with pointers to the point where you want to quit, then you may want to mess with C# just to get your confidence back.

Trust me, after you deal with C++, C# will be a walk in the park :)!
I wanted to avoid this thread, but here's my 2 cents.

I started with Basic (GWBasic, QBasic), and moved on to Visual Basic. That time, I tried really hard to learn C++. Really hard. I probably spent months trying to learn that thing, and never moved on beyond std::couts. Tutorials and resources on the web and books just didn't provide enough information for me, and nobody to ask questions to. So I grabbed a book on C, and learned the whole thing in 2 weeks, and even made an app and sold it for $12 in those 2 weeks.

The knowledge in C later proved very useful when transitioning to C++. Things started to make sense to me.

C++ is not for beginners. I think C is more beginner-friendly than C++ is. The reason why is that there's so much things going on in C++, even in the Hello World app that's populating the online tutorials.

Here:
You need to explain #include preprocessor
You need to explain the std namespace.
Before that, you need to explain what a namespace is.
Then you need to explain using namespace. Why do some people put it outside the main() method, and why do others put it inside the main() method. What are the differences?
You need to explain the :: operator, and how using namespace affects that.
You need to explain what cout and cin is (is that an object, a class, a method, what is it?).
You need to explain << and >> operators (wait, that's a bitshift, then why on earth would I want to bitshift a string??)
And before you can do that, you need to explain operator overloading, and the fact that cout and cin overload these operators.

All of these is for a simple Hello World, assuming that the students already knows the basic of programming (methods, operators, classes). Explain that to someone who completely has no knowledge of programming.

Compare this to Python, Ruby, and other languages. Even C doesn't need this much explanation.
I had a pascal class in high school, and had some matlab programming in college (and a day or two of AmigaBASIC, and some bat file scripting, and some dBase scripting) but C++ was the language where I was learning to be a programmer rather than slinging bits to placate absurdly easy assignments.

Then I did some fiddling in php. Some work related stuff in perl. C++ was still core of my learning and personal projects. And by then some 6 years had passed and I was barely competent. Then I moved to C# and increased my productivity about two orders of magnitude after the month or so of learning curve.

So now I wander about forums trying to prevent people from making the same mistake I did.
my progrssion

basic
z80 asm, first without an assembler thus my programs looked like this
37 C9 45 30 AF
great fun, esp when the internet didnt exist
asm
C
then heaps (amiga)

washu why early version of ms c+ msvc it was junk compared to borland (msvc1 is the buggiest program Ive used in my life, using it an hour without a crash was something worth celebrating)
msvc 5 & esp 6 is when they became top of the heap

This topic is closed to new replies.

Advertisement