gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Which programing-language should I learn?

#50410 - illvit - Tue Aug 09, 2005 10:53 am

I have decided that I want to begin to make own NDS-games. Which programing-language should I learn? C or C++?

#50413 - Sausage Boy - Tue Aug 09, 2005 11:35 am

Doesn't really matter, as they are almost the same. A C program will compile in a C++ compiler 99% of the time. Most beginners find classes complicated, and recommend C to begin with. You should probably begin with PC programming, as it is a lot easier, and get a good hang of it. C++ is better for console programs, imho, as it uses cout instead of printf.

The choice between C and C++ is a choice between not object oriented and object oriented programming. I suggest you use C++, but simply don't make any classes and stuff like that until you feel ready.
_________________
"no offense, but this is the gayest game ever"

#50414 - illvit - Tue Aug 09, 2005 11:42 am

Thanks for answear

I don't understand what OOP is, could you explain it?
...and classes too

OpenGL or DirectX?

Thanks

#50415 - Sausage Boy - Tue Aug 09, 2005 11:58 am

In traditional programming, the program moves from command to command, jumps
to functions, executes the commands there, jumps back etc...

In OOP, you base your program on a bunch of objects (classes) that communicate with
each other and do certain tasks. This requires an entirely different way to think, but is
usually very flexible. Classes communicate with the world through API's (just regular
functions, nothing fancy and complicated), and this allows you to change how the class
works internally, as long as you don't touch the API.

That was pure OOP, you can also combine the two, and have classes that encapsulate
stuff, but you're using them as you would in traditional programming. This is very flexible
too, and the method I tend to use.

For example, I have a Background class for my DS programming, and I can write
Code:
Background bg0(0, MAIN);
bg0.init(0, 31);
bg0.LoadPalette("master.pal");
bg0.LoadTiles("bg.raw");
bg0.LoadMap("bg.map");


instead of

Code:
BG0_CR = BG_256_COLOR | BG_TILE_BASE(0) | BG_MAP_BASE(31);

*about 10 lines of code that I don't feel like writing now*


It's alot easier to see what it does, and is faster to use. And you can make classes manage themselves with destructors and stuff, so you don't have to
worry so much about them. It's great!
_________________
"no offense, but this is the gayest game ever"

#50416 - illvit - Tue Aug 09, 2005 12:04 pm

Takk s? mykkje

Thanks

#50417 - Sausage Boy - Tue Aug 09, 2005 12:19 pm

Oh, OpenGL and DirectX are also way too complicated to begin with,
I suggest you use something like SDL, http://www.libsdl.org/index.php

It's easy and cross platform compatible.
_________________
"no offense, but this is the gayest game ever"

#50442 - abigsmurf - Tue Aug 09, 2005 6:55 pm

I'll possibly get flamed for this but for learning OOP principles, Java is a much easier language to start off with. To learn fundamental programming basics, try visual basic.

As for a demonstration of OOP here's a comparrison of hello world programs which just displays a lots of "hello world"s

using a linear programming Language (BASIC) which operates using a list of commands.

10 Print "hello world"
20 goto 10

using OOP (JAVA), this won't actually run by itself but I can't be bother to write a full program. OOP works by calling methods/functions which you can tie to objects. It allows for space saving re-use of code and modular programming.

Void HelloWorld()
{
system.out.println("Hello World /n");
HelloWorld(); // performs the method again causing an infinate loop
}


Both OOP and Linear programming can perform the same tasks , the only difference is the structure and the amount of code needed

#50446 - dovoto - Tue Aug 09, 2005 8:31 pm

abigsmurf wrote:
I'll possibly get flamed for this but for learning OOP principles, Java is a much easier language to start off with. To learn fundamental programming basics, try visual basic.


yes please someone flame him
_________________
www.drunkencoders.com

#50448 - El Hobito - Tue Aug 09, 2005 8:46 pm

I'm afraid the only real way to learn programming is to get stuck right in there. Java gets you into all sorts of bad habits i know cos i am one and because i learned c after i find it harder. Stay away from visual basic at all costs

