lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Sun, Aug 24, 2014 at 10:25:00AM -0700, Coda Highland wrote:
> On Sat, Aug 23, 2014 at 2:19 PM, William Ahern
> <william@25thandclement.com> wrote:
<snip>
> > Sigil hater?
> >
> > I never understood why so many people* are for strong typing on the one
> > hand, but violently oppose the use of sigil notation on the other. It seems
> > like a contradiction.
> >
> > * I'm not necessarily speaking of your preferences.
> 
> Makes sense to me -- sigils are essentially language-enforced
> Hungarian notation, minus the mnemonics that are Hungarian notation's
> claimed advantage. It renders information about the variable
> everywhere it appears that could just as easily be seen at its point
> of declaration.

Sure, assuming you could find it. But much like Lua, often there's no
separate declaration, just a definition. And sigils also perform as a type
of operator in many contexts, which is important because Perl doesn't
support pass by value for arrays and hashes. If you don't explicitly pass by
reference, Perl will automatically convert those types to a list of
arguments passed by value on the stack.

> Furthermore, in Perl, the different sigils actually refer to the same
> variable in different ways, which aren't obvious from the syntax,
> requiring you to understand the sigils before you can even start, and
> using the wrong sigil means the program completely misbehaves.

I think you're confusing package globs with regular variables, but in any
event the same name does not refer to the same variable. Lexical variables
are completely distinct.

	my $foo = "hello world";
	my @foo = qw/one two three/;

defines two completely different variables.

Package/global variables, by contrast, are wrapped in a glob container. So
with

	$foo::foo = "hello world";
	@foo::foo = qw/one two three/;

there's a single "glob" called *foo::foo, which internally stores two
separate variables, $foo::foo and @foo:foo. You can access and modify each
independently. Globs serve some admittedly idiosyncratic Perl symbol lookup
rules. But given all the confusion that novices have with Lua's seemingly
simple and straight-forward syntax, I'm not sure how complex Perl's syntax
is in the grand scheme of things.