[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Say No to global-by-default
- From: Sean Conner <sean@...>
- Date: Wed, 4 Jul 2018 17:32:52 -0400
It was thus said that the Great Gregg Reynolds once stated:
> On Wed, Jul 4, 2018, 3:53 PM Egor Skriptunoff <email@example.com>
> > I do not hate globals :-)
> > I'm trying to solve the problem "the compiler silently ignores all
> > variable name typos".
> > It's the expectation of many programmers that a compiler should check for
> > misspelled identifiers and warn the user at compile time.
> Now I'm completely confused. I never heard of a compiler that could do
> that. What does "misspelled identifier" mean to a compiler? I must be
> missing your point, sorry.
int foo(int bar)
int baz = 5;
return baa + bar;
a.c: In function oo':
a.c:5: error: `baa' undeclared (first use in this function)
a.c:5: error: (Each undeclared identifier is reported only once
a.c:5: error: for each function it appears in.)
But in C, you have to declare every variable upfront. In Lua:
local baz = 5
return baa + bar
'baa' is treated as a global variable who's value is nil (and thus in *this*
case you get an error, but this won't happen in all cases).