Live data from Hacker News

GoSTL: Algorithm and datastructure library for Go similar to C++ STL

github.com

11–20 of 48 posts

Re: GoSTL: Algorithm and datastructure library for Go similar to C++ STL

#11
post #4

Earlier quoted context omitted.

what do you mean by "random urls"?

Having `import "github.com/liyue201/gostl/ds/array"` in codebase looks weird and unsafe. Like, who's liyue201 and what exactly I'm importing? Vendoring helps a bit, but it's still ugly. Same problems exist in other languages, although "import numpy as np" doesn't explicitly say that you're importing a random head from someone's master.

It's not much different from

    import com.mysql.cj.jdbc

Re: GoSTL: Algorithm and datastructure library for Go similar to C++ STL

#12
post #7

There's a lot of good work put into this. If it is intended as a tool to help port C++ code out of C++ into Go, it looks very useful. If it is intended as a tool to help Go programmers, it has made a common, but regrettably very serious mistake, that programmers make when porting code: It has precisely copied the original API, despite the fact the original API is quite unidiomatic in the new language. I don't want a…

> It has precisely copied the original API, despite the fact the original API is quite unidiomatic in the new language.

STL isn't even idiomatic in C++ ;)

Re: GoSTL: Algorithm and datastructure library for Go similar to C++ STL

#13
post #7

There's a lot of good work put into this. If it is intended as a tool to help port C++ code out of C++ into Go, it looks very useful. If it is intended as a tool to help Go programmers, it has made a common, but regrettably very serious mistake, that programmers make when porting code: It has precisely copied the original API, despite the fact the original API is quite unidiomatic in the new language. I don't want a…

This example

    func isEven(iter iterator.ConstIterator) bool {
        return iter.Value().(int)%2 == 0
    }
    ...
    algorithm.CountIf(a.Begin(), a.End(), isEven)
is certainly off-putting. It starts out with a "deque", which is basically []any (in modern Go), needs Begin and End pointers, and then even doesn't pass the actual value, but the iterator (which can be modified in the call). I'd rather see something more idiomatic like this

    CountIf(len(a), func(i int) bool {return a[i] % 2 == 0 })
As you say, it might be helpful if you're porting something that relies heavily on STL, but only if you don't understand the code, and are willing to take the risk of subtle differences between the C++ and Go implementations.

Re: GoSTL: Algorithm and datastructure library for Go similar to C++ STL

#14
post #4

Earlier quoted context omitted.

what do you mean by "random urls"?

Having `import "github.com/liyue201/gostl/ds/array"` in codebase looks weird and unsafe. Like, who's liyue201 and what exactly I'm importing? Vendoring helps a bit, but it's still ugly. Same problems exist in other languages, although "import numpy as np" doesn't explicitly say that you're importing a random head from someone's master.

> explicitly say that you're importing a random head from someone's master

You don't import HEAD from master. Do you even understand how go.mod, go.sum and the checksum database work?

Re: GoSTL: Algorithm and datastructure library for Go similar to C++ STL

#15
post #4

Earlier quoted context omitted.

what do you mean by "random urls"?

Having `import "github.com/liyue201/gostl/ds/array"` in codebase looks weird and unsafe. Like, who's liyue201 and what exactly I'm importing? Vendoring helps a bit, but it's still ugly. Same problems exist in other languages, although "import numpy as np" doesn't explicitly say that you're importing a random head from someone's master.

Frankly if it imparts that kind of concern, that is the dependency system working properly.

‘require “leftpad”’ may look safer, but is in fact not, and unless you happen to know what is in the standard library of Node.js off the top of your head, provides not so much as a clue that the library is even third party.

Re: GoSTL: Algorithm and datastructure library for Go similar to C++ STL

#16
post #7

There's a lot of good work put into this. If it is intended as a tool to help port C++ code out of C++ into Go, it looks very useful. If it is intended as a tool to help Go programmers, it has made a common, but regrettably very serious mistake, that programmers make when porting code: It has precisely copied the original API, despite the fact the original API is quite unidiomatic in the new language. I don't want a…

> It has precisely copied the original API, despite the fact the original API is quite unidiomatic in the new language. STL isn't even idiomatic in C++ ;)

I really wish someone takes the work of ditching the STL as a whole and make an unofficial “version 2” of the same standard library. I mean, IO sucks ass, std::string really sucks, containers like unordered_map are really slow (because of the pointer stability requirements), custom allocators are cumbersome, the regex library is a mess, why are string_view and span different things, yada yada. (And darn those long compile times and horrendous debug-mode performance!)

Basically, something like a more updated version of EASTL (https://github.com/electronicarts/EASTL) might be really useful.

Re: GoSTL: Algorithm and datastructure library for Go similar to C++ STL

#17
its not even close. its a wrapper around something the language doesn't support. trying to make it support something like iterators and ranges, plus its not generic is just asking for code bloat and spaghetti. we all seen libraries like this before, they fail cause the language doesn't have support for it.

Until it does, keep the source in line with current best practices.

Re: GoSTL: Algorithm and datastructure library for Go similar to C++ STL

#18
post #2

Off topic: is there still no alternative for putting random URLs directly in a source code in order to use some libs?

This is how imports work in go. You make it look like a url, but then can choose in the mod (the module) file if it is local or to keep the url. This makes it quite clean because files have the same import url even as relative paths change, so you can move files all around and the import statements can stay the same. It also has the added advantage that there is no single module repository like in npm. So any url / GitHub repo works so no module can permanently own a name.

Re: GoSTL: Algorithm and datastructure library for Go similar to C++ STL

#19
post #4

Earlier quoted context omitted.

what do you mean by "random urls"?

Having `import "github.com/liyue201/gostl/ds/array"` in codebase looks weird and unsafe. Like, who's liyue201 and what exactly I'm importing? Vendoring helps a bit, but it's still ugly. Same problems exist in other languages, although "import numpy as np" doesn't explicitly say that you're importing a random head from someone's master.

What namespacing do you envision? On the one side you don't like short names that are installed locally and on the other you seem to not like the full url noting where to retrieve the library.

Re: GoSTL: Algorithm and datastructure library for Go similar to C++ STL

#20
post #2

Off topic: is there still no alternative for putting random URLs directly in a source code in order to use some libs?

It's not random. It's what you as a developer wanted as a dependency, and it's cryptographically pinned to the exact version you wanted.
Post reply on HN