Jump to content



Photo

Newbie C++ Help


  • Please log in to reply
211 replies to this topic

#181 Siliad

Siliad

    Neowinian

  • Joined: 04-December 01

Posted 09 June 2009 - 02:17

Hi guys. I'm not in any computer-related programs in University/College but I've decided that I have too much free time, and I'd like to pick up programming as my hobby (don't really have a real one at the moment). I was thinking of starting with C++ to learn the basics of OO programming, and then moving onto C# or Objective-C... My end goal is to either join an indie game development team until I have enough experience to possibly lead my own way down the line or to write iPhone or Android applications... depending on how I feel after experiencing some programming. I'm not a total newb, I took some high school programming courses (in Java and Visual Basic, I also know HTML/CSS from personal experience) so I'm not going into this completely blind.

Any pointers for someone in my position? Tips? Advice that isn't "don't even bother trying?" Thanks in advanced! I have lots of motivation and a strong will so I think I should be able to do it.


#182 code.kliu.org

code.kliu.org

    Curmudgeon

  • Joined: 25-May 09
  • Location: .us

Posted 10 June 2009 - 00:41

If you've done Java, you've already had an overdose of OO. I'd actually recommend starting with C. It will give you a much better understanding and appreciation of How Things Really Work, and once you've gotten that, the higher languages will make much more sense.

#183 Andre S.

Andre S.

    Asik

  • Tech Issues Solved: 10
  • Joined: 26-October 05

Posted 10 June 2009 - 00:53

Hi guys. I'm not in any computer-related programs in University/College but I've decided that I have too much free time, and I'd like to pick up programming as my hobby (don't really have a real one at the moment). I was thinking of starting with C++ to learn the basics of OO programming, and then moving onto C# or Objective-C... My end goal is to either join an indie game development team until I have enough experience to possibly lead my own way down the line or to write iPhone or Android applications... depending on how I feel after experiencing some programming. I'm not a total newb, I took some high school programming courses (in Java and Visual Basic, I also know HTML/CSS from personal experience) so I'm not going into this completely blind.

Any pointers for someone in my position? Tips? Advice that isn't "don't even bother trying?" Thanks in advanced! I have lots of motivation and a strong will so I think I should be able to do it.

I'll have to disagree with kliu0x52 and recommend a modern language such as C#. C doesn't teach you to think with objects and encourages practices considered sloppy such as extensive use of the preprocessor, global functions and variables, abuse of casts, using return codes for error-checking, memcpy(), and the list goes on. Skip C for now, you can always learn it later, it's very simple (and very stupid).

To learn the basics of OO you're much better off with a real, pure OO language like Java or C# than C++. C++ is hard to learn and you won't be productive with it before quite a while. However, it's definitely a big plus (a double plus :p) to know C++ if you want to work as a programmer, and going through it definitely teaches you a lot of things about how higher-level languages work under the hood. I personally started with C++, and I must say all the other languages were a breeze and a relief after that.

#184 code.kliu.org

code.kliu.org

    Curmudgeon

  • Joined: 25-May 09
  • Location: .us

Posted 10 June 2009 - 01:36

C doesn't teach you to think with objects

It teaches the underpinnings of OO. He's already done OO in Java. C teaches you how OO is implemented. Back when I tutored people and had to explain to them things like static and virtual methods, I often found that the best explanations, the ones that elicited a "oh, I get it now, that makes so much more sense than how I was taught" was when I broke things down and explained how OO was implemented and how that affects why some things in OO are the way that they are.

It's the difference between telling someone that they can use a fire extinguisher to put out a fire and explaining to someone what goes on chemically when something burns and how, as a result, you can stop a fire by either depriving it of the reactants--the latter makes the former more understandable and also opens up a wider perspective (e.g., "so that means that I can also stop a fire by dumping sand on it since that too will choke out the oxygen, right?").

encourages practices considered sloppy such as extensive use of the preprocessor, global functions and variables, abuse of casts, using return codes for error-checking, memcpy(), and the list goes on.

