Code Monkey home page Code Monkey logo

Comments (8)

sharkdp avatar sharkdp commented on May 24, 2024 1

I didn't know that we could use dbg as a namespace name in addition to the macro name. Neat!

I started an initial implementation here: #68
Glad for any feedback.

from dbg-macro.

mhammerc avatar mhammerc commented on May 24, 2024

Implementation idea:

dbg(dbg_hex(number))

dbg_hex is a simple templated struct which hold the value. std::ostream& operator<< would be specialized to print as hex like you shown in the README.

from dbg-macro.

sharkdp avatar sharkdp commented on May 24, 2024

Thank you for your feedback!

I see how this could be useful and I kind of like the idea. The issue I see is that this could lead to feature creep.

For now, this header has a very simple "API": the dbg(…) macro - nothing more. If we decide to add custom formatting options, I'm afraid it would lead to a whole bunch of things that could potentially be added.

Also, I would like to avoid adding more names to the global namespace. If at all, it should probably be dbg(dbg_macro::hex(…)). If this could somehow nicely integrate with the I/O manipulators from <ios> and <iomanip>, that would be an option. But I don't want dbg(…) to take a second optional argument (see #2).

from dbg-macro.

mhammerc avatar mhammerc commented on May 24, 2024

I agree to not polluting the global namespace. But to keep consistency, maybe we should also move the dbg(...) macro to that new namespace? Or name the namespace dbg!

There are lots of flag from <ios> header. Best case would be supporting all of them.
When debugging, we want to be fast. No time to write a complex line like std::cout << std::hex << value << std::endl. Especially if we have more than one value to print (dbg() already solve this problem).

One problem is that std::ostream (cout, cerr and more) save flags that were set.

std::cout << std::hex;
std::cout << 15 << std::endl;

This code effectively print f (https://godbolt.org/z/caMvrD). If we apply flags from <ios> we have to duplicate std::cerr to not break user-defined flags (std::ostream stream(std::cerr.rdbuf())). Example: https://godbolt.org/z/J0GnAr

I suppose that debugging is consistent enough on a project lifetime so we can do the following (it is not a naming proposition):

 dbg::set(std::hex);
 dbg::set(std::boolalpha);
 ...
 dbg(true);
 dbg(15);

We keep the fast use of dbg() for all values, with an added optional set(), which could be project-scoped (example: set at top of the main()).

from dbg-macro.

mhammerc avatar mhammerc commented on May 24, 2024

Congrats!

I'll take a deep look in a day or two. Promise I'll feedback!

from dbg-macro.

mhammerc avatar mhammerc commented on May 24, 2024

I didn't know that we could use dbg as a namespace name in addition to the macro name. Neat!

A macro is a preprocessor! That mean it gets translated in pre-processing which happen before compilation πŸ˜‹

from dbg-macro.

sharkdp avatar sharkdp commented on May 24, 2024

A macro is a preprocessor! That mean it gets translated in pre-processing which happen before compilation yum

I was afraid that the preprocessor (because it does not know anything about the syntax) would maybe affect a string like namespace dbg { when a #define dbg(…) … was around.

from dbg-macro.

mhammerc avatar mhammerc commented on May 24, 2024

I left a review! Great work :)

from dbg-macro.

Related Issues (20)

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.