Y
HN Search
Hacker News Search
new
|
comments
|
top
|
jobs
NateDad
searching PlanetScale…
1.
▲
2.
▲
3.
▲
4.
▲
5.
▲
6.
▲
38 ms
·
361.
▲
by
NateDad
12y ago
Sorry to be confusing and/or confused. Map access in Go returns value, boolean where the boolean indicates if the key existed in the map. This is in contrast to most functions which can fail with a generic "error" value. So
362.
▲
by
NateDad
12y ago
Sorry, you're right. I was thinking of tuples without defined types for the slots, like "this function returns a tuple of two objects", not "this function returns a tuple of (string, int)".
363.
▲
by
NateDad
12y ago
A tuple appears to be a special case of a struct. Not sure why you need (int, bool) when you can have struct{i int, b bool}... the tuple you have to access via index, and the struct you access via name... and by name is much more clear in
364.
▲
by
NateDad
12y ago
Cramming a lot of logic into a single line of code is an anti-pattern and not a goal of the go language. Also see the aforementioned "the answer is to write a loop".
365.
▲
by
NateDad
12y ago
There are no list comprehensions, but they're just trivial loops, anyway. Generators of a sort can be created, but are not commonly used. There are several web frameworks, I don't know flask, so can't answer if any are like
366.
▲
by
NateDad
12y ago
For most people's uses, it's the same. Certainly, there can be performance benefits if your language's implementation uses lazy evaluation and you have a very large list and you only need to evaluate a small portion of the li
367.
▲
by
NateDad
12y ago
Most of the questions about "how do I do X in Go?" are answered with "just write a loop". Yes, that means map/reduce, filter, fold, zip, etc. If writing simple loops gets your hackles up, Go is not the language fo
368.
▲
by
NateDad
12y ago
This is why Go has standalone functions and interfaces. You can easily share logic between types without having the types be the same thing. The biggest problem with inheritance is that it's a lot like monkey patching (except in pro
369.
▲
by
NateDad
12y ago
It's awesome because it's just a go package - no external dependency... Your application still ships as a single binary.
370.
▲
by
NateDad
12y ago
http://npf.io/2014/07/intro-to-boltdb-painless-performant-pe...
371.
▲
by
NateDad
12y ago
There is almost never code that requires inheritance.
372.
▲
by
NateDad
12y ago
Yes but you really almost never need to do that. The speed difference is usually only a factor of 2ish... It's not like the factor of 10-30x for interpreted languages.
373.
▲
by
NateDad
12y ago
Almost everything you said is blatantly incorrect with the possible exception of better weather (some of us actually like having seasons... But it is obviously much colder in winter).
374.
▲
by
NateDad
12y ago
False is not a valid value for an error... Welcome to static typing ;). It's either nil or some valid error.
375.
▲
by
NateDad
12y ago
You can always call a function and not assign the return calls to anything. If you have func foo() (string, error) You can still call it thusly: foo() However there are tools to check for unchecked errors like this one: https://g
376.
▲
by
NateDad
12y ago
What's the difference between that and multiple returns? You can have func foo() (string, int) func bar(a string, b int) And do bar(foo()) The only thing you couldn't do is make a slice of tuples... But you can make a slice of str
377.
▲
by
NateDad
12y ago
Juju ( https://jujucharms.com )
378.
▲
by
NateDad
12y ago
When you're dealing with Google, Microsoft, Amazon, etc etc.... someone's going to be slow, someone's going to be fast. Maybe Azure paid for first dibs, I don't know. From experience I'd say probably Azure just wa
379.
▲
by
NateDad
12y ago
See, that's not a problem of the map, that's a problem of poor error handling. If for some reason database.ControlCenters() could ever not return a valid map, it would also return an error value. controlCenters, err := data
380.
▲
by
NateDad
12y ago
Not sure what you mean by needing a dummy value if your function only returns success/failure. That's what a boring old error return is for. func foo() error
381.
▲
by
NateDad
12y ago
disclaimer: I'm a Juju dev It's a lot more than configuration management. It's coordinating multiple machines across a cloud (public or private) - we call it "orchestration". It's not just "install this s
382.
▲
by
NateDad
12y ago
Heh, good point :)
383.
▲
by
NateDad
12y ago
What's the difference between a nil map and a non-nil but empty map? You asked if the map had a value for your key, and it said no.
384.
▲
by
NateDad
12y ago
I don't think it's dangerous at all. What's the difference between an empty, non-nil map and a nil map? Why should their behavior differ? The fact that a map can be nil is effectively like an implementation detail. You ask
385.
▲
by
NateDad
12y ago
Go doesn't have tuples because they aren't very compatible with compile-time type safety. You could using []interface{} as a tuple, but why would you? Go does have anonymous structs, they're just only of moderate use in
386.
▲
by
NateDad
12y ago
Go has effectively built in option types - multiple returns... And almost every function that can fail uses them. That's what I was trying to say. No, you can't implement actual option types in any kind of reasonable way, but you
387.
▲
by
NateDad
12y ago
This is one nice thing about go maps... They won't panic if you try to access a null map, they just return the zero value (and false). var m map[int]int = nil a, ok := m[1] // returns 0, false
388.
▲
by
NateDad
12y ago
I;m sorry there wasn't more talk of Go, I think the author might like some of what Go has to offer. For example, the comparison about maps at the bottom would benefit from seeing the way Go maps work. There's the single assignment
389.
▲
by
NateDad
12y ago
If, somehow, figuring out what interfaces a type implements is valuable, I would use a tool, like this one: https://github.com/dominikh/implements
390.
▲
by
NateDad
12y ago
Yeah, this type of check is nice if you intend to implement an interface, but don't actually use the type as that interface in your package. This will give a compile time error if your type doesn't satisfy the interface. You could
More ›