6 ms·
Sad thing is that there is always a bunch of whining in any thread about 1.18 with people complaining about how much generics are going to ruin the language. I
by avl999 5y ago
Sad thing is that there is always a bunch of whining in any thread about 1.18 with people complaining about how much generics are going to ruin the language. I cannot wait for this release either, getting a proper set of data structures and concurrency libraries will be worth their weight in gold.
- digianarchist 5y agoSome things are just really painful to do in Go: merging maps, drilling into a JSON structure, checking if an element exist in a slice. Hopefully generics alleviates some of this boilerplate.
- skybrian 5y agoI haven't used Go in a while, but those don't sound particularly hard. Isn't searching for an element just a for loop?
- erik_seaberg 5y agoRereading the same loop more than once is not a good use of time. A generic function can be named and reused forever.
- skybrian 5y agoWhen I was writing Go I used to write little helper functions named "findThingy" that just wrapped a single for loop. A typical module might have a few of them. It wasn't hard to read and it wasn't that big a deal. I think the boilerplate from error handling hurts readability more. It will be nice not to have to do that, though, if I get back to Go again.
- akshayshah 5y agoI'm particularly excited to have all the patterns from the slice tricks wiki page[0] shipped as a standalone package. (I'm not sure why the slices package doesn't include any of the good stuff...) Understanding those patterns requires internalizing the relationship between slices and arrays, which is important but too high of a bar for a simple, safe in-place filter. [0]: https://github.com/golang/go/wiki/SliceTricks#additional-tricks https://github.com/golang/go/wiki/SliceTricks#additional-tri...
- azth 5y agoWhat's quite sucky is that they will remain as standalone functions and not member functions, so you can't chain them (e.g. slice.Sort(...).Filter(...).Reduce(...))`. Not sure why golang is resistant to adding member functions to types.
- EdSchouten 5y agoWhy not just get a “pipe” operator added to the language instead? Many functional programming languages already have one. https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/functions/#pipelines https://docs.microsoft.com/en-us/dotnet/fsharp/language-refe... No need to alter the type system of the language, while it’s clearly a syntactical improvement you’re looking for.
- jen20 5y agoI (sadly) can't imagine that getting through the language modification process, somehow, though it certainly would solve this particular problem! If we're looking for things that Go could usefully take from functional languages I'd personally start with the much lower-hanging fruit of some guarantees about mutability of structures, though. (ps: Hi, Ed!)
- erdeibit 5y agoMy guess is that compilation time could be increased, which would let Go in the same boat as Rust or C++. I suspect every nice or must-have feature you add to a language, you must take the choice between deal with it in runtime or compilation time. Not adding features, no choice to take.
- azth 5y agoIt shouldn't affect compile times though. golang compile times arealready in a similar ballpark to Java (if not slower) for large codebases.
- aaomidi 5y agoTo be fair, I am really excited for generics. However I do think the lack of the is the major reason go is such a readable language. Not being able to hide complexity behind types of types of types really ends up making code easier to follow. I'm excited and anxious about generics in go.
- lttlrck 5y agoIsn't interface{} similar to void * - the king of hiding types?
- hellcow 5y agoYes, but it's a bit like Rust's `unsafe` in that reaching for it first is not a great practice. There's usually a better way. Using interface{} where you truly don't know and can't predict the data being sent to you is mostly something that libraries (like encoding/json) have already handled, so I don't have to interact with it much directly. I think generics are going to have the biggest impact in adding effortless type safety to all kinds of libraries, though.
- aaomidi 5y agoI really don't come across this in most projects I read and learn from.
- azth 5y agoNot sure golang is readable compared to other more expressive statically typed languages like Java and C#.
- aaomidi 5y agoDefinitely is for me and I used to only use Java for years. You can potentially test this for yourself by opening two large open source projects in each language and trying to figure out an issue from their issue tracker.
- geodel 5y ago> Sad thing is that there is always a bunch of whining in any thread about 1.18 with people complaining about how much generics are going to ruin the language. FWIW I think their complain even if not totally objective still have more weight as compared to non-users who say "I will use Go only when it has real generics/error handling/sum types/21st century features blah..blah.."
- tomjen3 5y agoThat depends on what the goal of Golang is. If they are happy with their current level of success, then sure. If not, there are a lot more non Golang programmers out there than there are current Golang programmers.
- pjmlp 5y agoSometimes there are tools that we have to use if we want to stay at current job, so it is nice when they actually update themselves into modern times, switching job everytime there is something we dislike isn't a viable long term career path.