Comments (5)
This is definitely the intended behavior. If you need to inequality
between things like this or zero/nil slices, you'll need something like
reflect.DeepEqual.
On Fri, Mar 20, 2015, 6:16 PM Mihai [email protected] wrote:
var xs struct{
x, y map[string]string
}
xs.x = make(map[string]string)
xs.x = make(map[string]string)
fmt.Printf("%s", pretty.Compare(xs.x, xs.y)) // returns an empty string—
Reply to this email directly or view it on GitHub
#3.
from godebug.
Debugging inequality on maps is not "pretty" thus the proposal to pretty print the diff between initialised and uninitialised maps.
Below is an example.
type Some struct{
Node *Some
one map[string]string
}
s := Some{}
s.one = make(map[string]string)
s1 := Some{}
if !reflect.DeepEqual(s, s1) {
fmt.Printf("s %v, s1 %v", s, s1)
}
Prints
s {map[] map[]}, s1 {map[] map[]}
from godebug.
I believe the examples show that Compare(x, y) == "" is the intended way to
check rough equality. My intent is that semantically equivalent objects be
considered equal. Zeroed and nil slices, for instance, should work the
same in correctly-written code. Empty and nil maps should similarly be
indistinguishable in normal use.
On Mon, Mar 23, 2015, 12:41 PM Mihai [email protected] wrote:
I see… though if Compare reports the diff between initialised and nil maps
it would improve the debug experience. I actually use reflect.DeepEqual to
test the inequality and Compare to print the differences.(which I think
it's how Compare is intended to be used). However if you have structs with
maps there is no way to tell why the inequality fails without to
reflect.DeepEqual on each map field. Let me know if there is something I'm
missing.
Here is an example:s := Some{}
s.one = make(map[string]string)
s1 := Some{}
if !reflect.DeepEqual(s, s1) {
fmt.Printf("s %v, s1 %v", s, s1)
}Prints
s {map[] map[]}, s1 {map[] map[]}
—
Reply to this email directly or view it on GitHub
#3 (comment).
from godebug.
While I agree that Compare is meant to be more coarse than reflect.DeepEqual, I think a "Why is reflect.DeepEqual returning false?" mode or function would be incredibly useful.
For instance reflect.DeepEqual
says that non nil functions are never equal, even if they have the same pointer value. pretty.Compare
will return nothing in this case. A pretty.DeepCompare
function would instead point out that the objects contain functions.
Similarly with other things that are not DeepEqual.
from godebug.
Thanks for the suggestion, but I think this feature request runs counter to the goals of godebug; I would check out go-spew which might have the level of detail that you want.
from godebug.
Related Issues (15)
- DiffChunks() with empty slices fails HOT 1
- Incompatibility with time.Time
- panic: reflect: call of reflect.Value.CanInterface on zero Value HOT 2
- Error calling String value method on nil HOT 1
- Compare() function uses a lot of RAM HOT 1
- Inifinite recursion issues. HOT 5
- Configuration for pretty.Compare HOT 2
- pretty.Compare can result in unexpected type coercion HOT 3
- diff.Diff() with an empty value produces one blank line HOT 2
- Add support for fmt.GoStringer interface HOT 1
- diff.Diff optimization if one input is empty. HOT 1
- Comparing two pointers should not nest HOT 1
- Special treatment for net.IP? HOT 2
- pretty doesn't respect method String() string HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from godebug.