Thank you for the feedback! I took Jan Mercl's suggestion and wrote the short function to see if it is useful. It is based on C Banning's suggested code. I'm going to start using it on my projects to see if it helps.
The module is called "hind": https://github.com/TomOnTime/hind hind.S(x) works on strings. The compiler should inline this. It should be no different that "len(x)-1" (other than conveying intent better). hind.G(x) uses reflect to work on anything you pass it. It is slow but it is a good placeholder until we have generics or whatever. It is useful for when showing intent is more important than performance. Feedback on the module would be greatly appreciated! If you use the module, I'd love to know if you felt it reduced your off-by-one errors (or the potential for them). Best, Tom On Sat, Jun 13, 2020 at 1:09 PM Jan Mercl <0xj...@gmail.com> wrote: > > On Sat, Jun 13, 2020 at 5:37 PM Jake Montgomery <jake6...@gmail.com> wrote: > > > You cant really write a short 'end()' function. You have to write an end > > function for every type of slice. Or use reflection, which would make the > > function slow, and not inlined. Generics anyone? > > I haven't mentioned anything about the function being universal. IMO > in the majority of cases, it does not have to be. Why is such > limitation being inserted? > > It takes probably less time to write the "specialized" end function > than we have already spent discussing it. And that's assuming it's a > good idea to do so in the first place, which I don't really accept. > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/CAA40n-VbNBCKkbrtwG7mb4GEKmM6OBe_AetPRMG6jAsVf_ULxA%40mail.gmail.com. -- Email: t...@whatexit.org Work: tlimonce...@stackoverflow.com Blog: http://EverythingSysadmin.com/ -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAHVFxgnyZOXyui4SrDUDSjKh8OrCpu0fHBy7Z%3DOR0omwoXahbA%40mail.gmail.com.