Re: [go-nuts] Parsing XML with namespaces in golang

2017-07-24 Thread Konstantin Khomoutov
On Mon, Jul 24, 2017 at 07:44:33PM -0700, emartinez1...@gmail.com wrote:

[...]
>>> So I'm trying to unmarshal an XML with namespaces in go but i just can't 
>>> find the right parser to do so. 
[...]
>> type Root struct { 
>> XMLName struct{} `xml:"urn:MNResultsResults MNResultsResults"` 
>> Cpcs []float64 `xml:"urn:MNResultsResults 
>> ssResultSet>ssResult>cpc"` 
[...]
>> const s = ` 
>>  
>>
>>  
>>   42.0 
[...]
> Is there any reason to declare the namespace 2 times?
> At first we declare XMLName (which doesn't seem to be used)

No, it is used: please read carefully the documentation on the
encoding/xml.Unmarshal (run `go doc xml.Unmarshal` or see [1]).
To cite the unmarshaling rules from there:

| * If the XMLName field has an associated tag of the form
|   "name" or "namespace-URL name", the XML element must have the
|   given name (and, optionally, name space) or else Unmarshal
|   returns an error.

So the "XMLName" of a field is special and is served (among other
purposes, if needed) to tell the decoder what's the name -- possibly
namespaced -- of the XML element which is to be represented by the
data type containing that field.

> and then we use urn:MNResultsResults again at CPC []

You're correct on this point: the second namespace is not needed.
Again, to cite the doc:

| * If the XML element contains a sub-element whose name matches
|   the prefix of a tag formatted as "a" or "a>b>c", unmarshal
|   will descend into the XML structure looking for elements with the
|   given names, and will map the innermost elements to that struct
|   field. A tag starting with ">" is equivalent to one starting
|   with the field name followed by ">".

>From this definition, it's not clear, whether the full (namespaced)
names of the elements are meant or local, or both are recognized --
that is, "XML-namespace name>Another-XML-namespace another-name" is
understood, too. I have assumed the latter, but I'm now not sure.

Seems to work both ways on playground, so I'd drop the NS from the tag of
the Cpc field.

1. https://golang.org/pkg/encoding/xml/#Unmarshal

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


[go-nuts] Correct way to track each individual goroutine

2017-07-24 Thread Tamás Gulácsi
See http://godoc.org/go4.org/syncutil/singleflight for another solution.
If you key by file name/id, and the function compresses when needed and then 
returns the (de)compressed file, it'll solve your problem.

-- 
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] Re: What is pprof overhead like when gathering a profile?

2017-07-24 Thread 'Jaana Burcu Dogan' via golang-nuts
What we do is to periodically turn on profiling for X seconds, collect some
data and turn it off again. We do it at every once a while periodically. We
target a single or a group of instances in a large group.

On Mon, Jul 24, 2017 at 6:11 PM, Dave Cheney  wrote:

> Another option is to profile a % of requests. In the past I've done that
> by enabling profiling on a set % of application servers then extrapolating
> from there.
>
>
> On Tuesday, 25 July 2017 10:55:42 UTC+10, Jaana Burcu Dogan wrote:
>>
>> It would be very speculative to provide reference numbers without
>> actually seeing the specific program. You can benchmark the
>> latency/throughput with the CPU profiler on to see a realistic estimate.
>> FWIW, memory profiling, goroutine, thread create profiles are always on. At
>> Google, we continuously profile Go production services and it is safe to do
>> so.
>>
>>
>> On Monday, July 24, 2017 at 5:44:10 PM UTC-7, nat...@honeycomb.io wrote:
>>>
>>> Hello,
>>>
>>> I am curious what the performance impact of running pprof to collect
>>> information about CPU or memory usage is. Is it like strace where there
>>> could be a massive slowdown (up to 100x) or is it lower overhead, i.e.,
>>> safe to use in production? The article here -
>>> http://artem.krylysov.com/blog/2017/03/13/profiling-and-op
>>> timizing-go-web-applications/ - suggests that "one of the biggest pprof
>>> advantages is that it has low overhead and can be used in a production
>>> environment on a live traffic without any noticeable performance
>>> penalties". Is that accurate?
>>>
>>> Thanks!
>>>
>>> Nathan
>>>
>> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/golang-nuts/e6lB8ENbIw8/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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] Why does this program carry test flags once compiled?

2017-07-24 Thread Rob Pike
I haven't got the context but I agree that importing the testing package
outside of a test is a very bad idea. If I could, I would disallow it
altogether.

-rob

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


[go-nuts] Correct way to track each individual goroutine

2017-07-24 Thread Glen Huang
I'm writing an image uploading server, and by posting to an url, users can 
upload an image, and then from another url, they can retrieve it back.

The tricky part is that I want to compress the image after uploading.

My current design is that uploading is finished as soon as the image is 
uploaded to the server, after which I spawn a goroutine to exec a command 
to do the compression. When the user requests the image , I'll wait for the 
command to finish if it still on going, after which I send the compressed 
image back.

I have two questions:

1. Does the design sound right to you?
2. How do I tell if the image still being compressed?

For #2, I currently use syncmap from 1.9. I store the file name as the key, 
and a wait group as the value. The wait group starts before I run the 
compression command, and is considered done when the command finishes. When 
an image request comes in, I check if the corresponding key exist, if not, 
it means the image is already compressed, so I just send it. If so, I wait 
on the wait group. Do you think that's the correct way of doing it?

The part that bothers me is that this seem to be a common problem which is 
to track the progress of each individual goroutine. Having to rely on a 
feature that just came out worries me a little bit given the age of go.

Do you think there is a more direct way to implement it?

Thanks.

-- 
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] Parsing XML with namespaces in golang

2017-07-24 Thread Tamás Gulácsi
No, you don't declare the namespace, but specify that which namespace the tag 
you're searching for is in. 

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


[go-nuts] Re: How to determine when to actually use goroutines?

2017-07-24 Thread Glen Huang
I just watched the presentation, it's a good one. Thanks for sharing it.

The summary seems more towards how to write goroutines correctly, but it 
contains good advices and the general message is clear for me now, make 
things simple and do things sequentially when possible.

On Tuesday, July 25, 2017 at 8:48:59 AM UTC+8, Dave Cheney wrote:
>
> This presentation, or more accurately, the summary at the end, may be of 
> interest to you.
>
> https://dave.cheney.net/paste/concurrency-made-easy.pdf
>
> A recording of this presentation at GopherCon Signapore is also available 
> by searching for those keywords.
>
> On Tuesday, 25 July 2017 01:34:30 UTC+10, Glen Huang wrote:
>>
>> Hi,
>>
>> I'm still pretty new to go. Hope this question isn't too stupid.
>>
>> I'm writing a restful API server, and in order to send a response, I need 
>> to query a db to get its content type and then send the actually file that 
>> lives on the file system. Now the question is, should I put db.QueryRow and 
>> os.Open each in a goroutine to make them concurrent?
>>
>> And a more general question is, when using APIs from the stdlib or 
>> 3rd-party packages, how do I determine whether to wrap them in goroutines 
>> when more than one of them need to happen sequentially and the order 
>> actually doesn't matter? Should I manually time the API executions to make 
>> the call? Should I writing things sequentially by default and only when 
>> hitting performance problems do I profile the program and wrap calls in 
>> goroutine?
>>
>> How do you decide when to use goroutines?
>>
>

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


[go-nuts] Re: How to determine when to actually use goroutines?

2017-07-24 Thread Glen Huang

> Why make them concurrent if you need to know to know the end result of 
the DB call *before* opening the file?

I actually don't need to know the result of the DB call before opening the 
file, only before sending the file as a response.

> only use goroutines when you know for a fact that you have an issue which 
needs solving via concurrency

Thanks, that's a good advice. So the question now comes to how to easily 
benchmark the written code. I haven't done anything like that, but from 
docs it seems I should use the benchmark functions from the testing package?

On Tuesday, July 25, 2017 at 8:44:10 AM UTC+8, nat...@honeycomb.io wrote:
>
> > I need to query a db to get its content type and then send the actually 
> file that lives on the file system. Now the question is, should I put 
> db.QueryRow and os.Open each in a goroutine to make them concurrent?
>
> Why make them concurrent if you need to know to know the end result of the 
> DB call *before* opening the file?
>
> > Should I writing things sequentially by default and only when hitting 
> performance problems do I profile the program and wrap calls in goroutine?
>
> Personally I would say yes, only use goroutines when you know for a fact 
> that you have an issue which needs solving via concurrency, e.g., IO-bound 
> workloads. While it's nice to have goroutines and channels within easy 
> reach, they do complicate program structure and can cause data races if not 
> used properly. Unless your app is problematically slow, design everything 
> to be as simple as possible. People tend to assume things like "DB queries 
> are slow" or "filesystem access is slow", but that doesn't mean doing 
> either of those things will cause issues, and even if they do, solutions 
> such as adding indexes to problematic fields or doing caching might help A 
> LOT more than trying to be more concurrent will.
>
>
> On Monday, July 24, 2017 at 8:34:30 AM UTC-7, Glen Huang wrote:
>>
>> Hi,
>>
>> I'm still pretty new to go. Hope this question isn't too stupid.
>>
>> I'm writing a restful API server, and in order to send a response, I need 
>> to query a db to get its content type and then send the actually file that 
>> lives on the file system. Now the question is, should I put db.QueryRow and 
>> os.Open each in a goroutine to make them concurrent?
>>
>> And a more general question is, when using APIs from the stdlib or 
>> 3rd-party packages, how do I determine whether to wrap them in goroutines 
>> when more than one of them need to happen sequentially and the order 
>> actually doesn't matter? Should I manually time the API executions to make 
>> the call? Should I writing things sequentially by default and only when 
>> hitting performance problems do I profile the program and wrap calls in 
>> goroutine?
>>
>> How do you decide when to use goroutines?
>>
>

-- 
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] Why does this program carry test flags once compiled?

2017-07-24 Thread Chris Broadfoot
One way around the flag problem is to accept an interface, instead of using
testing.T.

Watch Mitchell Hashimoto's talk from GopherCon from about 39m30s:
https://youtu.be/8hQG7QlcLBk?t=2368

http://github.com/mitchellh/go-testing-interface

On Mon, Jul 24, 2017 at 1:44 AM, roger peppe  wrote:

>
>
> On 24 July 2017 at 09:12, Howard Guo  wrote:
>
>> Thanks Nigel! I should definitely consider improving the test case.
>>
>> Go compiler appears to automatically places test flags into executable
>> whenever "testing" package is included - no matter the function using
>> "testing" package is dead code or otherwise. So here's a bug report for go:
>> https://github.com/golang/go/issues/21141
>>
>
> Although this could be considered a bug, it's not one that can be fixed,
> because people rely on this behaviour of the testing package.
>
> Consider it a warning not to include testing dependencies in production
> code.
>
>
>>
>> Kind regards,
>> Howard
>>
>> On Sunday, 23 July 2017 06:54:28 UTC+2, Nigel Tao wrote:
>>>
>>> On Sat, Jul 22, 2017 at 7:08 PM, Howard Guo  wrote:
>>> > https://github.com/HouzuoGuo/laitos
>>>
>>> It's tangential to your question, but out of curiousity, I skimmed the
>>> source code. In things like func TestUDPServer in
>>> https://github.com/HouzuoGuo/laitos/blob/master/frontend/plain/udp.go,
>>> you say:
>>>
>>> var stoppedNormally bool
>>> go func() {
>>>   etc
>>>   stoppedNormally = true
>>> }()
>>> etc
>>> server.Stop()
>>> time.Sleep(1 * time.Second)
>>> if !stoppedNormally { etc }
>>>
>>> This is an example of incorrect synchronization as per
>>> https://golang.org/ref/mem#tmp_10
>>>
>>> There may be other such races in your code. I didn't do an exhaustive
>>> review. It may be worthwhile to run your test suite under the race
>>> detector.
>>>
>> --
>> 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.
>>
>
> --
> 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.
>

-- 
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] Parsing XML with namespaces in golang

2017-07-24 Thread emartinez1847
Thanks!.

 XMLName struct{} `xml:"urn:MNResultsResults MNResultsResults"` 
Cpcs []float64 `xml:"urn:MNResultsResults 
ssResultSet>ssResult>cpc"` 

Is there any reason to declare the namespace 2 times? At first we declare 
XMLName (which doesn't seem to be used) and then we use 
urn:MNResultsResults again at CPC []

El lunes, 24 de julio de 2017, 5:04:58 (UTC-3), Konstantin Khomoutov 
escribió:
>
> On Sun, Jul 23, 2017 at 01:51:41PM -0700, emarti...@gmail.com 
>  wrote: 
>
> Hi! 
>
> > So I'm trying to unmarshal an XML with namespaces in go but i just can't 
> > find the right parser to do so. 
> [...] 
>
> This (elided for brewity) 
>
> 8< 
> package main 
>
> import ( 
> "fmt" 
> "encoding/xml" 
> ) 
>
> type Root struct { 
> XMLName struct{} `xml:"urn:MNResultsResults MNResultsResults"` 
> Cpcs []float64 `xml:"urn:MNResultsResults 
> ssResultSet>ssResult>cpc"` 
> } 
>
> const s = ` 
>  
>
>  
>   42.0 
>  
>  
> 12.333 
>  
>
> ` 
>
> func main() { 
> r := Root{} 
> err := xml.Unmarshal([]byte(s), &r) 
> if err != nil { 
> panic(err) 
> } 
> fmt.Printf("%+v", r) 
> } 
> 8< 
>
> works by printing 
>
>   {XMLName:{} Cpcs:[42 12.333]} 
>
> (Playground link: https://play.golang.org/p/RehqytlFQ9). 
>
> The chief idea is that the namespace must be separated from the element 
> or attribute name it qualifies with a space character. 
>
>

-- 
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] Why default stack size is 1gb?

2017-07-24 Thread 张李阳
my mistake, i mean the *max* stack size is 1gb which i saw it here
, not the default stack
size. Sorry for confusing

On Tue, Jul 25, 2017 at 7:33 AM Florin Pățan  wrote:

> Iirc the default stack size is 2 or 4 kb not 1 gb. Where did you found the
> reference?
>
> --
> 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.
>

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


[go-nuts] Re: What is pprof overhead like when gathering a profile?

2017-07-24 Thread Dave Cheney
Another option is to profile a % of requests. In the past I've done that by 
enabling profiling on a set % of application servers then extrapolating 
from there.

On Tuesday, 25 July 2017 10:55:42 UTC+10, Jaana Burcu Dogan wrote:
>
> It would be very speculative to provide reference numbers without actually 
> seeing the specific program. You can benchmark the latency/throughput with 
> the CPU profiler on to see a realistic estimate. FWIW, memory profiling, 
> goroutine, thread create profiles are always on. At Google, we continuously 
> profile Go production services and it is safe to do so.
>
>
> On Monday, July 24, 2017 at 5:44:10 PM UTC-7, nat...@honeycomb.io wrote:
>>
>> Hello,
>>
>> I am curious what the performance impact of running pprof to collect 
>> information about CPU or memory usage is. Is it like strace where there 
>> could be a massive slowdown (up to 100x) or is it lower overhead, i.e., 
>> safe to use in production? The article here - 
>> http://artem.krylysov.com/blog/2017/03/13/profiling-and-optimizing-go-web-applications/
>>  
>> - suggests that "one of the biggest pprof advantages is that it has low 
>> overhead and can be used in a production environment on a live traffic 
>> without any noticeable performance penalties". Is that accurate?
>>
>> Thanks!
>>
>> Nathan
>>
>

-- 
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] Re: Code Review - Applying functions on custom types

2017-07-24 Thread roger peppe
On 24 July 2017 at 23:21, Sofiane Cherchalli  wrote:

> Yes, I'm trying to stream CSV values encoded in strings. A schema defines
> a type of each value, so I have to parse values to verify they match the
> type. Once validation is done, I apply functions on each value.
>

Is the schema dynamically or statically specified? That is, do you know
in advance what the schema is, or do are you required to write
general code that deals with many possible schemas?

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


[go-nuts] Re: What is pprof overhead like when gathering a profile?

2017-07-24 Thread jbd via golang-nuts
It would be very speculative to provide reference numbers without actually 
seeing the specific program. You can benchmark the latency/throughput with 
the CPU profiler on to see a realistic estimate. FWIW, memory profiling, 
goroutine, thread create profiles are always on. At Google, we continuously 
profile Go production services and it is safe to do so.


On Monday, July 24, 2017 at 5:44:10 PM UTC-7, nat...@honeycomb.io wrote:
>
> Hello,
>
> I am curious what the performance impact of running pprof to collect 
> information about CPU or memory usage is. Is it like strace where there 
> could be a massive slowdown (up to 100x) or is it lower overhead, i.e., 
> safe to use in production? The article here - 
> http://artem.krylysov.com/blog/2017/03/13/profiling-and-optimizing-go-web-applications/
>  
> - suggests that "one of the biggest pprof advantages is that it has low 
> overhead and can be used in a production environment on a live traffic 
> without any noticeable performance penalties". Is that accurate?
>
> Thanks!
>
> Nathan
>

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


[go-nuts] Re: What is pprof overhead like when gathering a profile?

2017-07-24 Thread Dave Cheney
Here's an entirely unscientific method to determine the overhead of 
profiling. The Go distribution contains a set of basic benchmarks, one of 
which is a loopback based http client server benchmark. Running the 
benchmark with and without profiling gives a rough ballpark for the 
overhead of profiling.

lucky(~/go/test/bench/go1) % go test -run=XXX -bench=HTTPClientServer
goos: linux
goarch: amd64
BenchmarkHTTPClientServer-42 84296 ns/op
PASS
ok  _/home/dfc/go/test/bench/go14.274s
lucky(~/go/test/bench/go1) % go test -run=XXX -bench=HTTPClientServer 
-cpuprofile=/tmp/c.p
goos: linux
goarch: amd64
BenchmarkHTTPClientServer-42 85316 ns/op
PASS
ok  _/home/dfc/go/test/bench/go14.402s

You could use this to experiment with the other kinds of profiles; memory, 
block, trace, etc.

If you wanted to go a step further you could adding profiling to your own 
project with my github.com/pkg/profile package then compare the results of 
a http load test with and without profiling enabled.

Thanks

Dave

On Tuesday, 25 July 2017 10:44:10 UTC+10, nat...@honeycomb.io wrote:
>
> Hello,
>
> I am curious what the performance impact of running pprof to collect 
> information about CPU or memory usage is. Is it like strace where there 
> could be a massive slowdown (up to 100x) or is it lower overhead, i.e., 
> safe to use in production? The article here - 
> http://artem.krylysov.com/blog/2017/03/13/profiling-and-optimizing-go-web-applications/
>  
> - suggests that "one of the biggest pprof advantages is that it has low 
> overhead and can be used in a production environment on a live traffic 
> without any noticeable performance penalties". Is that accurate?
>
> Thanks!
>
> Nathan
>

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


[go-nuts] Re: How to determine when to actually use goroutines?

2017-07-24 Thread Dave Cheney
This presentation, or more accurately, the summary at the end, may be of 
interest to you.

https://dave.cheney.net/paste/concurrency-made-easy.pdf

A recording of this presentation at GopherCon Signapore is also available 
by searching for those keywords.

On Tuesday, 25 July 2017 01:34:30 UTC+10, Glen Huang wrote:
>
> Hi,
>
> I'm still pretty new to go. Hope this question isn't too stupid.
>
> I'm writing a restful API server, and in order to send a response, I need 
> to query a db to get its content type and then send the actually file that 
> lives on the file system. Now the question is, should I put db.QueryRow and 
> os.Open each in a goroutine to make them concurrent?
>
> And a more general question is, when using APIs from the stdlib or 
> 3rd-party packages, how do I determine whether to wrap them in goroutines 
> when more than one of them need to happen sequentially and the order 
> actually doesn't matter? Should I manually time the API executions to make 
> the call? Should I writing things sequentially by default and only when 
> hitting performance problems do I profile the program and wrap calls in 
> goroutine?
>
> How do you decide when to use goroutines?
>

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


[go-nuts] What is pprof overhead like when gathering a profile?

2017-07-24 Thread nathan
Hello,

I am curious what the performance impact of running pprof to collect 
information about CPU or memory usage is. Is it like strace where there 
could be a massive slowdown (up to 100x) or is it lower overhead, i.e., 
safe to use in production? The article here 
- 
http://artem.krylysov.com/blog/2017/03/13/profiling-and-optimizing-go-web-applications/
 
- suggests that "one of the biggest pprof advantages is that it has low 
overhead and can be used in a production environment on a live traffic 
without any noticeable performance penalties". Is that accurate?

Thanks!

Nathan

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


[go-nuts] Re: How to determine when to actually use goroutines?

2017-07-24 Thread nathan
> I need to query a db to get its content type and then send the actually 
file that lives on the file system. Now the question is, should I put 
db.QueryRow and os.Open each in a goroutine to make them concurrent?

Why make them concurrent if you need to know to know the end result of the 
DB call *before* opening the file?

> Should I writing things sequentially by default and only when hitting 
performance problems do I profile the program and wrap calls in goroutine?

Personally I would say yes, only use goroutines when you know for a fact 
that you have an issue which needs solving via concurrency, e.g., IO-bound 
workloads. While it's nice to have goroutines and channels within easy 
reach, they do complicate program structure and can cause data races if not 
used properly. Unless your app is problematically slow, design everything 
to be as simple as possible. People tend to assume things like "DB queries 
are slow" or "filesystem access is slow", but that doesn't mean doing 
either of those things will cause issues, and even if they do, solutions 
such as adding indexes to problematic fields or doing caching might help A 
LOT more than trying to be more concurrent will.


On Monday, July 24, 2017 at 8:34:30 AM UTC-7, Glen Huang wrote:
>
> Hi,
>
> I'm still pretty new to go. Hope this question isn't too stupid.
>
> I'm writing a restful API server, and in order to send a response, I need 
> to query a db to get its content type and then send the actually file that 
> lives on the file system. Now the question is, should I put db.QueryRow and 
> os.Open each in a goroutine to make them concurrent?
>
> And a more general question is, when using APIs from the stdlib or 
> 3rd-party packages, how do I determine whether to wrap them in goroutines 
> when more than one of them need to happen sequentially and the order 
> actually doesn't matter? Should I manually time the API executions to make 
> the call? Should I writing things sequentially by default and only when 
> hitting performance problems do I profile the program and wrap calls in 
> goroutine?
>
> How do you decide when to use goroutines?
>

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


[go-nuts] 10x latency spikes during GC alloc assist phase

2017-07-24 Thread stbaker


Hi,

We are experiencing a problem that I believe may be related to issue 14812 
 but I wanted to ask here before 
adding to that case or filing a new issue. Of course, we’d also greatly 
appreciate any advice about how to make our program performant.

Here is what we observe: at Laserlike one of our core user-facing services 
(the “leaf”) typically responds to a particular rpc in <400ms.  During GC 
we see spikes in latency to >5s on some simple requests.  The stop the 
world periods are short, so the GC spikes appear to happen at other times.

We have been unable to replicate this in a simple program, but we did run 
our code in a test mode that repros it.  In our test environment the server 
loads ~10 GB of persistent data (never deleted so doesn’t really need to be 
GCed), and we ask for 8 processors.  We are running go version 1.8.3 on 
kubernetes on GCP machine of type n1-highmem-64.  To create the problem we 
send the server a single request with >500 tasks..


This google drive folder has leaf-logs-full.redacted.txt as well as other 
performance tooling files 
.
 
 A snippet from that log here shows normal query responses and timing:

I0719 22:50:22.467367 leaf.go:363] Worker #5 done search for '[redacted]', 
took 0.013 seconds

