Code Monkey home page Code Monkey logo

Comments (3)

twitu avatar twitu commented on May 28, 2024

I added some configuration to this.

plugins.sbt

addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.3")

I added more configuration from sbt-scalafmt-defaults which has a collection of default scala settings.

After this running sbt scalafmtAll formats all scala source files in the project. There are task keys that can be used to add formatting checks to CI as well.

I'm linking a PR for review to check that the settings and reformatting rules are comfortable.

from mlscript.

LPTK avatar LPTK commented on May 28, 2024

Thanks for the suggestion, but I'm a bit torn on the subject of automated formatting.

On one hand, I agree that the formatting in the current code base is messy in some places, and can be improved. We try to keep under 100 columns, but sometimes don't respect that.

On the other hand, I often deeply dislike the output produced by scalafmt. Whenever something overflows, it suddenly choses to put everything on different lines, even single parens and braces, creating a huge amount of wasted whitespace and essentially noise.

We've actually been using scalafmt in another project, and I find it quite annoying. It creates needlessly big diffs for small changes when it decides to refactor the whole expression's layout, for example.

I found the dense code difficult to navigate and understand

I'm not surprised you found the code hard to follow, but I'd be surprised if that was mainly because of the formatting. The code base is at times quite complex. Introducing excessive whitespace in the middle of complex and dense logic does not make the logic simpler to understand, unfortunately. Quite the contrary I would say – the more information-dense the code is, the more you can grasp at a glance without having to go back and forth across wastelands of auto-formatting gore generated by scalafmt 😛

I think the code logic should be better documented and simplified, for example by using more intermediate functions and more named local values. This is likely yo have a much bigger impact than formatting.

So I'd much rather you suggest clarifying changes and manual formatting improvements whenever you come across such things, than to adopt automated formatting for the project wholesale, at least for now.

from mlscript.

twitu avatar twitu commented on May 28, 2024

As we discussed in the sample PR, commonly used formatting rules makes many whitespace changes and creates larger diffs. This is not desirable.

However there is some value to having consistent (if not very strict) styling. It does make it a little easier to write and understand. There could be a bare bones formatter setting that could be created from these possible configurations.

Some points I can think of -

  • white space formatting (2 spaces, remove trailing white space)
  • new line before method, class, object declarations to make it less like a wall of text
  • shorter lines while staying withing a nesting depth limit

from mlscript.

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.