• brian@programming.dev
      link
      fedilink
      arrow-up
      0
      ·
      9 months ago

      I refuse to believe that people use a php style guide. I have yet to open a php file in the course of any job that doesn’t mix tabs and spaces arbitrarily on top of numerous other horrors.

      Luckily it’s not often that I have to, so sample size may play in a bit…

  • NuXCOM_90Percent@lemmy.zip
    link
    fedilink
    arrow-up
    0
    ·
    9 months ago

    Most languages with “official” formatting guidelines are due to limitations of the compiler/interpreter. Mixing whitespace in Python (or older Fortran) is a great way to error out massively.

    For the more modern compiled languages, there is no need. But there still tend to be popular formats from companies like Google

    • Kogasa@programming.dev
      link
      fedilink
      arrow-up
      0
      ·
      9 months ago

      You say this, but C# does have official code style conventions. It’s not about the compiler at all but about ensuring a relatively homogeneous coding style across the ecosystem, so a .NET dev can work on different projects without needing to refamiliarize.

      • NuXCOM_90Percent@lemmy.zip
        link
        fedilink
        arrow-up
        0
        ·
        9 months ago

        If indentation and newline policies prevent developers from migrating from one project to another then either your developer suck or your language does.

        That said, C# is somewhat special in that it is both a language and a corporate flag by Microsoft. Similar to how Google pushes to have their style guides made public so that other projects will adopt them. Which has less to do about making it so that one developer can bounce between projects (because they should be able to anyway) but to instead push Google as the goal everyone aspires to and emulates.

        • Kogasa@programming.dev
          link
          fedilink
          arrow-up
          0
          ·
          9 months ago

          There’s a lot more than indentation and newline policies. The default editorconfig is a few hundred lines. But there’s also no reason not to standardize indentation and newline policies.

        • stevecrox@kbin.social
          link
          fedilink
          arrow-up
          0
          ·
          9 months ago

          This is about thew new starter cost.

          When a developer joins a team, they will not be as productive as they have to learn the code, frameworks, libraries, the project purpose, the tooling, etc… Often this impacts other members of the team lowering the entire teams productivity.

          When you use productivity tracking (e.g. things like capacity planning) you will see the teams performance drop and it will take time for it to exceed the previous measured performance. This is the cost of adding a new starter.

          So if it takes 6 weeks for a new starter to increase overall team producitivty then planning someone on a project for 4 weeks is pointless since the team will have a higher delivery rate without the extra person. This is typically why an organsation loses its ability to migrate staff between projects.

          Code formating affects the layout of the code and our brains do all sorts of tricks around pattern recognition, so if your code formatting rules are too different a someone migrating between projects has to spend time looking for code and retraining their brain.

          Its an additional barrier and a one within an organisations skills to remove (by forcing a common code standard).

  • Ephera@lemmy.ml
    link
    fedilink
    arrow-up
    0
    ·
    9 months ago

    In my experience, they’re rarely as strictly enforced as e.g. flake8 does it for Python, but yeah, there is usually some resource suggesting a code style. If all else fails, you can look at some of the code the language authors have written. They’ll usually have developed a rather consistent style…

  • Nachorella@lemmy.sdf.org
    link
    fedilink
    arrow-up
    0
    ·
    9 months ago

    Rust has a style guide and comes with a linter. But I don’t think you need to follow it if you don’t want.

  • DrDeadCrash@programming.dev
    link
    fedilink
    arrow-up
    0
    ·
    9 months ago

    If you’re using visual studio (2022 is current) the idiomatic styling will be mostly correct by default (Ctrl k,e will reformat).

    • brian@programming.dev
      link
      fedilink
      arrow-up
      0
      ·
      edit-2
      9 months ago

      I’ve found it to be less strict than I’d prefer. Things like whether parameters are aligned or indented, whether or not the first one is on its own line, what statements are indented in fluent calls that have blocks, etc.

      A lot of other formatters (prettier, anything for python, etc) force something consistent in those cases, whereas it seems like the dotnet formatter prefers to leave things as they were.

      I’d love for it to be more opinionated and heavy handed if anyone has suggestions

  • navigatron@beehaw.org
    link
    fedilink
    arrow-up
    0
    ·
    9 months ago

    JavaScript / TypeScript are famously free-form, but a number of styles (and style-enforcing tools) have emerged.

    “Prettier” is the most recent. It actually parses your code into an AST and then re-prints it according to its style.

    “ESLint” is the most widespread; it is more of a framework into which rules can be plugged.

    I use “XO”, which is essentially a custom eslint ruleset with a few other nice things tacked on.

    The best part of eslint/xo is the “—fix” command, which can auto-fix most mistakes.

  • TehPers@beehaw.org
    link
    fedilink
    English
    arrow-up
    0
    ·
    9 months ago

    Someone else already mentioned Rust, but to add to it, rustup installs rustfmt (opinionated formatter) and clippy (linter) by default, but you can choose not to run them or even install them. rustfmt has a few configuration options, but is for the most part strict in how it formats code.

    PEP8 is nice since it sets some common rules across Python projects, but I’m not a fan of some of the decisions they made. The biggest one for me was discouraging defining variables/attributes/etc that use the same name as built-ins. That means no variable named input, no attr on your data model named id, etc. Still, since the language doesn’t strictly enforce this, you can easily adjust these rules to meet your project’s needs.

    I believe go requires you to run the bundled formatter to even compile the code, but I could be misremembering.

  • stevecrox@kbin.social
    link
    fedilink
    arrow-up
    0
    ·
    9 months ago

    Python is unique in formatting forms part of the syntax, every language has linters but its far more common for orgs to tweak the default rules .

    For example Java has Checkstyle. The default rules ‘sun checks’ give a line length of 80, tabs are 4 spaces and everything is placed on a new line.

    Junior devs inevitably want to trash the line length (honestly on 1080p monitors, 120 makes sense,).

    There is always a new line/same line discussion (everyone perfers same line but there is always one die hard new line person).

    The tab width discussion always has one junior dev complain that “tabs are better”, as someone who started development on Visual Studio 6 where half the team double spaced, the other half used tabs. Those people get a lecture from me on how we can convert tabs to spaces but not the inverse so it will always be spaces if I am near.

    With Checkstyle you upload the rule file as an artifact into your M2 repository. Then you can pull it down as a dependency when the checkstyle plugin runs.

  • nephs@lemmygrad.ml
    link
    fedilink
    arrow-up
    0
    ·
    9 months ago

    Javascript has airbnb style guide, enforceable through eslint. There’s also react related eslint extensions to give you a lot of best practices to follow.

    There’s also prettier, which is just about formatting.

  • Kogasa@programming.dev
    link
    fedilink
    arrow-up
    0
    ·
    9 months ago

    For practical advice, I recommend starting a project with dotnet new editorconfig which covers many of the .NET coding conventions. If you want more strict standards you can use StyleCop, but you will need to configure it a bit to be consistent with the .NET conventions.