Conversation
|
@wilzbach What's your rationale for including this in the std lib, I remain unconvinced of it's need. |
This is based on the As said this implementation is not perfect, but I thought that I share the opinion with other people that a default debugging function would be useful and we can continue the discussion here. |
|
|
I agree with @9il. One should be able to use this formatting helper to write data to any OutputRange. |
|
Can't this be a normal template function that takes the variables as aliases, using dump!(x, y);But this doesn't allow expressions; maybe add an overload for these? |
|
@schuetzm You can also use |
9cb4406 to
b620b99
Compare
Yep as said I just opened this PR, because everyone agreed that
I experimented a bit and there are a couple of design questions: 1) Should we allow runtime arguments?Pro: No need for lambdas setting separators: 2) What should
|
But |
|
Agree that @9il 's suggestion is the best way forward. |
|
There are already multiple mechanisms for doing this, I don't see that adding another adds much value. |
|
@WalterBright: Which are those? |
|
@9il suggestions? |
|
Codecov Report
@@ Coverage Diff @@
## master #4318 +/- ##
==========================================
+ Coverage 88.78% 88.79% +<.01%
==========================================
Files 121 121
Lines 74154 74223 +69
==========================================
+ Hits 65840 65903 +63
- Misses 8314 8320 +6
Continue to review full report at Codecov.
|
|
@wilzbach, thanks for your PR! By analyzing the annotation information on this pull request, we identified @andralex, @9rnsr and @9il to be potential reviewers. @andralex: The PR was automatically assigned to you, please reassign it if you were identified mistakenly. |
I worked a bit on this and I think the way I found is quite nice - it reuses the int x = 5, y = 3;
assert(dump!(x, y)("%s = %s, ") == "x = 5, y = 3");
// with order
assert(dump!(x, y)("%2$s = %1$s, ") == "5 = x, 3 = y");
// with runtime args
assert(dump!(x, y)("%s = %s, ", () => 42) == "x = 5, y = 3, () = 42");
// with runtime args & position-specifier
assert(dump!(x, y)("%1$s = %2$s; ", "var1") == "x = 5; y = 3; 0 = var1");
// with types
assert(dump!(x, y)("(%s: %3$s) = %2$s, ") == "(x: int) = 5, (y: int) = 3");
assert(dump!(x, y)("(%s!%3$s) = %2$s, ") == "(x!int) = 5, (y!int) = 3");
// custom separator
assert(dump!(x, y)("%s = %s; ") == "x = 5; y = 3");
// all printf formatting commands work
assert(dump!(x, y)("%-4s = %4s, ") == "x = 5, y = 3");
// special formatting (if applicable for all types)
auto z1 = 2.0, z2 = 4.0;
assert(dump!(z1, z2)("%s = %.3f & ") == "z1 = 2.000 & z2 = 4.000");
// functions
assert(dump!(x, y, () => x + y)("%s = %s; ") == "x = 5; y = 3; () = 8");
// runtime paramters
auto b = (int a) => ++a;
assert(dump!(x, y)("%s = %s, ", b(x), x - y) == "x = 5, y = 3, 0 = 6, 1 = 2");
// validate laziness
auto c = (ref int a) => ++a;
assert(dump!(x, y, () => x + y)("%s = %s, ", c(x), x - y) == "x = 5, y = 3, () = 8, 0 = 6, 1 = 3");
assert(dump!(x, y, () => x + y)("%s = %s, ", c(x), x - y) == "x = 6, y = 3, () = 9, 0 = 7, 1 = 4");This was copied from the unit tests, in case the PR changes. Any output range can be passed as first argument, e.g. Anyways this isn't perfect yet, but before I invest more time into testing this, I wanted to know whether this still looks interesting. Also I am not quite sure what the best way for an interface to
CC @burner |
|
I'm not vested in this, since I generally use But I don't see in your list, a simple |
That's exactly why I wanted to know whether this is seen as something that benefits the majority.
Well, yes that's just an API question. |
|
@wilzbach IMO the current version is way to complicated. IMO it should be stupid simple, something like: dump(x, y) == "x == 5, y == 6"or people should use writeXXX or logX |
The problem is that AFAIK only with alias parameters we can get the variable name. dump!(x, y) // x == 5, y == 6
dump(x, y) // arg.1= 5, arg.2 = 6 |
|
See the NG discussion at: http://forum.dlang.org/post/iebzhymdicrshqsyfbre@forum.dlang.org |
|
Moving this to the Phantom Zone as its going nowhere. |
|
What's the holdup on this one? I thought it was going well. Though IMO, to simplify the code, we should simply support just |
|
Is this addition required? I honestly don't see any benefit when compared to the existing methods. |
I agree |
|
Since there wasn't any activity on this PR for quite some time and we don't have a champion for it + we can already do this with what we have in |
Idea: provide a user-friendly to dump variables
Origin: #3971
I took the macro from @tofuninja and cleaned it a bit, s.t. we don't forgot about it.
The advantage of a mixin is that we automatically infer the name of the expression, but I guess we should probably also provide a non-mixin variant too?
Other ideas are welcome!