Programming On The Pandora For Mortals


I know that python would be easy to put on, but as I am not a python user, but a PHP user, I hope that a php binary could be built that I can use for making scripts :)
 
QUOTE
Nothing particually unusual until I hit Polymorphism. Then the next thing I remember was picking myself up off the floor with blood flowing from my eyeballs. In not more than 10 words WTF is Polymorphism?

Polymorphism is something they teach in C++ class, I forget what it is.

Use the Wikipedia!
Assuming that I'm getting it right, but 10 words isn't enough:

A variable is a variable, a function is a function, but an Object can be referred to as a variety of things depending on -how- you reference it. Coded properly you could potentially refer to "object" as:

object +=1.

or you could say

x = object(input).

and both could be correct ways of addressing the same 'object' depending on the properties coded in the code that initalizes the object.



Of course that said I'm having trouble getting my head wrapped around how one actually uses it though.

---

Or all that could be senseless blather caused by the blood pouring from my ears.
 
Last edited by a moderator:
Polymorphism is something they teach in C++ class, I forget what it is.
Use the Wikipedia!

Thanks lulz but that's 13 words. :p It had pointers in it I think. If I blink quickly I can still see bits of the web page...shiver...
Actually I don't have a problem with pointers (to the address of a value). It's pointers that point to pointers that point to arrays of pointers each pointing to a pointer that points to a function that :blink: <thud>
 
Last edited by a moderator:
Polymorphism is treating one object like it's a different one.
10 words, if "it's" counts as a single word.
 
Of course that said I'm having trouble getting my head wrapped around how one actually uses it though.
I think that is part of my problem. I'm ok with simple programs but when it comes to "projects" I run out of steam.
2-3 hrs free time per evening is a lot but not a lot of coding time. The language is only half of it. I need to learn how to program big programs.
At the moment I'm way to busy waiting for my pandora. Mind you I have a couple of months to learn something.

Short term I should RTFM on python and pygame (Bennu nags at me though). Longer term, once we all have delivery of our bundles of joy, and I find a good pandora based tutorial I may will try a little C++.

I have coded a little on the Arduino which is C based. It'd be cool if someone could port this. Yes it's open source.
 
Last edited by a moderator:
Polymorphism is treating one object like it's a different one.
10 words, if "it's" counts as a single word.
Stan you're a wizard! :D Good enough for me and I can understand that with out my eyeballs exploding.
So it's a bit like using a bike for a frying pan. I can see this could be very usful.

Of course is Alex says he used it in sqdef then I need to know this.
 
Last edited by a moderator:
I have coded a little on the Arduino which is C based. It'd be cool if someone could port this. Yes it's open source.
"The open-source Arduino environment makes it easy to write code and upload it to the i/o board. It runs on Windows, Mac OS X, and Linux. The environment is written in Java and based on Processing, avr-gcc, and other open source software. "
"The Arduino programming language is an implementation of Wiring, a similar physical computing platform, which is based on the Processing multimedia programming environment. "
You said "which is C based" did you mean that you're just going to program the boards with bare C (avr-gcc) or what you are referring?
I somehow ... get a bit mystified about what is so great about the Arduino - i build my own AVR boards and use some pre-built prototyping boards that come with no special software, i can do just fine with avr-gcc + avr-libc + avrdude + text editor.
I'll be compiling avr-gcc (avr-toolchain incl avr-libc) and avrdude anyways,
the arduino environment should be easy enough to support once we have (do we have? i dont know and dont really care of java) proper Java VM for it,
if i get interested enough i might test to see if i can get it to work and make a .pnd for it ... though i wont be using it,
I use avr-gcc w avr-libc + avrdude + SciTE, and i'm happy :) - i have an AVRISP mkII so programming shouldn't be a problem either.

edit:typo
 
