Re: [go-nuts] Rate controlling the Go http server

2018-02-02 Thread Jesper Louis Andersen
A simple solution is to have a channel of type struct{} of some bound, say 10. A process only gives service as long as it can pull a message from the channel. More advanced solutions include handling the channel as a token bucket and regulating it to have a drip-rate. Even more advanced solutions

Re: [go-nuts] Re: Inheritance and OOP: Go one better

2018-02-13 Thread Jesper Louis Andersen
On Thu, Feb 8, 2018 at 6:53 PM wrote: > Closures and function types/fields may have a place in discussing OOP-like > Go constructs. > > Yes! One can implement roughly any feature of the OO crowd with closures and types. Although it can be far more verbose to do so in the language. -- You receiv

Re: [go-nuts] Re: All Forms of Wishful Generics

2018-02-19 Thread Jesper Louis Andersen
On Sun, Feb 18, 2018 at 4:47 AM Lars Seipel wrote: > > Go already has a NaCl backend which might fit the bill. See > misc/nacl/README for how to set it up. It links to a design document > (https://golang.org/s/go13nacl) with some background. > > The sucessor of that project is WebAssembly. WebAs

Re: [go-nuts] Re: All Forms of Wishful Generics

2018-02-20 Thread Jesper Louis Andersen
On Mon, Feb 19, 2018 at 9:29 PM Rob Pike wrote: > Jesper, > > I find myself in rare but mild disagreement about your claims for > stack-based virtual machines. Please have a look at this short paper about > the Dis VM from Inferno: http://flint.cs.yale.edu/jvmsem/doc/inferno.ps > > There is a cha

Re: [go-nuts] Appreciating Go

2018-02-22 Thread Jesper Louis Andersen
Usually, the type theoretic basis is what is called a sum-type. They are corresponding to a logical OR or a '+' addition operation in algebra. A "struct" is rightfully a variant of a product-type, or a logical AND or a '*' multiplication operation in algebra[0]. Most (commonly used) programming lan

Re: [go-nuts] Channels vs Actors

2018-03-05 Thread Jesper Louis Andersen
To add to Bakul's description: A key difference in an actor-inspired model compared to a CSP-inspired one is that identity is subtly different. In Go, channels have identity and can be referenced. They can have multiple readers and writers. In Erlang, it is processes who has identity and you can s

Re: [go-nuts] Re: Channels vs Actors

2018-03-08 Thread Jesper Louis Andersen
On Thu, Mar 8, 2018 at 10:37 AM Haddock wrote: > The fundamental problem with asynchronous programming is that asynchronous > messages that depend on each other from the application logic "may not > meet" and miss each other. Let's say, several threads start to search > through a pile of data sta

Re: [go-nuts] Help On Kqueue Server

2018-03-11 Thread Jesper Louis Andersen
On Sat, Mar 10, 2018 at 10:19 AM Anto Aravinth wrote: > Hello all, > > I'm learning golang and I wanted to try out this. Wanted to make a event > driven server using Kqueue sys call (I'm on mac). A simple echo server will > do. > If you want to learn this, I suggest you start off with something

Re: [go-nuts] Re: float64 - xml marshalling to 2464700.000000 rather than 2.4647e+06

2018-03-31 Thread Jesper Louis Andersen
The underlying question is: why do you want to use an 'f' representation of a floating point value rather than a 'g' representation? If I read the XML Schema specification correctly, then an xs:double value is allowed to be in scientific notation, so there should be little reason to output this va

Re: [go-nuts] Tcp connection reset

2018-04-13 Thread Jesper Louis Andersen
TCP connections are normally Close()'d, which starts the gracefully dance of sending FIN packets back and forth. RST is a far more abrupt situation, which is normally reserved for a few exceptional cases. I find it rare that one needs the RST from the userland outside kernel jurisdiction. Hence my

Re: [go-nuts] sync.Cond implementation

2018-04-16 Thread Jesper Louis Andersen
On Sat, Apr 14, 2018 at 7:02 PM Penguin Enormous wrote: > But looking at your answer, I see that you may imply certain race > conditions are allowed. Could you explain a bit more on that? Aren't race > conditions supposedly bad? > > Race conditions can, in certain cases, be benign if guarded prop

Re: [go-nuts] sync.Cond implementation

2018-04-16 Thread Jesper Louis Andersen
day, April 16, 2018 at 7:08:27 AM UTC-4, Jesper Louis Andersen wrote: > >> On Sat, Apr 14, 2018 at 7:02 PM Penguin Enormous >> wrote: >> >>> But looking at your answer, I see that you may imply certain race >>> conditions are allowed. Could you explain a bit

Re: [go-nuts] Re: Go could really use a while statement

2018-05-03 Thread Jesper Louis Andersen
The reason is simply that good syntax is a really hard problem which incorporates both tech and people. In principle, you can get away with very few things in a language before it is turing complete. It is enough to have eg 'WHILE do ' where stmts can form a block of statements. Or just have recu

