Remove object-oriented primitive methods

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Remove object-oriented primitive methods

fschmidt
Administrator
fschmidt wrote
Like with String, I would let these methods be used in an object-oriented way like:
a = (10).long()
b = 3
c = b.double()
c.type() == "double" or error "not double"
http://luan-forum.7479.n7.nabble.com/Number-module-tp730.html

I thought more about this and I realize that the whole idea of having object-oriented methods on any primitive is wrong.  If I see x.foo() I have no idea where foo() comes from.  The current idea of forcing require() calls to make clear where everything comes from is lost for something like s.upper() .  If I eliminate object-oriented primitive methods, then seeing x.foo() immediately tells me that x is a table and foo is a method in that table.  The only exception is when I call java() but this doesn't apply to casual Luan programmers.

This is another example of removing a feature from Luan to improve it.  The object-oriented string methods are magic that are confusing and aren't needed.  Using a local variable for these functions is both clearer and faster to execute.

In this case, the above Number methods become:
local Number = require "luan:Number"
local long = Number.long
local double = Number.double
local number_type = Number.number_type

local a = long(10)
local b = 3
local c = double(b)
number_type(c) == "double" or error "not double"
Woe to those who call bad good and good bad -- Isaiah 5:20
Following the Old Testament, not evil modern culture
Reply | Threaded
Open this post in threaded view
|

Re: Remove object-oriented primitive methods

Hugo <Nabble>
Yes, this makes sense. You know I don't like assigning functions to local variables, so that's the only part I don't agree with. But the rest is fine and you can go ahead and make this change.
Reply | Threaded
Open this post in threaded view
|

Re: Remove object-oriented primitive methods

fschmidt
Administrator
done, closing
Woe to those who call bad good and good bad -- Isaiah 5:20
Following the Old Testament, not evil modern culture