[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Say No to global-by-default
- From: Sean Conner <sean@...>
- Date: Wed, 4 Jul 2018 17:41:47 -0400
It was thus said that the Great Gregg Reynolds once stated:
> Ok, but what does that have to do with spelling?
I mispelled 'baz' as 'baa'.
-spc
> On Wed, Jul 4, 2018, 4:33 PM Sean Conner <sean@conman.org> wrote:
>
> > It was thus said that the Great Gregg Reynolds once stated:
> > > On Wed, Jul 4, 2018, 3:53 PM Egor Skriptunoff <
> > egor.skriptunoff@gmail.com>
> > > wrote:
> > >
> > > >
> > > > 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.
> >
> > [spc]lucy:/tmp>more a.c
> >
> > int foo(int bar)
> > {
> > int baz = 5;
> > return baa + bar;
> > }
> > [spc]lucy:/tmp>gcc a.c
> > 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:
> >
> > function foo(bar)
> > local baz = 5
> > return baa + bar
> > end
> >
> > '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).
> >
> > -spc
> >
> >
> >