Last edited by a moderator:
I have coded a little on the Arduino which is C based. It'd be cool if someone could port this. Yes it's open source.
"The open-source Arduino environment makes it easy to write code and upload it to the i/o board. It runs on Windows, Mac OS X, and Linux. The environment is written in Java and based on Processing, avr-gcc, and other open source software. "
"The Arduino programming language is an implementation of Wiring, a similar physical computing platform, which is based on the Processing multimedia programming environment. "
You said "which is C based" did you mean that you're just going to program the boards with bare C (avr-gcc) or what you are referring?
I somehow ... get a bit mystified about what is so great about the Arduino - i build my own AVR boards and use some pre-built prototyping boards that come with no special software, i can do just fine with avr-gcc + avr-libc + avrdude + text editor.
I'll be compiling avr-gcc (avr-toolchain incl avr-libc) and avrdude anyways,
the arduino environment should be easy enough to support once we have (do we have? i dont know and dont really care of java) proper Java VM for it,
if i get interested enough i might test to see if i can get it to work and make a .pnd for it ... though i wont be using it,
I use avr-gcc w avr-libc + avrdude + SciTE, and i'm happy :"] - i have an AVRISP mkII so programming shouldn't be a problem either.[/quote]edit:typo

Arduino uses C, it's just the environment (the IDE) that's written in Java. people like it because 1) they have a lot of examples / tutorials, 2) you write your code in the IDE, click one button, the Arduino updates and restarts and starts executing your program immediately, 3) no external programmers / drivers to deal with, Arduino has built-in USB programmer, 4) it's pretty cheap. I'm sure you can find more reasons if you check an Arduino site. I like it cause it's really quick to prototype stuff.
 
Last edited by a moderator:
At least you've got a clear approach to it may88 ;) But yeah, I agree with the others. In the long run, C/C++ is usually "the way to go" with game development.
As for learning it, I doubt it matters as you probably won't have all that many uses for polymorphism while developing games, but you should try and find a tutorial (or book) around C++ that is oriented around developing games. The one from cppresource is just a barebones dry "thing", more like a pocket-reference :) Maybe try some of the online resources at gamedev.net? Better do that in the mean time than wait for a Pandora-oriented tutorial.

Anyway, IMHO, a Pandora game development tutorial should not teach "how to make a game" (as in drawing, timing, events, input, etc.), but "how to make your game work" on the Pandora and precisely that.
 
I have coded a little on the Arduino which is C based. It'd be cool if someone could port this. Yes it's open source.
"The open-source Arduino environment makes it easy to write code and upload it to the i/o board. It runs on Windows, Mac OS X, and Linux. The environment is written in Java and based on Processing, avr-gcc, and other open source software. "
"The Arduino programming language is an implementation of Wiring, a similar physical computing platform, which is based on the Processing multimedia programming environment. "
You said "which is C based" did you mean that you're just going to program the boards with bare C (avr-gcc) or what you are referring?
I somehow ... get a bit mystified about what is so great about the Arduino - i build my own AVR boards and use some pre-built prototyping boards that come with no special software, i can do just fine with avr-gcc + avr-libc + avrdude + text editor.
I'll be compiling avr-gcc (avr-toolchain incl avr-libc) and avrdude anyways,
the arduino environment should be easy enough to support once we have (do we have? i dont know and dont really care of java"] proper Java VM for it,
if i get interested enough i might test to see if i can get it to work and make a .pnd for it ... though i wont be using it,
I use avr-gcc w avr-libc + avrdude + SciTE, and i'm happy :"] - i have an AVRISP mkII so programming shouldn't be a problem either.[/quote]edit:typo[/quote]Arduino uses C, it's just the environment (the IDE) that's written in Java. people like it because 1) they have a lot of examples / tutorials, 2) you write your code in the IDE, click one button, the Arduino updates and restarts and starts executing your program immediately, 3) no external programmers / drivers to deal with, Arduino has built-in USB programmer, 4) it's pretty cheap. I'm sure you can find more reasons if you check an Arduino site. I like it cause it's really quick to prototype stuff.

