[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Thoughts on optional commas
- From: steve donovan <steve.j.donovan@...>
- Date: Thu, 8 Mar 2012 10:18:01 +0200
On Thu, Mar 8, 2012 at 12:58 AM, Jay Carlson <nop@nop.com> wrote:
> for i,v in pairs(fragments) do
> xml.parse(v, {
> function end_tag(t)
> print("closing tag", t, "at index", i)
> end
> })
> end
>
> when there's a table+closure's worth of garbage created per iteration.
I suppose a clever compiler could hoist the {...} out of the loop
(perhaps LuaJIT can already do this) but this is a good point.
Although the point would be that every decent Lua programmer needs to
have a handle on the cost of various code constructs, plus the wisdom
to know when it doesn't matter (a tall order?)
However, I'm not sure of the wisdom of not allowing new notations
because they make inefficiency easier.
On the subject of surprising commas, look at this map literal in Go:
var m = map[string]int {
"one": 1,
"two": 2,
"three":3,
}
Here you actually _need_ the trailing comma, because the semi-colon
insertion algorithm gets confused, pretty much like the JS situation.
Apparently all new Go programmers have to learn this the hard way...
steve d.