paulofmandown / rotLove

Roguelike Toolkit in Love. A Love2D/lua port of rot.js
http://paulofmandown.github.io/rotLove/
Other
258 stars 25 forks source link

30log strange deep-copy behavior #39

Closed airstruck closed 7 years ago

airstruck commented 7 years ago

30log does something strange.

Whenever a class is instantiated, it deep-copies everything from the prototype into the newly-created instance. This is troubling for a number of reasons:

You can probably guess where I'm going with this. It might not be a bad idea to ditch 30log and show people how to patch it in themselves (something like package.loaded['rot.class'] = require('30log')() before loading rotLove should do it).

airstruck commented 7 years ago

This ticket is starting to remind me of that ear of corn in the back of my fridge I keep meaning to throw out.

Possible ways forward:

For what it's worth, I like the first option. Any thoughts on this?

Zireael07 commented 7 years ago

I'd do 1 and 2 at the same time (file a ticket on 30log and scrap 30 log from rotLove).

paulofmandown commented 7 years ago

I'm ok with ditching 30log, especially after this commit duplicated the functionality we were using.

Sent from my Lge LG-VS985 using FastHub

timothymtorres commented 7 years ago

I'd agree to tossing 30log in the trash. We might be better off using middleclass or writing our own Metatables. Personally I'm a fan of middleclass, good documentation and easy to use!

airstruck commented 7 years ago

Sounds good, thanks for the feedback! I've opened https://github.com/Yonaba/30log/issues/35.

30log can be plugged in with a single line of code, so people can still use it if they want:

package.loaded['src.rot.class'] = require('30log')()

@timothymtorres, we've already got a solution in class.lua that mimics the parts of 30log's API that we use. Middleclass can also be plugged in by doing something like the above, but it needs to be shimmed with extend, and initialize needs to be mapped onto init (see https://github.com/paulofmandown/rotLove/pull/25#issuecomment-312970524).

I'll write a PR soon with 30log removed, and we can write something up in the docs with snippets for plugging in other class libraries.

airstruck commented 7 years ago

With 30log gone, I've added some special-purpose collection classes (called "PointSet" and "Grid") to my local copy to use instead of the foo[x..','..y] and foo[x][y] idioms. These store data in a densely-packed format that can be iterated quickly, along with a hash part for quick retrieval. The calling code is neater and more concise, and the tests run roughly twice as fast (not a proper benchmark, but a good sign anyway).

Will push a PR soon, just waiting on #53 to make sure it gets rebased properly.

cpeosphoros commented 7 years ago

I'm working on a 30log fork which aims to rehaul and streamline the whole inheritance/instantiation process: https://github.com/cpeosphoros/30log-plus

The main reason I choose to fork from 30 log was ditch the minimalist philosophy in exchange for stronger class identity, less code duplication in applications and better performance for heavy classes' instantiation.

The second main reason was having stronger mixin support.

The trade over I choose was having a heavier OO library in exchange for better application code.

One of my TODO list's item is exactly removing deepcopy processing for both cases inheritance/instantiation.

It is still very early WIP and it doesn't currently address your issue, but I'll be glad to hear from you guys if there are other features you would like to see implemented.