#50451 - Chetic - Tue Aug 09, 2005 8:57 pm

dovoto wrote:
abigsmurf wrote:
I'll possibly get flamed for this but for learning OOP principles, Java is a much easier language to start off with. To learn fundamental programming basics, try visual basic.



yes please someone flame him


Didn't you say you liked C# yourself?
Hah! Got you! :P
_________________
Packin':
Grey DS with FlashMe v7
1Gbit XG2T 2005 (Neoflash compatible)
GBAMP, Supercard CF, 512Mb Magic Key 3 and EZFA 256Mbit

#50458 - dovoto - Tue Aug 09, 2005 10:14 pm

Chetic wrote:
dovoto wrote:
abigsmurf wrote:
I'll possibly get flamed for this but for learning OOP principles, Java is a much easier language to start off with. To learn fundamental programming basics, try visual basic.



yes please someone flame him


Didn't you say you liked C# yourself?
Hah! Got you! :P


I said i liked C#... I even like VB to tell the truth but I would not call either of them a good place to learn fundamentals :) and java? ewww

You will not go wrong learning c++ and c together with a bit of arm asm thrown in to keep things interesting.
_________________
www.drunkencoders.com

#50459 - abigsmurf - Tue Aug 09, 2005 10:26 pm

dovoto wrote:

You will not go wrong learning c++ and c together with a bit of arm asm thrown in to keep things interesting.


You could however be starting from scratch and look and see a page of code full of pointers and complicated String handling functions (I've seen textbooks where they don't use pre built string functions) and go 'buh?'

Java for all the hate it gets is much easier to read than C++ and quicker to learn. You can't tell me that pointers aren't a nightmare to learn to get your head round.

#50460 - sajiimori - Tue Aug 09, 2005 10:34 pm

Sausage Boy had it basically right to start. Honestly, just about any procedural language will let you learn the basics of structured programming, but you'll need to know C eventually.

#50466 - Caligo - Tue Aug 09, 2005 11:29 pm

Doesnt the performance suffer from programming strictly OOP? i know its reccomended using as few methods and classes as possible when programming in java for cell phones etc. loading a class to memory just takes too much space. most people write the entire program in one method if they can get away with it. Does this apply to C/C++ and the GBA/NDS also, or is it just a crappy java compiling thingy?
_________________
The greatest signature in the world! -Tribute

#50467 - dovoto - Tue Aug 09, 2005 11:38 pm

Java on cell phones is a horrid horrid abomination that not even java deserves to be associated with.

The unclean approach is necessary due to some very poorly implemented JVMs.

The overhead you incure by using c++ on DS is generaly negligable. If you find yourself at the limits of the performance that c++ can provide you will likely have to implement it in ASM to get the results you seek.

The choice between c++ and c should be one of comfort and portability more so than speed or resource usage.
_________________
www.drunkencoders.com

#50468 - sajiimori - Tue Aug 09, 2005 11:56 pm

Quote:
Doesnt the performance suffer from programming strictly OOP?
That's a complicated, ambiguous, and often irrelevant question.

It's complicated because the question could be rephrased as: "Is there any program that breaks the rules of object orientation and cannot be implemented as efficiently while conforming to those rules?" It's an intractable problem.

It's ambiguous because it depends on language implementations and the definitions of object orientation.

It's irrelevant because performance hardly ever depends on the high-level organization of an application.

#50469 - Sausage Boy - Wed Aug 10, 2005 12:04 am

I think it's a good question, I would have asked it. :P

It's true that OOP code is often slightly less efficiend than other code,
but the difference is usually too small to be noticed.

You can of course create terribly inefficient code with OOP, but you can create
equally horrible code without it.

So, speed shouldn't really be a part of the equation when you choose.
_________________
"no offense, but this is the gayest game ever"

#50485 - tepples - Wed Aug 10, 2005 4:30 am

OOP involves significant use of virtual methods. A problem with OOP when improperly applied is that a virtual method call in an inner loop will often kill performance.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#50509 - NoMis - Wed Aug 10, 2005 8:17 am