+1 That was exactly what I was going to say. And I like it coz i can make leds flash. (mood lights, POV(failed), binary clock) That level of stuff.
But I could live with a command line option for a while. The IDE is very lazy and as a shows the serial output from the arduino easily.
 
Last edited by a moderator:
omg. Okay, polymorphism is easy. Its just a nasty word.

"Treating one object like another" is sort of right, well, not really ;)

Polymorphism is really just where you have many classes that can respond to the same operation. The classic example is you might hve a Class called Square, and another called Triangle; both are descended from Shape.

If they all havea operation 'draw', then 'draw' is considered polymorphic (essentially.)

The advantage is..

If two classes are derivbed from one common parent, they can be treated as the parent .. you lose visibility to their unique properties, but you can still treat them as the parent.

So rather than doing two loopds.. one to daw triangles and one for squares, you can instead have (say) one loop that draws the shape class, and goes through square and triangle polymorphicly.

Another example..

You _Drive_ a car or truck; you don't have to learn to drive two cars in different ways, since they all desxcend from the same basic model.

jeff
 
Stan you're a wizard! :D Good enough for me and I can understand that with out my eyeballs exploding.
So it's a bit like using a bike for a frying pan. I can see this could be very usful.
Something like that. They usually have a little bit more in common than that though :p
Imagine you build a robot. The robot knows how to drive a Vehicle, where a Vehicle has a throttle and a steering wheel. You can put that robot into a Car, and the robot can drive it. If you put the robot into a Boat, there again, the robot can drive it. The robot doesn't know anything about Car or Boat, just Vehicle, with a steering wheel and throttle. You could create a new type of Vehicle (Motorcycle or Airplane, for example) and so long as the interface (Steering wheel and throttle) are basically the same, your robot sees it as a Vehicle and can drive it.
In real life, vehicles require more than just a steering wheel and throttle, and between vehicles those things are completely different anyway, but I hope you understand anyway.
 
Last edited by a moderator:
omg. Okay, polymorphism is easy. Its just a nasty word.
Jeff is right, it's pretty simple when you get down to it.

Python has some really powerful polymorphic features, because the language uses dynamic typing (also called "duck" typing.) Essentially, you don't ever check the type of anything... if it walks like a duck and quacks like a duck, we don't really care if it's a duck or just a guy holding a tape recorder wearing clown shoes. So long as it does what we need.

So you can do cool stuff like
a = "hello"
b = [1,2,3,4,5,6,7,8,9,0]

print len(a)
print len(b)

In this case we don't care what type "a" and "b" are, so long as we know that the "len" function can process them.
This isn't strictly polymorphism (I don't think) since you're not invoking methods of the objects "a" and "b", but it's in the same general vein.

an example of actual polymorphism in Python:
say you want to change your output from a console to a file. Normally you'd just open a file at the top
f = open("output.txt")

and change all your
print "Hello, World!"

statements to
f.write("Hello, World!\n")

However, what if you already have a program that has 10,000 print statements and you don't want to modify them all?
Well, if you go look at how print is designed, you see that it calls the .write() method of sys.stdout already!

So to redirect all your stdout to a file, all you have to do is put this at the top:
import sys
sys.stdout = open("output.txt")

and all your print statements will be redirected. Now the actual implementation of the sys.stdout.write() function is different for console and for file output, but the print statement doesn't care, it just calls write() on whatever variable is contained in sys.stdout.

Hope that helps someone!
 
Last edited by a moderator:
I was just being specific. If I hadn't specified C/C++, someone might assume I'm talking about PyGame or something like that, which is obviously a different baseline.

Or *gasp*, flash games, or Gamemaker-type games, since those are quite common as well. (perhaps even moreso than C/C++ homebrew games)

Never assume, when it's so trivial to be more specific. ;)

Polymorphism is really just where you have many classes that can respond to the same operation. The classic example is you might hve a Class called Square, and another called Triangle; both are descended from Shape.
If they all havea operation 'draw', then 'draw' is considered polymorphic (essentially.)

