TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Sigils are underappreciated (2022)

150 点作者 luuuzeta将近 2 年前

22 条评论

jerf将近 2 年前
I like to rate programming language&#x27;s features not by how much I use them when I&#x27;m in the given language, or how good they make me feel, but by how much I miss them when I&#x27;m in a different language, once I&#x27;m fluent in that language and writing in the native idiom. (This is important. If you&#x27;re still trying to write X in Y, yes, you&#x27;ll miss the features from X, but that&#x27;s not a useful data point.)<p>By this metric, rather a lot of features turn out to be less important than they may seem at first. Many things are a zero on this scale that I think might surprise people still on their second or third language. From this perspective you start judging not whether a language has this or that exact feature that is a solution to a problem that you are used to, but whether it has a solution at all, and how good it is on its own terms.<p>So while sigils have a lot of company in this, they are also a flat zero for me on this scale. Never ever missed them. I did a decade+ of Perl as my main language, so it&#x27;s not for lack of exposure.<p>(As an example of something that does pass this test: Closures. Hard to use anything lacking them, though as this seems to be a popular opinion nowadays, almost everything has them. But I&#x27;m old enough to remember them being a controversial feature. Also, at this point, static types. Despite my decades of dynamic typed languages, I hate going back to dynamic languages anymore. YMMV.)
评论 #36120120 未加载
评论 #36120047 未加载
评论 #36119898 未加载
评论 #36120451 未加载
评论 #36122960 未加载
评论 #36120200 未加载
评论 #36123532 未加载
评论 #36121229 未加载
评论 #36123238 未加载
评论 #36124867 未加载
评论 #36120183 未加载
xupybd将近 2 年前
Sigils in Perl were awful. They didn&#x27;t behave concretely. Sometimes it was sort of a type annotation sometimes they were a weird incantation.<p>Things like implicit scalar conversion<p><pre><code> @foods = qw(burgers fries shakes); $length = @foods; print $length, &quot;\n&quot;; </code></pre> Yeah it&#x27;s easy to understand once you know what is happening but it&#x27;s obscure. There are no easy clues to let you know what is happening.<p>Then there are situations where you have a scalar but it&#x27;s a ref<p><pre><code> %author = ( &#x27;name&#x27; =&gt; &quot;Harsha&quot;, &#x27;designation&#x27; =&gt; &quot;Manager&quot; ); $hash_ref = \%author; </code></pre> So it&#x27;s not a type its more of a language implementation detail that doesn&#x27;t add value to the programmer.<p>Where as with the Hindley–Milner type system the types exist and add value without requiring all of the extra code. You can infer the type most of the time and you get a nice strong type check at compile time.<p>Sigils seem like a step in the opposite direction to strong inferred types. You have to add a little bit of boiler plate but it&#x27;s not that strict so it&#x27;s meaning can still be confusing.
评论 #36120249 未加载
评论 #36121456 未加载
评论 #36121093 未加载
karmakaze将近 2 年前
Perl5 got sigils wrong, where more complex usages hinted at incorrect human parsing of expressions. That was designed borrowing from natural language, so wd should probably throw out the early part of the post. Now the post says in Raku<p><pre><code> @ says “Use me with an array-like interface” % says “Use me with a hash-like interface” &amp; says “Use me with a function-like interface” $ says “I won’t tell you what interface you can use, but treat me as a single item” </code></pre> I don&#x27;t use Raku nor used much of Perl5 (only enough to learn it&#x27;s good for writing, not for reading). Sigils in Raku may be fine and better than not using them. I&#x27;ll accept that.<p>However, I much prefer inferred static typing and referential transparency where everything produces a value and it&#x27;s not material whether it&#x27;s a precomputed value or something that will produce the value when &#x27;pulled on&#x27;. The last part works well with pure functions and lazy evaluation. Until someone claiming benefits of sigils has used this alternative for large, long-lived code written and maintained by many, I&#x27;ll leave sigils to Raku alone.
whakim将近 2 年前
I think there&#x27;s a piece of insight missing from the author&#x27;s analysis of non-programmatic sigils. To wit, the sigils are <i>only</i> valuable when <i>both parties deeply understand the information that the sigil is trying to convey</i>. The &quot;$framework at $dayjob&quot; 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. The email inbox example is similar. (I&#x27;d argue the hashtag&#x2F;@-symbol example is a bit more complicated, because those symbols service important UX functions.)<p>I think this insight crystalizes the trade-off. I agree with the author that sigils are <i>a</i> powerful way of communicating useful information in a concise fashion. But does their inscrutability to non-expert users justify their existence? I&#x27;d argue it usually doesn&#x27;t. Whenever I&#x27;ve had to pick up a language that uses a lot of sigils (or even just had to read source code in one of those languages if I don&#x27;t use it daily), I always find the sigils require a bit of extra mental effort to process. It seems like other languages manage to express meaning in a way that is less burdensome to non-experts.
评论 #36121293 未加载
评论 #36121742 未加载
评论 #36121507 未加载
评论 #36132807 未加载
throwaway290将近 2 年前
Rambling and I disagree with a lot.<p>&gt; We had that problem at $day_job: our code was a mess, but everyone thought $framework would magically fix it.<p>Replace with &quot;a&quot; or &quot;that one&quot; and it&#x27;s the same or even better.<p>The reality is that $dayjob (or %dayjob% etc) signals &quot;hey I&#x27;m a programmer&quot; and is less to type.<p>&gt; I need to be able to quickly distinguish between the two types of labels so that I can notice emails that don’t have exactly one folder-label. This is a job for sigils.<p>Prefixing email labels is a workaround in this case because you don&#x27;t need to notice emails that belong to two folders if your filtering system is good.<p>&gt; As you’ve probably noticed, I’ve been saying “has an array-like interface” instead of “is an Array ”. That’s because – and this is a crucial distinction – Raku’s sigils do not encode type information. They only tell you what interface you can use.<p>&gt; ...<p>&gt; And Buf s aren’t Array s, nor are they any subtype of Array . But they can be used with an array-like interface, so they can be stored in an @ -siglied variable.<p>Sounds like a missed opportunity to type buffers as byte arrays...
评论 #36120587 未加载
powera将近 2 年前
We are past the point where sigils are useful for a modern compiler or machine interpreter. A limited ability to avoid collisions with &quot;reserved words&quot; ... would be more of a mis-feature than a feature.<p>The value of a sigil is for the other humans reading the code. And, I agree it can be quite valuable there.
评论 #36122018 未加载
crabmusket将近 2 年前
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&#x27;t have the rigor of something like the Ada Rationale[1], it gives a real sense of <i>why</i> something might have been designed the way it was.<p>Maybe I just enjoy reading this sort of thing. But we are so often told to choose the &quot;best tool&quot;, or find ourselves evaluating programming languages for all sorts of reasons. Being able to understand a language in its context, the choices it made in comparison to the alternatives, can only help with that.<p>When I read the rationale for a new early-stage language Austral[2], I found myself actually able to evaluate what I thought the language might be good for, how it might evolve while under the control of the same creator, whether it fit with my personal strengths, weaknesses, methods and aesthetics, etc.<p>By contrast, I was perusing the documentation for Odin, another new language, at around the same time. While I don&#x27;t want to disparage the incredible amount of work it took to a) build a programming language and ecosystem and b) document it, I found myself wishing for a similar &quot;rationale&quot; document so I could actually compare Odin with Austral at a more abstract level than reading syntax.<p>Odin&#x27;s &quot;overview&quot; begins with an example of the lexical syntax of comments, rather than what the principle &quot;Striving for orthogonality&quot;[3] in its FAQ actually means and how it is borne out in the language as designed, compared to other approaches that could have been taken.<p>Austral, by contrast, has a great section called &quot;the cutting room floor&quot; where the creator discusses different approaches to resource safety, the difficult tradeoffs to be made, and why Austral decided on possibly the severest of all the approaches. This isn&#x27;t <i>just</i> philosophy; it tells me something useful about the tradeoffs involved in using the language.<p>Anyway, the OP helped me to understand very clearly that Raku&#x27;s priorities and values are extremely different to my own, and that it would likely be a bad choice for me to invest time in.<p>[1] <a href="http:&#x2F;&#x2F;ada-auth.org&#x2F;standards&#x2F;12rat&#x2F;html&#x2F;Rat12-TOC.html" rel="nofollow">http:&#x2F;&#x2F;ada-auth.org&#x2F;standards&#x2F;12rat&#x2F;html&#x2F;Rat12-TOC.html</a><p>[2] <a href="https:&#x2F;&#x2F;austral-lang.org&#x2F;spec&#x2F;spec.html" rel="nofollow">https:&#x2F;&#x2F;austral-lang.org&#x2F;spec&#x2F;spec.html</a><p>[3] <a href="https:&#x2F;&#x2F;odin-lang.org&#x2F;docs&#x2F;faq&#x2F;" rel="nofollow">https:&#x2F;&#x2F;odin-lang.org&#x2F;docs&#x2F;faq&#x2F;</a>
评论 #36133023 未加载
nige123将近 2 年前
Sigils are just part of the picture. For Raku &quot;twigils&quot; (secondary sigils) are important too:<p><a href="https:&#x2F;&#x2F;raku-advent.blog&#x2F;2022&#x2F;12&#x2F;02&#x2F;day-2-less-variable-wattage-more-flow&#x2F;" rel="nofollow">https:&#x2F;&#x2F;raku-advent.blog&#x2F;2022&#x2F;12&#x2F;02&#x2F;day-2-less-variable-watt...</a>
smeagull将近 2 年前
Sigils are why I gave up learning PERL. Everything I learned had a half life of 10 minutes.<p>I haven&#x27;t programmed C in a decade, I still remember most of it.
评论 #36133106 未加载
mfranc42将近 2 年前
Yes. Namespaces good. Escape sequences good. Terse syntax good. As long as it&#x27;s not rare and obscure good. :-)
p6steve将近 2 年前
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&#x27;t like them <a href="https:&#x2F;&#x2F;rakujourney.wordpress.com&#x2F;2022&#x2F;12&#x2F;24&#x2F;on-sigils&#x2F;" rel="nofollow">https:&#x2F;&#x2F;rakujourney.wordpress.com&#x2F;2022&#x2F;12&#x2F;24&#x2F;on-sigils&#x2F;</a>
评论 #36133038 未加载
mkoubaa将近 2 年前
Avoiding sigils is a good future proofing strategy. When you find out you need a new syntax it&#x27;s nice to have a set of symbols that are guaranteed not to break existing code
评论 #36177215 未加载
js8将近 2 年前
Regarding sigils, there is also ? and ! in Scheme and Clojure, and don&#x27;t get me started on Forth, it&#x27;s pretty much sigils all the way down.
评论 #36120207 未加载
评论 #36127861 未加载
mihaic将近 2 年前
Personally, I have the exact opposite thoughs on sigils: they break my fluency in reading code.<p>Not all sigils are as bad, but to me it&#x27;s as if there&#x27;s a word from a foreign language italicized in an english sentance -- that means I&#x27;ll have a reading pause there.<p>The dollar sign is among the worst, and curly braces are the lightest, with ”@&quot; bring in the middle in terms of pausing reading.
stephc_int13将近 2 年前
I am in the &quot;the less sigils the better&quot; camp.<p>Code clarity should be seen as higher priority than terseness or typing speed.
flumpcakes将近 2 年前
If the author is reading,<p>The link in the yellow box to the follow up article links to the article itself instead of &#x2F;2022&#x2F;12&#x2F;23&#x2F;sigils-2&#x2F;.<p>Also a missing word &quot;hash&quot; in the link towards the bottom of the article to hash_literals in the Raku documentation.
jakear将近 2 年前
Well that&#x27;s a whole lot of talk with 0 concrete code examples...<p>One interesting thing, the author mentions VS Code as abolishing the need for Hungarian notation, which is funny - the entire VS Code codebase in written in Hungarian.
Arathorn将近 2 年前
it’s always been a naughty pleasure that Matrix uses sigils both for ‘mainstream’ user IDs (@user:domain.com) and room aliases (#room:domain.com) as well as more developer focused things - $ for event IDs, ! for room IDs: <a href="https:&#x2F;&#x2F;spec.matrix.org&#x2F;v1.7&#x2F;appendices&#x2F;#common-identifier-format" rel="nofollow">https:&#x2F;&#x2F;spec.matrix.org&#x2F;v1.7&#x2F;appendices&#x2F;#common-identifier-f...</a><p>I have a bad feeling this is due to me doing too much Perl as a child. But folks don’t seem to complain about it, especially since we also sprouted a proper URI scheme too.
__MatrixMan__将近 2 年前
I&#x27;m not sure I understand what counts as a sigil and what doesn&#x27;t. How many sigils does the following line have?<p>&gt; echo $foo # $foo refers to the contents of the variable foo
评论 #36133080 未加载
kqr将近 2 年前
One of the things sigil allow you to do is overload other syntax. The example I usually bring up is the difference between<p><pre><code> @hash{a,b,c} </code></pre> which returns a list containing the values associated with keys a, b, and c; and on the other hand<p><pre><code> $hash{a,b,c} </code></pre> which returns the single item associated with the key constructed from concatenating a, b, and c (used to emulate a three-dimensional array.)
AtlasBarfed将近 2 年前
Templating is practically universal.<p>And string interpolation (basically the same thing) is on python, groovy, and I think is coming to java.
评论 #36121087 未加载
emmelaich将近 2 年前
Pedant mode: In BASIC, since the $ is at the end of var name, is it not a sigil?