Hot answers tagged

73

I'm only a casual Go user, so take the following with a grain of salt. Wikipedia defines green threads as "threads that are scheduled by a virtual machine (VM) instead of natively by the underlying operating system". Green threads emulate multithreaded environments without relying on any native OS capabilities, and they are managed in user space instead of ...


70

One potential reason for this omission is that it's really easy to model sets with a map. To be honest I think it's a bit of an oversight too, however looking at Perl, the story's exactly the same. In Perl you get lists and hashtables, in Go you get arrays, slices, and maps. In Perl you'd generally use a hashtable for any and all problems relating to a set, ...


64

What happens in Rust if you define a function that implements a trait but you don't use impl? It just doesn't work? You need to explicitly implement the trait; happening to have a method with matching name/signature is meaningless for Rust. Generic call dispatching Are these the only non-trivial differences? If so, it would appear Go's Interface/Type ...


50

The best way to ask is probably to the people working on it; exactly what I did! Tl;dr: it was originally there before make and &{}, and it's still the function to use in some situations. Basically, here are the most important parts quoted: So what's the reasoning behind new ? Is it something useful ? Should we use it ? You cannot ...


35

The Hindley-Milner type inference is used for Hindley-Milner type systems, a restriction of System-F type systems. The interesting feature of HM type systems is that they have parametric polymorphism (aka. generics). That is the single biggest type system feature that Golang refuses to have. With that frustrating restriction, HM-style type inference is ...


21

In practice, there is very little difference: both represent separate units of execution whose primary interface with the outside world is via messages. The differences are in the implementation details of the languages. Here are a few such details: Channels in Go are typed; if you want to send messages with different data, you need separate channels. ...


21

