[webkit-dev] Easing printf based debugging in WebKit with an helper.

Shezan Baig shezbaig.wk at gmail.com
Fri Jul 20 09:48:03 PDT 2012

On Fri, Jul 20, 2012 at 11:48 AM, Brady Eidson <beidson at apple.com> wrote:
> On Jul 20, 2012, at 7:53 AM, Shezan Baig <shezbaig.wk at gmail.com> wrote:
>> And because I'm in the middle of debugging a particular issue, I don't
>> really want to create a new type that wraps up those (potentially
>> unrelated) variables, just in order to create an overloaded "debug()"
>> function that does the pretty printing.
> I'm not quite sure what your point is here.
> - If you mean you don't want to be hassled by added a new template for a super long debug statement - debug(a, b, c, d, e, f, g, h, i, j, k, l) when the built in utility only supports up through k - then that seems somewhat silly as doing so would be simple and mechanical.
> - If you mean you don't want to be hassled to add a new overload for the type you'd like to print, then you'd still have to add a new operator << overload for that type if it didn't already exist.
> - If you mean you don't think that debug() statements could be broken up in to multiple lines, of course they can.
> debug("Selectively printing variables:";
>    if (isSet(someVar1))
>         debug("someVar1 = ", someVar1);
>    if (isSet(someVar2))
>         debug("someVar1 = ", someVar1);
>    if (someVector.size())
>         debug(" someVector.items = ", someVector);
> debug("\n");

Yes, this one is pretty much what I meant.  My example was a bit
simplified, but I was thinking more along the lines that the code
around the debug() statements could be expensive, for example,
calculating some value from multiple sources and printing the final
result.  Within the context of a single function, it might not make
sense to create a separate function that is responsible for
calculating those values, especially if the variables involved are not
typically related.

But your points about readability and such are understood.


> Also notice it would be easy to templatize a debug() override to handle the pretty-printing of the vector directly, in addition to other POD and non-class types.
> Even without the vector enhancement, this version is simple easier on my eyes as it's not at odds with the entire rest of our code base.
> ~Brady
>> -shez-
>> _______________________________________________
>> webkit-dev mailing list
>> webkit-dev at lists.webkit.org
>> http://lists.webkit.org/mailman/listinfo/webkit-dev

More information about the webkit-dev mailing list