(Re-adding list in here with Bakul's okay.)

2018-02-22 12:27 GMT-08:00 Bakul Shah <ba...@bitblocks.com>:
> On Thu, 22 Feb 2018 12:02:35 -0800 "Devon H. O'Dell" <devon.od...@gmail.com> 
> wrote:
>> Hi all,
>>
>> It's been some time since I really contributed much of anything to the
>> project (sorry!), but after 8 years, I'm finally writing Go outside of
>> the project itself (and outside of porting efforts). I was lamenting
>> to some coworkers about the lack of a comparable feature to C's
>> "malloc idiom" and they suggested I write an experience report on it.
>> I wrote the bulk of the article a month ago, but finally put in some
>> finishing touches and published.
>
> I still run FreeBSD at home and test any go programs I write
> on it as well as MacOS (and sometime on plan9)! But FreeBSD
> support seems to be falling further and further behind.

I'm aware of some strange crash, but I don't have any FreeBSD systems
anymore to investigate. Are there other areas that FreeBSD is lagging
in? (Maybe tangent should go to separate thread :))

>> For whatever it's worth (probably not much):
>> https://9vx.org/post/a-malloc-idiom-in-go/
>
> I think you are suggesting inferring types of subobjects given
> that the parent type specified in a literal. So that you can
> type
>
> func NewSet(sz int)*Set {
>         return &Set{cap: sz, members:{}}
> }
>
> Or even
>
> func NewSet(sz int)*Set {
>         return &{cap: sz, members:{}}
> }
>
> Or even
>
> func NewSet(sz int)*Set {
>         return &{sz, {}}
> }
>
> I agree. Though some people won't like the extreme brevity of
> the last form!

Yes, this is exactly the idea. I like this empty-compound-literal
form, but I agree that the last form is probably asking for trouble.
For example, if the last two members of type Set are e.g. *Foo and
map[T]T', you probably meant to allocate the map. I think compound
literals for structs should retain field names. I definitely like the
second idea where you infer the type based on the return value (after
all, it _is_ known!).

--dho

-- 
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.

Reply via email to