Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411490 Posts in 69377 Topics- by 58433 Members - Latest Member: Bohdan_Zoshchenko

April 29, 2024, 06:09:30 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Starting with Python and Pygame
Pages: 1 [2]
Print
Author Topic: Starting with Python and Pygame  (Read 7643 times)
OryBand
Level 0
***


Screamadelica.


View Profile WWW
« Reply #20 on: August 26, 2008, 06:04:52 AM »

OK. I think this thread wandered along away from it's original intention - Helping Lucaz decide on which programming language to learn programming games with.

So I'll answer him with what I think on this issue.

What I have to say might be kinda long, but this is because I'll try to explain kinda deeply every statement I'll make.

What kind of games do you wish to make?
First, I think it should be good for you to decide on what kinds of games you want to make. Heavy, big games, like Half-Life, Gears of War and Sins of a Solar Empire or smaller ones, like the ones you can get for free on the net?

I know that for the first attempts you should focus on small ones, but I'm talking about what your final target is. After you've finished all the books and tutorials and game examples. Where do you want to reach?

Difference between programming languages
Second, I think that it should be good to distinguish the group of programming languages C++ belongs to, and the one where Python belongs.

In short:

C++ is a classic programming language. By "classic" I mean that your code is turned into binary commands for the computer to interpret prior to executing the application (or game).

Btw, the action of turning the code into binary commands is called "compiling". This "compiling" must be done, because the computer doesn't understand the english language you program with. It only understand numbers, memory addresses and electrical surges.

Python is a scripting language. By "scripting" I mean all of the code you write is already compiled and ready for execution beforehand.

Also, in scripting languages you usually have to be less specific in details on what you're writing.

