Re: [go-nuts] [Go2] append

2017-08-07 Thread Jan Mercl
On Mon, Aug 7, 2017 at 9:52 PM Gert  wrote:

> Exactly, pretty sure some day if Go get used in a power plant or
something we will have a outage for bugs like this that fly under the radar
so easily passing all tooling, error checks and probably unit tests too :)

Detecting the buggy case, unfortunately, requires first to solve the
halting problem. So revisit this one afterwards ;-)

-- 

-j

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] [Go2] append

2017-08-07 Thread Gert

On Monday, August 7, 2017 at 9:39:06 PM UTC+2, Jan Mercl wrote:
>
>
> Does this code really output what you want it to output? 
> https://play.golang.org/p/DWQXtkGByv
>
> Assigning the result value of append to a different variable than its 
> first argument is completely valid, but one has to be really sure why to do 
> that. Did you mean https://play.golang.org/p/-OMw3qGYjU ?
>
>
Exactly, pretty sure some day if Go get used in a power plant or something 
we will have a outage for bugs like this that fly under the radar so easily 
passing all tooling, error checks and probably unit tests too :) 

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] [Go2] append

2017-08-07 Thread Jan Mercl
On Mon, Aug 7, 2017 at 9:23 PM Gert  wrote:

> Can append or the compiler be made to prevent or warn for bugs like this?

No. Slice is a value and append accepts s not  as its first argument.
That means the new slice value need be returned for code that uses the
resulting slice, which is the case most often seen.

> func main() {
> a := []byte("Help")
> b := append(a, []byte(" Me ")...)
> c := append(a, []byte(" Her")...)
> fmt.Println(string(a), "-", string(b), "-", string(c))
> }

Does this code really output what you want it to output?
https://play.golang.org/p/DWQXtkGByv

Assigning the result value of append to a different variable than its first
argument is completely valid, but one has to be really sure why to do that.
Did you mean https://play.golang.org/p/-OMw3qGYjU ?

-- 

-j

-- 
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.
For more options, visit https://groups.google.com/d/optout.