I0719 22:50:22.467406 leaf.go:225] Worker #5 starting search for 
'[redacted]'

I0719 22:50:22.467486 leaf.go:363] Worker #6 done search for '[redacted]', 
took 0.001 seconds

I0719 22:50:22.467520 leaf.go:225] Worker #6 starting search for 
'[redacted]'

I0719 22:50:22.468050 leaf.go:363] Worker #9 done search for '[redacted]', 
took 0.005 seconds


We have observed that if a GC cycle happens to start while serving traffic 
(which is often) AND there is a large amount of time spent in assist, then 
our serving latency skyrockets by 10x.  In the log the slowdown commences 
roughly when pacer assist starts at I0719 22:50:31.079283 and then reverts 
to normal latencies shortly after the gc cycle completes at I0719 
22:50:36.806085.

Below I copy parts of the log where we see latencies of up to 729ms on 
tasks.  I also bold the line that shows 32929ms spent on alloc gc assist.

We have captured an attached cpu profile during this time which seems to 
confirm a large amount of time spent in runtime.gcAssistAlloc.func1.


Pardon our ignorance about GC in golang, but our hypothesis about what may 
be going wrong is that our large in-memory data structures are causing gc 
to often go into assist mode, and that for reasons we don’t understand 
malloc becomes expensive in that mode.  Since we also create ~100k new data 
objects when processing user requests, we are guessing those allocs become 
very slow.  Another piece of evidence for this hypothesis is that we have 
another (prototype) implementation of this kind of service that makes more 
use of object pools and doesn’t seem to have as much of slowdown during GC.

