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
I'm sorry if I accidentally started a flame war, but I have never been a member of a forum before
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.
Advertisement

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!

[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).
[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 ]

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.
I started with C++ as my first language. I'm glad I did, but I wouldn't recommend it to others
+1 biggrin.png
Advertisement

[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
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.
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.

@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.

This topic is closed to new replies.

Advertisement