Re: [go-nuts] Re: go 1 on Ubuntu 18.04

2018-05-08 Thread Jesper Louis Andersen
On Tue, May 8, 2018 at 9:43 AM Dave Cheney wrote: > Please allow me to clarify, anyone other than Jan never needs to set > GOROOT. > > While I do agree with this advice, it unfortunately doesn't teach people as to why it is a bad idea to set GOROOT, and what kinds of troubles you are likely to ru

Re: [go-nuts] Please help me solve a bug with my licencing system!

2018-05-12 Thread Jesper Louis Andersen
On Sat, May 12, 2018 at 12:04 AM wrote: > How do you recommend I check errors. I dismiss them because I don't like > if err !=nil { log.error(err.error()} > being all over my project. Suggestions please, Thanks! > > Code have a positive path on which the normal operation happens. But code also ha

Re: [go-nuts] Re: dynamic programming or something else

2018-05-15 Thread Jesper Louis Andersen
Immediate idea would be to try to exploit https://en.wikipedia.org/wiki/Fibonacci_number#Matrix_form and its representation. This yields the memoization trick from above. If done correctly, it might be possible to get the O(lg n) run-time which would be highly desired. On Tue, May 15, 2018 at 6:

Re: [go-nuts] time.Now takes ~3758 ns/op, is that normal?

2018-05-24 Thread Jesper Louis Andersen
On Thu, May 24, 2018 at 10:08 AM wrote: > > After I benchmark time.Now on my computer, I found that the time.Now > takes about 3758 ns to perform one operation, which is not very fast. The > benchmark is here > > (benchmarked on my

Re: [go-nuts] Re: Counting semaphore vs Workerpool

2018-05-28 Thread Jesper Louis Andersen
There is also a hybrid model: Model A: for each work item, create a goroutine. This is easy to program, but uses additional resources for the goroutines. Model B: keep a worker pool and feed a channel. This bounds the goroutine count and requires more code to pull off and make correct. I'm going

Re: [go-nuts] Ternary ... again

2018-08-16 Thread Jesper Louis Andersen
On Tue, Aug 14, 2018 at 6:43 PM Mark Volkmann wrote: > I’m new to Go and I imagine the idea of adding a ternary operator to Go > has been discussed many times. Rather than repeat that, can someone point > me to a discussion about why Go doesn’t add this? I’m struggling to > understand why it is d

Re: [go-nuts] Generics - Min challenge

2018-09-14 Thread Jesper Louis Andersen
On Wed, Sep 12, 2018 at 4:49 PM Wojciech S. Czarnecki wrote: > > This is not metaprogramming! > > Every and each statement is written by the human author in plain Go > and no code is produced by the program itself. > > The key of metaprogramming is the ability to treat code as data which can be m

Re: [go-nuts] Re: Wuffs: a new, memory-safe programming language

2019-01-10 Thread Jesper Louis Andersen
On Wed, Jan 9, 2019 at 7:07 PM Eric S. Raymond wrote: > > I agree. The class of old C program I am interested in is, however, > not generally limited by CPU but by network and (less commonly) disk > stalls. Again bear in mind that my type examples are NTP and DNS service. > A lot of other legac

Re: [go-nuts] Re: Wuffs: a new, memory-safe programming language

2019-01-10 Thread Jesper Louis Andersen
On Wed, Jan 9, 2019 at 7:55 PM 'Thomas Bushnell, BSG' via golang-nuts < golang-nuts@googlegroups.com> wrote: > > I'm curious about why transpilation would have significantly mitigated the > Heartbleed bug. > > Heartbleed is a bug which relies on two things: - Failure to do proper bounds checking

Re: [go-nuts] Re: Wuffs: a new, memory-safe programming language

2019-01-10 Thread Jesper Louis Andersen
nds checking/memory protection > library/technique for C I referred you to? Even a decrease in performance > will probably still be on par or better than the equivalent Go program. > > Much simpler and efficient. > > On Jan 10, 2019, at 10:49 AM, Jesper Louis Andersen < > jesp

Re: [go-nuts] Re: Wuffs: a new, memory-safe programming language

2019-01-10 Thread Jesper Louis Andersen
On Thu, Jan 10, 2019 at 6:26 PM Thomas Bushnell, BSG wrote: > I'm not sure the second one here is right. Heartbleed does not depend on > unitialized memory as far as I can tell. It works to copy whatever lies > after the incoming request buffer back to the attacker. It happens that in > the actua

Re: [go-nuts] Re: Wuffs: a new, memory-safe programming language

2019-01-10 Thread Jesper Louis Andersen
On Thu, Jan 10, 2019 at 7:39 PM Thomas Bushnell, BSG wrote: > >> The server crashes - that's how we handle "any other exception", as a > rule. > > I write Erlang for a living. We don't crash a server, ever, on a failure. Unless the failure is persistent :) > > I don't know what you mean by "just

