by siscia · 7y ago · 0 comments
All those arguments are fine and correct in small projects or libraries, there go is perfect.
But they really don't hold on big project like docker or containerd.
While it is clear what lines of code does, at a tactical level, it is extremely difficult to follow what happen in the big picture, the strategic level. Where the values comes from and where they go? When? How and why?
Honestly I keep seeing this in all big go project, despite the lack of generics.
Again if you need a small micorservice, use go! It is the best option right now. But I wouldn't bet any big codebase on it.
On teams of enough engineers, especially as those engineers rotate in and out of maintenance roles, richer abstractions tend to obfuscate intent and hurt maintainability more than help it.
For me it's mainly due to the lack of generics and helper tools that naturally spawn from generics. Go's solution to having less LOC inside a function is _only_ to create helper methods/funcs. These helpers are bound to specific data structures and often are only applicable to that one use case in that one method that they came from. Your ability to make that helper function apply to more code depends heavily on what data structures are being used.
This form of non-generic bloat was far worse for me than the classic examples of `Fooi32()` and `FooString()`. The latter I don't mind at all.
Rust aids this process to me by, well, having generics. Converting one data structure into another becomes a breeze, and converting a Slice of those data structures is just as easy. I'll be really interested to see how Go feels once generics make it in - though I suspect I'll stick with more explicit memory management.
Speaking of memory management, it would be nice if Go had a way to intelligently indicate which structures are safe for concurrent use and which aren't. I've found in Rust that the explicit nature of the concurrent safety is not something I knew I wanted in Go. I know Go will not likely ever match Rust's safety, but if it at least indicated that something was an thread-unsafe implementation that would be golden.
[1] edit: Oh, and there is a disclaimer in this that the projects I'm involved in seem to heavily rely on managing several data structures in repeated ways. Aka, very generic friendly.. so not having generics made my projects extra painful. This is not likely the norm.
This has been my experience as well. People just parrot what the golang authors say about it being a language suites for "large scale development", whatever that means, without providing anything to back it up. Just because they said it was must be it's true? In practical experience, it's a verbose, clunky, and awkward language to use for any non-trivial code bases.
Rust is still too young to take advantage of this, but in due time it will.
The maintainability of the code is mostly determined not by how good the underlying language is but how good is that DSL. To take an example that's been widely discussed in HN, let's think about machine learning - the look, structure and maintainability of your code is highly influenced by the choice of your framework/"DSL" e.g. pytorch vs tensorflow1.x vs straight numpy vs Caffe will have major differences despite being in the "same language".
And in that regard, the features of the core language matter only in regard of whether they facilitate making a good DSL. Of course, some languages fail because their choices result in the "core DSL" i.e. standard libraries that everybody uses being fragmented and confusing; Go has it quite good IMHO for the standard library; but for every specific domain it also matters if the DSL for that domain is good, whether it's an ORM layer or a OpenGL interface or a deep learning framework or an physics simulation library - whether the language abstractions mean that these DSL's (often being interfaces/wrappers to some third-party code written in another language) are going to be good and convenient, or whether the language structures limit the DSL so it becomes unwieldy to use.
Every time I've seen this, it's been a disaster. Custom DSLs for business logic are, 100% of the time, a red flag of a development process gone off the rails.
(We may work in different industries.)
Go prevents you from doing this at a very low level. This is a huge advantage.
So you're right, for programming in the large it's very important how well the language supports creating good reusable APIs and data structures. I think that's why so many people make such a big deal about generics in Go, though personally I think it's a poor example and the complaints are tiresome. I think I'd focus more on whether the language has things like macros and lambdas/continuations that let non-API idioms be expressed consistently and conveniently, as though they're part of the language (even though I think creating a true DSL is usually a bad idea). Not sure Go meets this standard TBH.
Well, nothing I'm aware of beats the LISP family of languages as far as "making a good DSL" goes, but none of those are particularly popular :(
That's what some Go proponents say, not necessarily reality, and there's no study about this, just hearsay.
I find Go hurts readability for larger programs because it prevents many structural abstractions that make code more clear and concise (as opposed to mere fancy "clever" code, which it still allows), and because it forces too much boilerplace (error handling, no generics, etc).
Every large projects contains re-implementations of the same things (from data structures to algorithms, to parallel processing handling) that could have been done once and re-used forever with generics and a little more power.
Not maybe because of the lack of generics?
If I recall correctly one of the arguments for lack of generic was that they would make more obvious code, hence easier to follow and read. Actually it seems like the lack of generic just make more obvious code, hence more difficult to read.
The other argument was compilation speed, that honestly I cannot complain about.
I don't believe that is a reason ever articulated by the core team, but a post-hoc justification by apologists. The reason the core team gave was that they had not settled on a design that would fit well with their other goals for the language, and it simply didn't make the short list for 1.0.
Compared to python or Java? Well written python basically resembles Go. And most Java I've come across tries to spread logic across class boundaries so you never get to have all the code in front of you at one time.
I attribute it more to a static type system that lacks features I've grown use to in modern languages. Most of my experience in Java is 1.6 and prior so its possible code bases have improved since then.
Could you give a couple of examples how this is made clearer in other languages?
Edit: And the intrusive data structures commonly used in C are way more complicated than the equivalent generic code (in my opinion).
A red-black tree implemented in the same simple style by an OpenBSD developer a couple of decades later was adopted almost overnight by all BSDs: https://man.openbsd.org/tree#EXAMPLES
Unlike the Linux version, the BSD version is as type-safe as a C++ template, permits a node to exist in as many collections as you want (one member field per collection), and like a template the BSD version can inline the comparison function. You even have the option of making all the routines extern or static, which you can't even do with C++ templates.
What the Linux version has going for it is that it doesn't need to rely on the preprocessor so the implementation looks a little neater and more like a C++ template--no columns of backslashes as required with preprocessor-based generation. But that's a horrible tradeoff. queue.h and tree.h have basically been frozen for decades.[1] After initial curiosity wanes (day #2 of many thousands), nobody reads the headers because the interface is simple and never changes.
[1] Various systems have tweaked things here and there (e.g. to add parameterized trace points), but the original APIs never changed and code has always remained portable at the source level. The only big change over all that time was most systems (BSDs, macOS) eventually dropped CIRCLEQ after someone (I think a FreeBSD developer) posted benchmarks showing it sucked relative to TAILQ. I actually preferred CIRCLEQ; the entire header is small enough that for awhile I just copied it around everywhere.
- Download one that uses interface{} / void pointers - okay, but not very efficient or type-safe.
- Download one that's intrusive - okay, but pretty convoluted.
- Write my own - a pain.
- Code generation - generics but worse.
(This isn't sarcastic.)
You can build any abstraction you want in C.
This is disingenuous. Show me Pi types in C.
I took a quick look at what these are. Couldn't they implemented with macros like (this builds a type "Utf8String" which "depends" on the value of the "ENCODING" parameter to figure out what set of functions to call for the guts of the functions that handle the type, e.g. RawStringUtf8Length):
enum Encoding { Ascii, Utf8, Utf16 };
#define TYPENAME Utf8String
#define ENCODING Utf8
#define CHARTYPE char
#include "stringdef.ph"
Then in stringdef.ph (ph=parametric header, just came up with it): typedef struct { size_t len; CHARTYPE* text; } TYPENAME;
#define MAKEFUNC(name) TYPENAME##name
#define RAWSTRINGFUNC(name) RawString##ENCODING
void MAKEFUNC(Create)(TYPENAME* str);
void MAKEFUNC(Destroy)(TYPENAME* str);
void MAKEFUNC(CreateFrom)(TYPENAME* str, const CHARTYPE* text);
/* this goes in a single C file, single header library style */
#ifdef IMPLEMENTATION
void MAKEFUNC(Create)(TYPENAME* str) { ... }
void MAKEFUNC(Destroy)(TYPENAME* str) { ... }
void MAKEFUNC(CreateFrom)(TYPENAME* str, const CHARTYPE* text) {
str->len = RAWSTRINGFUNC(Length)(text);
str->text = RAWSTRINGFUNC(Duplicate)(text);
}
#endif
#undef MAKEFUNC
/* cleanup input parameters so includers wont need to do it */
#undef CHARTYPE
#undef ENCODING
#undef TYPENAME
Then you can use the above simply like Utf8String u8s;
Utf8StringCreateFrom(&u8s, "foo...");
It isn't exactly pretty, but seems to do the work. The ENCODING parameter is only conceptually an Encoding enum, but this can be enforced with some dummy (unused) code that does use of the ENCODING value as Encoding (and if extra strength is needed, as enums are weakly typed, instead of native enums, you could define macros that create stronger "enums" out of structs).Interpreter, but close enough :)