News for hackers. Stuff that matters.
Re:A Prettier JavaScript Formatter by Dangeranger on Tuesday January 10, 2017 @02:05PM (#13367840)
After using Elm and the elm-format package in Emacs for the last few weeks I can say that not having to format the source and just letting your editor do it for you on save or via a command is so very nice.

This is a trend that I feel is going to catch on across any language that can support it. It makes trivial decisions and arguments about formatting a thing of the past.

Re:A Prettier JavaScript Formatter by StevePerkins on Tuesday January 10, 2017 @03:14PM (#13368517)
> This is a trend that I feel is going to catch on

This has been pretty standard practice in the boring ol' enterprise for at least 10 or 15 years.

Java has Checkstyle, with format-on-save support for IntelliJ, Eclipse, and NetBeans at the very least. Visual Studio supports this for all of the .NET languages. Obviously, Golang has `go fmt`. Etc.

Not to be snarky, but whenever a bold new trend seems to be really "catching on"... it's almost always a rehash of something that the enterprise was doing back in the 90's, or academic researchers were writing papers about back in the 70's. The only things that ever really change in this industry are: (1) solutions that were once impractical on old hardware become practical on newer hardware, and (2) solutions that were over-engineered in their original form come back in more user-friendly simplified forms.

Re:A Prettier JavaScript Formatter by DontGiveTwoFlux on Wednesday January 11, 2017 @12:39AM (#13372015)
Have you used the Visual Studio tools?

Could you point me in a direction to set this up on my system?

Re:A Prettier JavaScript Formatter by overcast on Tuesday January 10, 2017 @02:21PM (#13368010)
It's almost crazy to think this already isn't just a thing. Why is this just coming to a head now, after all these years of carrying on over code formatting?
Re:A Prettier JavaScript Formatter by kajecounterhack on Tuesday January 10, 2017 @02:35PM (#13368156)
Many communities have been using their own solutions for it for a while (e.g pylint / pep8 if you've used Python, clang-format for C++, js-beautify for javascript, etc) and many companies use "linter as style enforcer" but you still need to watch out for some things that linters don't catch in most languages.

FWIW if you use vim, this plugin is great: https://github.com/google/vim-codefmt

Re:A Prettier JavaScript Formatter by mrgoldenbrown on Tuesday January 10, 2017 @04:01PM (#13368938)
I'm not convinced it is just coming to a head now. I've seen automatic/forced formatting on projects at least as far back as 2000, when I entered the workforce.
Re:A Prettier JavaScript Formatter by djeikyb on Tuesday January 10, 2017 @10:16PM (#13371453)
The ones I've used for java have been consistently bad though. Autoformat as a commit hook leads to ugly code. Granted, I mean "bad" as in "gets ya 75% of the way".
Re:A Prettier JavaScript Formatter by overcast on Tuesday January 10, 2017 @04:04PM (#13368964)
Yes, forced/automated based on that company standards. I'm referring more to universal.
Re:A Prettier JavaScript Formatter by nine_k on Tuesday January 10, 2017 @02:28PM (#13368074)
I bet you heard of "go fmt".
Re:A Prettier JavaScript Formatter by overcast on Tuesday January 10, 2017 @02:40PM (#13368191)
Right, but that's a single relatively new language.
Re:A Prettier JavaScript Formatter by mhd on Wednesday January 11, 2017 @06:35AM (#13373216)
I wonder why this is suddenly accepted. Having very rigid coding standards used to be a no-go for projects you were either not paid for or in an industry where "creative expression" mattered more (i.e. not J2EE).

There were coding styles, but actually enforcing them wasn't something regularly done (linting is okay), for fear of "bondage & discipline" complaints.

Now the former "rock star" Ruby developers are embracing static typing and Ein Code, Ein Style formatting. Weird.

Re:A Prettier JavaScript Formatter by benologist on Tuesday January 10, 2017 @04:00PM (#13368934)
Gofmt was the catalyst for me. I do it with StandardJS in Visual Studio Code on save automatically, I won't waste my time manually formatting code - or caring about it - again.

Personal code formatting preferences is a problem. Devs should just let go of it, once it applies automatically your preferences quickly change.

You can even wire up GitHub etc repos to automatically reject pull requests that add pointless formatting preferences someone will pointedly defend.

Re:A Prettier JavaScript Formatter by jeremy_wiebe on Wednesday January 11, 2017 @12:06AM (#13371894)
Can you point me to more information regarding Github and rejecting pull requests that are strictly formatting changes? Sounds interesting...
Re:A Prettier JavaScript Formatter by benologist on Wednesday January 11, 2017 @11:17AM (#13374962)
The formatters have command line programs that return error codes if a file requires fixing so you can require not getting an error from that in your testing or building process.
Re:A Prettier JavaScript Formatter by zem on Tuesday January 10, 2017 @02:46PM (#13368253)
i hate the output of elm-format, though :( it's very wasteful of vertical space.
Re:A Prettier JavaScript Formatter by david-given on Tuesday January 10, 2017 @06:09PM (#13370125)
Tangential question:

Why do Haskell and Elm format lists like this?

    type alias Circle =
        { x : Float
        , y : Float
        , radius : Float
        }
...and not like this:

    type alias Circle = {
      x : Float,
      y : Float,
      radius : Float
    }
...? The first makes me shudder with revulsion every time I see it --- that's not where commas go, dammit --- and there must be a reason, which I've never been able to figure out.

The Elm style guide mentions in passing that trailing commas require a diff that adds a field to modify two lines but one, but that applies to leading commas too if you add the field at the beginning of the list.

Re:A Prettier JavaScript Formatter by jkochis on Tuesday January 10, 2017 @08:45PM (#13371074)
I get why this bothers a lot of people, but OTOH I get why some people like it. I think the reason for the former in the mind of the user is that the comma clearly signifies that you are adding another value after it, and you save valuable key strokes not having to add a comma to the end of the preceding line just to add another k:v on the line you're concerned about.
Re:A Prettier JavaScript Formatter by Vinnl on Wednesday January 11, 2017 @10:11AM (#13374419)
- It allows you to easily delete a line without needing to also modify the line before. - It also makes your diffs cleaner. With the latter, if you add a line, you'll also have to inspect the `radius: Float` line when doing a code review, even though it only added a comma.
Re:A Prettier JavaScript Formatter by jeremy_wiebe on Wednesday January 11, 2017 @12:09AM (#13371910)
Putting he comma at the start of the line allows for deleting any line without having to edit another (unless it's the first in which case the missing brace is more obvious IMHO.

The trailing comma is more easily missed I'd say.

Re:A Prettier JavaScript Formatter by zem on Tuesday January 10, 2017 @07:24PM (#13370661)
this diff, right here, is what i'm complaining about. i decided to bite the bullet and start running elm-format since it was part of the 0.17->0.18 automigration tool, but it has yet to grow on me.

https://github.com/martindemello/crosspad.elm/commit/c67deb4...

Re:A Prettier JavaScript Formatter by softawre on Tuesday January 10, 2017 @05:16PM (#13369697)
And this is why we have yet to converge. We are people, we have opinions! And some of us lead teams and make decisions.