Hacker Newsnew | past | comments | ask | show | jobs | submit | more coderedart's commentslogin

Won't you still have to escape the closing bracket if it occurs inside the string?


Only if you want to refer to it literally as a closing quote rather than having it act as a closing quote. That case is extremely rare.


Its definitely rarer than double or single quotes occurring in string. But I was wondering about the parent comment's concern of passing a string through multiple levels of escaping.

> until you need to get your string through several levels of escape. how many backslashes to add? depends on how deep your pipe is and how each of those layers is defined


This is the beauty of balanced quotes: they completely eliminate the need for multiple escapes.

When the same character is used as both an open and close delimiter, you have to disambiguate between three possibilities: opening a new string, closing the current string (which may or may not be embedded) and a literal character as a constituent of the current string. By convention, an unescaped double-quote inside a string indicates closing that string, so you need different escapes to indicate opening embedded strings and constituents.

You could have done that by using two different escape characters, but for historical reasons there is only one escape character: the backslash. So that one character has to do double-duty to disambiguate two different cases. But in fact it's even worse than that because string parsers have a very shallow understanding of backslashes. To a string parser, a backslash followed by another character means only that the following character should be treated as a constituent. So you still need to disambiguate between actual constituents and opening an embedded string, and the only way to do that, because all you have is the backslash, is with more backslashes. The whole mess is just a stupid historical accident.

If you used balanced quotes you only have one case that needs to be escaped: constituents. So you never need multiple escapes.

Note that I made a mistake when I wrote:

> Only if you want to refer to [a close-quote character] literally as a closing quote rather than having it act as a closing quote.

You have to escape both open and close quotes to refer to them as constituents. In other words you would need to write something like this:

«Here is an example of a «nested string». The start of a nested string is denoted by a \« character. The end of a nested string is denoted by a \» character.»

Note that it doesn't matter how many levels deep you are:

«Even when you write «a nested string that refers to \« or \» characters» you only need one level of escape.»

Note that when you refer to quote characters as balanced pairs as in the examples above you don't actually need the escapes. The above strings will parse just fine even without the backslashes, and they will print out exactly as you expect. The only "problem" will be that they will contain embedded strings that you probably did not intend. The only time escapes are actually required is when referring to an quote characters as constituents without balancing them. This will always be the case if you refer to a close-quote without a corresponding preceding open-quote, which is the reason I got it wrong: escaping close-quotes will be more common than escaping open-quotes, but both will be needed occasionally.


I totally agree with the idea that balanced quotes are needed to make quoting sane. If the quotes in a string are balanced then it should be possible to quote it with no changes.

I would also advocate the principle that you don't escape the escape character by doubling it. There are two problems with replacing \ with \\: firstly the length of the string doubles with each nested quotation; secondly you can't tell at a glance whether \\\\\\\\\\\\\\\\\\\n contains a newline character or an n because it depends on whether the number of backslashes is odd or even.

Another useful principle is to escape a quote character with a sequence that does not contain that character: then it is much easier to check whether the quotes are balanced because you don't need to check whether any of them are escaped.

