ShortURL icon indicating copy to clipboard operation
ShortURL copied to clipboard

Add Golang Version

Open ddbullfrog opened this issue 7 years ago • 4 comments

Add Golang Version

ddbullfrog avatar Jul 13 '17 04:07 ddbullfrog

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?

ocram avatar Jul 14 '17 12:07 ocram

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.

bgadrian avatar Jun 14 '18 08:06 bgadrian

Thanks, @bgadrian!

We now have a third candidate for the Go implementation: https://github.com/delight-im/ShortURL/pull/32

ocram avatar Jun 14 '18 19:06 ocram

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?

ocram avatar Jun 14 '18 19:06 ocram