Note on large in-memory data-structures:

The principal data structures can be thought of as:

Map[uint64][]byte (about 10M map entries, the slice lengths between 5K to 
50K) (around ~10G total memory usage) 

Map[uint64][]uint64 (about 50M map entries, the slice lengths vary between 
10 and 100K, in a zipfian distribution, about 3G total memory usage)

These data structures mostly stay as is over the life of the program.

We are trying to figure out how to solve this so would appreciate any 
advice. An engineer on our team wrote up the following ideas, none of which 
are that great:

   1. 
   
   Figure out a simple way to prevent our goroutines slowing down during 
   GC.  I had some hopes LockOSThread() could be made to work, but it didn't 
   seem to help in my experiments.  I'm not ruling this solution out entirely, 
   but if it's the write barriers that are the main problem, I don't have much 
   hope.
   2. 
   
   Run at least 2 replicas of all our servers.  Manage their GC cycles 
   ourselves, synchronized so that at most one replica is in GC at any given 
   time.  The clients should either send all requests to both replicas (and 
   cancel when one replies), or use some more complicated Kubernetes and 
   client logic so a GCing replica is never sent requests.  This is the 
   simplest solution that is likely to work, and doesn't require us to change 
   our habits too much.  It just costs more. :)
   3. 
   
   Refactor our current servers and program future servers with the 
   explicit goal of reducing GC burden.  Give our servers more memory and 
   increase SetGCPercent() so that Garbage Collection happens less frequently. 
Use simpler data structures with fewer pointers to reduce the length of 
   time the GC cycle lasts when it does run.  This isn't a perfect solution, 
   because the GC will still hit us on occasion, but it reduces the harm.
   4. 
   
   Throw out much of the convenience of Go and write our own 
   all

[go-nuts] delve

2017-07-24 Thread rob

Hi.  I need help with using delve.  Where should I direct my questions?

I don't know where else to ask, so I'm asking here first.

--rob solomon

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


[go-nuts] Ann: pgx v3 - PostgreSQL Driver and Toolkit

2017-07-24 Thread Jack Christensen
pgx is a pure Go driver and toolkit for PostgreSQL. pgx is different 
from other drivers such as [pq](http://godoc.org/github.com/lib/pq) 
because, while it can operate as a database/sql compatible driver, pgx 
is also usable directly. It offers a native interface similar to 
database/sql that offers better performance and more features.


https://github.com/jackc/pgx

## Features

pgx supports many additional features beyond what is available through 
database/sql.


* Support for approximately 60 different PostgreSQL types
* Batch queries
* Single-round trip query mode
* Full TLS connection control
* Binary format support for custom types (can be much faster)
* Copy protocol support for faster bulk data loads
* Extendable logging support including built-in support for log15 and logrus
* Connection pool with after connect hook to do arbitrary connection setup
* Listen / notify
* PostgreSQL array to Go slice mapping for integers, floats, and strings
* Hstore support
* JSON and JSONB support
* Maps inet and cidr PostgreSQL types to net.IPNet and net.IP
* Large object support
* NULL mapping to Null* struct or pointer to pointer.
* Supports database/sql.Scanner and database/sql/driver.Valuer 
interfaces for custom types
* Logical replication connections, including receiving WAL and sending 
standby status updates

* Notice response handling (this is different than listen / notify)

## Performance

pgx performs roughly equivalent to [go-pg](https://github.com/go-pg/pg) 
and is almost always faster than 
[pq](http://godoc.org/github.com/lib/pq). When parsing large result sets 
the percentage difference can be significant (16483 queries/sec for pgx 
vs. 10106 queries/sec for pq -- 63% faster).


In many use cases a significant cause of latency is network round trips 
between the application and the server. pgx supports query batching to 
bundle multiple queries into a single round trip. Even in the case of a 
connection with the lowest possible latency, a local Unix domain socket, 
batching as few as three queries together can yield an improvement of 
57%. With a typical network connection the results can be even more 
substantial.


See this 
[gist](https://gist.github.com/jackc/4996e8648a0c59839bff644f49d6e434) 
for the underlying benchmark results or checkout 
[go_db_bench](https://github.com/jackc/go_db_bench) to run tests for 
yourself.


In addition to the native driver, pgx also includes a number of packages 
that provide additional functionality.


## github.com/jackc/pgx/stdlib

database/sql compatibility layer for pgx. pgx can be used as a normal 
database/sql driver, but at any time the native interface may be 
acquired for more performance or PostgreSQL specific functionality.


## github.com/jackc/pgx/pgtype

Approximately 60 PostgreSQL types are supported including uuid, hstore, 
json, bytea, numeric, interval, inet, and arrays. These types support 
database/sql interfaces and are usable even outside of pgx. They are 
fully tested in pgx and pq. They also support a higher performance 
interface when used with the pgx driver.


## github.com/jackc/pgx/pgproto3

pgproto3 provides standalone encoding and decoding of the PostgreSQL v3 
wire protocol. This is useful for implementing very low level PostgreSQL 
tooling.


## github.com/jackc/pgx/pgmock

pgmock offers the ability to create a server that mocks the PostgreSQL 
wire protocol. This is used internally to test pgx by purposely inducing 
unusual errors. pgproto3 and pgmock together provide most of the 
foundational tooling required to implement a PostgreSQL proxy or MitM 
(such as for a custom connection pooler).


https://github.com/jackc/pgx

Jack


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


[go-nuts] Why default stack size is 1gb?

2017-07-24 Thread Florin Pățan
Iirc the default stack size is 2 or 4 kb not 1 gb. Where did you found the 
reference? 

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


[go-nuts] Re: Code Review - Applying functions on custom types

2017-07-24 Thread Sofiane Cherchalli
Hi Whom,
Yes you could with columnar CSV and apply functions to column values, something 
basically similar to what does spark. In my case I receive streams of rows.
Thx

-- 
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] Re: Code Review - Applying functions on custom types

2017-07-24 Thread Sofiane Cherchalli
Yes, I'm trying to stream CSV values encoded in strings. A schema defines a 
type of each value, so I have to parse values to verify they match the type. 
Once validation is done, I apply functions on each value.

Working with basic types instead of custom types that wrap the basic types, 
sounds to me that it would make it difficult to have a good abstraction... What 
do you think?

-- 
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] Offline Go Documentation Tools

2017-07-24 Thread Rob Pike
The "go doc" (distinct from "godoc") command works fine offline. It fact it
never goes on line.

-rob


On Tue, Jul 25, 2017 at 2:45 AM, Tyler Compton  wrote:

> For cursor-sensitive help dialogs, you may find Language Server
> Protocol[1] interesting. It provides what you're looking for in Visual
> Studio Code with Go today, and will help provide that functionality to
> editors like [Neo]vim in the future.
>
> 1. http://langserver.org/
>
> On Mon, Jul 24, 2017 at 8:45 AM andrey mirtchovski 
> wrote:
>
>> > What do you use to read documentation when you are offline?
>>
>> godoc -http=:6060
>>
>> --
>> 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.
>>
> --
> 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.
>

-- 
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] Re: No Allman-Style, No go!

2017-07-24 Thread Hrobjartur Thorsteinsson
On this last comment, I would like to comment,

Overall I agree with last commenter, the coolest programmer is the one that
does not have any quarrels about style, just gets along with the group and
helps get the job done.

That being said, golangs approach to braces a part of logical syntax is
unusual in comparison to other languages that use braces to encapsulate
code blocks.

Regarding source control diffs and spaces - I can in fact add loads of
spaces and newlines into my go code, and indeed it compiles and it does
show up in source diffs. I like spaces in my code in a similar way to how I
like to have paragraphs in essays I write. I would argue that everyone
likes to use spaces for clarity.

Python does not help the argument for the golang style in my opinion,
because Python encapsulates code blocks using indent, and just like other
languages you are allowed to put your new lines and white spaces wherever
you feel it helps. If you like add loads of silly new lines after you
conditionals, Python don't care, but pylint does. In python you can alo put
your code in a one-liner, or on a new line..., or spread a statement
between many lines. So I don't see that Python makes code encapsulation
syntactically a part of the conditional syntax like golang does.




On Sun, Jul 23, 2017 at 5:12 PM, me  wrote:

>
>
> On Saturday, July 22, 2017 at 4:59:04 AM UTC-6, ohir wrote:
>>
>>
>> Every development team has right to reformat source to their tastes on
>> the editor openfile then reformat to compiler taste on savefile.
>>
>
> Except, that some people are minimalists and don't use fancy editors that
> have all these bells and whistles...
>
> I find when you have an editor doing all kinds of tricks, it means the
> code is too hard to write and your editor is giving you a warning sign that
> what you are doing requires editor tricks, and that's bad.
>
> For example, if you are making your editor type out the word FUNCTION for
> you every time you hit "F" then maybe it would be better to change the
> language you are using, to make FUNCTION become "fn" or 'func"... so that
> you don't have to have your editor doing so many tricks.
>
> For the case of GoLang, one thing I do find annoying about gofmt is that
> very short IF ELSE blocks span multiple lines..
>
> if a
> x
> else
> y
>
> instead of on a single line. But, that's what gofmt is supposed to stop:
> debates about this.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/golang-nuts/rzLzp_Z74ik/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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] How make fastest map[uint32]uint64 with fixed size(250m)?

2017-07-24 Thread roger peppe
If it's hard to make a perfect hash function, and assuming you don't need
modification after initialisation, you could use struct {keys []uint32;
vals []uint64}, sort the keys and their associated values, then binary
search. By storing keys and values in different slices, you save 25% space
because the keys can be packed together.

On 24 July 2017 at 18:03, Jan Mercl <0xj...@gmail.com> wrote:

> On Mon, Jul 24, 2017 at 5:32 PM il  wrote:
>
> > Can you help me best solution?
>
> Create a perfect hash function in 28 bits. Use a [1<<28]T array for the
> map values.
>
>
> --
>
> -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.
>

-- 
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] How come Math Big module has no Pow functions?

2017-07-24 Thread Jan Mercl
On Mon, Jul 24, 2017 at 5:33 PM me  wrote:

> The math unit has Pow() functions..
>
> How come the Big (math) package has nothing similar?

It has: https://golang.org/pkg/math/big/#Int.Exp

-- 

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


[go-nuts] Re: How make fastest map[uint32]uint64 with fixed size(250m)?

2017-07-24 Thread Klaus Post
On Monday, 24 July 2017 17:32:48 UTC+2, il wrote:
>
> I have task:
>
> 1. Initialize map(250 million items)
> 2. Fill all values
> 3. Start http server.
> 4. Process requests. Iterates all values.
>
> I need fast "for" and read access with reasonable memory consumption. This 
> is very important.
>

If you iterate all entries, why are you using a map and not a slice?
 

> Can you help me best solution?
>

You need to be a bit more specific. This sound like something where you can 
easily share your existing code and describe the actual problem you are 
trying to solve as well as which problems you are having.

Thank you!
>

/Klaus 

-- 
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] GoDoc: ignore GOPATH, local serving of help files

2017-07-24 Thread Jan Mercl
On Mon, Jul 24, 2017 at 5:33 PM me  wrote:

> $ GOPATH= godoc -http :6060 &

-- 

-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] How make fastest map[uint32]uint64 with fixed size(250m)?

2017-07-24 Thread Jan Mercl
On Mon, Jul 24, 2017 at 5:32 PM il  wrote:

> Can you help me best solution?

Create a perfect hash function in 28 bits. Use a [1<<28]T array for the map
values.


-- 

-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] Why default stack size is 1gb?

2017-07-24 Thread Jan Mercl
On Mon, Jul 24, 2017 at 5:32 PM taozle  wrote:

> I found that the default stack size for 64-bit is 1gb, but i can't see
any reason for such a large stack, can anyone help me find out the purpose
for this?

Where did you find that info? AFAICT it's not true. Thread stack size is
probably same or similar to the default C stack size on each platform and
goroutine stack defaults to few kB only.

-- 

-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] Offline Go Documentation Tools

2017-07-24 Thread Tyler Compton
For cursor-sensitive help dialogs, you may find Language Server Protocol[1]
interesting. It provides what you're looking for in Visual Studio Code with
Go today, and will help provide that functionality to editors like [Neo]vim
in the future.

1. http://langserver.org/

On Mon, Jul 24, 2017 at 8:45 AM andrey mirtchovski 
wrote:

> > What do you use to read documentation when you are offline?
>
> godoc -http=:6060
>
> --
> 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.
>

-- 
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] No Allman-Style, No go!

2017-07-24 Thread 'Eric Johnson' via golang-nuts


On Saturday, September 21, 2013 at 7:04:09 AM UTC-7, Michael Daconta wrote:
>
> As you can see, the code has semi-colons in each required location.  So, I 
> ask you - why is the above code illegal?
>

Why is breaking the speed limit illegal? On many roads, it is set 
arbitrarily low because that's the way the neighbors want it, with no 
evidence that it makes anyone safer. In the case of Go, the spec defines it 
that way, that's why it is illegal. If you've ever written bash scripts, 
you likely know there are some very weird choices in that language too. 
That doesn't keep people from using it.
 

> All I've heard so far, is that "it is because the automatic insertion of 
> semi-colons requires this stupid behavior".  Given the above code should 
> require NO automatic insertion of semi-colons - why the stupid behavior?
>

Calling the behavior stupid will not win anyone over to your side.
 

> As for the folks on the thread saying "get over it" - sorry, I would turn 
> the question back to you and say - why are you blindly accepting something 
> so foolish?  There are things in a programming language that MUST be 
> enforced, this should not be one of them.
>

I've spent several decades programming. Brace style has never affected my 
ability to code effectively, and I've always needed to be flexible, in 
order to adopt to the tastes of the people I work with. So in that sense, 
it doesn't matter. Indeed, given a choice, I mostly prefer something that 
conserves on vertical space, since the view in my editor is a critical 
constraint, thus preferring to have braces on the same line. Python goes 
one step further and eliminates both braces, which is a step too far, for 
me. Entirely a personal preference, from what I can tell. As for having Go 
enforce a particular format, it turns out to be very valuable, because it 
means that looking at diffs in source control never has the problem of 
showing just changes to spaces, and you can look at anyone else's code, and 
see the exact same style. THAT was a very valuable design choice.

As for accepting something so foolish, *every* language has design 
trade-offs. I do not accept them blindly, but accept them deliberately.
 

>   So, either the language designers must admit their language is poorly 
> designed,
>

Nope - they just made a design trade-off that you happen to disagree with.
 

> or they need to fix the problem!
>

The Go community seems to be *very* pragmatic, and evidence driven. The 
language doesn't have features unless their needed. Can you define and 
demonstrate the problem? Can you show the brace style gets in the way of 
effective Go programming? If you can come up with relevant evidence, then 
you probably stand a chance of convincing people that the language at least 
needs to allow for braces on the next line, even if it isn't the default. 
Given that the industry has been chasing this question for decades, though, 
I don't think you'll find the evidence.
 

>   Ignoring the problem or flippantly asserting there is no problem,
>

The language designers used their combined decades of experience and made a 
choice. The community has accepted this design trade-off. Whereas, you 
assert there is a problem, but provide no data. That's the source of the 
skepticism.
 

> is the worst thing they can do as it goes against the very reasons you 
> design a new language for in the first place.
>

On the contrary, they made the language to suit their needs, and their 
background. Your mileage may vary.

Eric. 
 

>
> - Mike
>
> On Saturday, September 21, 2013 9:49:42 AM UTC-4, Rémy Oudompheng wrote:
>>
>> Compiler laziness is a minor argument. Humans must also understand 
>> semicolon insertion rules, justifying the choice of simple rules. 
>>
>> The choice of a standard formatting also makes the use of grep easier. 
>>
>>
>> 2013/9/21, Michael Daconta : 
>> > I assume you say this with tongue-in-cheek; however, I cannot believe 
>> this 
>> > design decision was made.  For something to borrow so liberally from C 
>> only 
>> > 
>> > to enforce "one-true" bracing style is frankly ridiculous. 
>> > When someone has coded for a long time using their favorite bracing 
>> style, 
>> > the numerous hours of frustration to learn this new language become not 
>> > worth it.  Just due to inadvertent, habitually return to a bracing 
>> style 
>> > the language designers deemed improper - which, in fact, is actually 
>> due to 
>> > 
>> > the laziness of their compiler.  I believe they could improve the 
>> compiler 
>> > to correct this.  So, while I could write my own compiler for this - 
>> there 
>> > is actually an easier solution, just ignore this language until the 
>> > language designers do the right thing.  And if not, ignore it all 
>> together. 
>> > 
>> > Though I like many features of the language from looking at the "go 
>> tour", 
>> > I can take it or leave it. 
>> > 
>> > While I new this post could be flame bait, I actually had to post it

Re: [go-nuts] Offline Go Documentation Tools

2017-07-24 Thread andrey mirtchovski
> What do you use to read documentation when you are offline?

godoc -http=:6060

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


[go-nuts] How to determine when to actually use goroutines?

2017-07-24 Thread Glen Huang
Hi,

I'm still pretty new to go. Hope this question isn't too stupid.

I'm writing a restful API server, and in order to send a response, I need 
to query a db to get its content type and then send the actually file that 
lives on the file system. Now the question is, should I put db.QueryRow and 
os.Open each in a goroutine to make them concurrent?

And a more general question is, when using APIs from the stdlib or 
3rd-party packages, how do I determine whether to wrap them in goroutines 
when more than one of them need to happen sequentially and the order 
actually doesn't matter? Should I manually time the API executions to make 
the call? Should I writing things sequentially by default and only when 
hitting performance problems do I profile the program and wrap calls in 
goroutine?

How do you decide when to use goroutines?

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


[go-nuts] How come Math Big module has no Pow functions?

2017-07-24 Thread me
The math unit has Pow() functions..

How come the Big (math) package has nothing similar?

Complications implementing it? Or just no one needed it yet?

Here is some brief research I did:
https://stackoverflow.com/questions/30182129/calculating-large-exponentiation-in-golang

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


[go-nuts] Offline Go Documentation Tools

2017-07-24 Thread me
Sometimes I want to disconnect my laptop or computer from the internet and 
work with go..

What do you use to read documentation when you are offline?

Here is some brief research I did:
http://www.andybritcliffe.com/post/44610795381/offline-go-lang-documentation

That appears to be one solution.

I do miss an IDE where I can just hit "F1" for help, and it is sensitive to 
what my cursor is over (finds the docs automatically with what your cursor 
is currently at).

The above sentence, is likely a challenge/threat to myself to create a Go 
IDE myself with F1 context senstive help... but that's a large software 
problem I can't handle right now ;-)

-- 
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] Re: No Allman-Style, No go!

2017-07-24 Thread me


On Saturday, July 22, 2017 at 4:59:04 AM UTC-6, ohir wrote:
>
>
> Every development team has right to reformat source to their tastes on 
> the editor openfile then reformat to compiler taste on savefile. 
>
 
Except, that some people are minimalists and don't use fancy editors that 
have all these bells and whistles...

I find when you have an editor doing all kinds of tricks, it means the code 
is too hard to write and your editor is giving you a warning sign that what 
you are doing requires editor tricks, and that's bad.

For example, if you are making your editor type out the word FUNCTION for 
you every time you hit "F" then maybe it would be better to change the 
language you are using, to make FUNCTION become "fn" or 'func"... so that 
you don't have to have your editor doing so many tricks.

For the case of GoLang, one thing I do find annoying about gofmt is that 
very short IF ELSE blocks span multiple lines..

if a
x
else
y

instead of on a single line. But, that's what gofmt is supposed to stop: 
debates about this.

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


[go-nuts] Re: Math on Huge (2GB) numbers in GoLang

2017-07-24 Thread me
p.s. if the c library GMP was written in times without 8 core processors, 
wouldn't go be able to use multiple processors better than GMP can? Or, GMP 
has been modified to utilize more processors recently..

Sorry, I know absolutely nothing about GMP, just that it exists. And, I'm 
not aware of the backbones of the mathematics algorithms, if they can use 
multiple processors (or goroutines) to do calculations or whether it is 
more of a serial one cpu problem to solve for the programmer.

This may help me (or any interested):

https://www.google.ca/search?q=gmp+multiple+cores

https://stackoverflow.com/questions/7901752/parallel-arbitrary-precision-arithmetic-library

Quote "The answer is yes, multi-threaded arbitrary-precision libraries *do 
exist*. But I'm not aware of a single one that is actually public. (with 
comparable speed to GMP)"

Interesting...

-- 
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] Math on Huge (2GB) numbers in GoLang

2017-07-24 Thread me


On Saturday, July 22, 2017 at 9:37:16 AM UTC-6, Rémy Oudompheng wrote:
>
>
> The most annoying issue you might encounter is that if your 2GB 
> strings are numbers printed in base 10, the math/big will not be able 
> to parse them in a reasonable time using the standard method 
> (SetString). 
>
> Rémy. 
>

2GB is just a rough estimate, it can be maybe 300MB (that's fine too).
The point is I will be working with massive numbers - not important exactly 
how big, but, bigger is better.

I will indeed be printing in Base 10, but also in Base 27 of my own number 
system I invented using characters (A-Z plus underscore) for a new 
mathematical theory.
That's to start, then maybe some other base used later greater than 27, but 
will still need to convert to base 10 often.

I have downloaded your bigfft from github and will be doing work with it, 
thanks!

-- 
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] Math on Huge (2GB) numbers in GoLang

2017-07-24 Thread me


On Saturday, July 22, 2017 at 9:19:44 AM UTC-6, Rémy Oudompheng wrote:
>
>
> I wrote a little module (github/remyoudompheng/bigfft) to play with 
> FFT-based multiplication of huge integers, while maintaining 
> interoperability with the math/big package. 
>
>
I think I saw that on Github and starred it the other day, thanks...
 

> On my computer, it multiplies 1Gbit numbers (300MB strings when 
> printed in base 10), in 24 seconds (the GMP library does it in 9.3 
> seconds). I assume that it would multiply your 2GB strings (6 Gbit 
> numbers) in about 2 minutes. 
>
>
That is acceptable. Does it ever change speed depending on what type of 
numbers you feed it?

For example adding 11 *  22
Versus some more complex number

4589347587934 * 874589371596

 As we all know benchmarks can give a false sense ;-)
Depending on inputs/parameters.

(but that may be for me to find out!)

-- 
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] Math on Huge (2GB) numbers in GoLang

2017-07-24 Thread me


On Saturday, July 22, 2017 at 9:06:03 AM UTC-6, hsmyers wrote:
>
> Like everything else, '*it depends…*'
>
> Do you want speed?
>

At some point, speed will become important, but if it's under 1 minute or 
around 2 minutes it's "good enough"...
 

> Do you want the bulk of the coding already available as a library/module?
>

Indeed, there is also this:

https://github.com/salviati/gogmp
 
Go bindings to gmp (c library)

And:
https://github.com/scorpioncompute/go-bigmath
And:
https://github.com/jsimnz/biggish
And:
https://github.com/YuriyNasretdinov/big