Libraries and re-use are absolutely a good thing. They have one giant downside, which is that if not carefully managed, they become the equivalent of the drawer in your kitchen that holds all of the odds and ends that don't go anywhere else. I saw this in action when I became responsible for the first ports of an entire business unit's worth of code (...


20

one use case - websockets: as websockets are long-lived compared to simple requests, on a busy server a lot of websockets will accumulate over time. microthreads give you a good conceptual modelling and also an relatively easy implementation. more in general, cases in which numerous more or less autonomous units are waiting for certain events to occur ...


19

Go isn't specifically a "systems programming language", it's a general purpose programming language. You don't need any prior knowledge of C to get started, it's not very close to C at all (even syntactically). You don't need specific systems concepts (Unix or otherwise) either. A fair understanding of how to get things done on the command line and how to ...


17

The old netchan was too intricate. The problem is to find a way to provide Go channel semantics on top of network hardware and software that, as always, finds a way to defeat all attempts at clean design. I will continue to ponder. -rob new netchan


16

There is no new paradigm. Object orientation is a pattern you use to write programs, which is not even clearly defined. Various languages provide various traits typical of object orientation (definition of new types, encapsulation, type hierarchies, polymorphism, message passing and more) but may fail to provide others. In those cases it is up to programmers ...


16

It might help to think of what Erlang was originally designed to do, which was to manage telecommunications. Activities like routing, switching, sensor collection/aggregation, etc. Bringing this into the web world - consider a system like Twitter. The system probably wouldn't use microthreads in generating web pages, but it could use them in its collection/...


16

The comment explains the reason - abs(-0) should return 0, but without the special case, abs(-0) would return -0. I assume Go uses IEEE floats so both +0 and -0 can be represented using different values for the sign bit.


13

There is a Google Custom Search page set up for Go Information "for everyone complaining that it is impossible to search for Go docs and info." I've also gotten good results through Google by including "go lang" as the first part of my search term. I do notice that I don't get a lot of independent blogs in my search results, but I do get results from Stack ...


13

He means that where you'd use something on the order of: class A : public B {}; in something like Java or C++, in Go you'd use (something equivalent to): class A { B b; }; Yes, this provides inheritance-like capabilities. Let's expand the example above a little bit: struct B { int foo() {} }; struct A { B b; }; A a; a.foo(); // not ...


13

See this StackOverflow answer regarding Go's type inference. I'm not familiar with Go myself but based on this answer it seems like a one-way "type deduction" (to borrow some C++ teminology). It means that if you have: x := y + z then the type of x is deduced by figuring out the type of y + z, which is a relatively trivial thing to do for the compiler. ...


13

You are not required to use GOPATH, but then you miss out on all the nice tooling that you get from the go command. They all expect code to be in the standard GOPATH hierarchy. You mentioned go install, but also go test (and the nice go test -cover coverage tool) won't work go get, which allows you to download remote code will write everything to the GOPATH,...


12

There's no equivalent. DDD needed a paradigm to support frequent rewriting in an evolutionary software development scenario. OOP looked like the only viable strategy back then. But Functional languages can serve such a scenario as well. You might want to have a look to Greg Young's video about DDD and Functional Programming and Patrik Fredriksson's video ...


12

In a language where you're not allowed to modify variables, the simple act of maintaining state requires a separate execution context (which most people would call a thread and Erlang calls a process). Basically, everything is a worker. Consider this Erlang function, which maintains a counter: counter(Value) -> receive ...


12

I don't see extension methods and implicit interfaces as the same at all. First let's speak to purpose. Extension methods exist as a syntactic sugar specifically to give you the ability to use a method as if it's a member of an object, without having access to the internals of that object. Without extension methods you can do exactly the same thing, you ...


11

Pass-by-reference makes some things more efficient and allows updates to parameters within subroutines, but it is by no means a panacea. Imagine a parallelized application. When using pass-by-reference, then you need a locking mechanism to keep a sane state. Pass-by-value doesn't have this limitation. I've seen multi-threaded programs which spend more time ...


10

A generic queue or array is generally not, by itself, thread safe, just like many other data types. Thread safety is usually accomplished in two ways: Using mutex locks - each thread that wants to modify a value has to wait. Delegation - only the owning thread can modify the value. Mutex locks are fairly straight forward - nobody owns the value, but only ...


10

There are a few differences between Go and C that makes the former at least more type safe: Unless you muck about with the unsafe package, you're not going to crash a Go program (in the sense that it won't do something that causes the OS to kill it). You may cause it to panic, but this is not the same thing as a crash (and it is recoverable). Go does not ...


9

I am not sure about go, but D clearly specifies which constructs may access the garbage collector (down at the end here; I actually think I saw a more detailed explanation on the site, but can't quickly find it). So you can choose where gc can and can't operate. Runs directly on the limited memory, with no latency means (hard) real time. Which means you ...


9

The short answer is that Go is a successor to C, and C's standard math library is also defined almost exclusively in terms of single- and double-precision floating point values. The longer answer is that in a statically-typed language without polymorphism or function overloading, like Go (or C), you need to settle on a type for a function to take and ...


9

The IEEE 754 floating-point standard allows signed zeros. A negative zero is equal to a positive zero, so it wouldn't be covered by the < 0 test.


9

(disclaimer: I like designing stuff like this but I'm new to Go, I haven't tried it in practice) Idea: Why not both? There are two polar options available if you take symlinking into account: (A) Code in src, symlinked to workspace / doc/ src/ server/ projectname/ client/ index.html go_workspace/ src/ companyname/ ...


8

This question/problem is kind of similar to this one. In Go, you don't really have OOP. If you want to "specialize" an object, you do it by embedding, which is a composition, but with some goodies making it partially similar to inheritance. You do it like this : type ConnexionMysql struct { *sql.DB } In this sample, ConnexionMysql is a kind of ...


8

If most people don't mind along with the senior developer then you will have very difficult time persuading them all. In this case I would recommend just keep going with the original convention set forth by the original developer and at least keep things consistent. If other people are not okay with that as well then you can focus on the ROI of converting ...


Only top voted, non community-wiki answers of a minimum length are eligible