Kyjor / JulGame.jl

JulGame is a game engine based on the Julia programming language with the help of SDL2.
https://docs.kyjor.io/JulGame.jl
The Unlicense
94 stars 3 forks source link

Pulling methods out of struct definitions #54

Closed mrufsvold closed 5 months ago

mrufsvold commented 5 months ago

Currently, much of the logic is stored in anonymous functions within struct definitions by overloading getproperty. This does allow OOP style code with scene.method() calls but it has two drawbacks:

1) Stack traces contain anonymous functions with uninformative names. It would be nice to see init(::Main) in the stacktrace instead of a gensymed string of characters. 2) Julia is designed for a more functional style so you're probably going to see a performance penalty for always having to go through the if s == :init ... elseif.. elseif... on every get property call. Using normal method calls allows multiple dispatch to do its thing and resolve the correct function, inline where appropriate, etc.

You could solve the first problem by just pulling these anonymous functions out, giving them names, and then still using get_property to dispatch to the correct function. Or you could go all the way and remove the OOP style and mayb see a performance benefit.

Anyway, I'm happy to do the work, but I wouldn't want to do such a major refactor without checking on the direction you'd like to go.

Kyjor commented 5 months ago

This is something I would like to do very soon. I have some major changes I'm going to merge today. So just after that is fine. When it's done, I'll personally test it since we don't have complete code coverage yet. Thank you!

mrufsvold commented 5 months ago

Great! Just ping me when you think you're ready. I came up with a pretty good system for reorganize the code last night, so I should be able to get it done quickly!

Kyjor commented 5 months ago

Sounds good! Just added some more automated testing as well so that should help a bit. After I merge that, I'll work on wrapping up the big change set and let yo u know. Should be about 30 minutes!

Kyjor commented 5 months ago

Just merged! You should be good to go. Thank you!

mrufsvold commented 5 months ago

The functions are moved out in #57 ! It'll take a lot longer to find every function call and reorder it, but that can be more incremental as different parts of the code base get updates!

Kyjor commented 5 months ago

Thank you!