Elixir: Diffing algorithm is sometimes hard to parse

Created on 24 May 2016  ·  10Comments  ·  Source: elixir-lang/elixir

Many times diffing is super helpful but sometimes it is very hard to understand exactly what is wrong:

screen shot 2016-05-24 at 22 57 01

The diff helps because it gives me an idea of _where_ is wrong but it is hard to put together exactly _what_. I have been thinking about this and what if we print the diff alongside the original lhs and rhs instead of a separate row? Something like this:

image

For maps, the lhs would show in red values that it is not on the lhs and the rhs in green values not in the lhs. Same keys different values follow the same rule. Or maybe for maps the diff: row is the best way to go still.

Thoughts?

To-do list taken from https://github.com/elixir-lang/elixir/issues/4682#issuecomment-221511114:

  • [x] 1. List diff needs improvement – make it less noisy and more content aware
  • [x] 2. Handle whitespace diff in some way (thoughts?)
  • [x] 3. Try separated diff
ExUnit Chore Advanced Discussion

Most helpful comment

Sometimes it just looks cute
screenshot 2016-06-03 14 15 42

All 10 comments

👍 . Also, whitespace diffs are not highlighted in any way, which has been annoying a couple of times.

Maybe one solution is to have the format diff function return a diff list, e.g. [eq: ..., less: ..., more: ..., [less: ...]] which can be arbitrarily nested. Then we print the lhs with eq and removals and the rhs with eq and additions. Thoughts @lexmag? :)

I think there are 3 problems mentioned in the issue:

  1. List diff needs improvement – make it less noisy and more content aware
  2. Handle whitespace diff in some way (thoughts?)
  3. Try separated diff

I'm starting work on 1. and 3.
I think having separated diff will be really good improvement, almost every diff tool provide both, unified and separated, diffing but I don't remember when I've used unified diff last time in such tools.
It should also solve the issue with inner string diff after https://github.com/elixir-lang/elixir/commit/bdee464c0cdb5fafb1ba2fd3f0fc28f03ffffb94.

I think the only whitespace diff that isn't handled is spaces, so maybe we can display the diff for those as spaces with a green or red background?

Traditionally an interpunct character (·) and the open box character (␣) are often used to signify whitespace.
https://en.wikipedia.org/wiki/Interpunct

I could have a go at implementing this or the coloured background solution if that's OK.

@lexmag I think I found a bug in the new diff!

image

The comma should be part of the diff most likely. :)

@josevalim the fix is in master.

Sometimes it just looks cute
screenshot 2016-06-03 14 15 42

Alright, there are first results for content-aware lists difference:

  • first pair of lines – current output
  • second pair of lines – new output

_ignore keywords formatting_

screen shot 2016-06-05 at 00 15 56

Those look great to me, specially the keywords one. :D

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andrewcottage picture andrewcottage  ·  3Comments

josevalim picture josevalim  ·  3Comments

coryodaniel picture coryodaniel  ·  3Comments

LucianaMarques picture LucianaMarques  ·  3Comments

DEvil0000 picture DEvil0000  ·  3Comments