15 ms·
Enums, immutables, and generics aren't good because they're exciting. They're good because they give us expressive tools to write descriptive, type safe systems
by cmrdporcupine 6y ago
Enums, immutables, and generics aren't good because they're exciting. They're good because they give us expressive tools to write descriptive, type safe systems that manage state better.
I don't like "modern" systems because I have a fetish for novelty. There's nothing novel about these concepts, they've been around since the 60s and 70s. I like these tools because they improve my ability to reason about the code, but more importantly they let the compiler and other static analysis tools reason about my code.
I am getting old and lazy. I want the compiler to do more for me, not less.
What I see is a situation where Go is gaining traction from two communities:
a) people who attempted to build large systems at scale in dynamic late bound languages like Python and Ruby and NodeJS etc, and hit the wall from a performance and maintainability POV. I could have warned you...
b) people who came from the Java world and got frustrated
with the language and tooling there
People coming from a) especially but also b) to some degree will be perfectly comfortable with Go missing the nicer aspects of modern static typed languages because they never had them in the first place.
As for...
"Go doesn’t have a virtual machine or an LLVM-based compiler."
How is this any kind of pro or con? It's just an implementation detail.
- akavi 6y agoExactly. I don't want sum types becuase they're exciting, I want them because they're the simplest way to communicate to the compiler that "my data can either be this or this and nothing else", so I don't blow off my foot by accidentally making it that. When I was younger and less jaded, it actually was fun and exciting thinking up ways to hack around language limitations like that. Now it's just frustrating.
- deleted 6y ago[deleted]
- frankie_t 6y agoThat actually surprises me a lot. I've seen plenty of critique about lacking generics and exceptions, while haven't seen much complaint about ADTs. From my rather dilettante point of view they are neither too complex for "philosophy of simplicity", nor they add much of compile time. It seems to me they even can be implemented as a syntactic sugar on top of type casts. I certainly cannot see them being more complex than generics.
- akavi 6y agoYeah, it's unclear to me why there's not more demand for them either. I think it might that most go users with prior static language experience are coming from Java, where there aren't sum types either. From my naive perspective, they seem like an easy win, and are 100% more important to me than generics.
- tleb_ 6y agoI believe sum types are not added because they come close in functionality to interfaces, the idea being that if something should be X or Y, you make an interface that X and Y implement. Edit: true explanation here https://golang.org/doc/faq#variant_types https://golang.org/doc/faq#variant_types
- SmooL 6y agoThat's fair from one use, but the other, way more common in Go, is the whole "I'm going to return either an object OR an error". There's no common interface between the two, it's a distinct two options. Because go has no native support for sum types you get all this nonsense where every function returns a tuple of an object and an error, with the implicit assumption (not at all checked by the compiler) is that if the error is nil, then the object is valid. It's awful
- karmakaze 6y agoThat's not even true in the stdlid--there are some io errors that aren't errors per se and at the same time perform an action and return a value, e.g. short-write.
- reificator 6y agoSure, and in those cases you could continue to return a tuple. In fact having those cases not return a Result<T, E> when everything else does would actually make it more discoverable; right now people assume err means failure.
- 6y ago
- dorian-graph 6y agoIf anything, nil checking in Go makes it quite exciting (will I get a nil pointer error somewhere? Who knows!). Sum types would make this quite boring though.
- masklinn 6y ago> If anything, nil checking in Go makes it quite exciting (will I get a nil pointer error somewhere? Who knows!). The most exciting part is finding that something is not nil but is actually nil. Great surprise, thanks typed nils!
- erik_seaberg 6y agoIt's the only language I've ever seen that tries to dispatch on what type of object you don't have. Very zen.
- spectralflux 6y agoSpeaking as someone who technically would fall in b) in your community list: Java has all of those nice features and tooling now of other static languages, and when I tried out Go I found it tedious to work without them, especially generics. I mean sure, I'd rather be working in Kotlin, but Java is at least acceptable now.
- cmrdporcupine 6y agoYeah I am speaking as a person who was a professional Java developer for years, but the last time I worked in it was 8 years ago, and it was painful given I had experienced working with Ocaml, Erlang, and Scala. Kotlin wasn't a thing yet. I've been working almost exclusively in C++ @ Google since then. Java looks much improved now. But I still feel like there's a culture of complexity and bloat in Java code ... But I work in the Chromium code base and it has the same problem :-)
- spectralflux 6y agoOld code and programmers with old ideas hold back "real life" Java projects quite a bit from what they technically could be in a more modern form. Complexity and bloat definitely come with that, I think some folk get used to building EnterpriseTurboWidgetFactoryImpl type horrors and never consider the language doesn't need to do that kind of thing any more... Java being so backward compatible I think also means it doesn't do enough to discourage that either though, which is also a reason why Kotlin is so nice -- the lowest effort solution is miles more understandable.
- x87678r 6y ago> I think some folk get used to building EnterpriseTurboWidgetFactoryImpl type horrors and never consider the language doesn't need to do that kind of thing any more. Did it ever though? I feel this junk comes from the Spring side more than pure Java. I'd love to know a good way to get rid of it as Spring is everywhere.
- 6y ago
- joelbluminator 6y agoHow often does "hit the wall from a performance and maintainability POV" happen with Python / Ruby / NodeJS ? I mean seriously, how many more huge projects do we need to build until we can show it's a sane alternative? 120 Billion worth Shopify isn't enough, maybe Instagram then? Github ?
- cmrdporcupine 6y agoIt entirely depends on what you're doing. There are two issues as I see it: a) Lack of static analysis tools means having to do more testing (manual or automated) for simple mechanical errors. b) For super high throughput low latency systems, they are not up to snuff. When I worked in real time bidding in ad-tech this was actually a serious concern. I'd reach for Rust (or C/C++) in this scenario now.
- joelbluminator 6y agoYes there are niches where Ruby won't work, even big niches like Kernel development or real time systems maybe. But for web development, in general, these languages have proven themselves for so long it's getting quite ridiculous now to say they won't work. As for testing - I disagree. Frameworks like Rails are so easily testable it's a breeze. Java/Spring dependency injection is jumping through hoops just to provide a testable framework I find it hard to believe it's any easier.
- jimbokun 6y ago> But for web development, in general, these languages have proven themselves for so long it's getting quite ridiculous now to say they won't work. And I don't think web development is where Go is getting traction. More in back end services and infrastructure. > Java/Spring dependency injection is jumping through hoops just to provide a testable framework I find it hard to believe it's any easier. As someone who develops with Spring everyday, I don't think it's the best solution for anything.
- 6y ago
- jahaja 6y ago> Enums, immutables, and generics aren't good because they're exciting. They're good because they give us expressive tools to write descriptive, type safe systems that manage state better. The main problem is just that these expressive tools scales poorly with regards to the number of people involved in the code base and its age. The amount of time to write and/or duplicate code is just a fraction of the amount of time it takes to read/understand/debug code that have degenerated over time due to the number of people involved and various amounts of "expressiveness". And no, a style guide isn't enough because these idioms change over time and there are a lot of social factors involved. Where for example the senior devs are actually the ones that a few years back decided that these overly-expressive code is the best thing since sliced bread.
- tsimionescu 6y agoI completely disagree. Code duplication is one of the worse things for readability, and generics quickly make up for their weight in gold on this front. Go code is very hard to read and review especially because it has so much repetition where little details can hide. "Is that a regular error check that logs and returns, or did I miss some actual logic there?", "Is that loop just trying to find a value in an array, or is it also doing something else?" etc - boilerplate upon boilerplate, which you learn to glaze over, until it's not really boilerplate and you miss something.
- jahaja 6y agoI think Go is pretty well known for being easy to read so I'm not sure what exactly you find hard to read. Duplicated code is not inherently unreadable. Code shouldn't be abstracted away and be made "reusable" before it's been duplicated once anyways. I also believe that the amount of additional code duplication created by the lack of expressive language features is overestimated. The examples you give doesn't seem to be specific to Go? In Go the error checks are, as most point quickly out, very explicit and often just err != nil checks. Not sure how they can be confusing, albeit repetitive. I'm a bit surprised by the amount of down votes my reply has received given that this is a pretty common sentiment among very experienced devs within the game dev industry.
- pjmlp 6y agoPascal sometimes in the mid-70's type state = (on, off); Go in 2020, about 50 years later, type state int const ( on state = 0 off state = 1 ) Yeah we don't need those modern features from PhD level languages.
- nmyk 6y agoFWIW, there's a slightly more concise way of expressing this in Go: type state int const ( on state = iota off )
- josephcsible 6y agoI don't think the concern was verbosity so much as lack of type safety.
- nmyk 6y agoFair enough. I would say if the way someone uses the Go "enum pattern" is causing them to have issues with type safety then their code could probably use a refactor, but the point does stand.
- josephcsible 6y agoHow is it possible to use the Go "enum pattern" without having issues with type safety? It's inherently not type-safe at all.
- nmyk 6y agoBy "issues" I mean software defects.
- asdkhadsj 6y agoAfter using Go for ~5 years, so many little things in Rust blew me away. I thought I was okay with Go's "enums" but then I saw Rust's Enums. Most notably, the real enum type combined with pattern matching was an eye opener over what I've been missing. Iterators were another one. The ability to express data transformation (mapps/filters/etc) in a very concise way blew me away. I had no idea what I had gotten used to in Go, though that's definitely not to say that I didn't feel the pain. There's advanced features in Rust I could live without, but most of it just feels empowering. The beauty in it though, in my mind, is that you don't need to use all that advanced stuff. You can write Rust shockingly similar to Go. The only thing Go truly nailed in my eyes is green threads. Those will always be better in Go than Rust (though futures are getting way better). Go nailed green threads. But all the other "lack of features as a feature" left me frequently wanting for more tools to solve simple problems. And I was a Go nut. I have a Gopher plushie in my car for Petes sake.
- falcolas 6y ago> I am getting old and lazy. I want the compiler to do more for me, not less. Ironically, and for the same reasons, I want the opposite. I want the compiler to stop fighting me on every little detail. I'm exceptionally tired of writing boilerplate interfaces, thinking excessively about what size of integer I want to use, or digging into lambda calculus just to make a stone-stupid compiler (or worse, a borrow checker) happy.
- dimitrios1 6y agoIt sounds like what you would prefer is a dynamically typed language like Ruby, Python, PHP, JavaScript, Clojure, Erlang, etc.
- cmrdporcupine 6y agoDon't get me wrong, I find Rust has pretty high mental overhead. The borrow checker really is not intuitive to me. For the niche that Go is applied in often.. .basically middleware type things, long running services, etc. I wouldn't necessarily jump to Rust. I think Rust is well suited to lower level systems development, as a replacement for C/C++ there. What's frustrating about Go to me is that we _need_ a nice clean compiled language with a static type system and garbage collection for services development. To replace Java, etc. But ... not this one. Go to me feels like a huge step backwards, and in my experience with code review with the Go folks at Google, it's a very strident and dogmatic language community, too. I'd like something like OCaml, but with less functional religion, maybe.
- iimblack 6y agoI’m keeping an eye on Crystal for this. Version 1 should be coming this year it seems.
- mikeschmatz 6y agoC# with .Net Core seems to fit the bill.
- nvarsj 6y agoAlso, ironically, go doesn't even do this - it fails compilation on the most useless and pedantic of errors - unused variables and imports. Despite the fact that it's common practice to comment out sections of code during development and debugging, which inevitably leads to unused variables/imports.
- bokwoon 6y agoIn Go you use the pattern of prefixing enum constants with the enum category to indicate that the enums are related to each other (e.g. StatusOk, StatusNotFound instead of status.OK, status.NotFound). Which is funny because today I came across this quote that "patterns are a demonstration of weakness in a language" in a Go talk https://youtu.be/5kj5ApnhPAE?t=276 https://youtu.be/5kj5ApnhPAE?t=276. I wish enums will eventually be implemented, generics are coming after all.
- H1Supreme 6y agoI write Go nearly everyday, and enums are the #1 thing I'd like to see. Honestly, it's kind of surprising that the language lacks this feature.
- tleb_ 6y agoSee here for an explanation. Not sure it's up to date though. https://golang.org/doc/faq#variant_types https://golang.org/doc/faq#variant_types
- tsimionescu 6y agoVariant types are very different from enums. Variant types allow you to define a type that is "one of these N types". Enums are the same thing at the value level: they allow you to define a type that is "one of these values". You can't implement one in terms of the other. Variant types do have some similar use cases with interfaces, but I don't see any relationship with enums in terms of use cases, so I don't think that applies. Also, let's not forget that even C has enums, so their lack of inclusion in Go is baffling (especially since they went and implemented the much more arcane yet limited `iota` feature).
- masklinn 6y ago> Also, let's not forget that even C has enums Not in any useful sense of the word. A C enum is a typedef and a few named constant, it's absolute shit, and if the choice was restricted to "C enum or nothing" then "nothing" was absolutely the right call. Go's typedecl + iota is actually a step up from C's enums, because (aside from "untyped constants") you need an explicit conversion from "any random integer" to your typedecl. It's not any more reliable or any safer at point of use, but it will prevent some misuses, or at least force the developer to consider what they're doing.
- mytailorisrich 6y agoComing from C and areas where C is used, enums tend to used with values defined explicitly because they usually don't represent an abstract set but indeed specific values that have to be respected. An example at random from a domain Go is used a lot in (networking): When you define an enum of the resources recors in DNS you want the values to match the RFC definitions as they are used in DNS packets. With that in mind Go's approach to enums makes sense: we usually want to label explicit values, potentially of an explicit type, we don't just want an abstract semantic label. I haven't touched Java in a long time, but as far as I recall low-level operations on fields, bitmaps, etc. were not a strong point.
- tsimionescu 6y agoSure, there is value in having your enums have specific values, but even in C they at least get a bit of namespacing. And yes, Java enums are very verbose if you want to use them for low-level operations, but that is almost entirely the fault of the rest of Java and not enums themselves specifcally.
- justin66 6y agoWhat language do you prefer for the typical Go use cases?
- boblivion 6y agoI thought a LLVM-based compiler would have been nice for a while but in reality a lot of the tooling is C or C++ based and the run-times here are fundamentally different. This is why putting Go and C code together is so inconvenient (and slow), the calling conventions / stack setup is very different. I really favor the C/C++ binary interface for its simplicity but Go is really good for what it is built for. But yes, compilers are always a good argument. I can understand however why C++ frustrated people. To get this beast to work for you, even after C++11 - it requires a lot from the developer. Today, things are a lot better though and they keep getting better.
- crimsonalucard5 6y agoI agree. Yes go is simple. But the people who complain about it are not asking for more complexity. Go feels like really simple integer arithmetic and all it's primitives with the concept of subtraction missing. No one is really asking for crazy features and all kinds of syntactical sugar all over the place like scala. We want simple but we want the minimal set of primitives to establish a sort of completeness over the entire ecosystem. In short, Go feels simple but incomplete. Like you said, the people who like go are typically people who are unaware of the missing primitives or people who typically are more interested in building something that works instead of how that thing was built. Not saying go programs are built in a bad way. Far from it, but you have to admit go programs lack elegance and good design. They are more simple, clear and readable but less re-useable.
- geodel 6y ago> How is this any kind of pro or con? It's just an implementation detail. It is pro in sense Rust developers spend inordinate time in blaming LLVM for slow compilation. Without Virtual machine is pro that steps to install, setup or upgrading virtual machines on target platform is no longer required
- cmrdporcupine 6y agoComing from the world of developing on the absolutely massive Chromium code base where compilation on a non-specialist workstation can take 3-4 hours, but build caching (goma) etc makes it mostly a non-issue [most of the time] ... I have a hard time believing that compilation times are honestly still a major issue for most developers. There are only a few code bases out there that are massive enough that compilation time on a modern machine is a major impediment to productivity. And in those cases I find that IDE and analysis tools on large codebases are an even bigger problem than compilation speeds... Also the VM argument you give makes little sense -- you can have your language run on a VM without the VM being a seperately bundled package like Java or .NET. For example: Python runs on a VM. Its own VM, which is part of the Python runtime itself. Now, it's not a particularly good VM, and Python is a late bound dynamic typed language so it's also pretty slow, but there's nothing stopping one from having a fast JIT VM with a static language like Go. Not saying one should do that, but it's entirely possible and there's arguments to be made either way.
- tsimionescu 6y agoI think compilation times in template-heavy C++ are still a major headache, especially since even modifications to private fields can trigger massive re-compilations.
- blandflakes 6y agoScala is pretty slow even with the build server up, and honestly it is a noticeable tax on my productivity/iteration time.
- cellularmitosis 6y ago> There are only a few code bases out there that are massive enough that compilation time on a modern machine is a major impediment to productivity. Depends upon what you mean by "major impediment to productivity". I think someone like Bret Victor would argue that if your feedback loop is greater than a couple of seconds, you're toast. From that perspective, _the majority_ of _all_ codebases are an impediment to productivity. https://vimeo.com/36579366 https://vimeo.com/36579366
- amedvednikov 6y agoIf you are interested in Go with enums, sum types, optionals, immutables etc, there's V.
- cmrdporcupine 6y agoSyntax looks nice. What's the concurrency story?
- politician 6y agohttps://vlang.io/ https://vlang.io/
- doitLP 6y agoYou forgot one: c) Minimalist-loving hipsters that read articles like this and bandwagon on Go just like any other trend (merits of the language aside). These are the same folks that use a hand crank to grind their coffee beans.
- cmrdporcupine 6y agoI mean, strictly speaking I should downvote you for tone... but I am laughing ;-) I know people who work at Capital One, I wonder how extensive Go usage is there... I have started looking at job postings recently and I see a lot that have aspirational-Go in their postings. I have managed to avoid Go during my tenure here at Google (which isn't hard since it's not used much at all, despite what people outside of Google seem to think), but I'm starting to worry that if I move on I'm going to have to take a job writing it. Who is hiring remote for Rust, Zig, OCaml, or Erlang? Those seem more palatable to me? :-)
- frockington1 6y agoBefore learning a new language I always look at Linkedin for open jobs. Last week, I could find next to nothing for anything Rust and OCaml. I eventually decided to modernize my C++ skills to be relevant again
- dbolgheroni 6y agoWhat does aspirational-Go means?
- blandflakes 6y agoI assumed it was job posts in the vein of "new code written in Go" or "migrating systems to Go", kinda like when somebody says "monolith moving to microservices" but actually you spend 95% of the time working on the monolith.
- LanceH 6y agoTell me there isn't a crowd latched on to "safety" that adds nothing else to every Go discussion.
- deleted 6y ago[deleted]
- snapetom 6y ago> How is this any kind of pro or con? You still need to be an expert on the virtual machine to not have things blow up. It's another factor of a complex equation. My last job had a group of admins that thought any Java app from the Apache Foundation was the solution. Whenever things went wrong, their solution was, "just up the max heap size!" However, they're admins and had no idea about the app and the users had no Java experience to actually suggest tuning the JVM. Yes, this was an org issue and a failure of tech leadership, but nevertheless, the JVM was a point of failure.
- cmrdporcupine 6y agoGo has a runtime with a GC with a heap size, just like the JVM does. People will end up having to tune their Go runtime GC's parameters, too. Whether the runtime is executing compiled native code, or executing JITted bytecodes is of little relevance to the user. What you're speaking to is the issues with a _separate_ VM process and a cultural thing with Java generally, not a VM in particular.
- cellularmitosis 6y agoMy understanding was that a golang program's heap size will automatically grow as needed, and later (eventually) shrink as memory goes unused. Is this true of java? Is it possible to run a java program in a way where it is allowed to use up all of the system's heap if needed, but also plays nicely with other processes on the system (i.e. yields the memory back to the OS after it becomes unused)?
- pjmlp 6y agoYes, it is matter of which JVM implementation gets used, and what configuration switches it offers.
- cmrdporcupine 6y agoMaybe this has been improved in the last 10 years but heap management imho is one of the not-great things about the JVM when I was using it. What is happening is quite invisible to sysadmins used to monitoring traditional unix processes. To them it looks like a giant memory hog, non-cooperative, when in reality the program might only be using a small % of what top is showing allocated to the process. The original JVM philosophy seemed to be to cohost a bunch of stuff in one monolithic JVM process, rather than run a bunch of separate communicating processes. And in fact this "container" philosophy is what the original J2EE servers operated with.
- quicklime 6y ago> "Go doesn’t have a virtual machine or an LLVM-based compiler." > How is this any kind of pro or con? It's just an implementation detail. This is actually one of my favorite things about Go. The fact that you get a single statically-linked binary at the end is so much nicer than having to mess around with JVMs and JAR files and CLASSPATHs. Sure, there's a lot of tooling to handle this in the Java world, but it adds significant complexity, and makes life difficult when you need to do something slightly different.
- stouset 6y agoNone of these are arguments against LLVM or a virtual machine, they're just implementation details of Java.
- moreaccountspls 6y agoSure, and if the moon was made of cheese, it would still be a sphere lighting up the night sky. The fact that the go designers prioritize things like statically compiled binaries is the whole magic of Go in the first place. The language is whatever, it's fine, it's cool. But like the article says, the magic is in its holistic attitude towards process, tooling, and distribution.
- ngrilly 6y agoYou are underestimating the impact of that choice on language design. When Java was designed, garbage collection was one of the major features, and almost all languages with GC were either interpreted or using a VM. Static native binaries with GC and goroutines is something relatively unusual in the design space. I can think of OCaml and Haskell doing something similar for example.
- pjmlp 6y agoCommon Lisp, Modula-2+, Modula-3, Oberon, Oberon-2, Active Oberon, Component Pascal, Eiffel, Objective Caml, Standard ML, Haskell, Dylan, Sather, Mesa/Cedar, BETA. All were able to AOT compile to pure sugar free native code, with various forms of GC support.
- courtf 6y agoI write in Kotlin regularly, and occasionally in Swift, but I use Go for anything server-related, if I can help it. I find the stdlib to be an incredible simplifying force for these programs, not least because deployment is trivial. I guess you could say I belong to the 'b' community. My issues with programming circa 2010 were in part related to tooling, but also just bloated, over-engineered code bases that obscure all basic computing behind layers of nigh impenetrable (but still leaky) abstractions. I can see how if you became fluent in a nicer language like Swift, it would be frustrating to move to Go and find your typical methods for expressing certain patterns are unavailable. They have been sacrificed for keeping the language overhead small, which in turn creates various warts and edge cases that give more ammunition for being frustrated with the language. I accept these tradeoffs when working in Go because I am typically thinking about concurrency and memory overhead in those projects, and Go makes measuring and reasoning about these properties of your program straightforward.
- arcturus17 6y agoDo you have an opinion on NodeJS + Typescript backends?
- atombender 6y agoI would love sum types (which would allow for real enums), too. Russ Cox has commented on Reddit why the Go teams considers them incompatible with Go [1]. The first challenge is zero values: For a sum type like (int, float), there's no natural zero value. I think that sum types would have to follow the same design as Go's interfaces; a sum type value has to be nillable. This is unfortunate, but the Go team burned some bridges when it decided to support nils, and they now have to deal with that problem. Secondly, there's the matter of what a sum type of interfaces means. I think this is solvable, too, and I don't agree that it presents a conflict. Sum types express the range of allowed values. What you do with a variable, once it holds a value, is no different than today: type Source sum { io.Reader, io.ReaderAt } var src Source switch t := src.(type) { case io.Reader: case io.ReaderAt: } This is no different from: var src interface{} switch t := src.(type) { case io.Reader: case io.ReaderAt: } [1] https://www.reddit.com/r/golang/comments/46bd5h/ama_we_are_the_go_contributors_ask_us_anything/d043ukb/ https://www.reddit.com/r/golang/comments/46bd5h/ama_we_are_t...
- stouset 6y ago> Russ Cox has commented on Reddit why the Go teams considers them incompatible with Go [1]. I wish people would stop beating around the bush and own up to these being design mistakes of the language. If you can't have nice things because earlier poor decisions (e.g., supporting nils) has walled you into a corner, it's a problem. It's not an example of "refreshing simplicity", it's a shortcoming of the language. Period. Every language has some warts, just acknowledge them!
- atombender 6y agoAs far as I'm aware, the Go team don't really consider them design mistakes.
- stouset 6y agoUnfortunately, I'm inclined to agree.
- 6y ago
- coldtea 6y ago>How is this any kind of pro or con? It's just an implementation detail. Not exactly. It's hardly a detail, and affects use. The first (not having a VM) in Go's case translates into AOT static compilation, and you not needing to have a VM installed to run your programs. The second (not using LLVM) translates in Go's case to faster compile times compared to LLVM based compiled languages. While both have their drawbacks (e.g. LLVM compiled code would probably be faster), both are pluses for my preferences/use cases - not mere implementation details.
- Can_Not 6y agoCrystal is everything I like about using golang combined with everything I like about not using golang.
- deckarep 6y agoI agree with this sentiment. A lot of this depends on purely the angle of how you view things. One example: People claiming the borrow checker gets in their way in Rust because it’s so strict. Guess what? If your code doesn’t compile due to the rigidness of the borrow checker, it’s incorrect I’m sorry to say. It’s either got a data race, use after free bug or some other invariant. You don’t want that behavior in your code at all. I’m happy to offload the responsibility to the compiler to check for this. You won’t get it until you’ve been bitten.
- dlubarov 6y ago> If your code doesn’t compile due to the rigidness of the borrow checker, it’s incorrect I’m sorry to say. There're plenty of bug-free code which the borrow checker doesn't permit. A very common example is nested calls with a &mut receiver: https://internals.rust-lang.org/t/accepting-nested-method-calls-with-an-mut-self-receiver/4588 https://internals.rust-lang.org/t/accepting-nested-method-ca...
- Matthias247 6y ago> Enums, immutables, and generics aren't good because they're exciting. That's your opinion, and maybe even that of other programmers which have good intention. However advanced PL features are still sometimes overused because the users find them very interesting and can't resist applying them everywhere. As an extreme example I read a statement from a Rust programmer about liking framework XYZ, because it creates those nice type-system puzzles and makes things super-safe. However for an outsider this super-safe code could also be undecipherable gibberish. Overall I think that while type-help can be good to avoid errors there is also a line where the complexity in type system features outweighs the complexity of the initial problem. And that after you cross the line programmers spend their time trying to understand complex but less-error-prone code instead of simple but easy-to-understand-and-fix code. Where that line exactly is depends on the problem space.I certainly think it is somewhere between Go's extremely simple approach and the extremely advanced feature sets that some other languages allow for.