Re: [go-nuts] how to use an instance across functions in a package w/o global vars

2019-04-12 Thread Michael Jones
This is really about you, your taste in design, and your sensibilities for information hiding. If you have a global symbol, be it a function name or data item, then that's what it is, a global. Globals, r/w data especially, invite subtle sharing complications, can cause complexity in attempts at m

Re: [go-nuts] how to use an instance across functions in a package w/o global vars

2019-04-12 Thread alex via golang-nuts
On Thursday, April 11, 2019 at 6:20:33 AM UTC-4, Dumitru Ungureanu wrote: > > It helps a lot! Thanks. > > I now have two things to moan about. > > If I was to pass c around, I would added it to the params list. If I had > more others, I'd built a struct. But now, if somehow I lose track of who's

Re: [go-nuts] how to use an instance across functions in a package w/o global vars

2019-04-11 Thread Dumitru Ungureanu
It helps a lot! Thanks. I now have two things to moan about. If I was to pass c around, I would added it to the params list. If I had more others, I'd built a struct. But now, if somehow I lose track of who's passing what and where, hard times debugging ahead. Having them declared at package l

Re: [go-nuts] how to use an instance across functions in a package w/o global vars

2019-04-11 Thread Jan Mercl
On Thu, Apr 11, 2019 at 11:56 AM Dumitru Ungureanu wrote: > > Secondly, as far as my knowledge goes: > > your example is declaring the function in place, it doesn't pass the > variable around to another function The `w` variable is visible in the closure. Closure is a function + closed over var

Re: [go-nuts] how to use an instance across functions in a package w/o global vars

2019-04-11 Thread Dumitru Ungureanu
First off, thank you for the time Jan. Secondly, as far as my knowledge goes: - your example is declaring the function in place, it doesn't pass the variable around to another function, i.e. goConect - my code evolved , so now, if I use a init func then it's off to init passing the

Re: [go-nuts] how to use an instance across functions in a package w/o global vars

2019-04-11 Thread Jan Mercl
On Wed, Apr 10, 2019 at 7:23 PM Dumitru Ungureanu wrote: > > In this particular case, w.DefineFunction Api does not acomodate such a > passing. Please explain why and/or what do you mean by that as I don't see where/what the problem is. > Reason I asked in the first place. Dependency injection

Re: [go-nuts] how to use an instance across functions in a package w/o global vars

2019-04-10 Thread Dumitru Ungureanu
In this particular case, w.DefineFunction Api does not acomodate such a passing. Reason I asked in the first place. Dependency injection of what sort can be used here... -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this g

Re: [go-nuts] how to use an instance across functions in a package w/o global vars

2019-04-10 Thread Jan Mercl
On Wed, Apr 10, 2019 at 2:42 PM Dumitru Ungureanu wrote: The alternative is to pass `w` around as a function argument. For that it will be necessary to create/initialize `w` in main or in a function call made from main. PS: Go has no global scope. The closest is universe scope, but programs cann

[go-nuts] how to use an instance across functions in a package w/o global vars

2019-04-10 Thread Dumitru Ungureanu
I have this. Enter code here... package main import ( "fmt" "log" "github.com/sciter-sdk/go-sciter" "github.com/sciter-sdk/go-sciter/window" ) var w *window.Window func init() { var err error w, err = window.New(sciter.DefaultWindowCreateFlag, sciter.DefaultRect) i