Hey, I have a question; recently I was playing around with drawing in Java/AWT/Swing, and I had to implement an ugly typecast to get something to work, but I don't understand why. Can you explain?

I was calling draw(Shape s) to draw rectangles with rounded edges. When I passed it a Rectangle2D (and later an RoundRectangle2D), it complained about allowing it, despite both classes implementing interface Shape.

So I typecasted to Shape, and it worked. :huh:

Shouldn't it just automatically figure out that Rectangle2D and RoundRectangle2D implement Shape, and allow it? Why does it need the manual typecast?

I mean, I can't think of any possible reason for why it'd need a manual typecast. When you typecast from double to int, you're altering the data, but when typecasting from RoundRectangle2D to Shape, nothing happens to the object. It continues to be the exact same object it always was, and since the draw Method is locked in stone, the type of the object being passed to it doesn't matter so long as it implements Shape.

So why then is it required? :huh:
 
Last edited by a moderator:
Because when I started learning C, I wanted to figure out how to do some of the stuff that was incredibly easy to do in Javascript. I got quite mucked up with function pointers, once I realized that I had to add lots of **'s and type out the entire parameter list multiple times.

Pages like this made me cringe!
 
Last edited by a moderator:
Interesting post...

So would something like this be polymorphism?

CODE
...some example code...
Because when I started learning C, I wanted to figure out how to do some of the stuff that was incredibly easy to do in Javascript. I got quite mucked up with function pointers, once I realized that I had to add lots of **'s and type out the entire parameter list multiple times.

Pages like this made me cringe!
Yeah, C makes me sad too. Javascript is actually a really nice language. It just has a bad rep because of a couple of faults that aren't really relevant to this discussion.

As I said before I'm not too clear on the exact definition of Polymorphism... so I can't say for sure if your example is polymorphic. It seems like it though?
If no one smarter can chime in, I'll reply later tonight in more detail.
 
Last edited by a moderator:
Kramy:
Ah Java... It's been a while since I wrote anything extensive in that language. And good riddance!
But let's get back to your problem.

QUOTE
So why then is it required?

From what I recall, it's a security measure :). It's because Java is kinda "not so simple" as to how arguments are passed to functions. Because your class is a reference type and not a primitive type, Java copies the reference and passes it as a value to the draw(Shape) method. But then there's the snag that it won't work without explicitly casting RoundRectangular2D into Shape. Why is that so, you ask? Simply put, because Java won't let you :).

In short and rather simple words: if you want to pass an object reference as a method argument in Java, you must use explicit casting.
It mostly comes from the whole ideas behind Java and that it's a "strongly typed" language.
How to solve it? Java-heads will probably tell you "use generics" :)

Bah... too much Java talk (after 3 years of experience I really dislike this language :) ).


But that's just from the top of my hat ;) I could be wrong and if that's the case then please someone correct me :)
 
QUOTE ("MDave")
He was talking about Javascript, not Java.

Oh, did he really? Let's check again, shall we? We'll just quickly skim through the most obvious stuff in other not to dwell upon the details of why he couldn't be writing about Javascript.

QUOTE ("Kramy")
Hey, I have a question; recently I was playing around with drawing in Java/AWT/Swing

One obviously can't miss the clearly stated Java, because even the names of Java and Javascript are...
QUOTE ("MDave")
Pretty different from each other

Yeah, couldn't agree with you more. The lack of script in the name is pretty apparent and distinguished. It's actually REALLY HARD to tell them apart, especially with those additional clues (AWT and Swing, slabbed right next to the word Java), which are technologies that are part of the Java API and aren't even really related to Javascript :). One could of course convert an AWT user interface written in Java into Javascript, but oh well, that's a different story all together.

So... you were saying MDave?


PS: Yeah, I had a bad day yesterday so my tolerance for smart-ass remarks (and failed ones at that) is quite close to being non-existant. So bear with me.
 
Back
Top