Re: [go-nuts] Re: Wuffs: a new, memory-safe programming language

2019-01-10 Thread Jesper Louis Andersen
On Thu, Jan 10, 2019 at 9:00 PM Thomas Bushnell, BSG wrote: > > I think the paper you linked is exciting, and actually suggests that the > hard work which needs to be done will solve the problem without a change of > language. This fits my intuition: the things necessary to take advantage of > ty

Re: [go-nuts] How to increase concurrent users in net/http

2019-01-14 Thread Jesper Louis Andersen
This might not be due to Go, but rather due to a resource limit imposed by the operating system: # 5000. *. (1. -. 0.1954);; - : float = 4023. This is close to 4096, assuming a constant factor of other stuff needing resources. Also, as a first step, I'd recommend running your load generator on a

Re: [go-nuts] performance optimization

2019-01-16 Thread Jesper Louis Andersen
On Wed, Jan 16, 2019 at 11:55 AM Wojciech S. Czarnecki wrote: > You can't expect a million interrupts per second and host OS running > simultaneously. > (1us gives some 4k instructions inbetween on recent 3GHz cpu core) > > And to add: if you do anything with memory, it is usually considerably l

Re: [go-nuts] lock for assigning to different elements of an array

2019-02-01 Thread Jesper Louis Andersen
On Thu, Aug 3, 2017 at 9:21 AM Henrik Johansson wrote: > I think I am mostly after a mental pattern to easily recognise when > synchronizations are needed. > Assume every write to memory takes 10 seconds and is asynchronous, except that you have Read-Your-Own writes in a goroutine. You can redu

Re: [go-nuts] Contributors wanted: Quantitative performance improvement study

2019-02-04 Thread Jesper Louis Andersen
On Sat, Feb 2, 2019 at 1:37 AM Milind Thombre wrote: > Wow! > > Django is an order of magnitude slower than nodejs. Good to know these > numbers. Thanks for the link Shulhan! I don't see *go* in the list, which > framework does a typical go web app use? > > This can be important, but I too want t

Re: [go-nuts] lock for assigning to different elements of an array

2019-02-04 Thread Jesper Louis Andersen
Adding [0] to the mix of papers one ought to read. Adrian Colyer had this under his looking glass some months ago: https://blog.acolyer.org/2018/08/09/bounding-data-races-in-space-and-time-part-i/ The work is being done as part of the mutlicore OCaml effort: as part of handling multiple cores, one

Re: [go-nuts] Is Go a single pass compiler?

2019-03-02 Thread Jesper Louis Andersen
On Thu, Feb 28, 2019 at 12:46 AM wrote: > Thanks, Ian. > > I remember reading in some compiler book that languages should be designed > for a single pass to reduce compilation speed. > > As a guess: this was true in the past, but in a modern setting it fails to hold. Andy Keep's phd dissertation

Re: [go-nuts] Deferring a close that can fail

2019-03-20 Thread Jesper Louis Andersen
On Wed, Mar 20, 2019 at 12:57 AM David Collier-Brown wrote: > Is there an idiomatic way to address this? I ended up reading influxDB > code and doing all sorts of deranged safety-critical-system DFAs to > reassure myself this will actually work, but every time I do that, my brain > hurts! > > Not

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

2017-07-23 Thread Jesper Louis Andersen
On Sun, Jul 23, 2017 at 10:17 AM 'meta keule' via golang-nuts < golang-nuts@googlegroups.com> wrote: > > Hi, > > here is a proposal for an alternative to Generics for Go2: > > >From a quick skim: It looks like you are trying to discuss a combination of three things: * universals * type inference

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

2017-07-25 Thread Jesper Louis Andersen
On Tue, Jul 25, 2017 at 6:56 AM Glen Huang wrote: > > 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 fini

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

2017-07-25 Thread Jesper Louis Andersen
In the Erlang world, when people ask this question, we often say: "identify the truly concurrent activities in the system--make those into processes". To wit, a common mistake is to apply too much concurrency in a system where none is needed. If you run a new goroutine, then there has to be a concu

Re: [go-nuts] Re: Generics are overrated.

2017-07-29 Thread Jesper Louis Andersen
On Sat, Jul 29, 2017 at 6:36 PM wrote: > I just want to know sincerely, if people REALLY need generics so much, or > they are just complaining because they are used to it and it's in their > favorite programming language. > > Generics tend to serve at least two purposes in a programming langauge.

Re: [go-nuts] Storing uint64 values in DB

2017-07-30 Thread Jesper Louis Andersen
An alternative is just to use a 'bytea' or a bitstring in Postgres since you have a hash value anyhow. * It'll take 9 bytes rather than 8. But space is usually cheap nowadays. * a bitstring will take exactly 8 bytes. * a bytea is varying and can be extended to a larger hash later easily if needed.