But you can get around that with Compile Time Polimorphism when needed.

NoMis
_________________
www.gamedev.at - The austrian gamedev site
hde.gamedev.at - The Handheld Dev Env plugins for Eclipse

#50522 - El Hobito - Wed Aug 10, 2005 11:48 am

count yourselves lucky we dont have to program everything in assembly....because it a real arse

#50523 - Sebbo - Wed Aug 10, 2005 11:49 am

personally, i started off with basic on a graphics calculator, then moved on to VB, and did some delphi/pascal a year later (stay away from delphi/pascal as much as you can, it is the programming language of satan himself)
now doing c++ with some c style strings at uni, and its good, just as long as you don't have a big break between programs, cos i forgot alot of it easily...slowly coming back tho

if you want i can sell you the c++ text book we used last term, the uni has decided to make us get a completely different book now that covers c++, web programming with CGI and OO design with the UML :-S cost me AU$100, i'll sell for about AU$60 tho if your interested

#50528 - d3tr0it - Wed Aug 10, 2005 12:40 pm

Well I actually started of with VB and then Delphi. I actually loved Delphi when I first found it... :p

I would not recommend that way though.
I think the best way to go is learning c++ directly

Altough in the university they recommended Lisp for learning the basics of programming.

#50534 - agentq - Wed Aug 10, 2005 2:26 pm

I think Delphi/Pascal is great, and a good way to learn programming. Pascal as a langauge is very well designed and gives you plenty of errors to tell you where you've gone wrong.

In contrast, C/C++ generally compiles this stuff fine, then crashes, which is not a lot of help for a beginner.

Don't think that because C/C++ is by far the most popular language, that it's also the best. C++ is very powerful and flexible, but it also has plenty of nasty bits, and there's a lot to get your head around.

Personally, I started in BASIC back in the 8-bit days and moved to Pascal later, and then to C, then C++.

#50536 - illvit - Wed Aug 10, 2005 2:39 pm

Then I think I go for C++

Someone gave me a tips about this site:
http://mindview.net/Books/TICPP/ThinkingInCPP2e.html

So I think I don't need to buy anything

#50650 - illvit - Thu Aug 11, 2005 11:03 am

A last question
Which compilator do you recomand?
Do I need any linker?

Thanks

#50654 - Mr Snowflake - Thu Aug 11, 2005 12:07 pm

Just get gcc or for the ds/gba devkitarm

#50655 - Sausage Boy - Thu Aug 11, 2005 12:14 pm

A linker will come with the compiler.

There are a few options. There's a beta of Microsoft Visual Studio here:
http://lab.msdn.microsoft.com/express/visualc/default.aspx

Visual Studio is an easy to learn and common compiler/IDE, so it's probably a good choice for a beginner.

Another good compiler is gcc, you can gind a windows version if it here.
http://www.mingw.org/
Gcc is kinda complicated, and you don't get an IDE, so I wouldn't recommend it for beginners. The good thing about it is that it's free, non Microsoft, cross platform
compatible etc... If you want to go with this, I suggest you get Dev-C++:
http://www.bloodshed.net/devcpp.html
This includes MinGW, but packaged in a nice IDE like Visual Studio.

If you want to make stuff for the DS, you'll need DevkitARM, which includes a version
of gcc that compiles for the ARM (DS processor).
http://www.devkitpro.org/
_________________
"no offense, but this is the gayest game ever"

#50661 - Elrinth - Thu Aug 11, 2005 3:32 pm

since no one else said it ;)

OOP means Object Oriented Programming... :D

Objects are made outta classes ;)

oh... and classes are made outta variables and functions.

#50705 - Abcd1234 - Thu Aug 11, 2005 11:02 pm

tepples wrote:
OOP involves significant use of virtual methods. A problem with OOP when improperly applied is that a virtual method call in an inner loop will often kill performance.


OOP doesn't necessarily 'involve significant use of virtual methods'. Heck, in C++, the default is for a method to be non-virtual. There's a reason for this (aside from the performance benefits). The problem is that, when people think OOP, they mistakenly assume that means inheritence, which, it turns out isn't all that useful most of the time, and ends up being horribly abused. In fact, many of the cases where inheritence is used can be refactored to use composition.

