News for hackers. Stuff that matters.
Re:Perl, the first postmodern computer language (1999) by tenebrisalietum on Wednesday May 04, 2022 @11:46AM (#31262102)
Here's one reason why sigils could be considered to suck.

`@array` - array of values.

`$array[1]` - get element 1 of the array.

`$array` - What do you think this does? Why can't we just `@array[1]`?

Re:Perl, the first postmodern computer language (1999) by xorcist on Wednesday May 04, 2022 @03:10PM (#31264585)
Perl has "contexts" as its type system. Sigils are a part of that.

There's a lesson here somewhere that most people don't generally want to understand stuff. So stuff that's the least bit different don't tend to go mainstream, things like Haskell have a hard time. Perl was a bit different but just happened to go mainstream anyway, and that probably coloured people's feelings for it, for better and for worse.

Re:Perl, the first postmodern computer language (1999) by matthewpersico on Wednesday May 04, 2022 @08:17PM (#31267697)
Because Perl is context sensitive and what we care about is not what is being stored but what is being accessed.

'array' is the variable.

'@array' gives me the list in 'array'.

'$array[1]' gives me the scalar ($) value at array[1].

`@array[3..7]` gives me the list (@) of values at array indexes 3-7, inclusive on both sides. (Why does Python use open ended ranges? <facepalm>) (Why is Python's slicing syntax an inflexible loop? <facepalm again>)

`@array[1]`, by the way gives me the list of values at array index 1, which is the same as `$array[1]`

Re:Perl, the first postmodern computer language (1999) by bmn__ on Wednesday May 04, 2022 @04:23PM (#31265365)
> Why can't we just `@array[1]`?

Because of slices. If you look at the complete table, you will never get confused again.

https://news.ycombinator.com/item?id=26578855

Re:Perl, the first postmodern computer language (1999) by gnubison on Wednesday May 04, 2022 @05:44PM (#31266249)
Sigils indicate what an operation evaluates to, not what the input type is. You get used to it.
Re:Perl, the first postmodern computer language (1999) by G3rn0ti on Wednesday May 04, 2022 @11:59AM (#31262274)
Raku actually adopted that latter syntax. Although, it’s optional as everything really becomes a reference anyway. So you don’t need the „@“ and „%“ sigils any more.
Re:Perl, the first postmodern computer language (1999) by csdvrx on Wednesday May 04, 2022 @11:58AM (#31262259)
> `$array` - What do you think this does?

I think it will throw an error if you declared my @array

> Why can't we just `@array[1]`?

Because that could return an array or a hash if you are dealing with structures likes arrays-of-arrays (AoA) or arrays-of-hashes (AoH).

To my naive take, it makes much more sense to only identify high level objects to put them under one category (arrays, AoA, AoH -> @) then consider everything else as "uncertain" and default to $.

Otherwise, you would have to declare AoA and AoH differently (ex: my @@AoA; my @%AoH;) and then the interpreter could see @AoA[1] and %AoH[1] as valid but %AoA[1] and @AoH[1] as invalid.

I could see that as potentially having value to know at a glance what you are dealing with, but it might break many things, and casting to a new object with my %aoh_1 = %{ $AoH[1] } makes more sense.

Re:Perl, the first postmodern computer language (1999) by jwilk on Wednesday May 04, 2022 @01:34PM (#31263484)
> Because that could return an array or a hash

@array[1] returns a single-element list-like thing. It mostly works, but you get a warning:

https://perldoc.perl.org/perldiag#Scalar-value-@%25s%5B%25s%...

Re:Perl, the first postmodern computer language (1999) by hedora on Wednesday May 04, 2022 @11:58AM (#31262256)
The last one produces a helpful error message at script interpretation time. @array[1] is probably also an error, or you're doing something very strange / wrong, and it'll stick out like a sore thumb during code reviews.