New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Scope macros in prelude #272

Open
mehcode opened this Issue May 23, 2018 · 9 comments

Comments

Projects
None yet
5 participants
@mehcode

mehcode commented May 23, 2018

Using the Rust 2018 preview mode in nightly I find myself wanting to just import all the log macros in one go vs. having to name them explicitly.

// Current situation
use log::{log, info, error};

// Desired situation (only imports log macros)
use log::prelude::*;
@sanmai-NL

This comment has been minimized.

sanmai-NL commented Jul 24, 2018

The practice of using globs to specify items does not leave you with less cognitive load as author, but does add cognitive load for readers not yet familiar with the full set of log macros.

@tkilbourn

This comment has been minimized.

tkilbourn commented Aug 13, 2018

I just ran into this, converting a medium-sized crate with lots of modules. use log::macros::*; would be acceptable to me as well, to call out that it's just the macros being imported.

@cavedweller

This comment has been minimized.

cavedweller commented Aug 14, 2018

I would also really like to have the macros namespaced so I could glob import them. This is not something I would expect to confuse people.

@alexcrichton

This comment has been minimized.

Member

alexcrichton commented Aug 14, 2018

The intention for the log crate in the near future is likely to take advantage of #[macro_export(local_inner_macros)] which won't need either a prelude module or a global import, and instead use log::info should work as expected.

@cavedweller

This comment has been minimized.

cavedweller commented Aug 14, 2018

@alexcrichton I think the comment here is that frequently we would frequently find ourselves with

use log::{warn, info, error}, when actually all I want to do is use log::*, then I frequently find myself being disrupted from my workflow when I need to go add another log level (since I didn't import them all because of deny(warnings).

I added syslog::macros::* for the Fuchsia syslog crate, and it works nicely.

@alexcrichton

This comment has been minimized.

Member

alexcrichton commented Aug 14, 2018

Ah ok, thanks for clarifying! Seems like a reasonable feature request to me!

@sanmai-NL

This comment has been minimized.

sanmai-NL commented Aug 15, 2018

@cavedweller and others reading that: a better way is to import all macros you ‘may’ use and allow unused imports on that import statement.

@cavedweller

This comment has been minimized.

cavedweller commented Aug 15, 2018

@sanmai-NL I think I disagree, for better or for worse, allows are significantly more confusing for a person onboarding to a codebase. They need to figure out what is special about that specific import, and then the statement doesn't get cleaned up when all the macros are actually all in use.

I don't think something like the import of logging utilities should take two lines either.

@sanmai-NL

This comment has been minimized.

sanmai-NL commented Aug 16, 2018

Any static analysis policy exception should of course be documented in a comment. Not cleaning the exception up would be proper in your case, it still applies, just happens to be inapplicable at some time, but could become applicable after a few changes. If you care about this then I’d suggest to just import what you use and change imports as necessary.

Complaining about the number of lines taken to achieve something (3 lines vs 1) is the kind of attitude that triggers me to put out this criticism. The job of a programmer is to produce quality software not type as little as possible (even though most of it is copy-paste, boilerplate stuff).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment