Live data from Hacker News

Sigils are underappreciated (2022)

raku-advent.blog

81–90 of 97 posts

Re: Sigils are underappreciated (2022)

#81
post #56
post #20

I think there's a piece of insight missing from the author's analysis of non-programmatic sigils. To wit, the sigils are only valuable when both parties deeply understand the information that the sigil is trying to convey . The "$framework at $dayjob" example illustrates this point. Programmers familiar with the use of sigils to indicate variables intrinsically grok this phrase, but it looks like gobbledygook to non-…

I might agree with you if I ask for the fact some of the most popular beginner languages use sigils: - BASIC - Shell scripting - PHP It’s also worth noting that all languages have special tokens to identify properties of the code. Eg why does a string need to be wrapped in quotation marks but integers do not? Why do single and double quotation marks behave differently in some languages? Why do function names behave d…

> I might agree with you if I ask for the fact some of the most popular beginner languages use sigils

20 years ago I might've agreed with you. But I do not think that PHP, BASIC and shell scripting are popular beginner languages in 2023.

> It’s also worth noting that all languages have special tokens to identify properties of the code. Eg why does a string need to be wrapped in quotation marks but integers do not?

Quotation marks and especially parentheses after function calls don't fit TFA's definition of a sigil because they aren't at the beginning of the word and (arguably only in the latter case) don't communicate meta-information about the word.

> At the end of the day, if you want to learn to program then you are always going to have some degree of syntax that you just have to learn.

I'll agree with you that the line between sigils and general syntax/punctuation is a bit of a blurry one - where do you stop? Using my definition above, I think wrapping strings in quotation marks is a clear win because it fits our widely-held shared understanding that quotation marks demarcate and group a sequence of words. Single and double quotes behaving differently is unintuitive for the same reason while not conferring a corresponding benefit on experts.

Re: Sigils are underappreciated (2022)

#82
post #7

Sigils in Perl were awful. They didn't behave concretely. Sometimes it was sort of a type annotation sometimes they were a weird incantation. Things like implicit scalar conversion @foods = qw(burgers fries shakes); $length = @foods; print $length, "\n"; Yeah it's easy to understand once you know what is happening but it's obscure. There are no easy clues to let you know what is happening. Then there are situations w…

Perl is the most confusing language I’ve ever used professionally, largely because of how it uses sigils sometimes as operators. The other source of confusion are the million and a half implicit variables that are context-specific. It’s the only language where even after ten years I still regularly have to google to do simple things like iterate over a hash. And half the time it doesn’t work because the hash is actua…

Perl is hardly alone in the million and a half implicit variables. Python is a far worse offender on this point and probably equally so in the context specific meaning of a statement (is this a generator or a list). My guess is this gripe is a familiarity thing. Iterating a hash in perl isn't that complicated, neither is iterating a hashref but you do need to be aware of which it is - which you should be anyway so you know whether you're modifying it locally or for the caller.

That said, I'm also in the camp of "I don't care much for sigils."

Re: Sigils are underappreciated (2022)

#83
post #81
post #56

Earlier quoted context omitted.

I might agree with you if I ask for the fact some of the most popular beginner languages use sigils: - BASIC - Shell scripting - PHP It’s also worth noting that all languages have special tokens to identify properties of the code. Eg why does a string need to be wrapped in quotation marks but integers do not? Why do single and double quotation marks behave differently in some languages? Why do function names behave d…

> I might agree with you if I ask for the fact some of the most popular beginner languages use sigils 20 years ago I might've agreed with you. But I do not think that PHP, BASIC and shell scripting are popular beginner languages in 2023. > It’s also worth noting that all languages have special tokens to identify properties of the code. Eg why does a string need to be wrapped in quotation marks but integers do not? Qu…

> 20 years ago I might've agreed with you. But I do not think that PHP, BASIC and shell scripting are popular beginner languages in 2023.

PHP and shell scripting are still massively used in 2023 (eg https://madnight.github.io/githut/#/pull_requests/2023/1). You have a point about BASIC but it was the de facto standard for computers at a time when people didn't have the web to quickly look up problems and thus learning to code was much harder. Yet we (in fact I) managed just fine.

> Quotation marks and especially parentheses after function calls don't fit TFA's definition of a sigil because they aren't at the beginning of the word and (arguably only in the latter case) don't communicate meta-information about the word.

I didn't say they are sigils. I said they're tokens. My point was that removing sigils doesn't remove meta-information encoded in magic characters:

- You have `foobar()` where the braces denote (call the function rather than pass the function reference

- "" == string which allows escaping and/or infixing vs '' which doesn't (other languages have different tokens for denoting string literals, like `` in Go)

- # in C and C++ is a marco

- // is a line comment in some languages. Others use #, or --

- Some languages use any of the following for multi-line comments: ```, /* /, and even {} is used. Whereas it's an execution block in some other languages

My point is you have to learn what all of these tokens mean regardless of whether they sit as a prefix or not. The that that they're a sigil doesn't change anything.

The real complaint people are making here is about specific languages, like Perl, overloading sigils to do magical things. That is a valid complaint but, in my opinion, it's a complaint against overloading tokens rather than sigils specifically. Much like a complaint about operator overloading doesn't lead to the natural conclusion that all operators are bad.

> don't communicate meta-information about the word.

We need to be careful about our assumption about whether a token effectively communicates meta-information because while I do agree that some tokens are more intuitive than others, there is also a hell of a lot of learned behaviour involved as well. And it's really* hard to separate what is easier to understand from what we've just gotten so use to that we no longer give a second thought about.

This is a massive problem whenever topics about code readability comes up :)

> I'll agree with you that the line between sigils and general syntax/punctuation is a bit of a blurry one - where do you stop?

shrugs...somewhere...? You can't really say there should be a hard line that a language designer shouldn't cross because it really depends on the purpose of that language. For example the language I'm currently working on makes heavy use of sigils but it also makes heavy use of barewords because it's primary use is in interactive shells. So stricter C-like strings and function braces would be painful in a read once write many environment (and I know this because that was my original language design -- and I hated using the shell with those constraints).

In a REPL environment with heavy use of barewords, sigils add a lot to the readability of the code (and hence why Perl originally adopted sigils. Why AWK, Bash, Powershell, etc all use them, etc).

However in lower level languages, those tokens can add noise. So they're generally only used to differentiate between passing values vs references.

But this is a decision each language needs to make on a case by case basis and for each sigil.

There also needs to be care not to overload sigils (like Perl does) because that can get super confusing super quick. If you cannot describe a sigil in one sentence, then it is probably worth reconsidering whether that sigil is adding more noise than legibility.

> sing my definition above, I think wrapping strings in quotation marks is a clear win because it fits our widely-held shared understanding that quotation marks demarcate and group a sequence of words. Single and double quotes behaving differently is unintuitive for the same reason while not conferring a corresponding benefit on experts.

Here lies the next problem for programming languages. For them to be useful, they need to be flexible. And as languages grow in age, experts in those languages keep asking for more and more features. Python is a great example of this:

- ''

- ""

- ''' '''

- """ """

- f""

...and lots of Python developers cannot even agree on when to use single and double quotes!

I tried to keep quoting simple in my own language but I ended up with three different ways to quote:

- '' (string literals)

- "" (strings with support for escaping and infixing)

- %() (string nesting. For when you need a string within a string within a string. Doesn't come up often but useful for dynamic code. A contrived example might look like: `tmux -c %(sh -c %(echo %(hello world)))` (there are certainly better ways you could write that specific code but you get the kind of edge case I'm hinting at).

As much as languages do need to be easy to learn, they shouldn't sacrifice usability in the process. So it is a constant balancing act trying to make something easy to learn, yet also powerful enough to actually have a practical use. Not to mention the constant push and pull between verbosity where some claim fewer characters (eg `fn` as a function keyword) improves readability because it declutters the screen from boilerplate, while others say terms like `function` are more readable because it is closer to executable pseudo-code. Ultimately you cannot please all of the people all of the time.

Re: Sigils are underappreciated (2022)

#84
post #13

Regarding sigils, there is also ? and ! in Scheme and Clojure, and don't get me started on Forth, it's pretty much sigils all the way down.

I perceive FORTH in a different way. The only sigil in FORTH is SPACE. Everything else is a letter.

Then you have Bjarne Stroustrup's "Generalized Overloading for C++2000", with which you can overload whitespace, uniquely redefining the meaning of space, newline, tab, and even the absence of space.

https://www.stroustrup.com/whitespace98.pdf

Re: Sigils are underappreciated (2022)

#85
post #24

Earlier quoted context omitted.

Perl's regex handling. That's the one I miss in whatever other language I program in. To be able to match AND get the matched substrings out in one line, makes this really succinct.

isn't that the same in any expression-oriented language ? E.g. in ruby this could be puts $1 if /(\d+)/ =~ 'test 123' # perl-like if m = /(\d+)/.match('test 123') then puts m[1] end # perl-less Perl's regexes do more things perhaps, but this is a relatively common thing, I believe.

($hour, $min, $sec) = $someTimeString =~ /(\d\d):(\d\d):(\d\d)/;

    if ($hour >= 12) {
       if ($min == 42) {
          doSomething();
       }
    }

Whereas in Python, Ruby even though it's only a tiny extra step, but that symantic distance in one's head when parsing out and naming the parts of a regex on the same is a convenience that when you get used to it, you really miss it.

    m = /(\d\d):(\d\d):(\d\d)/.match( someTimeString )
    hour = m[0]
    min  = m[1]
    sec  = m[2]
    if hour >=  ...

Re: Sigils are underappreciated (2022)

#86
post #20

I think there's a piece of insight missing from the author's analysis of non-programmatic sigils. To wit, the sigils are only valuable when both parties deeply understand the information that the sigil is trying to convey . The "$framework at $dayjob" example illustrates this point. Programmers familiar with the use of sigils to indicate variables intrinsically grok this phrase, but it looks like gobbledygook to non-…

>Programmers familiar with the use of sigils to indicate variables intrinsically grok this phrase, but it looks like gobbledygook to non-programmers.

While I understand where you're coming from, I'd argue that programming-related concepts are all "gobbledygook to non-programmers", that's to be expected. Having something like (this is close to valid Raku but it's not)

    Positional[Any] ages = [42, 38, 25];
doesn't make it any easier than

    my @ages = [42, 38, 25];
unless you already have prior knowledge of arrays, assignments, types, etc.

Re: Sigils are underappreciated (2022)

#87

I wish that more programming languages would include detailed rationales and justifications of their features like this in their documentation. While this blog post doesn't have the rigor of something like the Ada Rationale[1], it gives a real sense of why something might have been designed the way it was. Maybe I just enjoy reading this sort of thing. But we are so often told to choose the "best tool", or find ourse…

Thanks for the Austral spec link! Programming languages come and go but I find it deeply interesting when language designers lay out the rationale behind possibly outlandish decisions in their programming languages. Case in point, Larry Wall and Perl-y languages [0]

[0] http://www.wall.org/~larry/natural.html

Re: Sigils are underappreciated (2022)

#88
post #79

I really like sigils for several reasons and I do miss them when in non sigil languages - imo raku made two big improvements over perl that is to avoid changing the sigil on accessing an item and to have an unsigilled option for people who don't like them https://rakujourney.wordpress.com/2022/12/24/on-sigils/

>and to have an unsigilled option for people who don't like them

Sigilled "variables" do lose many of the perks that sigils provide though, as codesections explains in the blog.

Re: Sigils are underappreciated (2022)

#89

I wish that more programming languages would include detailed rationales and justifications of their features like this in their documentation. While this blog post doesn't have the rigor of something like the Ada Rationale[1], it gives a real sense of why something might have been designed the way it was. Maybe I just enjoy reading this sort of thing. But we are so often told to choose the "best tool", or find ourse…

Thanks for the Austral spec link! Programming languages come and go but I find it deeply interesting when language designers lay out the rationale behind possibly outlandish decisions in their programming languages. Case in point, Larry Wall and Perl-y languages [0] [0] http://www.wall.org/~larry/natural.html

Oh that's really nice too. Thanks for the link!

Re: Sigils are underappreciated (2022)

#90

I'm not sure I understand what counts as a sigil and what doesn't. How many sigils does the following line have? > echo $foo # $foo refers to the contents of the variable foo

The author defines a _sigil_ as follows:

* a non-alphabetic character

* that is at the start of a word

* that communicates meta-information about the word.

He gives the example of `echo $USER`, where `$` is a single that communicates that `USER` is a variable, presumably with some contents. Thus, I'd wager `$` is a sigil in `$foo`.

Post reply on HN