OOP is, really, just a nice, formalized way ot tying data together with the code that modifies it. It also encourages modularity and contract-based design patterns, since you can formalize the interfaces to code and then hide away the internals ('course, you can do that with procedural code, too, but OOP makes it aeasier).

But there's nothing about OOP that's inherently slow. Heck, you can develop OO code in straight C if you like, using structs and function pointers... oh, wait, that's just a C++ class without the syntactic sugar.

As an aside, the real-time operating system VxWorks is, AFAIK, written in C++.


Last edited by Abcd1234 on Thu Aug 11, 2005 11:15 pm; edited 1 time in total

#50706 - sajiimori - Thu Aug 11, 2005 11:11 pm

There's something even better to say about the virtuals comment:

Everything is a problem when improperly applied.

#50710 - tepples - Fri Aug 12, 2005 12:35 am

Abcd1234 wrote:
The problem is that, when people think OOP, they mistakenly assume that means inheritence

"Mistakenly"? The Wikipedia article on OOP includes a section distinguishing "object-based" from "object-oriented" programming.

Quote:
OOP is, really, just a nice, formalized way ot tying data together with the code that modifies it. It also encourages modularity and contract-based design patterns, since you can formalize the interfaces to code and then hide away the internals ('course, you can do that with procedural code, too, but OOP makes it aeasier).

According to the article, this is "object-based" programming, and that's what I tend to aim for on comparatively small systems such as the GBA. If what you say is true, that what Wikipedia calls "object-based" is generally recognized as "object-oriented", then please go correct the Wikipedia article.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#50741 - Abcd1234 - Fri Aug 12, 2005 3:23 pm

tepples wrote:
"Mistakenly"? The Wikipedia article on OOP includes a section distinguishing "object-based" from "object-oriented" programming.


Well, that's funny, because later in that same article, it says the following:

'Hierarchical taxonomies often do not match the real world and real-world changes according to some critics, and should be avoided. However, many OOP proponents also suggest avoiding hierarchies, instead using OO techniques such as "composition".'

#50750 - sajiimori - Fri Aug 12, 2005 5:56 pm

Oh for heck's sake, it doesn't matter!!

#50797 - MumblyJoe - Sat Aug 13, 2005 4:05 am

illvit wrote:
Then I think I go for C++

Someone gave me a tips about this site:
http://mindview.net/Books/TICPP/ThinkingInCPP2e.html

So I think I don't need to buy anything


I have read Bruce Eckel's "Thinking In" series for C++ and Java and found them pretty darn good. Another author that I highly recommend for C++ is Scott Meyers, though his books aren't free.


As for the Everything vs C++ argument that always comes up in these situations, I firmly and strongly believe that C++ is the way to go for the DS. There is many other cases where it is not suitable, though personally I think it is a fantastic language and programming method.

Having said that, I understand a lot of people feel that C++ is just syntactic sugar for C. Yes, that is partially true, but I say take the sugar and raise your productivity by coding in a clear efficient OOP manner. It may take some time to get used to coding correctly in C++, but then again a lot people seem to have trouble coding correctly in anything so that may be unimportant.

One last point, and one that I wish was stressed much much more to begginner programmers. Take the effort from day one to write code that causes compile time errors.

An example:

Most beginner books write things like this:
Code:
int myfunc(int* array, int size);


You should write it like this (or similar):
Code:
const int myfunc(const int* const array, const unsigned int size);


This is both for clarity, possible compiler optimisations, and compile time error generation. The amount of people who seem to avoid the const keyword at all cost (particularly with its other use of marking class member functions for const object use) is simply astounding.


Sorry for ranting :)
_________________
www.hungrydeveloper.com
Version 2.0 now up - guaranteed at least 100% more pleasing!

#50847 - sajiimori - Sat Aug 13, 2005 8:32 pm

Consting objects that are passed or returned by value is silly. The caller has no reason to care whether the function modifies its copy of a value, and the function has no reason to care if the caller modifies the result.

Compilers don't make optimizations based on const declarations because they can't assume that constness isn't casted away. I also don't remember ever catching an error due to a const declaration.

And yet... I use const declarations religiously. I even declare local variables const. It lets readers make more assumptions about the presence of side-effects.

#50874 - FourScience - Sun Aug 14, 2005 2:23 am

I'd flame him for recommending Visual Basic as an intro language. I don't abhor it, but the whole IDE of Visual Studio only complicates the learning process.

Java is good to learn OOP with, but you miss out on pointers and memory manipulation. So don't learn it unless for OOP.

Procedural is the way to begin. Pascal or Basic are good places to start. Then C.

While still a beginner, avoid Assembly (ASM), and using advanced graphic libraries like OpenGL or DirectX. You really shouldn't try to learn to program using the DS.

None of my comments consider the professional uses of the aforementioned languages, only their learning value.
_________________
Work in progress: Dual-Soft.com

#50930 - illvit - Sun Aug 14, 2005 7:15 pm

Thanks everybody for the answears.
I posted here because I were wondering which language I should study, so I, in the future could make games, and I got the answear. Thanks

#50934 - wintermute - Sun Aug 14, 2005 7:21 pm

some useful links for reading material can be found on the devkitpro site

http://www.devkitpro.org/reading.shtml

#50942 - dagamer34 - Sun Aug 14, 2005 7:51 pm

Whatever language you do pick, I would not recommend buying a book for it. You often will never use it, and it will be wasted money. The internet is a vast resource for information so get out there and learn!
_________________
Little kids and Playstation 2's don't mix. :(

#50949 - sajiimori - Sun Aug 14, 2005 8:32 pm

This thread clearly isn't over because all 4700 members haven't posted their opinions yet.

#50989 - wintermute - Mon Aug 15, 2005 4:25 am

sajiimori wrote:
This thread clearly isn't over because all 4700 members haven't posted their opinions yet.


just wait until he asks which editor he should use ;)

#51074 - FourScience - Tue Aug 16, 2005 3:55 am

wintermute wrote:
sajiimori wrote:
This thread clearly isn't over because all 4700 members haven't posted their opinions yet.


just wait until he asks which editor he should use ;)


LOL!

Well, maybe it was implied to begin with. As for that....


Hahaha.... no, nobody get started with that.
_________________
Work in progress: Dual-Soft.com

#51080 - LOst? - Tue Aug 16, 2005 5:42 am

Actually, if you know what C++ classes do behind the scene, you will wish you never even started thinking OOP. There is better ways of tying data together, and faster ways of accessing them.

I rether go by a simple C struct, and pointers, instead of a protected and private data that does nothing but slow down read and write.

Imagine you want to do a 3D game using hardware accelerated graphics. The first choice you get is C++ classes when using D3D from Microsoft. Everything is nicely put into classes, and virtual methods. But this is such a waste of speed! Just because you get 3D for free doesn't mean you can waste cycles on stack loading and all that. What you need to make a good 3D game is a lot of CPU power to calculate all the realistic 3D space math things such as ragdoll and stuff.
Yea, you are a waster! Get back to assembler and kick ass! I will use C because it has everything I need, and the extra can be accessed from assembler.

So, if you want object oriented code, write it yourself, and don't trust the compiler to speed it up for you because it won't. I trust the human brain more than a compiler.


EDIT: 4699 members to go lol
_________________
Exceptions are fun

#51097 - inthearmsofsleep - Tue Aug 16, 2005 9:43 am

sajiimori wrote:
This thread clearly isn't over because all 4700 members haven't posted their opinions yet.

for some reason i can't learn c or c++ no matter how hard i try.....there are too many confusing terms involved. My opinion: it's not worth the hours trying to wrap my mind around when i could be getting work done that i already know how to do.
4698 to go.

#51113 - illvit - Tue Aug 16, 2005 1:57 pm

wintermute wrote:
sajiimori wrote:
This thread clearly isn't over because all 4700 members haven't posted their opinions yet.


just wait until he asks which editor he should use ;)

Which edtor should I use?

#51130 - FourScience - Tue Aug 16, 2005 5:39 pm

Response to illvit:
Quote:
Which edtor should I use?

...and the floodgates shall be released!

Well, I'd rather suggest recommended features:
* tabbed file views
* code formatting is a must
* brace indicators are helpful
* a simple to configure build/compile button is always a plus

I currently prefer jEdit, but it doesn't have tabbed file views so switching between multiple files is a PAIN; it uses a drop-down list of current files that you must manually remove to keep it clean. It does have good tabbing and code formatting however.

Response to Lost:
I agree with using the most efficient language/compilar especially when dealing with limited resources, but I'd just like to comment on the merits of C++ and other OOP languages. While there's an obvious and certain performance cost, development time and quality is the benefit. Some things are much quicker to code and keep working using C++ rather than C, and that's why C++ is so popular for games. I agree with using C when that's all that's needed, of course.

These days commercial game budgets and development timelines are getting HUGE, so the real issue is reducing those costs, instead of producing the most optimized product. Thus, game dev libraries are commonly written in C++.[/quote]
_________________
Work in progress: Dual-Soft.com

#51136 - sajiimori - Tue Aug 16, 2005 7:12 pm

Quote:
Actually, if you know what C++ classes do behind the scene, you will wish you never even started thinking OOP.
Let me know if you'd like to become better informed about modern compiler output, how to view compiler output from GCC and MSVC, and how to profile your code in order to focus your optimizations on bottlenecks. If you can't or don't do these things, your speculation carries little weight.

In particular, I'd like to show you what GCC and MSVC can do with code that uses the following class that I wrote for work:
Code:
template<class T, int FRACTION_BITS> class Fixed;

#51138 - LOst? - Tue Aug 16, 2005 7:18 pm

sajiimori wrote:
Quote:
Actually, if you know what C++ classes do behind the scene, you will wish you never even started thinking OOP.
Let me know if you'd like to become better informed about modern compiler output, how to view compiler output from GCC and MSVC, and how to profile your code in order to focus your optimizations on bottlenecks. If you can't or don't do these things, your speculation carries little weight.

In particular, I'd like to show you what GCC and MSVC can do with code that uses the following class that I wrote for work:
Code:
template<class T, int FRACTION_BITS> class Fixed;


Go ahead! I would love to see C++. I want to use it more. I just don't get the best output. See here for my explanations:
http://forum.gbadev.org/viewtopic.php?p=51079#51079
_________________
Exceptions are fun

#51147 - illvit - Tue Aug 16, 2005 8:22 pm

Someone told me that assembly is the best, is that true?

THanks again for all the reply
You are the best

#51162 - tepples - Tue Aug 16, 2005 9:54 pm

In theory, assembly language is capable of producing the fastest binary. But in practice, programmer time can cost more than machine time, and C is "good enough" in most cases given how little programmer time it demands compared to assembly. Use assembly only if you have profiled your program, optimized the inner loops of your program, and found that your fastest C is too slow to satisfy the real-time constraint.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.


Last edited by tepples on Tue Aug 16, 2005 10:20 pm; edited 1 time in total

#51165 - natrium42 - Tue Aug 16, 2005 10:13 pm

illvit wrote:
Someone told me that assembly is the best, is that true?

THanks again for all the reply
You are the best

Use the best tool for the job :)

(1) Portability
If you use assembly, you lose portability because assembly differs between CPU architectures. With C/C++ you can usually just recompile for a different architecture without any code changes.
If you really need a highly-optimized routine (see point 3), you can use inline assembly with most C/C++ compilers.

(2) Maintainability
C/C++ is arguably easier to maintain than assembly code. It's also easier to read for other people.

(3) Performance
Usually programs spend 99% of their time in 1% of their code. You need to only optimize this 1% of code. Use of inline assembly is possible if a better algorithm cannot be found. Don't bother optimizing the rest of the code, since it's almost never executed.
_________________
www.natrium42.com

#51242 - illvit - Wed Aug 17, 2005 2:33 pm

THanks, then I will go for C++