Comment by u8

10 hours ago

This is why I love Go. Nobody was asking for this, but they took the time to do it right and continue to Push go as a memory safe, high-level systems language.

People were definitely asking for it.

  • It's been discussed for a long time, and the related proposals were heavily upvoted, including various older proposals.

    As I understand it, part of the reason it took a while is that the core Go team was generally of the opinion that doing user-facing SIMD APIs the right way was to design a high-level, cross-platform API that would stand the test of time, and that was then punted a few times given its complexity and need to do other things.

    Part of what helped the current approach take off was switching to a philosophy of designing a lower-level architecture-dependent API first (the 'simd/archsimd' package), and then later doing a higher-level portable API (the 'simd' package, which is topic of this blog post).

    That two-level approach I think also gave some additional freedom for the design and implementation of the friendlier / high-level 'simd' package, including because the lower-level 'simd/archsimd' package is available for people who need or want to drop down.

    It's a nice design.

This is kind of the opposite of Go. Not giving people what they are asking for.

There are pros and cons of course. You don't have 17 different ways to iterate over an array, so that's nice. But you also went 13 years without generics, despite them being one of the most requested features, because the designers didn't want that complexity inside Go.

Overall I think Go is better for this philosophy but there are times where the language is clearly written more for its maintainers than it's users.

  • > But you also went 13 years without generics

    Go shipped with generics (aka bounded parametric polymorphism), but only for built-in types: slices, arrays, and maps. That, with subtyping via interfaces, handled most demand for generics. The most common pain point was custom containers.

    Go was first released in November 2009. Russ Cox posted "The Generic Dilemma" [1] in December 2009. The comments show the generics debate raging from the earliest days.

    As a fun side note, I forgot I posted a comment on that post pointing to Ada's generics. I was in college, and Ada was our intro language.

    [1]: https://research.swtch.com/generic

    > the designers didn't want that complexity inside Go.

    Yes, with some nuance. Go's goal of writing server programs didn't require the type-system complexity and run-time hit of user-defined generics. [2]

    > Go was intended as a language for writing server programs [...] Polymorphic programming did not seem essential [...] so was initially left out for simplicity. > > Generics are convenient but they come at a cost in complexity in the type system and run-time. It took a while to develop a design that we believe gives value proportionate to the complexity.

    [2]: https://go.dev/doc/faq#beginning_generics

    Out of curiosity, I collected all proposals for Go's journey to generics. https://gist.github.com/jschaf/eaa7aff1af14ea7276a18a1b7370d...

  • Some of the concerns around generics and why it took so long were for the users as well. One of the biggest draws to Go has always been that you get the performance of a compiled language and yet compile times are so low that it can feel like you're developing with an interpreted language. The design of generics needed to maintain the compile time advantage or else it wouldn't feel like Go any more.

Mostly safe, contrary to other safer languages, Go memory model doesn't prevent data tearing.

go data races aren't memory safe

  • That's not what "memory safe" means. "Memory safe" is a term of art meaning "not susceptible to memory corruption exploits", like stack and heap overflows, UAFs, and type confusion. Last I checked, there are essentially no non-contrived memory corruption exploits for Go programs; the best you get are people demonstrating register control on contrived programs.

    The definition I'm giving is the same as the ISRG's definition at MemorySafety.org. It's the thing everybody is talking about when they talk about memory safety.

    The claim being made here is "big if true", because it would imply a lot more languages than Go "aren't memory safe", despite decades without memory corruption exploits.

    • The exploits aren't the only issue; they just get a lot of air time.

      It's remarkably easy to segfault Go applications with data races. Any object with multiple words (so a slice that's an array pointer, a size, and a capacity. Or a fat pointer with the object pointer and the vtable pointer), can be read in an inconsistent state from two threads which can cause out of bounds reads and writes. And this comes up all the time with how heavily the language encourages concurrency.

      It's just difficult to actually exploit because of other considerations that practically add a lot of runtime entropy.

      4 replies →

  • Yeah, we get it, you performatively hate go.

    • I'm fine with Go, worked on peerdb & wal-g in Go. I enjoy programming in C too which lacks memory safety. I just don't claim otherwise

  • Yes, but in practice they are extremely hard to exploit. It has been discussed extensively here on HN and in other forums.

  • That does not make sense to me. Go is memory-safe, but it does not guarantee data-race freedom.

    So whats your point here? Haskell?

    • > That does not make sense to me.

      You said that because you assumed Go is memory-safe in all conditions.

      > Go is memory-safe

      Yes, but only if there's no data race.

      Go is not like Java. Java doesn't guarantee no data race, but when it happens, it's still memory-safe.

      7 replies →

    • There is no memory safety without freedom from data races. One is a prerequisite of the other. This is why languages like C# throw exceptions on unsynchronized concurrent access to some container types, and treat all property accesses as atomic.

      8 replies →

    • I suppose that if you create a map in one thread, and then access it from another thread, then that might cause segmentation faults? Because map is a type that is implemented in C.

      1 reply →

(removed)

  • Go is broadly considered to be a memory safe language.

    See for example comments from tptacek like:

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

    (The gist: memory safety is a term of art coined by security practitioners. Go, Python, Rust, Java, others: memory safe. C/C++: memory unsafe. Periodically, people in different slices of industry or academia come up with new definitions of memory safety that declare Rust or Go or other languages to be memory unsafe, but that is not by the broadly accepted definition across industry.)

    • He’s very wrong about this. Just because ‘tptacek posts a lot and did security once upon a time does not make him “broad consideration”.

  • You can write unsafe code in Go (import unsafe), but then, you can do the same in Rust. Unsafe code is not the default, and in day to day Go i rarely see the use of the unsafe package.

    • What he probably means is data-races in go can result in memory/type unsafe accesses -- I suspect, likely due to slice types -- not sure if that is true/false.

      8 replies →

  • No idea why you're getting downvoted for true statement. Without a ? like in C# you're always at risk of a nil pointer being dereferenced