ShortURL
ShortURL copied to clipboard
Add Golang Version
Add Golang Version
Thanks!
There has already been an existing pull request for a Go implementation here: https://github.com/delight-im/ShortURL/pull/19
There are a few minor differences, though. Could you explain them perhaps?
For example, why does your code not make use of a Codec
which is suggested in the other implementation? Is it not necessary? And why do you buffer in a byte array first and only convert to a string at the end? Is this better for performance? Or just a personal preference?
If I can respond, as a Go newbie myself:
-
it is Not optimal to use String = string + string (like in any language), the go docs says to use a bytes buffer or in the recent version they added a Strings Builder. None of the pull requests use these methods.
-
encoders/decoders, from what I can see what is Go idiomatic, in the builtin libraries they have 2 interfaces (Encode and decode, marshall and unmarshall), and they work with bytes), everything is a []byte. https://golang.org/pkg/encoding/#pkg-overview
With my limited knowledge I would say that none of these PR are idiomatic Go.
Thanks, @bgadrian!
We now have a third candidate for the Go implementation: https://github.com/delight-im/ShortURL/pull/32
This one here is currently the shortest and simplest implementation, which is great.
It does not use a string builder, but it does not simply concatenate strings, either. Instead, it uses a byte array that acts as a buffer. Shouldn’t this be fine, @bgadrian?