Re: [go-nuts] Worker pool library.

2017-07-30 Thread Jesper Louis Andersen
Have you tried running your program under the race detector? (go test -race) >From a quick skim of the sources, I think there is a race on the line here https://github.com/brunoga/workerpool/blob/3aec5bae30ec64df86d045730e1a4b8bcc4ae774/workerpool.go#L202 because multiple workers are going to wr

Re: [go-nuts] Re: Experience using Go for a student projet

2017-07-30 Thread Jesper Louis Andersen
The documentation for https://golang.org/pkg/sync/#WaitGroup.Add suggests you should move the wg.Add(1) out of the Goroutine from here: https://github.com/Vivena/babelweb2/blob/03d03818e125f6f34c3b323b6cba786075888c00/main.go#L63 to there https://github.com/Vivena/babelweb2/blob/03d03818e125f6

Re: [go-nuts] Go channels overused and hyped?

2017-08-11 Thread Jesper Louis Andersen
On Tue, Aug 8, 2017 at 8:01 AM snmed wrote: > > I stumbled over a nice and very interesting Blog entry "Go channels are > bad and you should feel bad > " > , I would like to hear some opinions about that article >

Re: [go-nuts] Go channels overused and hyped?

2017-08-12 Thread Jesper Louis Andersen
On Fri, Aug 11, 2017 at 2:22 PM Chris Hopkins wrote: > The microsecond or so of cost you see I understood was *not* due to > there being thousands of operations needed to run the channel, but the > latency added by the stall, and scheduler overhead. > One particular case, which many benchma

Re: [go-nuts] Re: [Blog] Context should go away for Go 2

2017-08-15 Thread Jesper Louis Andersen
The key point in Go is rather simple: Since goroutines clean up for themselves, and since goroutines are not isolated from each other, memory-wise, you need an explicit cancellation system. And programmers must abide by its rule for the correct operation of the program. Programs communicate over

Re: [go-nuts] Generics and readability

2017-08-25 Thread Jesper Louis Andersen
On Thu, Aug 24, 2017 at 5:14 PM wrote: > func (r genType1) f(x, y genType2) (z getType2, err > error) > > In a language such as OCaml, you would define `f` as: let f r (x, y) = ... And the system would infer the type of `f` automatically. In your case it would probably infer something like v

Re: [go-nuts] Re: Generics and readability

2017-08-27 Thread Jesper Louis Andersen
On Sat, Aug 26, 2017 at 7:03 PM wrote: > > Generics user here, since Bjarne Stroustrup's CFront, the very first C++ > compiler. > > Whenever you use complex idioms you reduce the amount of people able to > understand your code and able to mantain it. The simpler the code, the more > people can he

Re: [go-nuts] Re: 『Q』How to make hugepagesize work with Go?

2017-09-06 Thread Jesper Louis Andersen
It is correct that you get superpages/hugepages automatically if they are enabled. But your software must also allocate pages in a way which lets the operating system carve out a huge page through a mmap() call (or similar). If the hugepage is 2 megabytes and your garbage collector allocates in 512

Re: [go-nuts] [urgent] the right way of using Blowfish decryption?

