Re:MoonScript, a programmer friendly language that compiles ...
by rweichler on Monday May 29, 2017 @08:22PM
(#14442263)
I see it as a toy language. The only person I think would find it useful is leafo himself since he can edit it however he wants. But everyone else should stay away from it. Plain Lua is so much better.
[ Parent
| on HN ]
Re:MoonScript, a programmer friendly language that compiles ...
by honewatson on Monday May 29, 2017 @10:47PM
(#14442747)
Can't agree with that. Having used both Lua and Moonscript quite a bit I think Moonscript is what most dynamic scripting languages should be. Simple, succinct and does what you need for a scripting language.
I really enjoy using it.
Re:MoonScript, a programmer friendly language that compiles ...
by rweichler on Tuesday May 30, 2017 @12:02AM
(#14442946)
Care to give an example?
Re:MoonScript, a programmer friendly language that compiles ...
by anonymoushn on Tuesday May 30, 2017 @12:19AM
(#14442986)
The list comprehensions are really great. Most of the time when I'm writing Lua I can't be bothered to write exactly what Moonscript outputs for a list comprehension because it's noisy, but it's what I really would write if I cared about tiny amounts of performance.
Re:MoonScript, a programmer friendly language that compiles ...
by rweichler on Tuesday May 30, 2017 @06:28AM
(#14444215)
Idk. Still not sold. You can do list comprehensions in regular Lua with something like this:
function listcomp(t, f)
local r = {}
for k,v in pairs(t) do
r[k] = v
end
return r
end
And then, your Lua code would be like: listcomp({1, 2, 3, 4}, function(k, v)
return v*2
end)
Which would be the equivalent to this in MoonScript: [v*2 for k,v in pairs({1, 2, 3 ,4})]
I dunno. Just seems like a wash to me. And then you think about the extra compile step to run MoonScript, and the potential performance hits, and I'm just turned off completely from it.
Re:MoonScript, a programmer friendly language that compiles ...
by shalabhc on Tuesday May 30, 2017 @06:48AM
(#14444303)
There are no potential performance hits. In particular the code generated for list comprehensions would be faster than your example because there is no extra function call per item.
Re:MoonScript, a programmer friendly language that compiles ...
by anonymoushn on Tuesday May 30, 2017 @06:47AM
(#14444298)
Over here it generated
local b
do
local _accum_0 = { }
local _len_0 = 1
for k, v in pairs({
1,
2,
3,
4
}) do
_accum_0[_len_0] = v * 2
_len_0 = _len_0 + 1
end
b = _accum_0
end
It did a pretty good job. Unlike your code, it doesn't have any function calls, and unlike the code I would probably write, it doesn't use the # operator.
Re:MoonScript, a programmer friendly language that compiles ...
by shalabhc on Tuesday May 30, 2017 @05:13AM
(#14443913)
There are a lot of features that make Moonscript much more convenient than plain Lua. Examples (try the first three in Lua):
- default values for function parameters
- list comprehensions
[x * 2 for x in *{1, 2, 3}]
- easier iteration (e.g. `for key, value in pairs obj`)- local is default, not global
- a simple class system if you need it
- `export`, `from` and `import` keywords
- `+=`, `/=`, `*=` etc. operators
- indentation based scope (ok, this is debatable)
I can't think of a single place where plain Lua is actually better. OK maybe `:` is better as a method call operator, but that's it.
Re:MoonScript, a programmer friendly language that compiles ...
by rweichler on Tuesday May 30, 2017 @06:35AM
(#14444249)
> default values for function parameters
function f(a, b, c, d)
a = a or 1
b = b or 2
c = c or 3
d = d or 4
end
> list comprehensionshttps://news.ycombinator.com/item?id=14444215
> local is default, not global
I think this is a con.
> a simple class system if you need it
I also think this is a con, because it limits flexibility.
Here's my class system:
Object = {}
function Object:new()
local self = setmetatable({}, {__index = self})
return self
end
And how to use it: local super = Object
Shape = Object.new(super)
function Shape:new(color)
local self = super.new(self)
self.color = color
return self
end
local super = Shape
RedShape = Object.new(super)
function RedShape:new()
local self = super.new(self, 0xff0000)
return self
end
If I want to add multiple inheritance, or interfaces, it is easy. Because it is just metatables. With MoonScript this is not possible.> `export`, `from` and `import` keywords
Sounds like a con to me. `require` is simple.
> `+=`, `/=`, `*=`
I agree with this one.
Re:MoonScript, a programmer friendly language that compiles ...
by shalabhc on Tuesday May 30, 2017 @06:51AM
(#14444320)
>
function f(a, b, c, d)
a = a or 1
b = b or 2
c = c or 3
d = d or 4
end
Compare with: f = (a=1, b=2, c=3, d=4) -> ...
Also note the latter is correct when you call it as f(false).
Re:MoonScript, a programmer friendly language that compiles ...
by partycoder on Monday May 29, 2017 @08:26PM
(#14442286)
It's a general purpose language, you never know who will use it and how.