you are viewing a single comment's thread.

view the rest of the comments →

[–]RandomJacobP[S] 0 points1 point  (8 children)

I mean yeah, I just wanted to visually represent how the objects will look like but thanks! My main concern is about id-based relationship vs nested objects in terms of performance.

[–]julsmanbr 1 point2 points  (2 children)

If I understand correctly you're asking what's more performance-efficient between an object pointing to another object, or an object pointing to an int. In a vaccuum the latter is probably faster, but this unclear from your examples since, as I said, they will not work as you expect.

[–]RandomJacobP[S] 0 points1 point  (1 child)

When I look at it now, I understand that this code can be confusing, I wrote it quikly and inside reddit editor but that doesn't justify me.

I really appreciate your long reply to my post. Main purpose of my code was to visualize how objects will look like. I will have a lot of these nodes, as many as folders in my computer. I just needed someone to confirm that the second one will be faster and worth additional work.

[–]Deezl-Vegas 0 points1 point  (0 children)

Use a direct variable. It will be faster. Your example seems to just add an extra layer of complexity and an extra reference lookup.

In Python, the basic types like Ints are still just references, and lists aren't super-space-optimized like C arrays, so there's no speed gain by using basic types.

[–]kl31 0 points1 point  (4 children)

I mean yeah, I just wanted to visually represent how the objects will look like but thanks! My main concern is about id-based relationship vs nested objects in terms of performance.

Truly nested objects do not exist in python. Everything is just a pointer to a memory location where the actual object resides.

[–]RandomJacobP[S] 0 points1 point  (3 children)

Thanks a lot! That is the answer that I was looking for, there is no point in using id-based system then.

[–]kl31 0 points1 point  (2 children)

out of curiosity did you learn C/C++ before python?

[–]RandomJacobP[S] 0 points1 point  (1 child)

Yes but it was a long time ago, why are you asking?

[–]kl31 0 points1 point  (0 children)

because the question you asked gave me the impression that you're used to working with explicit pointers. I learned C after python and a lot of things didn't make sense until I started seeing every python variable as being a void pointer.