Re:"Useless Ruby sugar": Endless (one-line) methods
by mhink on Friday December 01, 2023 @01:17PM
(#38490177)
This is my biggest gripe with the widespread use of Prettier over in JS/TS land, especially when using React. It always seems to introduce *more* formatting inconsistency because it's only looking at line length to decide when to format. So in the same block of code I'll have things like:
Which is infurating because it's not visually consistent so the code starts to look like syntactic soup. It's the same thing with components, really.
[ Parent
| on HN ]
Re:"Useless Ruby sugar": Endless (one-line) methods
by kevincox on Friday December 01, 2023 @01:47PM
(#38490588)
This is also my main gripe with automatic formatting. Since they don't really understand the code they almost all work based on number of characters in a line. However I really don't care about characters in a line (except for at the extremes). What is much more important is how many ideas are in the line. If I have an array with 3 very interesting elements I don't want them on the same line even if they happen to be quite short.
Re:"Useless Ruby sugar": Endless (one-line) methods
by JohnFen on Friday December 01, 2023 @01:53PM
(#38490649)
Good formatters do understand the code, though. They parse it much like a compiler does.
Re:"Useless Ruby sugar": Endless (one-line) methods
by kevincox on Friday December 01, 2023 @01:55PM
(#38490672)
They understand the syntax of the code. They may even understand the types and relationships. They don't understand meaning and can only have very rough estimates at logical complexity.
Re:"Useless Ruby sugar": Endless (one-line) methods
by vidarh on Friday December 01, 2023 @03:30PM
(#38491912)
I've yet to experience a good formatter.
Re:"Useless Ruby sugar": Endless (one-line) methods
by vidarh on Friday December 01, 2023 @03:33PM
(#38491942)
Prettier always makes me want to rage-quit. Thankfully I'm at a career level where I usually have the power to dictate it be removed. A formatter that does not understand or allow for careful alignment to make concepts clear is a formatter I don't want near my code.
Re:"Useless Ruby sugar": Endless (one-line) methods
by the_real_osho on Friday December 01, 2023 @09:34PM
(#38495327)
So you just railroad a potential majority that would prefer to use it?
Re:"Useless Ruby sugar": Endless (one-line) methods
by vips7L on Saturday December 02, 2023 @02:37AM
(#38496733)
Companies are not a democracy.
Re:"Useless Ruby sugar": Endless (one-line) methods
by fsckboy on Saturday December 02, 2023 @06:03PM
(#38503088)
so, companies are dictatorships? or what do you mean more precisely?
Re:"Useless Ruby sugar": Endless (one-line) methods
by vidarh on Saturday December 02, 2023 @05:04AM
(#38497470)
It's part of my job to "railroad" potential majorities that would prefer to do things that my judgment suggests will make things worse.
They're free to do it in their personal trees all they want. But if they commit changes that make the code less readable because some tool is being opinionated and can't be configured properly, their change won't pass code review.
Re:"Useless Ruby sugar": Endless (one-line) methods
by larschdk on Friday December 01, 2023 @01:51PM
(#38490626)
I tried your code on prettier.io and got a result that was more visually consistent than what you pasted here.
Re:"Useless Ruby sugar": Endless (one-line) methods
by oprypin on Friday December 01, 2023 @03:15PM
(#38491700)
I think the commenter meant that it can produce such an inconsistent result if the identifier names add up to approximately the line length, but the example didn't actually make it so; the identifiers are much shorter than that.
Re:"Useless Ruby sugar": Endless (one-line) methods
by searls on Monday December 04, 2023 @07:27AM
(#38516441)
This is a huge reason why I still use StandardJS and—shifting back to Ruby—why I rejected the countless requests for implementing line-length or any other metrics analysis rules for Standard Ruby (https://github.com/standardrb/standard). There is always a legitimate edge case when it comes to length of lines and functions and the alternative—chopping them off arbitrarily—is rarely an improvement.