You don't have to use the preprocessor that much, and C does not encourage the use of global variables. The so-called "abuse" of casting is just a way of revealing How Things Really Work. And I don't see how memcpy is abusive.

Skip C for now, you can always learn it later, it's very simple (and very stupid).

It's very simple. And insanely powerful. And absolutely essential for anyone who wants to be a real programmer (instead of just a hobbyist). And an understanding of C will make so many things in other languages make more sense.

I'll admit that I do harbor a very deep disdain for Java and C# (I've been known to call them toy languages when I'm cranky :)). "Modern" languages focus on making life easier for the programmer. And they focus on a "bigger picture" approach to development. It's all about big, grand architecture and it's great if you are working on some large project comprised of various interconnected components. And if that's what you're doing, then yea, go ahead and use an OO language--there is a time and place for them! But be aware that they really narrow your perspective; learning C# is like vocational training while learning C is really learning how to program. Someone (I forgot who) once wrote that Java and C# is a lot like a hardware store approach: you walk in and look on the shelf for some part to do the thing that you need; it takes away from a lot of the problem solving and ingenuity of real programming.

The other big problem is that abstractions are not perfect. One of the Google founders once joked that software gets twice as slow every 18 months and that's why we need Moore's Law. But why is that? When people are so far separated from What Really Goes On Underneath, they are liable to make dumb design decisions. For example, SOAP. Or anything XML, for that matter (obviously, whoever thought it'd be cute to use XML for everything has no friggin' idea of the costs associated with using XML as a format). If you knew that concatenating two strings involves creating a new string, copying the contents of string A, copying the contents of string B, and freeing string A and B, then you'd be more careful about using such operations unnecessarily. If you understood what kind of huge bookkeeping costs the heap manager has to go through to allocate the memory of string C and "free" the memory for string A and string B (heaps are very complicated and are very expensive clock-cycle-wise), then you'd be even more keen to avoid such operations (or use the stack or some custom allocation scheme if possible). If you understood what the system has to go through to carry out a floating point operation, then you'd use x+=x<<1 instead of x*=1.5 (okay, granted, knowing C won't expose the costs of floating point or heaps, which is why I also advocate learning a bit of assembly :)). The "modern" languages want you to ignore such inconvenient details. And as more people write code without knowledge of What Really Goes On, then we will get progressively less efficient code (I'm not saying that you should abandon C# for C, but rather that if you knew C, then that understanding of the guts of the system will make you a more efficient C# programmer).

#185 Siliad

Siliad

    Neowinian

  • Joined: 04-December 01

Posted 10 June 2009 - 05:10

Hello. Thanks for the replies.

My former experience with programming happened over 6 years ago so I am quite rusty and do not remember, but I think I would be able to pick it up eventually. Thank you both for your advice, but I think starting with C may be a good idea after all - kliu0x52 makes a very convincing argument :)

I plan on starting as a hobby, but depending how much I enjoy doing it, it could move onto a full-time career for me. I've grown up around computers yet never dived into programming seriously. I think that time has come now. Any advice on where to start? Any good books or websites for someone in my position? I do not remember much about OO or procedural programming at all.... my most recent programming knowledge is HTML & CSS which probably won't help with where I am headed. Any direction would be appreciated!

#186 ekw

ekw

    ͼ(͌͝-͚͌͜-͌)ͽ

  • Joined: 11-November 08
  • Location: California

Posted 10 June 2009 - 05:41

Hello. Thanks for the replies.

My former experience with programming happened over 6 years ago so I am quite rusty and do not remember, but I think I would be able to pick it up eventually. Thank you both for your advice, but I think starting with C may be a good idea after all - kliu0x52 makes a very convincing argument :)

I plan on starting as a hobby, but depending how much I enjoy doing it, it could move onto a full-time career for me. I've grown up around computers yet never dived into programming seriously. I think that time has come now. Any advice on where to start? Any good books or websites for someone in my position? I do not remember much about OO or procedural programming at all.... my most recent programming knowledge is HTML & CSS which probably won't help with where I am headed. Any direction would be appreciated!

I doubt you will score a fulltime career without a CS degree. In my university comp sci classes has a few 40-50 year old people trying to get their degree because they can't even find a job with 20+ years of programming experience.

But as a hobby, by all means pursue it. You can probably start off with some programing tutorial videos (good place to look is @ torrents) and pick it up pretty quickly with your prior experience.

As far as developing applications, I can't help you there (I'm more of a systems programming guy). But i can tell you that its best to use a sophisticated IDE (For example, you really wouldn't want to program a gui by hand, i tried it and progress has been veerryy slow for me [lost motivation])

SO where to really start? thats up to you. Google something like "developing applications for iphone" and see where that takes you. Hit a roadblock? google the obstacle and learn how to overcome it. Thats how i self-learn, maybe it will work for you.

#187 Andre S.

Andre S.

    Asik

  • Tech Issues Solved: 10
  • Joined: 26-October 05

Posted 10 June 2009 - 14:17

Thank you both for your advice, but I think starting with C may be a good idea after all - kliu0x52 makes a very convincing argument :)

I'll eventually take the time to respond to his argument properly, but I'm not that strongly opposed to learning C first. After all, I started with C++, which is a superset of C. So, C it is, then. It's one of the least productive languages on earth, but it does show you the basics. Just don't stick around with it for too long, you'll grow bored.

Any advice on where to start? Any good books or websites for someone in my position?

A good C tutorial :

http://www.cprogramm....html#ctutorial
A good book : http://www.amazon.co...5/ref=pd_cp_b_1

A good development tool : http://www.microsoft.com/express/vc/

Tip : when you create a new project in Visual C++, make sure you select a general, empty project (I think the default is a Win32 application). Also, since you want to write C, not C++, go to your Project Properties and somewhere in the compiler options you'll be able to set "Compile as C" (it will be Compile as C++ by default).

Have fun. :)

Edited by Dr_Asik, 10 June 2009 - 14:44.


#188 hdood

hdood

    Neowinian Senior

  • Joined: 25-February 04

Posted 10 June 2009 - 14:42

Hi guys. I'm not in any computer-related programs in University/College but I've decided that I have too much free time, and I'd like to pick up programming as my hobby (don't really have a real one at the moment). I was thinking of starting with C++ to learn the basics of OO programming, and then moving onto C# or Objective-C... My end goal is to either join an indie game development team until I have enough experience to possibly lead my own way down the line or to write iPhone or Android applications... depending on how I feel after experiencing some programming. I'm not a total newb, I took some high school programming courses (in Java and Visual Basic, I also know HTML/CSS from personal experience) so I'm not going into this completely blind.

There is no generic answer, what tool you should pick depends entirely on what it is you want to do, and not to discourage you, but it's a very long road.

Before you learn any programming language, you should be comfortable with the underlying programming concepts that are common to most languages and understand how computers and operating systems work. Learning a lower-level language like C (or C++ without all the abstract stuff) is helpful here, as it teaches you how the system works without a lot of abstraction.

If you want to write games for Windows, there is really only one path, and that is learning C++ and C (most C features are available from C++ as well, and most C code is valid C++). That is only the start though. After you do that, you have to learn the most common Windows APIs (which are all C, but accessible from C++). Once you've got the foundation of C++ and Windows down, you can move on to learning the basic 3D concepts (provided you understand the math already). Once that's done, you can start learning Direct3D and the other toolkits that make up DirectX (ie sound, input/output, etc). You'll also have to learn the basics of the various graphics and 3D tools, since you'll probably want to make basic mock-up graphics yourself.

If, on the other hand, you want do do iPhone development, you'll have to fork up the cash for a Mac and the development tools (you cannot do this from Windows), and then learn objective-C and the basics of OS X. Android, I believe is focused solely on running Java programs (at least it is on the phones currently on the market), so you'll have to know Java and the APIs it uses.

#189 Andre S.

Andre S.

    Asik

  • Tech Issues Solved: 10
  • Joined: 26-October 05

Posted 10 June 2009 - 15:00

If you want to write games for Windows, there is really only one path, and that is learning C++ and C (most C features are available from C++ as well, and most C code is valid C++). That is only the start though. After you do that, you have to learn the most common Windows APIs (which are all C, but accessible from C++). Once you've got the foundation of C++ and Windows down, you can move on to learning the basic 3D concepts (provided you understand the math already). Once that's done, you can start learning Direct3D and the other toolkits that make up DirectX (ie sound, input/output, etc). You'll also have to learn the basics of the various graphics and 3D tools, since you'll probably want to make basic mock-up graphics yourself.

For a game development career, that's true, but a hobbyist can write games for Windows using C# and XNA, or Python and PyGame or any similar tools, and be a lot more productive (and have that much more fun doing it) than going the long-winded C++/D3D path. Also, all the non-framework-specific things you learn using these tools are valid if you later learn C++ and DirectX. 3D math, pathfinding, game architecture, basic UI skills, etc., those are the most important skills and they apply whatever language you use.

#190 Siliad

Siliad

    Neowinian

  • Joined: 04-December 01

Posted 10 June 2009 - 18:11

Thanks again for the replies!

I doubt you will score a fulltime career without a CS degree. In my university comp sci classes has a few 40-50 year old people trying to get their degree because they can't even find a job with 20+ years of programming experience.


Yeah, I realize this. If programming became more of a hobby for me, I'd have no problem going back to school for a CS degree. Then again, Ken Levine, creator of System Shock & BioShock, had a BA and look at him now... so I have hope.

Thanks for your advice as well, Dr_Asik... especially the Visual C++ settings advice... I probably would not have been able to figure that out myself!

hdood, thanks for the informative reply. In terms of PC game development (starting with Windows), I'd most likely start with 2D games (platformers, RPGs)... of course, this is once I even get to the point of being able to do this, which I realize is down the long road. (Then again, with learning any skill, it takes years so I don't expect programming to be any different... if anything, I imagine it takes longer)

I understand there is a large difference in difficulty in creating 2D vs 3D games as well... but that is far down the road. I guess I shall get my bearings on C/C++ down first. I understand why people go to school to learn this stuff - it can be intimidating without direction from a knowledgeable person.

I'll be checking this thread from time to time, so if anyone has last-minute advice on direction for me, I would appreciate it. :)

#191 hdood

hdood

    Neowinian Senior

  • Joined: 25-February 04

Posted 10 June 2009 - 18:31

hdood, thanks for the informative reply. In terms of PC game development (starting with Windows), I'd most likely start with 2D games (platformers, RPGs)...

[...]

I understand there is a large difference in difficulty in creating 2D vs 3D games as well... but that is far down the road.

Yeah, but 2D stuff is actually made with Direct3D now. It's just a 3D scene with no depth so that everything looks flat. If you're running Vista or Windows 7 you're even looking at a Direct3D scene right now. Your browser window is actually two flat triangles put together to create a square, and then the contents of the window is pasted onto them as a texture.


Asik's suggestion of C# and XNA might be an option to get something working faster and familiarize yourself with gaming concepts, even if the language and toolkit isn't very relevant for real game development.

#192 Andre S.

Andre S.

    Asik

  • Tech Issues Solved: 10
  • Joined: 26-October 05

Posted 10 June 2009 - 19:24

It teaches the underpinnings of OO. He's already done OO in Java. C teaches you how OO is implemented. Back when I tutored people and had to explain to them things like static and virtual methods, I often found that the best explanations, the ones that elicited a "oh, I get it now, that makes so much more sense than how I was taught" was when I broke things down and explained how OO was implemented and how that affects why some things in OO are the way that they are.

First, you overestimate his skills in object-oriented programming. He's done a high school class in Java 6 years ago. It takes much more than a single introductory course in programming to learn anything about OOP, even if it's in a pure OO language like Java; moreover, this was a high-school level course and he's likely forgotten most of it.

As a result, learning C won't help him understand the underpinnings of OOP because he barely has any notion of OOP. Rather than bringing him a better understanding of already well-known high-level languages, it will teach him how to do things in a simple procedural way, making the transition to OOP less natural. I think it's better to get a very good feeling of OOP asap because good habits are essentials and bad habits are hard to get rid of. Thus my recommendation of C#. Or even C++ for that matter (even though it sucks as an OO language).

It's the difference between telling someone that they can use a fire extinguisher to put out a fire and explaining to someone what goes on chemically when something burns and how, as a result, you can stop a fire by either depriving it of the reactants--the latter makes the former more understandable and also opens up a wider perspective (e.g., "so that means that I can also stop a fire by dumping sand on it since that too will choke out the oxygen, right?").

Sure. But it's better to teach them first how to use a fire extinguisher, so that if a fire starts before the course is over, at least they'll be able to do something against it. Knowing how to use a fire extinguisher, they could even start earlier practicing other fire-fighting skills such as safely evacuating the building, using the right extinguisher against a certain type of fire, etc. With a higher-level language, you're not only productive faster, you also start learning other important programming skills earlier, such as reusing well-tested code instead of making up your own, decoupling components using interfaces, events, making exception-safe code, etc. It's not wasted time.

You don't have to use the preprocessor that much, and C does not encourage the use of global variables. The so-called "abuse" of casting is just a way of revealing How Things Really Work. And I don't see how memcpy is abusive.

How things really work is that there are no type, no variables, no decimal values, no characters, no internet connections. There are just bits and buses. A C variable is an abstraction over a reserved memory area in assembly. A C for loop is syntactic sugar for a jump and a label in assembly. It's nice to know about it, but you rarely need to know what's happening at that level. And the same applies with C# vs C. Sure it's nice to know what really is a virtual method, but you rarely need to care about that. It's pretty advanced stuff and a beginner doesn't need to know about it right off the bat, it can be overwhelming. I think it's much more encouraging if a beginner can quickly see results with few lines of code and make lots of cool applications, then if he wants to take it to the next level he can look under the hood and try to understand how to write better code.

Also, you shouldn't be thinking your design at such a low-level. You should think your design at the highest possible level (interfaces, objects, packages, etc), and the highest possible level in C is depressingly low. There should be a difference between design and implementation, and C offers little support for that.

As for memcpy() : http://www.theregist...anishes_memcpy/

It's very simple. And insanely powerful. And absolutely essential for anyone who wants to be a real programmer (instead of just a hobbyist). And an understanding of C will make so many things in other languages make more sense.

"Real programming" isn't synonymous with "system programming". Writing a windows application in Visual Basic is real programming. Writing an ASP.NET application for a web browser is real programming. Some programmers make a living out of just that, and they probably know a lot of things about application development a system programmer doesn't know. It's just a different field of specialization. A lot of C programmers today are unwilling to learn anything else than C and they can't do OOP and they can't do functional programming. Is that better? I think it's worse.

As for the rest, I share your views about the importance of learning the fundamentals of computing (yes, including C) and how it's important to know the implications of what you're writing in higher-level languages. Any good software engineering or computer science program in university should teach you that; if they don't, choose another university. But I think new programs should not be written in C unless it's absolutely necessary. Usually you can use at least C++. And usually only part of the program absolutely requires the use of a system language; the rest can be written in Python or Java or whatever. If you take games, for instance, only the engine is written in C++, the actual logic is written in Lua or other scripting languages. I think using these new languages greatly helps to make a smaller codebase, one that's faster to develop, easier to read, maintain and expand upon; and you can easily get good performance with them if you know what you're doing.

Edited by Dr_Asik, 10 June 2009 - 19:34.


#193 code.kliu.org

code.kliu.org

    Curmudgeon

  • Joined: 25-May 09
  • Location: .us

Posted 10 June 2009 - 21:45

