Skip to main content
GameDev.net gamedev.net
🔒 Locked

C++ or C?

Started by Sheepz May 4, 2009 at 8:07 PM 97 replies 20.4k views
Original Post
Sheepz
Sheepz
Been debating on which language to learn? C++ has OOP, but im not a big fan of it. There seem to be less resources for learning regular old C however so that is why I am a bit worried about it. I am looking to program for fun, and do a few games too. I am going with C or C++ becasue they are lower level, faster, and more powerful than the other options. I have some programming knowledge with perl but its limited to the basics. If you guys know any good books to pick up too feel free to list them.
wild_pointer
wild_pointer
There's no reason you couldn't use C++ to write C code with some niceties. For your purposes, something like Python or C# might be a better though. Any difference in speed is minimal and likely will never be an issue for you. Consult any of a number of "what language should I learn?" threads for more info.
[size=2]
rip-off
rip-off
It seems you have already narrowed down your choice to C or C++. I am going to give some general advise about why that might not be a great idea.

Quote:

I am going with C or C++ becasue they are lower level, faster, and more powerful than the other options.

Well, you have the "lower level" part right, but the others are not guaranteed. Simply put, a beginner probably will not be able to write the fastest code, in any language. Powerful doesn't have any precise meaning when applied to programming languages, so you would have to clarify what you mean when you say a language is "more powerful".

How well do you know Perl? The general consensus here is that sticking to one language until you know it well is a good idea. When you are a beginner, jumping between languages can cause confusion. I don't know if there are any good game programming libraries in Perl, but I am sure there are some.

If I had to choose between learning C and learning C++, I would learn C++. Not just for object oriented programming, but for its standard library, generic programming and RAII, exceptions, references and many more features. There are a lot more differences between C and C++ which you may not be aware of.

But if I had to choose between C++ and a more modern language then I probably would choose the modern one, something like C# or Python.
XTAL256
XTAL256
Quote:
Original post by Sheepz
Been debating on which language to learn? C++ has OOP, but im not a big fan of it.

Why? OOP is a lot easier than plain old C. You may not yet be at the stage where you can see the benefit, but i can tell you it would be a lot easier to write a large application (like a game) in an OO language. Sure, it can still be done in C (GIMP is written entirely in C) but OOP just allows everything to come together a lot nicer.

Quote:
I am looking to program for fun, and do a few games too. I am going with C or C++ becasue they are lower level, faster, and more powerful than the other options.

I think that's probably the other way around. low-level programming, while some find it fun, is generally a pain in the ass. Just look at string manipulation in C compared to C++ (with std::string). That is an example of how OO makes things a lot easier.
[Window Detective] - Windows UI spy utility for programmers
Sheepz
Sheepz
One more thing, I have been using the Bloodshed Dev-C++ complier and im running vista 64bit. I seem to be having issues with getting my programs to run. They compile fine and it ran fine once and now it just won't work. Any other compliers that are more compatible or should I just use commandline and notepad?
Zahlman
Zahlman
Quote:
Original post by Sheepz
I am going with C or C++ becasue they are lower level, faster, and more powerful than the other options. I have some programming knowledge with perl but its limited to the basics.


1) Please tell me why you think being "lower level" is a benefit.
2) Please tell me what you think you're going to accomplish where being "faster" is going to be in the slightest bit useful.
3) Please tell me what you think "more powerful" even means in the context of programming langauges.
4) Please tell me what you think is "limited" about perl, or any other programming language for that matter.
Codeka
Codeka
Quote:
Original post by Sheepz
One more thing, I have been using the Bloodshed Dev-C++ complier and im running vista 64bit.
Why you shouldn’t use Dev-C++.

The problems you're describing are probably not the fault of Dev-C++, though. I suggest you download Visual Studio 2008 Express Edition, try to compile/run your program there, and if you're still having problems, come back with a more complete description of the problem and people will be more than willing to help you out.

I would still second what everybody else says, though. C and C++ are complex languages that require a certain level of understand of programming in general before you can make the most of them. It's better to get an understand of general programming on a "simpler" language first. That's just my opinion of course, and if you're really set on C++ then nothing anybody here can say will stop you trying, I'm sure :-)
MrMark
MrMark
Quote:
Original post by Sheepz
One more thing, I have been using the Bloodshed Dev-C++ complier and im running vista 64bit. I seem to be having issues with getting my programs to run. They compile fine and it ran fine once and now it just won't work. Any other compliers that are more compatible or should I just use commandline and notepad?


