[Python] Pong

1.0

By Thierry, 1 week ago

I found some very useful C++ tutorials when I first came here.

So I will do my best to propose an equivalent using Python.

Here is my work on Pong

Last comments

Codnpix

NEW 1 day ago

Steph Steph

Could there be a way to have a equivalent to Python tracemalloc https://docs.python.org/3/library/tracemalloc.html in CircuitPython ?

I don't think that kind of python lib are available for CircuitPython/MicroPython but maybe we could find a way to get a similar kind of objects memory allocation output. Maybe this could help for debuging while building a game with CircuitPython...

Steph

NEW 4 days ago

Thierry Thierry

I am always open to discussion... but when my words are distorted, discussion is no longer possible.

I say and maintain that:

"there are some RAM issues with OOP and current port of CircuitPython on the META..."

Let's take a simple example with which the problem occurs.
Here is a (beginning of) OOP version for the Snake game:

https://gist.github.com/iw4rr10r/8031233d7b050a45e675e199b82fdaa8

If I uncomment the instructions between lines 81 and 98, and delete the comments that expose the problem, the code is exactly 3182 characters long. Now, if I run it on the META, this is what happens:

Traceback (most recent call last):
  File "code.py", line 109, in <module>
MemoryError: memory allocation failed, allocating 10240 bytes

Now, if I comment on lines 84 and 96-98 (which do nothing extraordinary and, in any case, do not consume more RAM), this is what a gc.mem_free() displays:

7040 Bytes

Now let's take the procedural version of the Snake game, which I published in the Academy workshop:

https://gist.github.com/iw4rr10r/690f22fe8506ab7a2739dd6b40377b94

This code contains exactly 6432 characters (almost twice as many as the OOP version above). If I run it on the META, here is what a gc.mem_free() displays:

6144 Bytes

So... even less available memory than with the OOP version. And yet... the procedural code works perfectly...

Do you still think I'm wrong (?) when I say:

"there are some RAM issues with OOP and current port of CircuitPython on the META..."


Besides, you say:

It is just annoying to do a search on python on the forum and read "OOP" next to "issue" or "problem"

Why is this so embarrassing, since there is really a problem that still needs to be clarified regarding the possibility of using the OOP with CircuitPython's port to the META? Why would you want to keep this problem quiet?

And why convey the idea I'm trolling (I'm quoting your expression from Discord) about the implementation of the object layer in Python? It was never about that! I'm just noting a clear problem with the opportunity of using OOP with the current port of CirctuitPython to the META... nothing more!

I'm not trolling.

I do not denigrate the Python language.
I do not denigrate CircuitPython which, by the way, is a great project.
I do not denigrate Soru's work, which makes us happy every day.

I'm just saying that there's a problem, and I'm looking for a solution, or at least a clear explanation.

Codnpix

1 day ago

Could there be a way to have a equivalent to Python tracemalloc https://docs.python.org/3/library/tracemalloc.html in CircuitPython ?

I don't think that kind of python lib are available for CircuitPython/MicroPython but maybe we could find a way to get a similar kind of objects memory allocation output. Maybe this could help for debuging while building a game with CircuitPython...

Thierry

NEW 4 days ago

I never said no one is stupid, except me sometimes ;)

It is just annoying to do a search on python on the forum and read "OOP" next to "issue" or "problem"

and it is not a good idea for me to do those posts in english, from work, and written form instead of a good talk.

whatever my point is, here are my apologies to whoever may have been hurt by my words.
it won't happen again.

Steph

4 days ago

I am always open to discussion... but when my words are distorted, discussion is no longer possible.

I say and maintain that:

"there are some RAM issues with OOP and current port of CircuitPython on the META..."

Let's take a simple example with which the problem occurs.
Here is a (beginning of) OOP version for the Snake game:

https://gist.github.com/iw4rr10r/8031233d7b050a45e675e199b82fdaa8

If I uncomment the instructions between lines 81 and 98, and delete the comments that expose the problem, the code is exactly 3182 characters long. Now, if I run it on the META, this is what happens:

Traceback (most recent call last):
  File "code.py", line 109, in <module>
MemoryError: memory allocation failed, allocating 10240 bytes

Now, if I comment on lines 84 and 96-98 (which do nothing extraordinary and, in any case, do not consume more RAM), this is what a gc.mem_free() displays:

7040 Bytes

Now let's take the procedural version of the Snake game, which I published in the Academy workshop:

https://gist.github.com/iw4rr10r/690f22fe8506ab7a2739dd6b40377b94

This code contains exactly 6432 characters (almost twice as many as the OOP version above). If I run it on the META, here is what a gc.mem_free() displays:

6144 Bytes

So... even less available memory than with the OOP version. And yet... the procedural code works perfectly...

Do you still think I'm wrong (?) when I say:

"there are some RAM issues with OOP and current port of CircuitPython on the META..."


Besides, you say:

It is just annoying to do a search on python on the forum and read "OOP" next to "issue" or "problem"

Why is this so embarrassing, since there is really a problem that still needs to be clarified regarding the possibility of using the OOP with CircuitPython's port to the META? Why would you want to keep this problem quiet?

And why convey the idea I'm trolling (I'm quoting your expression from Discord) about the implementation of the object layer in Python? It was never about that! I'm just noting a clear problem with the opportunity of using OOP with the current port of CirctuitPython to the META... nothing more!

I'm not trolling.

I do not denigrate the Python language.
I do not denigrate CircuitPython which, by the way, is a great project.
I do not denigrate Soru's work, which makes us happy every day.

I'm just saying that there's a problem, and I'm looking for a solution, or at least a clear explanation.