2017-09-12 Thread Jesper Louis Andersen
It is very likely that ECB mode is the culprit here because Blowfish is a 64bit cipher and thus uses an 8-byte blocksize. However, Go's crypto/cipher doesn't have ECB mode. And for good reason: it is a quite dangerous mode to use in general (A good example is on the wikipedia page for it, for inst

Re: [go-nuts] Re: context cancellation flake

2017-09-17 Thread Jesper Louis Andersen
On Sun, Sep 17, 2017 at 12:46 PM Steven Lee wrote: > Thank you Silviu, that seems to work. > > Do you know exactly why it flakes? what is racing? just for me to have an > understanding of why this happens > > It is somewhat common to use the TCP window as a feedback mechanism to the server. If yo

Re: [go-nuts] Tiny FSM

2017-09-24 Thread Jesper Louis Andersen
This method is common in functional programming as well. You are, essentially, computing a fixed point over the state machine (or in Rob's example a lexer state). That is, you are taking a set of state transitions and turning them into a function when looked at from the "outside". If you have a de

Re: [go-nuts] Re: concurrent write-only to map ok?

2017-10-15 Thread Jesper Louis Andersen
An added advantage of a channel solution is that it is far easier to reason about from a correctness point of view. And it needs less information transfer on the side for human beings. Don't underestimate the power of a solution which is easily picked up by later readers of the code base. On Sun,

Re: [go-nuts] access runtime implemented functions

2017-10-15 Thread Jesper Louis Andersen
The short answer: you can't, and it is a feature. The runtime "injects" certain functions into certain packages in order to build a bridge between the (internal) runtime and the "package world" accessible to programmers. Thus, they are only accessible in that package specific package (time). The

Re: [go-nuts] Re: How to pass a value to multiple readers of a shared channel

2017-10-17 Thread Jesper Louis Andersen
If you have serious performance needs, then something like the "Disruptor" pattern is useful. There are ports of that from Java to Go out there, but I don't know how stable or useful they are. The Disruptor pattern is to keep a circular ring-buffer of elements. The writer and each reader keeps tra

Re: [go-nuts] Re: Ternary operator needed in Go

2017-10-18 Thread Jesper Louis Andersen
If a language has two syntactic classes, statements and expressions, then having a choice operator in both seems somewhat redundant and bounds for confusion. If on the other hand, your language only has expressions, then there is only a single choice operator, and this whole thing doesn't matter.

Re: [go-nuts] Re: select is still a little unfair if there are more than 4 cases?

2017-10-28 Thread Jesper Louis Andersen
I don't think it needs to be uniformly fair. It just needs to prevent starvation of a channel for infinity. Any proof would have progress covered if we pick every channel once in a while, even under a heavily unfair weighting. You have to balance out the overhead of rolling a fair dice and the spee

Re: [go-nuts] Re: select is still a little unfair if there are more than 4 cases?

2017-10-29 Thread Jesper Louis Andersen
On Sat, Oct 28, 2017 at 11:59 PM John Souvestre wrote: > If it were uniformly fair then you couldn’t guarantee picking every > channel once in a while. Statistically it would be become more and more > probable, but never 100%. > > > You are touching on the subject of there being different ways

Re: [go-nuts] Golang capacity

2017-11-12 Thread Jesper Louis Andersen
To elaborate on Jan's point: If you extended capacity every time you called append, then you will have to reallocate and copy data quite a lot. So a clever system pushes a little bit more capacity in at the end to avoid such copies whenever an append happens. It is a trade-off between space usage

Re: [go-nuts] Can/should the SSA optimizer cross package boundaries?

2017-11-12 Thread Jesper Louis Andersen
In addition to tail-call optimization, you also need a "contification" pass, which removes intermediate functions in the SSA basic blocks where possible. The observation is that if a function always returns to the same point, then it can be turned into a continuation, which is exactly what an SSA b

Re: [go-nuts] Golang capacity

2017-11-12 Thread Jesper Louis Andersen
might require you to have 2 credits per slot though. If it works out, I'm pretty sure this is the way to attack them problem. (Mind you, I haven't done it with rigor, so I might be wrong). On Sun, Nov 12, 2017 at 5:01 PM Bakul Shah wrote: > On Sun, 12 Nov 2017 15:45:40 + Jes

Re: [go-nuts] Can/should the SSA optimizer cross package boundaries?

2017-11-12 Thread Jesper Louis Andersen
On Sun, Nov 12, 2017 at 9:15 PM Petar Maymounkov wrote: > This is an interesting suggestion. But it makes me wonder how this > compares against generating directly a bag of LLVM statically-typed > functions > and trying the intelligence of the LLVM SSA optimizer. Do you know if this > one resorts

Re: [go-nuts] Re: [urgent] need aguments to justify use of Go for a scientific application

2017-12-06 Thread Jesper Louis Andersen
The best point in time to switch languages are when one of the following things is happening: * There is a small experiment on the side of the larger system which can be handled in another language. * There is a large project which has failed internally in the business, it is severely behind and n

Re: [go-nuts] Traceroute

2017-12-06 Thread Jesper Louis Andersen
Hi! I think it would be far easier to help you if you wrote down what you tried, what happened and what you expected to happen. That way, people will be able to dig into the problem you are having more easily. In particular, what do you mean when you say it doesn't work correctly? On Mon, Dec 4

Re: [go-nuts] Re: Why is the cpu usage so high in a golang tcp server?

2017-12-19 Thread Jesper Louis Andersen
In addition, look at allocation. If you can keep the garbage collector constantly busy it'll use the available CPU cores in the machine. It is likely to improve the system by quite a lot. On Tue, Dec 19, 2017 at 11:36 AM Gulácsi Tamás wrote: > You don't need to use bufio, but you'll need bufferi

Re: [go-nuts] Re: select multiple expressions per case

2017-12-21 Thread Jesper Louis Andersen
To generalize, you have a number of events, either send or receive, on channels. One could also imagine that timers are events of a special kind. Likewise, atomic updates, data swaps and so on are events in a generalized select statement. These can be combined, either through "and" style semantics

Re: [go-nuts] Measuring low latency operations

2018-01-15 Thread Jesper Louis Andersen
General rules: * If possible, use the benchmark system inside the "testing" package. It will eliminate some common mistakes in benchmarking, but keep your head straight while doing it, so you don't accidentally measure setup time, or something else which is outside the thing you are trying to test

Re: [go-nuts] Re: How to implement Segment Tree in key/value datastore to use Google S2 geometry?

2018-01-15 Thread Jesper Louis Andersen
My intuition is that this screams S2 at the top of its lungs, provided that you can hook into the structure. It is simply storing a radix tree (PATRICIA) of S2 cells and attaching information about box bounding to all of these. This yields a compressed trie-like structure that you can probably mai

Re: [go-nuts] Re: Go schedule latency issue

2018-01-22 Thread Jesper Louis Andersen
Beware of running the test generator on the same machine as the SUT (system under test). There are several things here: * On localhost, the network stack bypasses several kernel parts. This may lead to wrong test data. * The test generator might steal resources from the SUT, skewing the numbers *

Re: [go-nuts] What is go concurrency based on?

2018-01-22 Thread Jesper Louis Andersen
The ultra-short and precise answer to this question is: multithreading. Go implements a multithreaded runtime which maps goroutines to threads in an N:M style. The idea is to obtain the efficiency of a libev model without limiting yourself to a single core. The hard part is to manage the mapping o

Re: [go-nuts] Go if else syntax .. suggested replacement

2019-05-12 Thread Jesper Louis Andersen
I don't think there are developers who find it unreadable once they know the logic of that operator. However, if you don't know the rules, then it looks like black magic. In large software developments, consistency beats convenience almost all the time. You can somewhat easily add another develope

Re: [go-nuts] Allow methods on primitives

2019-06-10 Thread Jesper Louis Andersen
On Mon, Jun 10, 2019 at 8:11 AM Michael Jones wrote: > I miss discriminated unions too. (Fancy new name, “sum types”). > They are called sum types because they work as an "addition" like construction in the type theory. Their dual, product types, are what people usually call records or structs i

Re: [go-nuts] how to access request data using global variable -- help

2019-06-10 Thread Jesper Louis Andersen
Hi! There is a fundamental thing you got to grok in Go, which is that the program is concurrent. If you have many requests to your server at the same time, they'll all try to write to your global `data`. This is called a data race, and it leads to all kinds of undefined behavior. You are not even

Re: [go-nuts] Allow methods on primitives

2019-06-10 Thread Jesper Louis Andersen
On Mon, Jun 10, 2019 at 1:34 PM Jan Mercl <0xj...@gmail.com> wrote: > > > On Mon, Jun 10, 2019, 13:07 Jesper Louis Andersen < > jesper.louis.ander...@gmail.com> wrote: > >> At some point, it is going to be "generally accepted" at which point >> lan

Re: [go-nuts] why need "assist garbage collection" at a GC cycle? (runtime Code)

2019-06-11 Thread Jesper Louis Andersen
Indeed. If you allocate data faster than the GC mark phase can find and mark it, it enlists the "mutator" (I.e., your program) to assist it in the GC. Roughly, allocations are now followed by some marking work, so the allocation rate doesn't outpace the marking rate. The solution is to lower your

Re: [go-nuts] Re: How to control go routine numbers in function call

2019-06-12 Thread Jesper Louis Andersen
And if you prefer a talk, there is one by Bryan C. Mills, https://www.youtube.com/watch?v=5zXAHh5tJqQ which describes common concurrency patterns and how to apply them. In your case, a buffered channel can work as a (counting) semaphore. The invariant is: the number of tokens in the channel is th

Re: [go-nuts] The "leave "if err != nil" alone?" anti-proposal

2019-06-30 Thread Jesper Louis Andersen
On Sat, Jun 29, 2019 at 9:30 PM Henrik Johansson wrote: > > I have a feeling that there is a quite large "silent majority" that pretty > much agrees with me. > > Go is a language with the following properties, among other things: * Massive concurrency through a high amount of gorutines * Identit

Re: [go-nuts] The "leave "if err != nil" alone?" anti-proposal

2019-07-01 Thread Jesper Louis Andersen
On Sun, Jun 30, 2019 at 7:05 PM Jan Mercl <0xj...@gmail.com> wrote: > On Sun, Jun 30, 2019 at 3:19 PM Jesper Louis Andersen > wrote: > > > This is where the try-construct will definitely improve the ergonomics > of the programming. > > With full respect to you opini

Re: [go-nuts] The "leave "if err != nil" alone?" anti-proposal

2019-07-01 Thread Jesper Louis Andersen
On Mon, Jul 1, 2019 at 3:43 AM Ian Lance Taylor wrote: > > Checked exceptions address some of the difficulties with exceptions. > However, they introduce new difficulties, and I do not believe they > work in large-scale programs. It is essentially a nominal effect system on exceptions. My bet i

Re: [go-nuts] Citation Needed

2019-07-08 Thread Jesper Louis Andersen
On Mon, Jul 8, 2019 at 11:22 AM Martin Schnabel wrote: > I would guess, that most of respondents using go for game development, > use it on the server side. Think multi-, browser- or mobile-games. > > Many modern games have considerable server side code bases as well for all kinds of things. And

Re: [go-nuts] Avoiding resource leaks with racing channels

2019-07-10 Thread Jesper Louis Andersen
On Tue, Jul 9, 2019 at 6:14 AM Daniel Eloff wrote: > If a select statement has multiple channels ready when it runs, then it > will choose one at a random. So if you fire something across a channel that > holds a resource, like an open file descriptor - you have no guarantees > that the other end

Re: [go-nuts] Avoiding resource leaks with racing channels

2019-07-10 Thread Jesper Louis Andersen
On Wed, Jul 10, 2019 at 6:45 PM Dan Eloff wrote: > On Wed, Jul 10, 2019 at 7:54 AM Michael Jones > wrote: > >> unbuffered means nothing is sent until is is simultaneously received, so >> there is no limbo or race or uncertainty. one sender "wins" the select and >> the others remain blocked waiti

Re: [go-nuts] Avoiding resource leaks with racing channels

2019-07-10 Thread Jesper Louis Andersen
On Wed, Jul 10, 2019 at 6:30 PM wrote: > > The best thing to do is to not use unmanaged resources. > Would be the Erlang solution. You cannot change the owner of an open file, and if the process owning it terminates, the file is closed. You can change ownership of a TCP socket, and then messages

Re: [go-nuts] Go for Data Science

2019-07-16 Thread Jesper Louis Andersen
On Tue, Jul 16, 2019 at 7:18 PM Slonik Az wrote: > REPL in a static AOT compiled language is hard, yet Swift somehow managed > to implement it. > > I must disagree. The technique is somewhat well known and has a long history. See e.g., various common lisp, and standard ml implementations. If you

Re: [go-nuts] P-local/M-local storage for goroutines?

2019-07-24 Thread Jesper Louis Andersen
On Wed, Jul 24, 2019 at 7:16 AM Zihan Yang wrote: > > I tried to evaluate the performance with lru & without lru, the > performance with a global lru is 10x slower than without lru at all. > > This would make me step back a bit and revisit my initial plan. If a global cache isn't helping, what ev

Re: [go-nuts] P-local/M-local storage for goroutines?

2019-07-25 Thread Jesper Louis Andersen
On Wed, Jul 24, 2019 at 6:05 PM Zihan Yang wrote: > I should have said that my evaluation is just self-written cycle > measurement, which is very rough and lack of repeated experiment. So the > factor number might be different in your case. But the contention for the > single sync.Mutex really hi

Re: [go-nuts] P-local/M-local storage for goroutines?

2019-07-26 Thread Jesper Louis Andersen
On Thu, Jul 25, 2019 at 1:47 PM Robert Engels wrote: > A sync.Map is lock free on read, and a single lock on writes and so will > out perform this solution in all cases. > > I wouldn't just matter-of-factly place lock-free algorithms above classical mutex locks in speed. -- You received this me

Re: [go-nuts] JSON Marshal for config file url encoding string.

2019-08-12 Thread Jesper Louis Andersen
Documented here: https://golang.org/pkg/encoding/json/#Marshal There is also a description of how to avoid it. On Mon, Aug 12, 2019 at 7:39 PM Rich wrote: > Hi I have an application that I wrote that uses JSON for the config file. > The application is a chatbot I use internally and allows users

Re: [go-nuts] Re: When doing "type X Y", is it a type alias or type redefinition or type adapter or something else?

2019-08-13 Thread Jesper Louis Andersen
On Tue, Aug 13, 2019 at 8:10 AM Sathish VJ wrote: > So doing *type X Y* is just a type declaration then? > > In a certain sense type X Y and type X = Y are both type declarations. They differ in that the first is generative, whereas the other is a synonym. In a generative pattern, you are

Re: [go-nuts] I know you cannot kill a goroutine, but ...

2019-08-13 Thread Jesper Louis Andersen
On Fri, Aug 9, 2019 at 8:34 PM wrote: > The current Go implementation smells of cooperative multitasking. Not a > bad thing, per se, but makes it hard to stop in certain degenerate cases. > Have I missed a way to deal with some of the discussed issues? > > My spider sense (intuition) says you mig

Re: [go-nuts] Re: mutual exclusion algorithm of Dijkstra - strange behaviour

2019-08-17 Thread Jesper Louis Andersen
On Fri, Aug 16, 2019 at 8:09 PM wrote: > The Go-Scheduler is unable to allow to switch to another goroutine in > busy-waiting-loops - > the only possibility to get around that problem is either to put > "switch-steps" into the source > - either "time.Sleep(1)" or "runtime.Gosched()". > I think th

Re: [go-nuts] Re: An old problem: lack of priority select cases

2019-08-31 Thread Jesper Louis Andersen
On Thu, Aug 29, 2019 at 7:02 AM Leo Lara wrote: > Hi Michael, > > The way I always have seen "transparent" used in software engineering is, > that the user of something (lirabry, service, framework, etc) can use it > without knowing its internal details, just normally, and the magic is done > in

Re: [go-nuts] Adding YAML to the stdlib

2016-09-23 Thread Jesper Louis Andersen
On Fri, Sep 23, 2016 at 8:06 PM, Zachary Gershman wrote: > I don't think the "I don't want this format in because I don't want to see > more of this format" doesn't work. People are going to keep using it, YAML > isn't a format that is going anywhere and I would love to know what you > would sugg

Re: [go-nuts] Any plan on improving Go's escape analysis?

2016-10-02 Thread Jesper Louis Andersen
On Sat, Oct 1, 2016 at 6:45 PM, Ian Lance Taylor wrote: > There are improvements to the compiler's escape analysis in every release. Also, escape/representation analysis is approximate in nature. So you can't easily detect all variants of this and have the compiler optimize them. A compiler ten

Re: [go-nuts] Go locking and channels much slower than Java equivalent, program spends most of time in sync.(*Mutex).Lock() and sync.(*Mutex).Unlock()

2016-10-02 Thread Jesper Louis Andersen
> > > This program has a store that holds the data, and a sync.Mutex that guards > concurrent access on reads and writes. This is a snippet of the locking > based implementation: > > type Store struct { >durations map[string]*Distribution >counters map[string]int64 >samples map[strin

Re: [go-nuts] Why "_ := x" is illegal but "var _ = x" is legal?

2016-10-13 Thread Jesper Louis Andersen
The rule is that a short variable declaration requires that at least one non-blank variable is new (the specification even says so) Consider _, y := 4,5 where one variable, y, is new. In _ := 6 or _, _ := 5, 7 this rule is violated, since there are no non-blank variables (and thus

Re: [go-nuts] About panic/recover in Golang

2016-10-13 Thread Jesper Louis Andersen
On Thu, Oct 13, 2016 at 3:54 PM Konstantin Khomoutov < flatw...@users.sourceforge.net> wrote: > > That's because there's the difference between the so-called normative > texts and so-called informative texts. Normative texts intently use dry > language with as minimal wording as possible to not a

Re: [go-nuts] Re: Proposal: add "future" internal type (similar to channel)

2016-10-20 Thread Jesper Louis Andersen
On Mon, Oct 17, 2016 at 5:08 PM adonovan via golang-nuts < golang-nuts@googlegroups.com> wrote: > > Go does not take a strong Erlang-like stance against concurrency with > shared variables, so mutexes really are critical to Go's concurrency. > > > Even Erlang took a more loose stance towards concu

Re: [go-nuts] A simple question - Can C++ and goLang coexist in the same ecosystem?

2016-10-24 Thread Jesper Louis Andersen
On Mon, Oct 24, 2016 at 2:51 AM Carlos Ferreira wrote: > > Using binds is a more efficient and direct approach. Also, why calling an > external command when you can just load a shared library? It never made any > sense to me... > One argument for calling externally is that it provides OS isolati

Re: [go-nuts] Re: A simple question - Can C++ and goLang coexist in the same ecosystem?

2016-10-24 Thread Jesper Louis Andersen
On Mon, Oct 24, 2016 at 11:51 AM Haddock wrote: > Just to be precise: Go has currently performance near Java, see > http://benchmarksgame.alioth.debian.org/u64q/go.html Nevertheless, that > is still 3x-15x faster than Python ;-), see > http://benchmarksgame.alioth.debian.org/u64q/python.html > >

Re: [go-nuts] Concurrently read map entries into a channel

2016-11-07 Thread Jesper Louis Andersen
On Sat, Nov 5, 2016 at 3:47 PM wrote: > > The map is also rather big and I want to avoid creating a temporary copy > of it. > > > In Erlang, you have a call on ETS tables called ets:safe_fixtable(Table, Fix). This makes the table safe for traversal until you remove the fix again. The rule is that

Re: [go-nuts] Memcached replacement in GO!

2016-11-16 Thread Jesper Louis Andersen
On Wed, Nov 16, 2016 at 3:10 PM Slawomir Pryczek wrote: > > - Much better Garbage Collection mechanism, that isn't skipping items with > short TTLs like LRU, so memory is not occupied with garbage data even if > item TTLs differ a lot. > > Could you expand on what this problem is? It sounds like

Re: [go-nuts] Why doens't function type support comparision but channel type does?

2016-11-24 Thread Jesper Louis Andersen
First idea: Two functions are the same if their pointers (or closure pointers) refer to the same value. This is usually a recipe for disaster. As many people have noted, program transformations made by the compiler can change the pointers. So the meaning of your program is suddenly dependent on the

  1   2   3   >