So here's a possible algorithm for quoting a string: first identify the top-level quote characters that don't match (this is not totally trivial but it isn't difficult or computationally expensive); then, in parts of the string that are not inside nested quotes, but only there, replace « with \<, » with \>, and \ with \_ (say). Does that work?


It might work but I think it misses the point. The current mess is in no small measure the result of assuming that we have to constrain ourselves to ascii. We don't. Once you accept balanced quotes you have implicitly accepted using unicode characters, at which point a whole host of new possibilities (and new problems -- see below) opens up. For example, the only reason you need \n (and \r and \t etc.) is because you want a way to use non-whitespace characters to represent whitespace. But this feature is already built in to unicode, which has dedicated non-whitespace versions of all of the ascii whitespace and control characters (␍, ␊, ␉ , ␀, etc.) so there is no need to escape any of these.

That leaves only the problem of escaping the escape character, and here again there is no need to constrain ourselves to ascii. There is no reason that the escape character needs to be backslash. In fact, that is a particularly poor choice because backslash, being an ascii character, is extremely precious real estate. In fact, it is doubly precious because it actually has a balanced partner in the forward slash, so if you are going to use backslash for any special purpose it should be partnered with forward slash as a balanced set (which open up the problem of what to use for the directory delimiter in your operating system, but that's another can o' worms).

I think the Right Answer is simply to choose a different character to serve as the escape character inside balanced strings. My first pick would probably be ␛, but there are obviously a lot of other possibilities.

This points to a potential danger of this approach: there are a lot of unicode characters that render very similarly, like U and ᑌ. You would need to choose the unicode characters with special meanings very judiciously, and make sure that when you are writing code you have an editor that renders them in some distinctive way so you can be sure you're typing what you think you're typing. But that seems doable.


Ty. I could feel that there was a joke in there somewhere, but didn't remember the mercury pressure thing


Water heater for bath/showers


There was v lang in recent memory which made grand claims.


using wasm goes into crazy territory imo. It would probably be bigger, and opaque, with no proper errors (unless you compile debug info which would make it much bigger).

I think we already have an almost perfect language i.e. Lua Everyone knows it (or can learn it easily). tiny runtime to embed. sandboxed by default. garbage collected. Only feature missing is static typing.


> Rust's borrow checker has a reputation for making it hard to write entity-component systems. And ECS are core to modern game dev.

Isn't it the opposite? That rust's borrow checker makes it hard for non-ECS paradigms due to ownership and XOR mutability rules. While ECS is best for rust, as it "owns" things and schedules the mutating functions without any conflicting race conditions.

The most popular engine in rust right now is bevy, which embraces ECS for everything (including UI).


Conclusions from a single data point are the most correct


I have 2 actually, I'm lazy as well.


> Zuck is an outright liar. There are now mountains of exceptionally good research showing a solid causal link between social media use and negative mental health impacts on young people (no, I will not google that for you, please do your own homework).

what is the point of the statement if you call someone a liar, claim that there exists material to prove the lie and then say, that you will not link to this material?.


Intellectual curiosity (as per our guidelines)

I'd like you to show some too.

Obviously you won't be able to refute what I said, because there are no papers out there that show there isn't a causal link between social media use and harms to mental health. That would be asking the impossible. But there is a massive and no longer ignorable body of work out there saying indeed there are direct causal links between social media use and mental harms. And Zuck just pretended that doesn't exist.

You know, I was actually hoping someone smarter and with more time than me would come back with something I'd missed.

Mark Zuckerberg stood up in front of a room full of grieving mothers and gave a limp, fake apology that made them burst into tears. His sheer lack of humanity and emotional disconnect with other humans could hardly be clearer.

  """
  "The existing body of scientific work has not shown a causal link
   between using social media and young people having worse mental
   health," Zuckerberg told the crowded room.

   Lori Schott, a bereaved mother from Colorado, said she cried when
   she heard Zuckerberg’s comments.
   """
Those mums showed up to the hearing with photos of their dead kids who had killed themselves as a direct result of using social media.

My point is less emotional. Given the preponderance of evidence against Zickerbergs comments, he lied.

So, above I said that means Mark Zuckerberg just lied to congress and that makes him a criminal in the US right? Whether under oath or not.

That's why I was downvoted. Nothing to do with encouraging you to do a simple search, which you could have done in the time it took you to write a snarky reply.

[0] https://www.theguardian.com/media/2024/feb/01/parents-tech-c...


I will recommend a couple great channels for Math:

1. https://www.youtube.com/@SawFinMath : She is a great Professor that walks through problems/solutions one step at a time, so that you can follow along. Has a bunch of Under Graduate course playlists like discrete math, calculus, (abstract or linear) algebra, statistics. highly recommended for the great pacing and solving a lot of problems live.

2. https://mathispower4u.com/ : Another professor who takes an open math textbook (free), and makes a course out of it. Its a little bit more difficult because of denser "pure math" material, but in return, you basically cover everything that a college usually would. He has courses like discrete math, calculus, graph theory, trigonometry, statistics, algebra, geometry etc. Also solves a lot of problems live.

I haven't really tried it, but apparently there is https://www.myopenmath.com/index.php which is sort of like exercism in that you follow along a textbook and solve problems. If someone has tried this, maybe they can share their experience.


The star of that benchmark is actually nanoserde.

1. outperforms a bunch of binary formats (as well as all other text formats) 2. has zero dependencies with fast compile times (even the derive macros are custom and don't use syn family crates as build-time deps)


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: