Giter Site home page Giter Site logo

Comments (5)

kylelemons avatar kylelemons commented on July 17, 2024

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.

themihai avatar themihai commented on July 17, 2024

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.

kylelemons avatar kylelemons commented on July 17, 2024

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.

voutasaurus avatar voutasaurus commented on July 17, 2024

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.

kylelemons avatar kylelemons commented on July 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.