Earlier quoted context omitted.
I think the way to say it is that Go requires you to declare every allocation, but allows over-declaration in the case of copying. > := [...] an error to use it when it doesn't allocate. > := [...] not allocating if you have a variable on the left that is already allocated, This appears to be a contradiction. I suppose you mean something like "error to use it when there's no possible context where that line of code w…
a, b := 1, 2 If either a or b (but not both) were already defined, this won't re-define (and reallocate space for) them.
Proposal: expression to create pointer to simple types
41–50 of 110 posts
Re: Proposal: expression to create pointer to simple types
#42I was surprised that you can't apply & to any value. I thought it was gut an ordinary operator and it would ensure that the value it was applied to would be put onto the heap. s := S{} sp := &s // Works _ = sp _ = &S{} // Works i := int32(1) ip := &i // Works! _ = ip _ = &int32(1) // Doesn't work! https://play.golang.org/p/fdgvbEwJWgh It seems odd that you can't apply & to a function's return value. I think the best…
>It seems odd that you can't apply & to a function's return value. Offtopic: Surprisingly I was asking myself this question but if possible in C... Is it?
In C:
int *f() {
int x = 0;
return &x;
}
It works, but it is wrong. The C type system isn't smart enough to realize the lifetime of x in this case. It is not allowed for a function return because C does have the concept of a temporary value so it is disallowed because it is basically always incorrect to do so.Note that C++ does somewhat allow this with lifetime extension. It is somewhat like what I expected Go to do, except because lifetime extension only extends to the enclosing block it is more of a footgun. With a dynamic tracing garbage collector like Go it not a footgun.
Re: Proposal: expression to create pointer to simple types
#43I was surprised that you can't apply & to any value. I thought it was gut an ordinary operator and it would ensure that the value it was applied to would be put onto the heap. s := S{} sp := &s // Works _ = sp _ = &S{} // Works i := int32(1) ip := &i // Works! _ = ip _ = &int32(1) // Doesn't work! https://play.golang.org/p/fdgvbEwJWgh It seems odd that you can't apply & to a function's return value. I think the best…
One of the things I think the Go tutorials don't make a big enough deal of is that Go is relatively explicit about allocations. := isn't just a shortcut for declaring variables, it's an allocation, and an error to use it when it doesn't allocate. var X Sometype isn't just a declaration, it's an allocation. := kinda smears the clarity by not allocating if you have a variable on the left that is already allocated, and…
temp := someFunc()
p := &temp
is any less explicit than p := &someFunc()
It seems that the `&` is still required to put something onto the heap.Re: Proposal: expression to create pointer to simple types
#44Earlier quoted context omitted.
One of the things I think the Go tutorials don't make a big enough deal of is that Go is relatively explicit about allocations. := isn't just a shortcut for declaring variables, it's an allocation, and an error to use it when it doesn't allocate. var X Sometype isn't just a declaration, it's an allocation. := kinda smears the clarity by not allocating if you have a variable on the left that is already allocated, and…
I’m not sure I understood this correctly. Does the following allocate (on the heap)? foo := MyStruct{}
foo := MyStruct{} // Could live on the stack
_ := &foo // Oh, now foo must live on the heap.Re: Proposal: expression to create pointer to simple types
#45How exemplary that he filled in the full template questionnaire for language changes, including questions such as "Would you consider yourself a novice, intermediate, or experienced Go programmer?" (he replied "I have some experience").
And the General who responds, "Right. Well done."
Re: Proposal: expression to create pointer to simple types
#46Earlier quoted context omitted.
Please don't use HN comments for posting low-quality jokes, even if (perhaps "especially if") they're considered acceptable/appropriate for other communities.
Can you point to some specific guidelines used to judge low-quality vs high-quality jokes for HN purposes? Or are we suppose to go by your personal and subjective opinion of low-quality vs high-quality comedy material?
Re: Proposal: expression to create pointer to simple types
#47Re: Proposal: expression to create pointer to simple types
#48Re: Proposal: expression to create pointer to simple types
#49Earlier quoted context omitted.
Can you point to some specific guidelines used to judge low-quality vs high-quality jokes for HN purposes? Or are we suppose to go by your personal and subjective opinion of low-quality vs high-quality comedy material?
In this case it seems pretty clear. If you're not sure you could try reading more posts before posting. You should be able to pick up the general vibe/tone.
Re: Proposal: expression to create pointer to simple types
#50Earlier quoted context omitted.
I found it more amusing that he listed 8 languages that he has experience with and then went out of his way to exclude JavaScript.
When you know JavaScript enough to be able to say that you don't know JavaScript.