
-----------------------------------
do_pete
Fri Sep 15, 2006 9:30 am

Trig calculations vs. lookup tables
-----------------------------------
I'm planning on making a game in Python that includes lots of trigonometry. Should I invest in making lookup tables to increase the speed or would that not make a difference?

-----------------------------------
[Gandalf]
Fri Sep 15, 2006 2:20 pm


-----------------------------------
I'm sure it would make at least a bit of a difference, though it really matters on how important speed and smooth execution will be in your game.  In any case, I don't see why you shouldn't use them..

-----------------------------------
Cervantes
Fri Sep 15, 2006 2:44 pm


-----------------------------------
"]In any case, I don't see why you shouldn't use them..
Because they use up memory. If you're already using lots, you should be careful about its use. If you want to be precise in the values you get, you'll have to use lots of memory to store that accuracy.

-----------------------------------
bugzpodder
Fri Sep 15, 2006 5:47 pm


-----------------------------------
if you are worried about speed, then you shouldnt be using python.

-----------------------------------
[Gandalf]
Fri Sep 15, 2006 6:01 pm


-----------------------------------
Cervantes, true that.  Though really, in most cases 1 degree accuracy won't take up a huge amount of memory and still does the job. 

About speed... As far as I know Python seems like one of the better choices with regards to speed while still being beginner friendly.
Ignoring O'Caml, that is. ;)

-----------------------------------
zylum
Fri Sep 15, 2006 6:46 pm


-----------------------------------
isnt java faster than python? either way, unless you are doing thousands of trig calculations per loop, it shouldnt slow down your program too much. do some benchmarks.

-----------------------------------
bugzpodder
Sat Sep 16, 2006 1:12 pm


-----------------------------------
python is an interpreted language.  C/C++ is compiled into bytecode.  Java sort of sits in a middle but its VM are optimized enough so that you won't see too much of a performance loss compared to C/C++ (although it is still present).  You may want to try out IronPython on the other hand since it works the same way as all other .net languages by compiling to IL.

-----------------------------------
wtd
Sat Sep 16, 2006 1:16 pm


-----------------------------------
C and C++ (and many other languages) are compiled into native machine code.

Java and Python are compiled to bytecode which is interpreted.  Or alternatively, the interpreting environment may Just-in-Time compile this bytecode to native machine code.

-----------------------------------
bugzpodder
Sat Sep 16, 2006 5:50 pm


-----------------------------------
right, thats what i meant  :D

-----------------------------------
do_pete
Tue Sep 19, 2006 9:33 am


-----------------------------------
Okay, thanks for the help. If I need more speed for my program is it possible to integrate C/C++ programs into it?

-----------------------------------
zylum
Tue Sep 19, 2006 10:44 pm


-----------------------------------
what exactly are you making that needs to that fast?

-----------------------------------
bugzpodder
Wed Sep 20, 2006 6:57 am


-----------------------------------
Sure, use IronPython

-----------------------------------
do_pete
Wed Sep 20, 2006 8:35 am


-----------------------------------
what exactly are you making that needs to that fast? I'm planning on making a 2d version of Battlefield 2.

-----------------------------------
bugzpodder
Wed Sep 20, 2006 9:14 am


-----------------------------------
or look into python C API.  although its more for C++ programmers to have access to python, rather than other way around

-----------------------------------
wtd
Wed Sep 20, 2006 10:45 am


-----------------------------------
I would mention that Ruby is considered to have one of the simplest C interfaces available.  With it you can wrap C code so that it can be called from Ruby just as you would call any other Ruby code.

-----------------------------------
do_pete
Wed Sep 20, 2006 11:26 am


-----------------------------------
Yes but we're doing Python for grade 11 programming so I'm stuck with it.

-----------------------------------
[Gandalf]
Wed Sep 20, 2006 3:17 pm


-----------------------------------
Stuck?  Hardly...  I'd say it's better than most of the alternatives that would have been chosen.

Just thought I'd add that in.

-----------------------------------
neufelni
Wed Sep 20, 2006 4:07 pm


-----------------------------------
I agree. Python is a great language. I'd much rather learn Python in school than Turing.

-----------------------------------
wtd
Wed Sep 20, 2006 4:19 pm


-----------------------------------
we're doing Python for grade 11 programming

Which version?

Oh, and don't be concerned with how fast your programs run.  Much more important is to learn to write and understand idiomatic Python code.

-----------------------------------
bugzpodder
Wed Sep 20, 2006 7:50 pm


-----------------------------------
wtd has on several occasions mentioned its drawbacks, but in most respects turing is a fairly good language to introduce to someone who is new to programming, esp given its structural resemblence to C++.

-----------------------------------
wtd
Wed Sep 20, 2006 10:49 pm


-----------------------------------
wtd has on several occasions mentioned its drawbacks, but in most respects turing is a fairly good language to introduce to someone who is new to programming, esp given its structural resemblence to C++.

Ignoring all other aspects of this, Turing has very little semantic or syntactic resemblance to C++.  Perhaps to C, but even then, not so much.

A closer match in terms of semantics would be Pascal, which due to the availability of free tools and its historically widespread use in education is still likely a better pedagogical language.

-----------------------------------
do_pete
Thu Sep 21, 2006 9:21 am


-----------------------------------
wtd has on several occasions mentioned its drawbacks, but in most respects turing is a fairly good language to introduce to someone who is new to programming, esp given its structural resemblence to C++.I think he means Python, not Turing. We are using the most recent version of Python, 2.4.3.

-----------------------------------
Cervantes
Thu Sep 21, 2006 9:39 am


-----------------------------------
We are using the most recent version of Python, 2.4.3.

Python 2.5 was released on Tuesday. [url=http://www.python.org/download/releases/2.5/]link!

But we can't expect your school to keep up with that, I guess. It's impressive enough that you're learning Python in class. I envy you.

-----------------------------------
do_pete
Thu Sep 21, 2006 9:52 am


-----------------------------------
I didn't know that, I thought that it was still just a release canditate.

-----------------------------------
bugzpodder
Thu Sep 21, 2006 7:53 pm


-----------------------------------
wtd has on several occasions mentioned its drawbacks, but in most respects turing is a fairly good language to introduce to someone who is new to programming, esp given its structural resemblence to C++.

Ignoring all other aspects of this, Turing has very little semantic or syntactic resemblance to C++.  Perhaps to C, but even then, not so much.

A closer match in terms of semantics would be Pascal, which due to the availability of free tools and its historically widespread use in education is still likely a better pedagogical language.

i thought C and C++ are almost identical minus OO stuff.  I recall a large comparison chart as an effort for Holtsoft to promote turing in an effort to show similarities between turing and pascal.  I think it is a fairly smooth transition from Turing to C++.  In fact that was the path I went down.  It wasn't that long ago.

-----------------------------------
wtd
Thu Sep 21, 2006 11:00 pm


-----------------------------------
i thought C and C++ are almost identical minus OO stuff. 

The object-oriented stuff is a fairly significant difference, but there are namespaces, templates, function/operator overloading...

C++ is best viewed as an entirely different language that happens to maintain a fairly high level of compatibility with C.

Objective-C is a perfect superset of C that adds support for object-oriented programming.
