Re: [go-nuts] How is a for loop preempted in Go?

2019-02-23 Thread David Finkel
[The other responses have been excellent, but I wanted to point one thing out.] On Fri, Feb 22, 2019 at 3:17 AM Jingguo Yao wrote: > Consider the following code which launches two goroutines. Each > goroutine uses a for loop to print messages. > > package main > > import ( > "fmt" > "run

Re: [go-nuts] Re: How to constant ?!

2019-05-28 Thread David Finkel
On Tue, May 28, 2019 at 11:04 AM Trig wrote: > Whoops... forgot to add the top line to the code syntax. I really wish > you could edit existing posts in this group. > > On Tuesday, May 28, 2019 at 10:03:05 AM UTC-5, Trig wrote: >> >> package main >> >> import "fmt" >> >> const ( >> ExposedC

Re: [go-nuts] [Urgency] Error ctim value get from file.Stat().Sys().(*syscall.Stat_t)

2019-06-20 Thread David Finkel
On Thu, Jun 20, 2019 at 12:55 PM GoFreshMan <1on1y4u1...@gmail.com> wrote: > *linux version: 5.1.9-300.fc30.x86_64* > *linux dist: fedora 30* > *go version: go1.12.5 linux/amd64* > > > [ ~/Rhizobium]$ stat README.md > 文件:README.md > 大小:461块:8 IO 块:4096 普通文件 > 设备:805h/2053d

Re: [go-nuts] Watches / Data breakpoints

2019-09-26 Thread David Finkel
On Thu, Sep 26, 2019 at 3:58 AM Stephen Illingworth < stephen.t.illingwo...@gmail.com> wrote: > Hi all, > > I have an awkward bug I'm trying to understand and I'm missing something > in my toolbox. Is there any way of monitoring a variable for changes made > to it? For example, I have a pointer ty

Re: [go-nuts] encoding/json character escaping question

2019-10-05 Thread David Finkel
On Thu, Oct 3, 2019 at 11:11 AM Poussier William wrote: > Hello > > The encoding/json package escapes 0xA (line feed), 0xD (carriage return) > and 0x9 (horizontal tab) using the escape character '\'. However, when it > comes to 0x8 (backspace) and 0xc (form feed), it uses the Unicode escape > seq

Re: [go-nuts] How to print an AST without formatting?

2020-01-10 Thread David Finkel
On Thu, Jan 9, 2020 at 10:22 AM wrote: > Hello, > > I am looking for a way to keep to original token positioning but I cannot > find how to avoid it when using `go/printer` or `go/format`. > Basically, how to make this example print the same string that was parsed: > https://play.golang.org/p/dI7

Re: [go-nuts] Re: stringer command and generated String() function

2020-02-19 Thread David Finkel
On Tue, Feb 18, 2020 at 8:57 AM Vincent Blanchon wrote: > Yes, definitely, good point. > Both are them are good depending on the case actually. > > > Le mardi 18 février 2020 16:55:02 UTC+4, Jan Mercl a écrit : >> >> On Tue, Feb 18, 2020 at 1:47 PM Vincent Blanchon >> wrote: >> >> > However, in

Re: [go-nuts] Re: Why isn't there strings.reverse("str") function?

2020-02-27 Thread David Finkel
On Thu, Feb 27, 2020 at 1:52 PM roger peppe wrote: > If you really just want to reverse rune-by-rune, it's pretty > straightforward: > > func Reverse(s string) string { > r := make([]byte, 0, len(s)) > for len(s) > 0 { > _, n := utf8.DecodeLastRuneInString(s) >

Re: [go-nuts] Re: OAuth2 token expiry logic

2020-04-20 Thread David Finkel
On Mon, Apr 20, 2020 at 11:02 AM wrote: > Whoops, you're right. I got my Time and Duration mixed up. Your question > still stands, though. The section on Monotonic Clocks at > https://pkg.go.dev/time?tab=doc is a bit dense, but my best guess is that > stripping the monotonic clock reading from th

Re: [go-nuts] pprof samples

2020-04-22 Thread David Finkel
On Mon, Apr 20, 2020 at 8:35 PM asaxena via golang-nuts < golang-nuts@googlegroups.com> wrote: > Hi, > > I am trying CPU profiling a program that runs for an hour. However when I > start pprof it says Total samples are only for 1.32 min. Why are the > samples not collected for the whole duration o

Re: [go-nuts] Re: [generics] how to constraint a type must be a map or a slice?

2020-06-20 Thread David Finkel
On Sat, Jun 20, 2020 at 11:03 AM T L wrote: > > > On Saturday, June 20, 2020 at 10:21:56 AM UTC-4, Axel Wagner wrote: >> >> I would assume it's >> >> type MapConstraint(type K comparable, V interface{}) interface { >> type map[K]V >> } >> >> func F(type M MapConstraint(K, V), K comparable, V

Re: [go-nuts] Re: [generics] how to constraint a type must be a map or a slice?

2020-06-20 Thread David Finkel
On Sat, Jun 20, 2020 at 4:53 PM Ian Lance Taylor wrote: > On Sat, Jun 20, 2020 at 12:08 PM David Finkel > wrote: > > > > Here's an almost working example: > > https://go2goplay.golang.org/p/qcdfl0tuHlb > > > > It looks like there's a bug in the t

Re: [go-nuts] Block-based data structures and the Type Parameters - Draft Design

2020-06-21 Thread David Finkel
On Sat, Jun 20, 2020 at 1:22 AM Andrew Werner wrote: > [The body of this email is a duplication of the README in > https://github.com/ajwerner/go2dequeue/ > which also contains the sample implementation] > > Exercise building a dequeue with the go2 Type Parameter Draft > > This project is an exp

Re: [go-nuts] [generics] type constraint for structs

2020-06-24 Thread David Finkel
On Wed, Jun 24, 2020 at 9:34 AM Robert Engels wrote: > Generics will not solve this fully anyway - you’ll still need reflection. > Why not just return empty if the user doesn’t pass a struct? > > That sounds like a bug waiting to happen. I have a library with a similar reflection-related use-cas

Re: [go-nuts] Why does html.UnescapeString not look for the trailing semicolon when finding HTML entities?

2020-07-05 Thread David Finkel
On Thu, Jul 2, 2020 at 1:18 PM Akash wrote: > html.UnescapeString("Should this word, ¤cy, be unescaped?") > > https://play.golang.org/p/vN5bvfooq8H > > Aren't HTML entities supposed to end with a semicolon? See > https://developer.mozilla.org/en-US/docs/Glossary/Entity > I think the answer is "ye

Re: [go-nuts] How to read (and write) the ECN bits?

2020-08-06 Thread David Finkel
On Thu, Aug 6, 2020 at 10:02 AM Uli Kunitz wrote: > Reading is possible with IP_RECVTOS on Linux but requires the use of > recvmsg, because the TOS field is provided as ancillary data. This wouldn't > be very portable though. Raw sockets with IP_HDRINCL are a better option if > portability is a c

Re: [go-nuts] Proposal: auto return String instead of []byte if requested

2020-09-12 Thread David Finkel
On Sat, Sep 12, 2020 at 4:25 AM 'Axel Wagner' via golang-nuts < golang-nuts@googlegroups.com> wrote: > Hi y'all, > > given that the concern here seems to be performance (though, TBH, I doubt > this particular case is much of a bottleneck), this seems to be far simpler > to address as a compiler op

Re: [go-nuts] how to get unsigned url (not signed url)

2020-12-24 Thread David Finkel
On Mon, Dec 21, 2020 at 5:54 PM Alexander Mills wrote: > this is a little irritating lol, i can get a signed url via: > > bucket := "bnk-photos" > filename := "mypic3.json" > method := "PUT" > expires := time.Now().Add(time.Minute * 10) > > url, err := storage.SignedURL(bucket, filename, &storage

Re: [go-nuts] Recomended GOPROXY (or not) for Open Source projects?

2021-06-25 Thread David Finkel
On Fri, Jun 25, 2021 at 1:23 PM josvazg wrote: > When working on internal company projects, it makes sense to use a company > wide GO Proxy assuring that all go dependency code is available and > immutable. But when you move to an Open Source project, you cannot longer > use such private proxy. >

Re: [go-nuts] Changing wall clock in unit test

2021-07-30 Thread David Finkel
On Fri, Jul 30, 2021 at 12:13 AM Carl wrote: > Hi, > > Is there a way to write a unit test that simulates a change in the wall > clock for a time.Time value? > I use a combination of two approaches to simulate the passage of time (often both work together): - have functions a `now` argument

Re: [go-nuts] Idea extending xerror.As

2021-09-19 Thread David Finkel
You might be interested in the original draft proposal for errors.As: https://go.googlesource.com/proposal/+/master/design/go2draft-error-inspection.md#the-is-and-as-functions In particular, it originally specified that errors.As would take a type-parameter. (the version of generics that was propo

Re: [go-nuts] Idea extending xerror.As

2021-09-19 Thread David Finkel
On Sun, Sep 19, 2021 at 4:02 PM David Finkel wrote: > You might be interested in the original draft proposal for errors.As: > > https://go.googlesource.com/proposal/+/master/design/go2draft-error-inspection.md#the-is-and-as-functions > > In particular, it originally specified

Re: [go-nuts] Idea extending xerror.As

2021-09-19 Thread David Finkel
ty much as-is, I think the biggest barrier would be a good name. (given that As is already taken) > > On Sun, 19 Sep 2021, 21:15 David Finkel, wrote: > >> >> >> >> On Sun, Sep 19, 2021 at 4:02 PM David Finkel >> wrote: >> >>> You might be interes

Re: [go-nuts] Idea extending xerror.As

2021-09-21 Thread David Finkel
err); ok { >> fmt.Printf("Path Error: %v", pe) >> } else if en, ok := errors.As[syscall.Errno](err); ok { >> fmt.Printf("errno %[1]d: %[1]s", en) >> } >> ``` >> >> Since it looks like the dev.typeparams branch has been merged into &

Re: [go-nuts] ast.NewPackage errors for built in types

2021-10-11 Thread David Finkel
On Mon, Oct 11, 2021 at 5:48 AM Steven Hartland wrote: > If the ast.Files passed to ast.NewPackage includes built in types such as > int it returns an error e.g. > file1.go:5:6: undeclared name: int > > Is there a way to prevent that? > Generally, I always add the `builtin` package to the list o

Re: [go-nuts] Re: Why go plugin addresses do not load with go binary #49225

2021-11-01 Thread David Finkel
On Mon, Nov 1, 2021 at 9:44 AM Manoj Chauhan wrote: > Hi Brian, > > greeter.go calls plugin.open and it will be work only for one sub version > of go. If plugin and binary are made in different sub versions of go1.15 > then plugin.open will not work. > It sounds like you want to ignore a major wa

Re: [go-nuts] HPC image processing in go?

2021-11-04 Thread David Finkel
On Thu, Nov 4, 2021 at 5:43 AM quin...@gmail.com wrote: > Hi, > > Has anyone got any experience of high performance image processing in go? > > By this I mean doing complex image processing in real time at 4K > resolution on commodity hardware. This is really pushing it using carefully > written

Re: [go-nuts] Which error handling pattern do you prefer?

2021-11-12 Thread David Finkel
On Fri, Nov 12, 2021 at 7:48 AM Miguel Angel Rivera Notararigo < ntr...@gmail.com> wrote: > I tend to use errX (X is adapted according to context) for function scoped > errors, and err for block scoped errors > > func MyFunc() error { >> v, errDS := doSomething() >> ... >> errDA := doAnother

Re: [go-nuts] grpc and golang struct tags

2021-11-30 Thread David Finkel
On Sat, Nov 27, 2021 at 10:53 AM Sankar wrote: > Hi > > I have a database that has a column `2xxCode`. This database is part of a > legacy system and I cannot make changes to this, as there are multiple > applications that depend on this, and some of the applications are > unchangeable. > > Now I

Re: [go-nuts] Re: Alternatives to wrapping errors

2022-01-01 Thread David Finkel
On Fri, Dec 31, 2021 at 5:12 AM Brian Candler wrote: > On Friday, 31 December 2021 at 08:10:49 UTC Henry wrote: > >> The purpose of error wrapping is to give contextual information about the >> error. It is supposed to help you understand and locate the error. For >> instance, *"invalid filename"

Re: [go-nuts] Looping and tail-end code

2022-01-12 Thread David Finkel
On Wed, Jan 12, 2022 at 5:02 AM Tobias Klausmann wrote > So what is the *idiomatic* way of being able to use `continue` (or > something like it), yet have "always do this" code at the end of the > loop? As I understand it, `defer` only works for ends of functions, not > ends of blocks, and label

Re: [go-nuts] Re: Why, oh why, do people do this? Things that annoy me in Go code.

2022-01-29 Thread David Finkel
On Sat, Jan 29, 2022 at 6:21 AM Tim Hardcastle wrote: > Agree with Rudolf on point 2. Long meaningful variable/function names are > good. Comments become obsolete, they become detached from their code, > they're only used to explain the name of the variable once and then you're > left with someth

Re: [go-nuts] Is there a way to specify or use the tmp directory used in testing?

2022-02-23 Thread David Finkel
On Wed, Feb 23, 2022 at 8:53 AM Leam Hall wrote: > My program uses data and template files located relative to the binary. > Since go test creates the binary under test in /tmp/go-build., there > are no data or template files. How do I either specify what directory to > build in so I can crea

Re: [go-nuts] Is there a way to specify or use the tmp directory used in testing?

2022-02-23 Thread David Finkel
On Wed, Feb 23, 2022 at 1:47 PM Gergely Brautigam wrote: > Hi! > > The best way to do it is, to have these files in a folder next to the test > called `testdata` and then when the test starts, simply copy them into a > temp location. And then make your program work with an environment property >

Re: [go-nuts] GO program's memory footprint is confusing

2022-05-09 Thread David Finkel
Looking at proc-10451, I see that there are two mappings with anonymous huge pages in that smaps output, and none on the other. Does one machine have transparent hugepages enabled, and the other not? You can check whether they're enabled on that system by looking at /sys/kernel/mm/transparent_hugep

Re: [go-nuts] Type switch on generic parameter

2022-08-11 Thread David Finkel
On Thu, Aug 11, 2022 at 7:40 PM 'Matt Rosencrantz' via golang-nuts < golang-nuts@googlegroups.com> wrote: > I'd really love to be able to do: > > type allowedTypes{ > int64|float64|string > } > > func Foo[T allowedTypes](arg T) { > switch t := arg { >case int64: >// somet

Re: [go-nuts] Any package implementing FIFO mutex?

2022-09-09 Thread David Finkel
Not a drop-in replacement, but there is net/textproto.Pipeline . (intended for sequencing text-based network protocols going over a socket, but it's not too far off) You'd call `Next()` to grab the sequence-handle and then call `p.StartRequest(id)` to gra

Re: [go-nuts] google code style is the same as gofmt in go codes?

2022-09-13 Thread David Finkel
On Tue, Sep 13, 2022 at 3:55 PM Moein Halvaei wrote: > When I read codes from https://cs.opensource.google/go, indents are 2 > spaces and when using gofmt indents are 2 tabs. Why? > Google's Codesearch defaults to matching Google's C++ style guide rather than Go's recommended style: https://googl

Re: [go-nuts] google code style is the same as gofmt in go codes?

2022-09-13 Thread David Finkel
On Tue, Sep 13, 2022 at 5:39 PM Axel Wagner wrote: > > > On Tue, Sep 13, 2022 at 10:46 PM David Finkel > wrote: > >> On Tue, Sep 13, 2022 at 3:55 PM Moein Halvaei >> wrote: >> >>> When I read codes from https://cs.opensource.google/go, indents are 2 &

Re: [go-nuts] Any information about adding a trailing comma in ast CompositeLit (for structs)

2022-10-24 Thread David Finkel
On Sat, Oct 22, 2022 at 10:00 PM Tajmeet Singh wrote: > Hello, > > I've been working on a utility to generate constructors for me when I > provide it with a path to the file containing the struct and it `Ident`. > The idea was that I would just create a ast.Node (FuncDecl) with all the > necessar

Re: [go-nuts] Any information about adding a trailing comma in ast CompositeLit (for structs)

2022-10-26 Thread David Finkel
On Mon, Oct 24, 2022 at 9:27 PM Tajmeet Singh wrote: > Thanks for looking at it :smile: > > Could you elaborate more on how the `SetLines` would work on a > `token.FileSet`? I thought that `SetLines` is only for the `os.File` types > :sweat: Do you mean that I should create offsets (using SetLine

Re: [go-nuts] Underscore symbol

2022-11-05 Thread David Finkel
On Sat, Nov 5, 2022 at 4:57 AM Chris Burkert wrote: > I am curious: from a compiler perspective, does that mean that by using _ > simply less assembler instructions are created by not handling those > registers which relate to _? > > That kind of depends on what you mean by "not handling". Since

Re: [go-nuts] Silly question about parentheses

2023-02-01 Thread David Finkel
On Wed, Feb 1, 2023 at 11:22 AM Chris Burkert wrote: > Looking into the spec: > > https://go.dev/ref/spec#Return_statements > ReturnStmt = "return" [ ExpressionList ] . > ExpressionList = Expression { "," Expression } . > ... no () here > > https://go.dev/ref/spec#Function_types > FunctionType

Re: [go-nuts] Why can't a regexp.Regexp be const

2023-02-13 Thread David Finkel
On Mon, Feb 13, 2023 at 6:48 PM Pat Farrell wrote: > This won't compile > > var ExtRegex = > regexp.MustCompile("(M|m)(p|P)(3|4))|((F|f)(L|l)(A|a)(C|c))$") > > with a > ./prog.go:10:18: > regexp.MustCompile("((M|m)(p|P)(3|4))|((F|f)(L|l)(A|a)(C|c))$") (value of > type *regexp.Regexp) is not const

Re: [go-nuts] Why is runtime.Gosched needed in this single-threaded, no-goroutines cgo program?

2023-02-16 Thread David Finkel
On Wed, Feb 15, 2023 at 4:05 PM Ian Lance Taylor wrote: > On Wed, Feb 15, 2023 at 8:42 AM 'Marko Bencun' via golang-nuts > wrote: > > > > I am running into a a weird error in C code that only materializes > > when calling it from Go using cgo. I hope you could help me understand > > this behavio

Re: [go-nuts] Redfining loop variable semantics - what's the plan?

2023-04-10 Thread David Finkel
On Mon, Apr 10, 2023 at 7:23 PM xi ool wrote: > Little late but I have to say the rational seems foolish : > > >1. Currently 25% of gophers who didn't read the language spec >experienced a 'bug' and got unexpected behavior.. > > This premise is a bit suspect. The current loop-variable be

Re: [go-nuts] I need confirmation about whether I'm in front of a linter false positive.

2023-08-14 Thread David Finkel
On Mon, Aug 14, 2023 at 4:54 PM Pablo Caballero wrote: > I started working on a Golang project (from my work). The following > pattern makes the company configured linter to complain with: > sloppyReassign: re-assignment to `err` can be replaced with `err := > myFunc2()` (gocritic) > > func myFun

Re: [go-nuts] Generic assembly function

2023-12-19 Thread David Finkel
On Thu, Dec 14, 2023 at 10:43 PM Clément Jean wrote: > Hi, > > I'm currently learning how to write Go assembly on arm64 and I made the > following functions: > > TEXT ·AddVector16(SB),NOSPLIT,$0-48 > MOVD a+0(FP), R0 > MOVD a+8(FP), R1 > MOVD a+16(FP), R2 > MOVD a+24(FP), R3 > VMOV R0, V0.D[0] >

Re: [go-nuts] Go 1.22 code simplification

2024-01-16 Thread David Finkel
I don't know of anything that does those rewrites (and haven't looked), but it looks like gofmt -s could support it by extending this type-switch: https://cs.opensource.google/go/go/+/master:src/cmd/gofmt/simplify.go;l=16-103;drc=9b89c380208ea2e85985ee6bf2b1d684274dfa1d I like the idea of an autom