[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Global by default
- From: steve donovan <steve.j.donovan@...>
- Date: Wed, 13 Feb 2013 08:48:56 +0200
On Tue, Feb 12, 2013 at 9:57 PM, David Olofson <email@example.com> wrote:
> TL;DR: Implicit behavior is dangerous.
For example, consider how the Lua-based language Moonscript handles
this. All declarations are local.
if a > 0
x = 1
x is local to the block, so it always prints out nil! You have to put
an explicit 'x = nil' or 'local x' before the if to force the
Functions may optionally declare exactly what upvalues they _are_
using. Here it's obvious enough from the context, but this is a
useful way to annotate the behaviour explicitly in more complicated
counter = 1
add = (x using counter) ->
counter = counter + 1
Furthermore, you need a new statement (export) to ensure that
something _does_ become global, and so forth.
MS is not Lua, (altho generates pretty clear Lua as output), but you
see the extra complexity needed to preserve 'local by default'