rustindia / Rust-for-undergrads

C/C++ programming probelms re-written in Rust
https://rustindia.github.io/Rust-for-undergrads/
GNU General Public License v3.0
253 stars 111 forks source link

More consistent coding style #64

Closed FrankKair closed 3 years ago

FrankKair commented 6 years ago

Hi, I think it would be nice to have a more consistent pattern, because some files differ a lot in coding style.

Examples:

// Brackets below
fn main()
{
// Brackets after
fn main() {
// No space between =
digit=n%10;
        r=(r*10)+digit;
        n=n/10;
// Space between =
let x = read();
        // Followed by no space between operator
        if(x>max){
            max=x;
        }

Even though someone could just "fix" this, I think that looking into some lint tool for Rust or some CI (like Travis) would be worth it.

What do you guys think?

morgangallant commented 6 years ago

Not a bad idea - I really liked how Go implemented gofmt, a consistent code styling tool which auto formats codebases into a particular style. The only problem with this, is the lack of customizability. Everything must look the same, but what if certain companies/teams prefer to have brackets below compared to after a function declaration?

I think an interesting addition would be a tool which has a per project .format.toml file which the project managers could create and maintain settings for each cargo project, if they choose to override the default settings.

FrankKair commented 6 years ago

There are some things that are conventions and styles that Mozilla / Rust team recommends, and writing code that deviates too much from these pattern is somewhat confusing for beginners. It's always best to enforce the best practices / styles adopted by the community.

thefzsalam commented 6 years ago

I had tried fixing that to an extent in some of my early commits. Happy to offer any further help. :)