Use Visual C++ Express. Its free from Microsoft has the same compiler, and debugger as the professional edition and all the documentation you would need when first starting out. It's also the simplest to use, and its debugger is the best I've seen.

moff
moff
I would recommend C++, and I would recommend starting out with character arrays before trying out the string class contrary to Zahlman's quote. Yes, it will be harder than a language like C#, Python, or Java, but I find the results are much more rewarding from learning the harder way to do things before learning the easy way. It is much harder to go from knowing the easy way, to learning the hard way (and you are much less inclined to bother) - better to have a clean slate, and make sure to get a good solid foundation. I don't have a recommendation for a starting book, but I do think it's better to find a decent book than try to learn from tutorials.

I still usually use character arrays more often than strings, or if I want a string, I'll write my own class - the standard string class isn't that great. But, the point is, I learned a lot about the details of how memory is stored, accessed, and what pointers are by starting with the harder way first. In the end, you'll know more about why and how things work. But if you want the instant pay off, sure, go with an easy language that will handle all of your memory and bounds checking for you.

Still, there is really no benefit to starting with C as far was I can tell, unless you are interested in getting into systems programming, writing device drivers, and operating systems - that sort of thing. It is fairly straight forward to learn those areas from a C++ background as well. Either way, the first programs you write won't be object orientated even if you do try to use a class or two. I wouldn't even think about that sort of thing until you have basic syntax down after writing a few short programs and working with some data structures. Oh, and I wouldn't try to use any of those things rip-off mentioned either - not in your first programs. It's really important to learn the details well, than to learn everything poorly by trying to do too much too soon. Don't just learn the syntax and basic idea - know it, and know what it's actually doing - before moving on to higher concepts. Write lots of short, pointless programs. Reinvent the wheel every chance you get. Then, once you know it all, you can start to use libraries and fancy IDE's and all those other luxuries.

I'm really just giving this reply because I'm so tired of so many people always advocating the easy way, quick way.
thePyro_13
thePyro_13
Quote:
Original post by Zahlman
4) Please tell me what you think is "limited" about perl, or any other programming language for that matter.


I think he means that his knowledge of perl is limited to the basics. Not that perl itself is limited.
XTAL256
XTAL256
Quote:
Original post by moff
I'm really just giving this reply because I'm so tired of so many people always advocating the easy way, quick way.

Well although i am more inclined to agree with Zahlman's point of view than your's i can see why it would be good to understand what you are doing and know the details. But i don't agree with that comment. People here definitely do not advocate the "quick" way, they advocate the best way, which in most cases is the way that has been done so many times before by professionals who know what they are doing. No-one should ever "reinvent the wheel", they can improve it if they know how but i highly doubt a beginner would be in a position to do so. Therefore, the best way usually ends up being the quick, easy way.
As an analogy, take driving a car. If everyone was required to learn how to build a car's engine from the ground up and understand how every part functioned before they were allowed to drive, do you think there would be any cars on the road? Sure people can learn to build a car if they wish but it's not a requirement to learn how to operate it.
/my 2c
[Window Detective] - Windows UI spy utility for programmers
Hannesnisula
Hannesnisula
I couldn't agree more with moff. I know a lot of people who learn how to use stuff but they are clueless about what they're actually doing or how it works, thus being unable to optimize things mostly. I personally know how much I've learned from "reinventing the wheel".

By doing as much as possible of the code by yourself will make you learn things you wouldn't otherwise. The "best way" seems to be using complete libraries, even though, in some cases, you could write your own which would be faster.

I really liked your analogy because I have a decent understanding of a car's mechanics thus made it ten times easier to learn how to drive. It's not required but it's a plus.

C++ is the only programming language I know and I haven't found any downside yet.

By the way; The title "Professional" doesn't always address the programmer's knowledge or/and intelligence.
benryves
benryves
Quote:
Original post by Hannesnisula
C++ is the only programming language I know and I haven't found any downside yet.
You probably haven't found any downsides because it's the only language you know, and so aren't aware that other languages may present a better way to achieve something. "If the only tool you have is a hammer, you tend to see every problem as a nail". [wink]
[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]
owiley
owiley
first off oop helps in that it keeps you, the coder, from rewritting alot of things that differ by some degree. One thing deign pattern. next get a better tool chain,IDE,
devc++ compiler is great in all but thats when it costed to get visual studio. Since its free and made by the company who make the os u are propably running its best bet to say they have a better tool chain for developing on that environment.And yes visual studio is the best. it has so many features.

Next c# is the language i recommend for you. its much like java but with a touch of c++. the tool chain for it is absolutely the best by far is there anything like it. C# is pretty decent with speed constaint and is used in major companies i would tell you one that i know for that use it some for tool development. but that might put me at risk
Bring more Pain
Acid-Chris
Acid-Chris
An alternative would be managed C++ as you can easily call c++ DLL's from it. Using C#, you would have to write a wrapper.

A downside of C++ would be that there's no garbage collector for example. I really miss it sometimes, even more on todays powerful machines.
DevFred
DevFred
Quote:
Original post by Hannesnisula
C++ is the only programming language I know and I haven't found any downside yet.

That's because you are used to header files, undefined behavior etc.

Switch to another language with a proper module system and garbage collections for a couple of weeks, and believe me you will see some downsides in C++ ;)
Telastyn
Telastyn
Quote:
Original post by moff
Yes, it will be harder than a language like C#, Python, or Java, but I find the results are much more rewarding from learning the harder way to do things before learning the easy way.


If you want rewarding, donate to a charity.

Quote:

It is much harder to go from knowing the easy way, to learning the hard way (and you are much less inclined to bother) - better to have a clean slate, and make sure to get a good solid foundation.


A good solid foundation can never be gained by learning with C++. You spend too much time dealing with bullshit than actually learning to program.

Quote:

I still usually use character arrays more often than strings, or if I want a string, I'll write my own class - the standard string class isn't that great.


There's a pointless exercise.

Quote:

But, the point is, I learned a lot about the details of how memory is stored, accessed, and what pointers are by starting with the harder way first.


Which is useless knowledge. Taking some time to learn some algorithms, or how to architect programs... y'know, actually program?

Quote:

In the end, you'll know more about why and how things work.


Not really. Even C provides just a facade over how things work.

Quote:

But if you want the instant pay off, sure, go with an easy language that will handle all of your memory and bounds checking for you.


You are not a manly man for fighting through hardship. Sitting around keeping tabs on bounds is time and energy you could have spent learning. Or making a game. Using your keys to turn a screw is stupid when there's a perfectly good power driver right in front of you.
CadetUmfer
CadetUmfer
Quote:
Original post by Telastyn
Quote:

But, the point is, I learned a lot about the details of how memory is stored, accessed, and what pointers are by starting with the harder way first.


Which is useless knowledge. Taking some time to learn some algorithms, or how to architect programs... y'know, actually program?


What? The Von Neumann architecture is here to stay, and our algorithms are based around that model. Better understanding that isn't "useless knowledge."

Understanding the stack and function calls, and virtual function dispatch--that stuff helped me become a better programmer. I'd take a doctor who knows how medicines work over one who can read journals and match up symptoms.

OP:

C++'s implementation of OOP sucks pretty bad. It's not the best language to learn those techniques.

C is pretty much THE standard implementation of structured programming. It's a great language to learn those techniques. (C++ Frequently Questioned Answers">read me).

C++ is the best way to learn C++.
Anthony Umfer
phresnel
phresnel
Quote:
Original post by Telastyn
actually program?


slight misunderstandig about that programming is the act of programming, not the act of hammering together the something in particular that you currently think of. Also, how do you define your "actual programming"? E.g., I don't want to go through the pain of writing device drivers, high throughput surface copy, mmap() based code, or coherent kd-tree/ray traversal code in C#. I can only imagine how the unsafe blocks, forced manual object disposals and explicit stackallocs clutter all my code.

Telastyn, nothing against C# (actually I am quiet fluent in it), but not using pointers, direct memory accesses and explicit memory handling is not automagically "actual programming". And really, C# is not the Snake Oil that, as it seems to me, you try to sell us. In the meanwhile we all know how much Telastyn lieks C#, where at the same time Telastyn's arguments against the dread C++ basically can be reduced to "coz' it's"
Quote:
Original post by Telastyn
bullshit.


Btw, the following has been done by an act of actual programming, too:
image of IBM402 plugboard, showing how programming was back in the day

Or, by "actually program", did you really mean something that goes into the direction of "Applications Development"?
clayasaurus
clayasaurus
You could always check out D http://digitalmars.com/d/

It's modern and doesn't suck, but it is also "low level" systems language with inline assembly if you really want it. It has direct access to C as well.

Topic Locked

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

Sign in to reply to this topic.