First, you overestimate his skills in object-oriented programming. He's done a high school class in Java 6 years ago. It takes much more than a single introductory course in programming to learn anything about OOP, even if it's in a pure OO language like Java; moreover, this was a high-school level course and he's likely forgotten most of it.

Fair enough. I'll concede that.

As for memcpy() : http://www.theregist...anishes_memcpy/

I'll nit on this red herring: that's a really bad article. In version 13.1 of its compiler (first used in VC7.1, XPSP2, and 2K3SP1 and supported the an appropriate SDK update around the time), Microsoft introduced "safe" copy methods that it has been encouraging everyone to move towards (and this was made the default in 14.0). These safe methods (which encompasses far more than memcpy) basically just add "cookies" to the memory that it checks to make sure are not overwritten, and all that MS was doing was saying finalizing this transition to those methods. These are still C functions, but with some nanny-checking. And the funny thing is, despite this new policy change Microsoft is still discovering bugs. As it turns out, Microsoft programmers are not dumb, and various analysis of patches that they've released have revealed that, for the most part, they've covered all the obvious problems; the sorts of problems that are being discovered are much more complex and nuanced and are not going to be solved this way.

"Real programming" isn't synonymous with "system programming". Writing a windows application in Visual Basic is real programming. Writing an ASP.NET application for a web browser is real programming. Some programmers make a living out of just that, and they probably know a lot of things about application development a system programmer doesn't know. It's just a different field of specialization. A lot of C programmers today are unwilling to learn anything else than C and they can't do OOP and they can't do functional programming. Is that better? I think it's worse.

I never said that people should not learn OOP. What I did say and emphasized in my sentence "And an understanding of C will make so many things in other languages make more sense." is that anyone who wants to do real programming needs to know C, not so much because they'll actually use C, but because it is the necessary foundation. Scientists crunching data from an experiment are not going to do 1.2345678 * 8.7654321 on a piece of paper. They will use a calculator or something like MatLab. So does that mean that we should tell elementary school kids, "hey, you don't actually need to do long multiplication in your life, so let's not waste time on that in class". As I said at the end of my post, "I'm not saying that you should abandon C# for C, but rather that if you knew C, then that understanding of the guts of the system will make you a more efficient C# programmer."

I think where we differ is whether that foundation should be established first or is something that you go back and build after you've gotten the rest, and that's a legitimate area of debate. I've long advocated for Perl as a good first get-your-toes-wet language because it's multi-paradigm (you can do classic imperative, you can do some OOP, and you can do functional programming--my personal experience was that Perl helped make learning Lisp easy) and, most importantly, it's extremely forgiving (because even I don't think that the first experience of a programmer should be some cryptic compiler warning :)). And then after that, get into C (I recommended C in this thread because he had already done some programming before, so he was, in my mind, at step 2). Once someone has gotten down the basics (the concept of variables, loops, conditionals, and functions), then it's time to build the formal foundation in part because it's so easy to ignore that foundation it once you've gotten the other stuff down (and it annoys me that so many people do ignore it) and in part because I see knowing the low-level stuff as helping grasp the nuances of the high-level stuff and not so much the other way around.

#194 Andre S.

Andre S.

    Asik

  • Tech Issues Solved: 10
  • Joined: 26-October 05

Posted 10 June 2009 - 23:46

The C language makes for a nice step 2, indeed. I think we agree for the most part, so I'll spare you the nitpicking (and I don't feel like it either :) ). Thanks for the intelligent discussion.

#195 Siliad

Siliad

    Neowinian

  • Joined: 04-December 01

Posted 11 June 2009 - 02:27

I think where we differ is whether that foundation should be established first or is something that you go back and build after you've gotten the rest, and that's a legitimate area of debate.


This is the main area that concerns me... I'm a little confused as to where to start. You guys are saying that C is a good step two, but I feel that after all this time away from the programming experience I've had, I should maybe start at step one for a month or two... or is that too short/long. Suggestions? :p



Click here to login or here to register to remove this ad, it's free!