1. 46
  1.  

  2. 14

    …this goes a lot deeper than I expected. You don’t often see a post that starts with “why do we have to say Box<dyn Error> instead of just dyn Error” and at the halfway point is in gdb looking at heap layouts.

    1. 3

      One of the many reasons I enjoy this blog. They go super deep on pretty much every post, and I always learn something. There was one a few months back about adding hot-reloading of symbols to a Rust binary, I learned a ton about ELF.

    2. 7
      fn main() {
          println!("Hello, world!");
      }
      

      It is pure, and innocent, and devoid of things that can fail, which is great.

      Nitpick, but println! can panic.

      1. 3

        Fabulous read. It is very helpful to see the differences spelled out using another language. I now fully grok why you can’t return a reference to local data. Previously, I did know that you couldn’t but the reason was not clear. That is no more.

        1. 1

          Obligatory UHF reference: Nothing! Absolutely nothing!

          1. 1

            Which suggests that anything that is printed (or even formatted to a string) ends up escaping to the heap in Go. So, uh, pro-tip, don’t do any logging!

            Or rather, don’t log with fmt.Printf or other printf-likes in code where performance really matters. There are loggers that don’t have this problem (I like zerolog; there are others).

            Yes, I know that isn’t really the main thrust of this article, but it’s an interesting point, and someone is likely to notice it, so I figured it should be elaborated on somewhere.

            1. 1

              this value of err is never used (SA4006)

              I’ve grown to love staticcheck when writing Go.

              Amazing article. I’m very happy that I rarely have to think about these details when writing code.