With or without a user interface?
>
>
When a user interface is needed, indeed Go is not so great for Desktop 
software:
but that's easily solved by: HTML 5 (or less) interface, chromium embedded 
interface (but, is large to ship DLL's with app)

Answer those first and then ask again.
>
> Oh! Replace Javascript with Perl…
>
>
I thought that so many people use javascript for so many things, that it 
would have some strange maths stuff out there, possibly even fast. 

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


[go-nuts] GoDoc: ignore GOPATH, local serving of help files

2017-07-24 Thread me
When running GoDoc locally to serve help documents offline, a server such 
as this is setup:

http://127.0.0.1:6060/pkg/ 


However, I want to ignore documenting anything in my GOPATH and just serve 
the go docs in GOROOT

Is it possible to do this with GODOC? Reading the documentation on godoc I 
could not find a way...

Setting up a dummy/false GOPATH would work but... that would not be a real 
solution to the problem.

The basic problem is as follows:
I want a local offline documentation system
But.. GOPATH contains experimental, possibly broken packages that don't 
compile, so I want GOPATH to be ignored by godoc.
I only want to serve the standard go documentation, nothing of my own 
packages

In the documentation for godoc it says "By default, godoc looks at the 
packages it finds via $GOROOT and $GOPATH (if set). This behavior can be 
altered by providing an alternative $GOROOT with the -goroot flag. "

So, -gopath flag does not exist? (to set an empty dummy).

Thanks in advance!

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


[go-nuts] How make fastest map[uint32]uint64 with fixed size(250m)?

2017-07-24 Thread il
I have task:

1. Initialize map(250 million items)
2. Fill all values
3. Start http server.
4. Process requests. Iterates all values.

I need fast "for" and read access with reasonable memory consumption. This 
is very important.
Can you help me best solution?
Thank you!

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


[go-nuts] Why default stack size is 1gb?

2017-07-24 Thread taozle
I found that the default stack size for 64-bit is 1gb, but i can't see any 
reason for such a large stack, can anyone help me find out the purpose for 
this?

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


[go-nuts] Job Advert

2017-07-24 Thread Adam Alton
Hello,

I'm from a startup in Edinburgh, Scotland and we're trying to hire a Senior
Go developer and we're trying to spread the word because it's a pretty
specialist area. The job can be found here -
https://makeitsocial.com/business/img/SeniorDeveloperServerSide.pdf.

Is job advertising something you do on your newsletter?

Thanks,

Adam

-- 
Adam Alton
Chief Operating Officer
adam.al...@makeitsocial.com

-- 
 

www.makeitsocial.com 

 / @Make_it_Social  / 
blog.makeitsocial.com 


This e-mail communication and any attachments are confidential and for the 
sole use of the intended recipient(s). Any review, reliance, dissemination, 
distribution, copying or other use is strictly prohibited and may be 
illegal. We have taken reasonable steps to reduce risks against viruses but 
cannot accept liability for any damages sustained as a result of this 
transmission. If you are not the intended recipient please delete this 
e-mail and notify the sender immediately by replying to this e-mail or by 
telephoning our main line listed above. Make it Social Ltd is registered in 
Scotland under the company number SC416721 with registered address is 
Norton House, North Deeside Road, Kincardine O'Neil, Aberdeen, AB34 5AA. 
Make it Social is VAT registered with the VAT number GB176417980.

-- 
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] Expiring map

2017-07-24 Thread DanB
Rajanikanth,

If it helps you, have a look on the library we have posted which follows 
ideas out of implementation of groupcache/lru.go, adding expiring 
capabilities to LRU (same logic of list indexing behind):
https://github.com/cgrates/ltcache

DanB

On Friday, July 21, 2017 at 2:01:15 AM UTC+2, Rajanikanth Jammalamadaka 
wrote:
>
> Thanks for the replies.
>
> Sameer: it would be awesome if you can open source them.
>
> Thanks,
> Rajanikanth 
>
> On Thu, Jul 20, 2017, 7:47 PM Sameer Ajmani  > wrote:
>
>> We have a few implementations of this inside Google (expiring.Map, 
>> timedcache, and lru.Cache).  It might make sense to open source these, if 
>> they have no internal dependencies.
>>
>> On Wed, Jul 19, 2017 at 3:22 PM Rajanikanth Jammalamadaka <
>> rajan...@gmail.com > wrote:
>>
>>> Does somebody have a recommendation for an expiring dict? If I have to 
>>> write my own, is there a way to avoid iterating over all the keys to delete 
>>> the expired entries?
>>>
>>> Thanks,
>>> Raj
>>>
>> -- 
>>> 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...@googlegroups.com .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>

-- 
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] [Ann] web2image to take screenshot of web page

2017-07-24 Thread Tong Sun
On Mon, Jul 24, 2017 at 6:44 AM, Konstantin Khomoutov wrote:

> On Sun, Jul 23, 2017 at 04:45:24PM -0700, Tong Sun wrote:
>
> > Please take a look at
> > https://github.com/suntong/*web2image*#-web2image
> [...]
> >   -d, --headless   use chrome-headless docker as client instead of chrome
> [...]
>
> I think it worth mentioning up-front in the README file that this tool
> relies on the presence of the Chrome (or alike) browser to do the heady
> lifting, that is, it's not standalone.
>

It is right there in the README file, right after the usage text
 https://github.com/suntong/web2image#chrome-headless

-- 
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] encoding/csv: Is this a bug?

2017-07-24 Thread howardcshaw
encoding/csv uses the io.Reader interface, so wouldn't you just need a 
CR->CR/LF filter that fulfills that interface?

Something like https://github.com/andybalholm/crlf should do the trick. 
Though it would be annoying to deal with when writing a generic program for 
handling arbitrary input, if you are dealing with an internal program and 
your own files and you know they are going to be generated that way...

f, err := os.Open("myfile.csv")
// handle error, defer close, etc
c := csv.NewReader(f)
// do stuff

would just become

f, err := os.Open("myfile.csv")
// handle error, defer close, etc
c := csv.NewReader(crlf.NewReader(f))
// do stuff

Howard

On Monday, July 17, 2017 at 10:07:43 PM UTC-5, Matt Harden wrote:
>
> I suspect that this has to do with the line-ending characters on a Mac. I 
> think Excel is writing the file with each line ending with a CR character. 
> The encoding/csv package expects RFC 4180 format (each line terminated with 
> CRLF), which is what Excel writes when you select "Windows Comma Separated".
>
> I don't know a super-easy way to make encoding/csv accept the first format.
>
> On Mon, Jul 17, 2017 at 4:42 PM Dat Huynh  > wrote:
>
>> Hi all,
>>
>> I have a problem with parsing a .csv file using the library 
>> "encoding/csv".
>>
>> I wonder if that is the problem of Microsoft Excel or the Go library.
>>
>> I am using Microsoft Excel version 14.2.2 on MacOS and go1.8.3 
>> darwin/amd64
>>
>> What did I do?
>>
>> Firstly I input the below values into an Excel sheet, and save as a .csv 
>> file.
>> value 11 value 12 
>> value 21 value 22 
>> value 31 value 32 
>>
>> If I choose "Comma Separated Values (.csv)" in the option "Format", type 
>> the file name "data.csv", and run my Go app, it returns:
>>
>> $ go run demo.go 
>> value 31 value 32]12
>>
>> If I choose "Window Comma Separated (.csv)" in the option "Format", type 
>> the file name "data.csv", and run my Go app, it works well.
>>
>> $ go run demo.go 
>> 0 [value 11 value 12]
>> 1 [value 21 value 22]
>> 2 [value 31 value 32]
>>
>> Could you please confirm if this is a bug of the library or MS Excel?
>>
>> Below is my code.
>>
>> package main
>>
>> import (
>> "encoding/csv"
>> "fmt"
>> "os"
>> )
>>
>> func main() {
>> file, _ := os.Open("data.csv")
>> defer file.Close()
>> csvReader := csv.NewReader(file)
>> records, _ := csvReader.ReadAll()
>> for index, record := range records {
>> fmt.Println(index, record)
>> }
>> }
>>
>> Thank you very much.
>>
>> Regards,
>> Dat Huynh.
>>
>> -- 
>> 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...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
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] Understanding least significant byte operation

2017-07-24 Thread Pablo Rozas Larraondo
Thanks Bakul, I think I have a better understanding of what's going on
after reading your response.

Is it correct to say that the Go compiler treats the prepended minus sign
differently depending on the variable being a signed or an unsigned
integer?

By looking at this example: https://play.golang.org/p/feqQsuPkqk

It seems to me that in the case of an unsigned integer it's treated as a
bitwise operation : -x == ^x + 1
But for signed integers -x == -1 * x

Cheers,
Pablo



On Mon, Jul 24, 2017 at 5:36 AM, Bakul Shah  wrote:

> This is a standard trick to find the least significant set bit in a word.
> Only works for 2's complement numbers!
> -x == ~x+1
> For example: x = 0011b (24), ~x+1 = 1100+1 = 1101. Adding them
> yields 0001; thus only the least significant set bit remains set.
>
> Note that func LSB(x uint64) uint64 { return x&-x } works too. In your
> example you get an error because in Go literal constants are untyped. It is
> a pragmatic decision -- see https://blog.golang.org/constants
>
> On Jul 23, 2017, at 5:50 AM, Pablo Rozas Larraondo <
> p.rozas.larrao...@gmail.com> wrote:
>
> I have seen Go code using this function to find out the least significant
> byte of unsigned integers:
>
> func LSB(ci uint64) uint64 { return uint64(ci) & -uint64(ci) }
>
> This function works fine but I wonder why, if call the same AND operation,
> it results in an error: "constant -X overflows uint64"
>
> Here is a playground example to illustrate this:
> https://play.golang.org/p/_0EYtlLnmG
>
> Does anyone know what changes when -uint64() is called in a return
> statement? How a negative uint should be interpreted?
>
> Thank you,
> Pablo
>
> --
> 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.
>
>

-- 
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] [Ann] web2image to take screenshot of web page

2017-07-24 Thread Konstantin Khomoutov
On Sun, Jul 23, 2017 at 04:45:24PM -0700, Tong Sun wrote:

> Please take a look at 
> https://github.com/suntong/*web2image*#-web2image
[...]
>   -d, --headless   use chrome-headless docker as client instead of chrome
[...]

I think it worth mentioning up-front in the README file that this tool
relies on the presence of the Chrome (or alike) browser to do the heady
lifting, that is, it's not standalone.

-- 
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] Why does this program carry test flags once compiled?

2017-07-24 Thread roger peppe
On 24 July 2017 at 09:12, Howard Guo  wrote:

> Thanks Nigel! I should definitely consider improving the test case.
>
> Go compiler appears to automatically places test flags into executable
> whenever "testing" package is included - no matter the function using
> "testing" package is dead code or otherwise. So here's a bug report for go:
> https://github.com/golang/go/issues/21141
>

Although this could be considered a bug, it's not one that can be fixed,
because people rely on this behaviour of the testing package.

Consider it a warning not to include testing dependencies in production
code.


>
> Kind regards,
> Howard
>
> On Sunday, 23 July 2017 06:54:28 UTC+2, Nigel Tao wrote:
>>
>> On Sat, Jul 22, 2017 at 7:08 PM, Howard Guo  wrote:
>> > https://github.com/HouzuoGuo/laitos
>>
>> It's tangential to your question, but out of curiousity, I skimmed the
>> source code. In things like func TestUDPServer in
>> https://github.com/HouzuoGuo/laitos/blob/master/frontend/plain/udp.go,
>> you say:
>>
>> var stoppedNormally bool
>> go func() {
>>   etc
>>   stoppedNormally = true
>> }()
>> etc
>> server.Stop()
>> time.Sleep(1 * time.Second)
>> if !stoppedNormally { etc }
>>
>> This is an example of incorrect synchronization as per
>> https://golang.org/ref/mem#tmp_10
>>
>> There may be other such races in your code. I didn't do an exhaustive
>> review. It may be worthwhile to run your test suite under the race
>> detector.
>>
> --
> 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.
>

-- 
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] Re: Code Review - Applying functions on custom types

2017-07-24 Thread roger peppe
On 24 July 2017 at 05:10, Sofiane Cherchalli  wrote:

> Hi Silviu,
>
> On Sunday, July 23, 2017 at 2:11:29 AM UTC+2, Silviu Capota Mera wrote:
>>
>> Hi Sofiane,
>>
>> "Is my design wrong?"
>> Without a bigger picture of what your final aim is, it's hard for an
>> external observer to tell you if your design is right or wrong.
>> I was unable to fully grasp the need for that intermediate (CSV prefixed)
>> structs in-between raw csv and real domain types, so I just assumed you're
>> working on some sort of a streaming processor / data importer of sorts
>> where values were represented by basic types (strings, numbers, etc).
>>
>
> Yes , the idea is to do streaming of incoming rows.
>

That sounds like a secondary goal to me. ISTM that you might be trying to
write a general package before you've got a decent use case.

What's an example of an actual problem that you're trying to solve
here?

I suspect that you might find that using encoding/csv directly can be pretty
good for streaming and processing CSV.

  cheers,
rog.

-- 
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] Understanding least significant byte operation

2017-07-24 Thread Jan Mercl
On Mon, Jul 24, 2017 at 12:25 AM John Souvestre  wrote:

> That looks like the least significant set bit to me.

To me too ;-)

But I was responding to your

> On Sun, Jul 23, 2017 at 7:26 PM John Souvestre  wrote:
>
>> I believe that the result is the least significant bit, not byte.

Where the word 'set' is not present.

-- 

-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] Why does this program carry test flags once compiled?

2017-07-24 Thread Howard Guo
Thanks Nigel! I should definitely consider improving the test case.

Go compiler appears to automatically places test flags into executable 
whenever "testing" package is included - no matter the function using 
"testing" package is dead code or otherwise. So here's a bug report for go:
https://github.com/golang/go/issues/21141

Kind regards,
Howard

On Sunday, 23 July 2017 06:54:28 UTC+2, Nigel Tao wrote:
>
> On Sat, Jul 22, 2017 at 7:08 PM, Howard Guo  > wrote: 
> > https://github.com/HouzuoGuo/laitos 
>
> It's tangential to your question, but out of curiousity, I skimmed the 
> source code. In things like func TestUDPServer in 
> https://github.com/HouzuoGuo/laitos/blob/master/frontend/plain/udp.go, 
> you say: 
>
> var stoppedNormally bool 
> go func() { 
>   etc 
>   stoppedNormally = true 
> }() 
> etc 
> server.Stop() 
> time.Sleep(1 * time.Second) 
> if !stoppedNormally { etc } 
>
> This is an example of incorrect synchronization as per 
> https://golang.org/ref/mem#tmp_10 
>
> There may be other such races in your code. I didn't do an exhaustive 
> review. It may be worthwhile to run your test suite under the race 
> detector. 
>

-- 
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] Parsing XML with namespaces in golang

2017-07-24 Thread Konstantin Khomoutov
On Sun, Jul 23, 2017 at 01:51:41PM -0700, emartinez1...@gmail.com wrote:

Hi!

> So I'm trying to unmarshal an XML with namespaces in go but i just can't 
> find the right parser to do so.
[...]

This (elided for brewity)

8<
package main

import (
"fmt"
"encoding/xml"
)

type Root struct {
XMLName struct{} `xml:"urn:MNResultsResults MNResultsResults"`
Cpcs []float64 `xml:"urn:MNResultsResults ssResultSet>ssResult>cpc"`
}

const s = `

  

  42.0


12.333

  
`

func main() {
r := Root{}
err := xml.Unmarshal([]byte(s), &r)
if err != nil {
panic(err)
}
fmt.Printf("%+v", r)
}
8<

works by printing

  {XMLName:{} Cpcs:[42 12.333]}

(Playground link: https://play.golang.org/p/RehqytlFQ9).

The chief idea is that the namespace must be separated from the element
or attribute name it qualifies with a space character.

-- 
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] Proposal remove function return type brackets

2017-07-24 Thread Gert Cuykens
Valid argument thx

On Sun, Jul 23, 2017 at 7:23 PM, Rémy Oudompheng
 wrote:
> With this proposal, can you tell whether the following function F
> returns one argument (a function) or two arguments (a function and an
> error) :
>
> func F() func(string) []byte, error {
>blah
> }
>
> Rémy.
>
> 2017-07-23 18:18 GMT+02:00 Gert :
>> I personally don't think () is necessary for output types and is only
>> confusing with the function attributes
>>
>> Example
>>
>> func Hello(b string) ([]byte, error) {
>>   
>> }
>>
>> func Hello(b string) []byte, error {
>>   
>> }
>>
>> func Hello(b string) a []byte, b error {
>>   
>> }
>>
>> Feel free to counter argument against the proposal or if already proposed
>>
>> --
>> 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.

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


[go-nuts] Re: Proposal: Blank types instead of Generics for Go 2

2017-07-24 Thread 'meta keule' via golang-nuts
I've updated the proposal to include ideas of how feature parity with 
generics could be reached.


Am Sonntag, 23. Juli 2017 10:17:04 UTC+2 schrieb meta keule:
>
>
> Hi,
>
> here is a proposal for an alternative to Generics for Go2:
>
> https://github.com/golang/go/issues/21132
>
> Please discuss!
>
>
>

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