For example:
In C++, when declaring a variable (it's like a a memory block which holds data for you), you have to state which type of data it will hold - like a full number (integer), a fraction number (float), letters (strings), etc. etc.

E.G. integer a = 17

In Python, for example, you don't have to do that. You just say a = 17 . This variable statement doesn't have to be compiled into binary, because the binary is already existent for you. Python just takes this statement and executes the binary commands necessary to do what you want. It has all the of the binary commands ready in its libraries.

At first this sounds as an advantage for Python, because it removes the necessity to compile everything you write prior to running it. Also, it removes the necessity to write more code.

However, this is also a disadvantage, because every statement and command in a scripting language takes a longer time to execute than it's "brother statement" in a classic programming language. This is because the scripting commands are more "general" and have lots more binary commands to run behind the scenes rather than the more specific commands in a classic language.

Just because you don't state what kind of data your 'a' variable will hold, doesn't mean the computer doesn't have to allocate memory on your computer to save that data. The specific amount of memory changes by each data type (full numbers/integers use a lot more memory room than letters/strings).

So, in Python, for example, since you don't mention what type you'll hold into this 'a' variable, the computer just allocates a lot more memory room for this variable than is needed.

In C++, it allocates just the amount it needs, since you declare it when you create this 'a' variable.

So basically, classic languages are more on speed of execution, but are less comfortable and harder to learn. However - You also learn a whole lot more.

Scripting languages are slower but more easy to learn. However, you miss a whole lot of the important stuff that is needed in order to program good.

Knowing to program "good" is a necessity, because you wouldn't want your games to be sluggish just because you didn't know the faster ways to write them, right?

This is just a small example to show the differences, pros and cons of each.

What I recommend for both types
Before I'll tell what I think you should start learning, I'll give some detail on which are (by me only) the best programming language for each group I've mentioned.

These are of course, C/C++ and Python. That's why I used them in my examples earlier.

C/C++ is the most popular language for writing games, especially "big ones". The application runs a lot faster than other languages (except using Assembly-like languages, but I'm not even going to talk about it) and gives you the most control over each aspect for your program.

Python is my choice for a scripting language. For two reasons:

  • It has a really comfortable syntax. A lot more than Perl, anyways.
  • It has a really, really, REALLY huge database of user-made libraries that can help you and allows you do almost anything you'd want with programming. PyGame is a good example of this. Ruby and Perl don't have such a large database of libraries.

What I think you should start on
OK, now for the big "what I think you should begin with". Smiley

I contradict with what most people said I here. I don't think you should start programming with a scripting language, like Python, Perl, Ruby, and such.

I think you should start with one of the more classic ones. C/C++ would be a good choice.

Why?

It's easy, because you'll learn a whole lot more than with learning Python.

I don't think that it will be good for you to start learning Python, where you'll miss a lot of the important stuff, and then move to C++, where you'll learn all the rest. You'll eventually feel very uncomfortable with all the more complicated stuff and just abandon them.

It will be good practice to start learning from the harder stuff and then going back to the easier stuff. You'll also understand when and how to use classic and scripting languages better, because you'll know the differences a lot better.

I don't want you to think that learning C/C++ is a lot harder than Python. It isn't. However, it takes more time and a bit more dedication. You'll get a lot more benefits if you'll do this.

Most of the programmers start with learning C/C++ and it's brothers, like Delphie/Pascal, Java, Basic, and such. It lets you learn a lot more.

I heard of a guy that started with Assembly, and he is, like, the king of programmers now. He understand every bit of every thing.

Have a friend help you
Yes, I agree with the rest in here. Have someone guide you. It's not that easy learning to program by your own.

Besides, the first thing to learn before programming is learning how the computer works (CPU, Memory, I/O, BUSes, Addresses, etc. etc.)

The End
Phew, that was a long post.

Hope I helped you. Smiley

Cheers,
Orestes
Logged

Never go to bed mad, stay up and fight. - Phyllis Diller
muku
Level 10
*****


View Profile
« Reply #21 on: August 26, 2008, 06:55:13 AM »

I disagree strongly with Orestes. "Good programming" nowadays isn't about understanding as many low-level details of the inner workings of your computer as possible. It's about clean architecture and proper choice of algorithms, and you can learn that just as well in a dynamic language as in a statically compiled one. In fact, I would say that it's easier to learn this in Python than in C++ because the concepts are presented much more clearly in the code and not buried in nitty-gritty implementation details.

Once you understand these things and you find that you really do need the additional performance gained by a compiled language (for many kinds of games this will never happen), moving on to C++ or another option should not be too difficult. Also be aware that programmer efficiency is simply higher in Python than in C++ as equivalent programs in the first are typically shorter by a factor.

Finally, I simply don't see how anyone could justify the statement that C++ is as simple to learn as Python. It's not, by a wide margin. C++, when you don't know all its intricate details and idiosyncrasies, will turn around and bite you wherever it can. Just look at all the subtle points the C++ FAQ has to deal with. Compared to that, in Python, things mostly "just work", and there's much less rope to hang yourself with.
Logged
Ragzouken
Level 0
***



View Profile WWW
« Reply #22 on: August 26, 2008, 08:46:41 AM »

I agree with muku. Also I'd like to add that in generally, in Python, if you need high performance you should write the high performance code as a C extension for python. There's also Psyco which will JIT compile python code which can give a great performance boost.
Logged

Thorst
Level 0
***



View Profile
« Reply #23 on: August 26, 2008, 09:55:44 AM »

I am not qualified to answer this question, but here are my reactions as another beginning programmer.  Orestes, thank you for spelling everything out the way you have.  My contention with your argument is that you seem to say the best place to start is at the most fundamental level.  But this argument seems to be against c/c++ as much as it is for it, because isn’t assembly more fundamental than c/c++, and isn’t circuit design more fundamental than assembly, and then silicon doping, and then the basic laws of physics that are really what govern the way computers work?

I suppose as you get more fundamental, you get diminishing returns.  So, I am not persuaded to start with c/c++ just because it is more fundamental than python.  I need to know why python is not classic enough, and why assembly is too classic.

Secondly, I have been reading, off and on, the python tutorial at python.org as well as The C Programming Language by Kernighan and Ritchie.  Muku, I have not found one language more difficult to learn than the other, at least in the first stages of learning.  Python looks friendlier, but it is just as confounding.

Python is probably easier for making useful programs, but for making little practice programs and learning about programming concepts, I don’t think what language you use matters.
Logged
jonny
Level 0
**



View Profile WWW
« Reply #24 on: August 26, 2008, 02:08:11 PM »

Would you learn a lot more by starting with C or C++? I don't know about that. You'd learn different concepts, but not more. Starting with something like Python would allow you to learn more high level concepts because, as I believe someone said previously, Python doesn't "get in the way" as much.

To me, it seems like C++ "forces" you to adopt good practices, simply because if you don't you will be paying for it in, and it will suck. Most of the time you have to learn that the hard way.

But you could also say that the good practices that C++ forces you to adopt are irrelevant in more forgiving higher level languages. And even more in that direction, one could also argue that C/C++ forces you to write bad code in order to make up for it's shortcomings.

But before I ramble on again and get more and more abstract I'll just stop here...
Logged
muku
Level 10
*****


View Profile
« Reply #25 on: August 26, 2008, 02:22:55 PM »

Secondly, I have been reading, off and on, the python tutorial at python.org as well as The C Programming Language by Kernighan and Ritchie.  Muku, I have not found one language more difficult to learn than the other, at least in the first stages of learning.

First of all, keep in mind that C is a much simpler language than C++. It's a misconception that C++ is just C with "something extra" tacked on. Idiomatic C++ code looks completely different from C.

Certainly, when you are just beginning to learn to program, any language will seem confusing. As you grasp the basics and move on to more advanced topics, you begin to see the differences. For one, in C/C++, you have to do all your memory management yourself, which can become very involved for nontrivial programs. Or take C string handling. In order to concatenate two strings in C, you have to understand arrays and pointers, you have to decide whether your strings will be allocated as static or dynamic arrays, you have to make sure your destination buffer has enough space to accommodate the concatenated string, you have to include a specific header file and call a library function. By contrast, in Python, you simply do
Code:
a = "Hello "
b = "World"
c = a + b
and that's that. This is even a complete runnable program as it stands.

Granted, the C++ STL alleviates this particular problem, but the point that you always have to think about where your objects get allocated and deallocated still stands. Garbage collection simply is that much more convenient.

I'll stop ranting now. Don't get me wrong, I don't think that C++ is a terrible language (although it has some grave flaws), I just think that it's a terrible first language. In fact, I've programmed in C++ for many years myself, but only after learning BASIC, Assembly and C. (Which isn't a sequence I would recommend nowadays either, but it was all I had at the time.) And I think its niche is shrinking with every bit that processors get faster.
Logged
Cymon
Level 9
****


Computer Kid


View Profile WWW
« Reply #26 on: August 27, 2008, 11:55:35 AM »

In fact, I've programmed in C++ for many years myself, but only after learning BASIC, Assembly and C. (Which isn't a sequence I would recommend nowadays either, but it was all I had at the time.) And I think its niche is shrinking with every bit that processors get faster.
This is almost exactly the order I went in. Throw Pascal in between BASIC and C and move Assembly to the end of the list (but before C++).

