3 ms·
And why on earth would you say that?
by xkapastel 6y ago
And why on earth would you say that?
- baby 6y agobecause it's a breeze to read Golang, due in parts to the lack of generics
- therealdrag0 6y agoWhy does genetics make things that’s for read?
- zdragnar 6y agoFunctions can be given semantic names (I.e. have meaning); block statements cannot. If writing a function that can take an array or slice of any type of data requires providing a generic argument (I.e. so you can specify that the function returns a slice of the same type of data as it was given), then you can name it "reverse" if it reverses the array, write it only once, and every timr you use it, you read "reverse" and know what it does. For loops dont have those names, and so have to be rewritten every time you use them. As such, every time you see a for loop, you have to read and parse every statement to see what it is doing, and if it has any unexpected side effects or bugs introduced via copy-paste or what not.
- therealdrag0 6y agoSorry I meant to say “why do genetics make things harder to read?”. Tbh I can’t tell if you’re responding to that or not
- zdragnar 6y agoI did misread your post, but I will also say that generics are a double edged sword when it comes to readability. Needing to declare genetic types in function signatures can add irrelevant detail and heavy syntax. For example, look at the interpreter interface in this typescript file: https://github.com/gcanti/io-ts/blob/master/src/Schema.ts#L29 https://github.com/gcanti/io-ts/blob/master/src/Schema.ts#L2... Granted, genetics don't need to be done that way, but it is among the more common and popular approaches. The type information is tangled up in the implementation, making focusing on either more challenging. Perhaps we need modes for syntax highlighting- one for types, one for implementation?
- hombre_fatal 6y agoLack of generics just means you have to copy and paste everything, like any time you want to reverse a slice. for i := len(a)/2 - 1; i >= 0; i-- { opp := len(a) - 1 - i a[i], a[opp] = a[opp], a[i] } Actively hurts reading code as you have to credentialize in a code base to begin to be able to file entire code blocks into copy and pasted "idioms". Without generics you have to hope the stdlib gets a blessed generic function like reverse() one day since you can't build one without rolling your own monomorphization code-gen or a goofball interface{}+cast hack. For people who supposedly prefer the lack of generics (which seems more like cargo culting or Stockholm Syndrome), no problem. We can just add a config option to golint that prohibits you from using generics. That way you don't need to hold up the rest of us. win-win.
- psanford 6y agoWeird. While you could copy that from the SliceTricks Go wiki page, you could also just use `sort.Sort(sort.Reverse())` which seems to address all of your complaints.
- littlestymaar 6y agoBut it uses an interface, which means dynamic dispatch and an allocation most of the time (because IIRC it tends to break the escape analysis). That's a recurrent issue with Go: you can either have ergonomic tools (with interface and reflection), or performant code (with no allocation) but you generally can't have both at the same time. Sure it's better than scripting language where you need to use another language when you need performance, but it's still kind of sad.