12 ms·
Go and Simplicity Debt
- pjmlp 9y agoThe good part of Go is having a programming language, which DevOps are adopting in place of C, allowing for safer userspace applications. The sad part is Google supporting Java, Kotlin, TypeScript, Dart and C++ progress o one side, all with lots of people knowledgeable in language design and then there is Go.
- ridiculous_fish 9y agoGoogle cache link: https://webcache.googleusercontent.com/search?q=cache:__B53pKdoxMJ:https://dave.cheney.net/2017/06/15/simplicity-debt+ https://webcache.googleusercontent.com/search?q=cache:__B53p...
- jasode 9y ago>But there is equally no question that adding these features to Go would make it more complex. [...] I have no doubt that adding templated types to Go will make it a more complicated language, I don't know if adding generics to Golang is the right thing to do but I don't agree with how Cheney has framed it. I wish programmers would use a more precise mental framework about "simplicity/complexity". It's not important if generics make the "language specification" more complex. What's really more important is if it makes the real-world language usage more complex. What matters is the sum of total complexity: the language spec + adhoc idioms/patterns/conventions/workarounds used in actual codebases. As an example, if you make a super simple language like Javascript in 1995 with hardly any features, what you eventually end up with is complexity in npm with dozens of modules for things like leftpad(). Or you can insist that "prototypes are simpler than OO" but you actually end up with a dozen OO-simulation libraries with different syntax out in the wild. Instead of the overall JS landscape being simpler, it is more complex. This does not mean you must put everything language feature including the kitchen sink into the language. The lesson learned from history is to talk about about simplicity/complexity in a more holistic way.
- munificent 9y agoThis is exactly Larry Wall's point when he talks about the "waterbed theory": https://en.wikipedia.org/wiki/Waterbed_theory https://en.wikipedia.org/wiki/Waterbed_theory Users don't often have the luxury of discarding essential complexity in the problem their trying to solve. So, if you don't give them the right tools to tackle that in your language, that doesn't mean they no longer need those tools. It just means they have to build them themselves first.
- grok2 9y agoI think the author was actually referring to the fact that it makes the written software using Go more complex to understand and maintain. Quoting: "...efforts to add templated types and immutability to the language would unlock the ability to write more complex, less readable software. Indeed, the addition of these features would have a knock on effect that would profoundly alter the way error handling, collections, and concurrency are implemented."
- i_don_t_know 9y agoIt's not clear to me how templated types and immutability inevitably lead to more complex and less readable software. Can you or someone else explain?
- catnaroek 9y agoTemplates have a very complex semantics, because they are checked at instantiation time and can be specialized anywhere. Fortunately, parametric polymorphism and templates have nothing to do with each other. :-)
- grok2 9y agoI think it's perhaps a reference to the original intent of Go at Google. They want new joinees to be quickly productive and also be able to write problem free software (and maybe maintain a lot of old software in addition to writing new software). Having more advanced language features is perhaps not conducive to this. Features like templates do take a bit more effort to grok and also take a bit more effort to understand the flow of code when maintaining software.
- benhoyt 9y agoI agree with the sentiments of this post (you can't "just" add generics; there are serious trade-offs), but I think his assertion that Python is "on the wrong side of history" is untrue. More people are using Python now than ever before, in more and more problem domains. It's great for certain things, just not very good at concurrency (alleviated by async) and particularly parallelism (though in practice you can often work around it with C extension modules and multiprocessing). But to say Python has "missed the boat" and is "on the wrong side of history" is not true.
- usuallybaffled 9y agoThe author was specifically talking about concurrency. You just repeated his point.
- SideburnsOfDoom 9y agoIf my experience with c# is anything to go by, you can't "just" add async either. The details of how it works are very complex, the syntax requires a lot of noise words all over the code, and there are many ways to get it wrong. That's just a cost of retrofitting a paradigm-changing feature.
- dhd415 9y agoI would say, based on some experience with async capabilities in Python, Java, Go, and C#, that C#'s async/TPL implementation is among the more elegant. Its internals may be complex and it is not without some caveats that must be understood, but I find that it introduces the least amount of extraneous keywords and code constructs in the business logic of an application. And unlike some languages such as Java, C#'s async capabilities are well-supported throughout its core libraries. As someone who builds a lot of data processing applications in Java that benefit from both high concurrency and non-blocking IO, I find myself wishing Java's async capabilities were more like C#'s.
- pdimitar 9y agoAnecdotal evidence from the Pythonistas I've known in my career -- they stick to it because they like it, it's old (to them that means it's a proven tech) and because there's too much intertia in their organization to move on to something else. Technologies aren't only popular because of their quality, or shall we bring PHP once again to prove this point?
- nicpottier 9y agoI know Go gets a lot of heat for not having generics, but having done a few fairly complex things in Go now, I really haven't missed them, nor have I had to bail out to interface{} in ways that I wouldn't have had to in other languages. The main reason for that is that golang lists and maps CAN be typed and while they aren't perfect, they are pretty darn great for most use cases. Certainly I understand some people have the need for specialized data structures, but I wonder how often a project needs that data structure to be totally generic, as opposed to just doing the work to implement it (yes even perhaps copy/pasting some other implementation) and moving on. That's ugly yes, but it just isn't that big a deal in my experience. In any case, the gains from having a great runtime that compiles to a binary, an excellent standard library and awesome concurrency primitives far outweigh the negatives for me. Really enjoy Go.
- pjmlp 9y agoI can have a great runtime, with static linking support in many other languages. The sync.Map in Go 1.9 is yet another example of the price to pay for lacking generics.
- pdimitar 9y agoWhat price are you talking about? They're adding a map that offers a bit more leeway when working with it from several goroutines, is all I am seeing without thinking extensively about it.
- pjmlp 9y agoAbandoning type safety with interface{} for keys and values. I was doing that with Turbo Pascal 6.0 and Borland C++ 2.x for MS-DOS with Turbo Vision and TObject as interface{} in 1993.
- nicpottier 9y agoSo what's your complaint? That you want a synchronized map? Then write a two line function that wraps your native golang typed mapped with sync.Mutex and be done with it. If you are sharing a map in this way across many goroutines you are probably "doing it wrong" in go anyways.
- frou_dh 9y agoAfter seeing Rich Hickey's excellent material on the matter^, I can no longer read anything talking about Simplicity and Complexity in programming without suspecting the author of being fast and loose with what those terms specifically mean. As it stands, they are recipe for different camps and sub-camps of programmers to talk past each other endlessly. ^ https://www.infoq.com/presentations/Simple-Made-Easy https://www.infoq.com/presentations/Simple-Made-Easy
- xyzzy_plugh 9y agoI tend to agree with you, but I think Cheney has done an excellent job here. Did you even read TFA?
- frou_dh 9y agoYes - evidently not as impressed. It's against the site guidelines to ask that btw. For example, I cannot accept that having no means to define immutable structures makes for an overall "simpler" programming model. What could be simpler than allowing information to be information? Whether having an additional concept makes Go more burdensome to learn and implement is another matter, and is on a different axis to Simplicity/Complexity (again, using Hickey's excellent deconstruction of simple/complex vs. easy/hard).
- catnaroek 9y agoSimplicity is very easy to objectively measure. Write down a formal semantics for the programming language in question, and count how many pages you used. But, of course, nobody will actually do this, because it would expose the inherent complexity of designs advertised as simple. Many people's feelings would be hurt in the process.
- majewsky 9y agoAs long as the result is shorter than 1500 pages (afair), your language is simpler than C++.
- 9y ago
- rwj 9y agoThe facet that is missing is the impact on users' code complexity. It is all well and good if Go is simple, but if my code is horrendously complex to compensate, it isn't a net win. I exaggerate, but a lot of the complaints for Go already stem from this trade-off. Focusing entirely on the language itself is a failure. Keep on eye on the language's users,
- coldtea 9y ago>By the time this decade rolled around, Node.js and Go had arrived on the scene, highlighting the need for concurrency as a first class concept. Various async contortions papered over the single threaded cracks of Python programs, but it was too late. Other languages had shown that concurrency must be a built-in facility, and Python had missed the boat. While concurrency is nice, some citation is needed here. For one, Python is not going anywhere, and remains spectacularly more popular than Golang. >But, no matter how important and useful templated types and immutability would be, integrating them into a hypothetical Go 2 would decrease its readability and increase compilation times—two things which Go was designed to address. Well, they sacrificed compilation times to get a native compiler (which has no real utility to the users of the language, on the contrary it makes bootstrapping a little more messy). Sacrificing it for Generics seems like a no brainer, but it seems they're not yet ready to bite the bullet. As for "sacrificing readability" I don't think that having 30 lines of code just because you need to make it work with different types is any easier than having 10 lines of the same code with parametric types. Not to mention NOT having to write any code at all, because the standard library can finally have code (e.g for math, collections, etc.) that works across all relevant types. With Generics people could just reuse a few generic implementations of channel uses to handle 90% of their concurrency needs. And it's also much better and easier to parse than using dreadful string templating kludges or interface{} to get the same behaviour. I mean, the author mentions all those languages with generics ("Rust, Nim, Pony, Crystal, and Swift showed that basic templated types are a useful, and increasingly, expected feature of any language—just like concurrency"). Does he see the users of those languages complaining about generics being a burden? Why do people always have to lament the terrible burden Generics will bring to Go in advance, when millions of us (literally, just add Java and C# programmers) just use generics in other languages without thinking twice about it? There's a proverb in my country, that "He who'd rather not knead the dough (to make bread), keeps sifting the flour for days". In programming terms it would translate roughly to: "He who is too lazy to build a bikeshed or doesn't like the prospect of building one, will keep on discussing the color it should give it". Which I think is the case whenever anybody from the core Go team discusses Generics. >As it stands now, generics or immutability can’t just be added to Go and still call it simple. It's 2017. Neither are particularly difficult to grasp for a modern programmer. Even enterprise Java programmers have been using the former for a decade already, and they're not known for the wild experimental nature...
- jhpriestley 9y agoNo one knew about generics until languages like Pony and Crystal proved that they were important? This may be a pedantic point, but technically, generics or templated types were already being used in some obscure, academic languages like Java, C#, and C++.
- cratermoon 9y agoAs I read it, the author wasn't discounting those languages or saying nobody had heard of generics, he was saying that newer languages demonstrate that generics are now expected. Remember, both c++ and Java got generics added on (and c# followed Java's lead). The introduction of languages that have generics designed in from day one is key. Even though Go doesn't (yet?) have them, the fact that its designers wrestled with the question from the start is an indicator that the concept has become central to programming language design.
- munificent 9y ago> Remember, both c++ and Java got generics added on (and c# followed Java's lead). C++ got templates 27 years ago. Java got generics 13 years ago. C# got them 12 years ago. Go was launched 10 years ago. I can't think of a single statically typed language with significant use when Go was developed that didn't have some for of type parametricity. Maybe C, but you could argue C users can simply opt into C++ if they want that. The Go folks aren't risking being on the wrong side if they history if they don't add generics. They were on the wrong side of history when the language launched. I do understand that generics are very difficult in an ahead-of-time compiled language where fast modular compiles are a priority one goal. I'm not saying its easy, at all. But there's no shortage of brilliant folks on the team. If they put their minds to it, they could solve this. Maybe it was because they had the luxury of controlling the language and core libraries. They could make the types and functions they cared about -- channels, arrays, slices, maps, append(), etc. generic since they could bake them right into the language. It's really easy to not empathize with a user's problem if you don't experience it yourself.
- pjmlp 9y agoYou got your history wrong. C++ got templates during the time it was being designed. Between C++ ARM and ANSI C++98, C++ compilers experimented with them, and its design reflected on the standard work. Borland was one of the first PC compiler vendors to support templates, still on their MS-DOS/Windows 3.1 compilers, with the release of Borland C++ 3.0. Microsoft Research already had a .NET prototype with generics support, by the time v1.0 was about to get released, but they decided it was more relevant to ship v1.0 than waiting for the generics support to be fully done. Don Syme from the F# team has a few blog entries about this. One of the first languages to get generics was CLU in 1975, shortly followed by ML and Ada in the early 80's.
- grabcocque 9y agoI don't think Cheney properly understands the concept of "simplicity" fully. A language is not simple because it meets some arbitrary measure of smallness. A language is simple if it decomplects unrelated concerns. Which go does admirably in certain areas, but its absence of generics certainly adds to cognitive overhead and unnecessary complexity elsewhere.
- gtrubetskoy 9y agoI'm glad the article begins with mentioning the GIL, the elephant in the room of Python and Ruby. I often wonder why it isn't getting the attention I believe it deserves - either the problem is just too hard to solve and has been written off as not worthy of addressing, or perhaps developers do not understand how much (unnecessary) complexity goes into deploying, running and monitoring a production Python/Ruby app only to work around the GIL limitation. I devoted a section of my recent blog post to the GIL problem here [1] if you're interested in why I believe it is such a problem and how cool it is that Go does not have it. It's not the only thing I like about Go, but it is one of the most important ones in my opinion. [1] https://grisha.org/blog/2017/04/27/simplistic-go-web-app/ https://grisha.org/blog/2017/04/27/simplistic-go-web-app/
- baq 9y agoIt can be argued that the GIL doesn't matter, because Python is too slow if you have a performance sensitive problem anyway. I'll give numpy as an example.
- josteink 9y agoGo: the only place in the known universe where you can find generics described as complex. Even though modern VB-programmers manage to deal with them just fine. So pardon my French, but what's the fucking issue? var typesafeListOfInts = new List<int>(); How is that hard?
- pjmlp 9y ago> Even though modern VB-programmers manage to deal with them just fine. Ironic, no?
- tonyedgecombe 9y agoSimple for Go developers is different to simple for the developers of Go.
- majewsky 9y agoThe point is not List<int>. The point is that the primary intention of Go is to push developers to write the most readable (and hence, maintainable) code possible. No one argues that List<int> will not make the code more readable (and in fact, Go has some very limited generics for lists, maps and channels for these usecases). The problem is that once you give people parametrized types, they're going to parametrize the shit out of them, leading to byzantine messes such as the C++ standard library or Boost. And that's not saying that something like Boost isn't an accomplishment in itself. But it's beyond hard to read, and when your language allows to write code like that, it's bound to appear in your codebase as well, and make maintaining it much harder than it needs to be.
- josteink 9y ago> The point is that the primary intention of Go is to push developers to write the most readable (and hence, maintainable) code possible. Lack of parameterized types leads directly to code-duplication. How is duplicate code more maintainable? > The problem is that once you give people parametrized types, they're going to parametrize the shit out of them, leading to byzantine messes such as the C++ standard library or Boost. An extraordinary claim with no backing what so ever. Just because C++ turned out terrible doesn't mean everything else has to. Look to C# and Java. They're doing just fine. Also: how is littering your code with "interface { }" any less Byzantine than simply using "T"?
- ShabbosGoy 9y agoI'm finding it difficult to accept the premise that generics and immutability are needed in Go. In my case, var foo map[<type>]interface{} solves 99% of issues where I would normally need generics. The author also doesn't really specify what kind of generics, there's a huge difference between parametric polymorphism (i.e. Haskell type classes) and Java/C++/C# generics. The sheer rapid pace of development and simplicity has made Go our primary stack.
- codygman 9y ago> var foo map[<type>]interface{} > solves 99% of issues where I would normally need generics. But it also opens you to to runtime conversion errors, spurious if checks for type information compilers with generics have, or slow reflection to find the type. > The author also doesn't really specify what kind of generics, there's a huge difference between parametric polymorphism (i.e. Haskell type classes) and Java/C++/C# generics. Java/C++/C#/Haskell generics all provide parametric polymorphism though. Haskell type classes provide ad hoc polymorphism, though I guess maybe they provide parametric polymorphism as well. Per Wikipedia: > In programming languages and type theory, parametric polymorphism is a way to make a language more expressive, while still maintaining full static type-safety. Using parametric polymorphism, a function or a data type can be written generically so that it can handle values identically without depending on their type.
- solidsnack9000 9y ago> I'm finding it difficult to accept the premise that generics and immutability are needed in Go. They aren't strictly needed; but that is not much of an argument. Having Maybe and Either available is a huge help. Those are examples of generic types I've really benefited from in Haskell, Scala, Rust, Kotlin, Swift... But of course I can code without them if I have to.
- GenericsMotors 9y agoLINQ gives a huge productivity boost...I wonder what a LINQ implementation in Go would look like. interface{} and run-time type assertions everywhere, probably.
- YZF 9y agoWrt/ to generics I think one interesting exercise would be to look at list and see what would need to happen such that it behaves more like the built in map. You'd want to be able to declare: - list[type] - delete should work. - len and cap should work. (rather than .Len() )... - range should work. - What do we do for iterators? I think it would make code that uses lists more readable/grokable. So you do get something in return for the debt you possibly took on to be able to implement list. In a sense that's also the way C++ trades things off, the library code is more difficult but the code using the library is simpler/safer.
- kbutler 9y agoWhile the author's main idea is good (it can be more complex to work around missing features than to have them designed in from the beginning), starting from an invalid premise really weakens the article. Node.js illustrates the need for concurrency, but is even more single-threaded than Python. Somehow, in spite of the GIL, Python has continued to increase in popularity, probably because the workarounds are pretty easy (use multiple processes or c extensions that give up the GIL or jython or...). Threads are not the only route to parallel execution, just as templates are not the only route to generic data structures.
- deckarep 9y agoThis is all about trade-offs right? Choose to have a simpler language when it comes to concurrency and multi-threaded programming and the outcome is a harder time troubleshooting at runtime. Or, make the compiler more powerful and annotate the code in such a way that the compiler does way more upfront on your behalf...now this means you don't have to work so hard to troubleshoot code in production. Personally, I'd rather work harder up front--even if it means a higher learning curve.