That game programming in python book looks pretty good to me. Maybe I'll pick it up so it can be yet another book that I don't ever take the time to get to.
Logged

Cymon's Games, free source code, tutorials, and a new game every week!
Follow me on twitter
OryBand
Level 0
***


Screamadelica.


View Profile WWW
« Reply #27 on: August 30, 2008, 05:07:34 AM »

Ack. Lips Sealed

Well, lucaz, what do you think?
Logged

Never go to bed mad, stay up and fight. - Phyllis Diller
Lucaz
Level 6
*


Indier than thou


View Profile WWW
« Reply #28 on: August 31, 2008, 12:58:11 AM »

I've been looking around a bit, and I'm reading a tutorial, Dive into Python, can't remember where I found it. I have read roughly the half of it. Haven't done anything with Python yet, but I'm understanding things pretty well, and I've seen a coupple of interesting stuff that seem really useful, specially the getAttr function. This week I'll try to put more time into it. I'm thinking I did a good choice with this.
Logged

muku
Level 10
*****


View Profile
« Reply #29 on: August 31, 2008, 01:45:06 AM »

Don't go too crazy with getattr though. Wink Overusing runtime inspection techniques where it's not really required is generally considered bad style. It can lead to "spaghetti code" just as bad as the maligned GOTO statement (which Python doesn't have for that very reason). There are places where getattr is useful, but as a beginner you should try to avoid it wherever possible. Also note that if you ever decide to switch to a compiled language later, you won't have this sort of facility available. That's not to say you shouldn't use any of the dynamic features Python offers over static languages, but be aware of the trade-offs involved.
Logged
Ragzouken
Level 0
***



View Profile WWW
« Reply #30 on: August 31, 2008, 02:33:24 AM »

For the beginner to programming, this book/tutorial is probably pretty good http://www.greenteapress.com/thinkpython/, it's endorsed by the people of #python on freenode. I don't think they have high opinions of Dive into python for some reason Tongue
Logged

Lucaz
Level 6
*


Indier than thou


View Profile WWW
« Reply #31 on: August 31, 2008, 03:34:47 PM »

Last night I didn't had time to read everything, so I'll post again.

As for what kind of game I want do... both interest me, I guess, but now small games sound more likely.

Although C++ is interesting, and surely I'll learn it at some point, at this moment I find Python to be more what I want. And I find high level programming more interesting than low level ones like C++. I'll learn it when I feel it's more adequate for what I want to do than Python.

Muku: I know, I'll just use it when there's an actual reason to go for it instead of more common ways.

Ragzouken: I'll check that one.
Logged

Pages: 1 [2]
Print
Jump to:  

Theme orange-lt created by panic