Giter Site home page Giter Site logo

my_rustfmt_config's Introduction

I find that long and often nested expression are a problem in a codebase, usually the represent bad abstractions and hide complexity the programmer should be aware of. This config does not favour code verticality, instead it makes long expressions clearly visible in the code base by allowing them to grow wider. By using a config with a low max_width this expressions will be split in different lines, therefore hiding its complexity and encouraging Rust programmers to use them. Bare in mind that just because a higher width is allowed, it does not mean is ok to reach it. In fact I use this higher limit to identify complex expressions that need to be reconsidered.

With this in mind the question is: Do I need a max_width? In my opinion yes, sometimes we don't have control over the code we use and it affects how we write our code in a project, this scenarios should not end in contributors having to deal with very wide lines of code.

I think the max width for Rust code should be that allowed for function declarations, and it should take into account that this is a typed programming language. I find that good functions usually don't need more than three parameters and if they do, usually it makes sense that some of them can be stored together. Assuming that a good argument name and its type name will need more or less 15 characters each, this gives us 90 characters for 3 arguments. Adding other 30 characters for the function name and the return type we get to 120 characters, the max_width of this config.

In Rust everything is an expression, but that does not mean every construct should be use freely as such. Hidden complexity in expressions is a problem in Rust and this config tries to make such complexity clear to the eyes, that is why the following arguments are set:

struct_lit_width = 0
single_line_let_else_max_width = 0
single_line_if_else_max_width = 0
struct_variant_width = 0

my_rustfmt_config's People

Contributors

hermegarcia avatar

Watchers

 avatar

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.