[go-nuts] Re: Calling Once (in the code)

2017-08-22 Thread dc0d
Just for the record, today I really needed this so here is this - primitive pkg, yet works for this purpose (mostly, and opinionated). -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this

[go-nuts] Re: Calling Once (in the code)

2017-08-11 Thread dc0d
Well said! Still I prefer functions to comments, when possible. As it's been said, code never lies, comments sometimes do. And a boom is simpler to understand (for me). Functions go boom; comments do not. On Saturday, August 12, 2017 at 1:48:05 AM UTC+4:30, Egon wrote: > > There are no good

[go-nuts] Re: Calling Once (in the code)

2017-08-11 Thread dc0d
Thanks for suggesting guru. I'll try it. If there is a convention for naming, it makes code more clear, otherwise, yes, it makes code more unclear - in my experience. In times it's not an easy task. But having a long function too, is not a good thing (IMHO). On Friday, August 11, 2017 at

[go-nuts] Re: Calling Once (in the code)

2017-08-11 Thread Egon
Note, this can fragment the code and make it harder to understand... (http://number-none.com/blow/john_carmack_on_inlined_code.html) As for the tool: guru can give you the callers of a function, so you might be able to derive something from it. + Egon On Friday, 11 August 2017 10:39:16

[go-nuts] Re: Calling Once (in the code)

2017-08-11 Thread dc0d
As he cleared up in his later quotes and tweets it's about replacing comments with functions. IMHO this way comments will turn into active (code) specifications and would help greatly specially in a statically types languages. They might even make writing more clear tests easier. But (IMHO)

[go-nuts] Re: Calling Once (in the code)

2017-08-11 Thread Henry
I am not aware of any such tools exist. You may need to roll out your own. However, don't you think that the purpose of Fowler,et al. proposing such guideline is to encourage function reuse? On Friday, August 11, 2017 at 2:39:16 PM UTC+7, dc0d wrote: > "When you feel the need to write a

[go-nuts] Re: Calling Once (in the code)

2017-08-11 Thread dc0d
"When you feel the need to write a comment, first try to refactor the code so that any comment becomes superfluous." - Martin Fowler, Kent Beck, John Brant, William Opdyke, and Don Roberts (1999) Refactoring: Improving the Design of Existing Code. Addison-Wesley. Based on this practice, the

[go-nuts] Re: Calling Once (in the code)

2017-08-10 Thread Henry
I don't fully understand the problem, but if you need a quick and dirty way to ensure a function is called exactly once, you can always use a global variable, have the function checks the variable when the function is called. If the function is called the first time, it will set the variable.