Log In  

I previously suggested that you pretend the 32k of lua token ram was filled with 16-bit tokens, rather than 32-bit, as that would make more sense in the limited address space and no one would ever have used a 32-bit token architecture on an 8-bit hardware architecture. That way we'd get 16k tokens instead of 8k.

I, uh, got no traction on that one, from what I could tell. ;) Gotta try, though, right?

Here's a less-significant proposal:

To encourage people to learn and use object-oriented programming, how about taking your token-pruning shears to any token that (de)references SELF? As it is, it's super prohibitive to put accessors or any simple functionality inside of class methods because of the token overhead of all the extra SELFreferences. The real-world justification would be that a compiler typically keeps self/this in a register.

Seems like other things already favor using classes, e.g. the relaxed timing on top-level table-member references. Maybe this would be consistent with that?

P#44732 2017-09-28 20:26 ( Edited 2017-09-30 23:53)

+1 if function class:stuff() is also 1 token!

P#44745 2017-09-29 01:44 ( Edited 2017-09-29 05:44)

I was thinking about this and imagining counter-arguments that might be made, including things I might think of myself that could nix the idea. Had some thoughts:

"But Felice, what if people start putting variables named SELF all over their code to try to take advantage of this?"

Well, kind questioner, I thought about the same thing. I'm fairly certain, though, that it's easy to determine whether or not the SELF being referenced is the first argument to the function or some later variable that's masking it.

"Okay, but Felice, even if you restrict it to the first argument to a function, that still won't prevent people from using it where the function isn't actually a lua pseudo-class method.

Ah, kind questioner, you and I think very much alike. I should get to know you. Anyway, I thought about this also, and came to the conclusion that the possibility of bad choices would most likely end up being overridden by a desire to discover and use a SELF that actually makes sense in the context of the function, thus leading to discovery of more instances where object-oriented programming would actually be useful and a good idea.

So, fair point, but outweighed by another, I think.


That's all I came up with. Honestly, I think it could be set up to prevent abuse, as mentioned. If only a token dereferencing the first argument would qualify to be elided, you really couldn't do much except try to make things object-oriented where it makes no sense, in which case you're just being dopey and you probably need to make the mistake so you can learn why not to.

Besides, if someone wants to write code that's got SELF all over where the variable is really something else, I'm not sure I care what kind of code they write. It's not code I'm going to spend any real time looking at, learning from, or trying to emulate, nor am I going to give anyone kudos for eking out a few extra cycles by making their code utterly unreadable. In fact, I think I might be inclined to point out the dubious nature of the practice, in hopes of discouraging junior programmers from following the lead. So I think it just wouldn't appeal to people to do that, even if it were possible.


As an aside, I like the idea above of also eliding the extra "TABLE:" scope token(s?) in "FUNCTION TABLE:METHOD()", but I fear it may be a lot more difficult to detect. If not, I agree that would also be really helpful in promoting the use of class methods. Declaring methods is, by itself, pretty costly.

P#44765 2017-09-29 22:43 ( Edited 2017-09-30 02:43)

I dunno if encouraging people to use OO design patterns is a major goal of Pico-8.

When you think of OO design patterns, classic 8-bit home computers and/or home consoles is not really the first thing that springs to mind.

P#44782 2017-09-30 16:49 ( Edited 2017-09-30 20:49)

Oh, I know. I'm not saying it's part of PICO-8's goals. I just think it's a good thing to learn.

I really just want to be able to use OOP myself, of course, without losing so many tokens to it. The rest of the argument is just me trying to retrofit proper justifications. :)

P#44785 2017-09-30 19:53 ( Edited 2017-09-30 23:53)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-29 08:24:29 | 0.007s | Q:15