Live data from Hacker News

Formatting code should be unnecessary

maxleiter.com

461–470 of 484 posts

Re: Formatting code should be unnecessary

#461

Along these lines, Go eliminates many formatting decisions at the syntax level. E.g., func main() { fmt.Println("HELLOWORLD") } is not just non-standard formatting, but illegal Go syntax. Similarly, extra parentheses around if clauses are not allowed.

> Similarly, extra parentheses around if clauses are not allowed. However 'if (x) == (1) {}' is totally fine with the formatter. As is an assignment of '(x) = (y)'. It's actively annoying too because like, extra parenthesis often have important meaning. For example, consider the following code: if (x.isFoo() || x.isBar()) /* && x.isBaz() */ { /* code */ } In that case, the code is obviously temporarily commented out,…

go is generally hostile to temporarily commenting out code. The if syntax issue you call out is just one aspect. Another is the inability to have unused variables.

Re: Formatting code should be unnecessary

#462

Along these lines, Go eliminates many formatting decisions at the syntax level. E.g., func main() { fmt.Println("HELLOWORLD") } is not just non-standard formatting, but illegal Go syntax. Similarly, extra parentheses around if clauses are not allowed.

> Similarly, extra parentheses around if clauses are not allowed. However 'if (x) == (1) {}' is totally fine with the formatter. As is an assignment of '(x) = (y)'. It's actively annoying too because like, extra parenthesis often have important meaning. For example, consider the following code: if (x.isFoo() || x.isBar()) /* && x.isBaz() */ { /* code */ } In that case, the code is obviously temporarily commented out,…

FWIW, in that scenario, for the reasons you've called out, I would normally dupe the if line and comment the original one for reference. Mind you, none of that would ever get committed, but for a temp local change it's fair game.

Re: Formatting code should be unnecessary

#463
post #222

Earlier quoted context omitted.

Define high? I think 120 is pretty reasonable. Maybe even as high as 140. Log statements however I think have an effectively unbounded length. Nothing I hate more than a stupid linter turning a sprinkling of logs into 7 line monsters. cargo fmt is especially bad about this. It’s so bad.

100 is the sweet spot, IMO. I like splitting long text as in log statements into appropriate source lines, just like you would a Markdown paragraph. As in: logger.info( "I like splitting long text as in log statements " + "into ” + suitablelAdjective + " source lines, " + "just like you would a Markdown paragraph. " + "As in: " + quine); I agree that many formatters are bad about this, like introducing an indent for…

Splitting log messages across lines like that is pure evil. Your punishment is death by brazen Bull. Sorry I don’t make the rules, just how it is. :(

Re: Formatting code should be unnecessary

#464

Earlier quoted context omitted.

Formatters eliminating long lines is a pet peeve of mine. About once every other project, some portion of the source benefits from source code being arranged in a tabular format. Long lines which are juxtaposed help make dissimilar values stand out. The following table is not unlike code I have written: setup_spi(&adc, mode=SPI_01, rate=15, cs_control=CS_MUXED, cs=0x01); setup_spi(&eeprom, mode=SPI_10, rate=13, cs_co…

Those kind of tables improve readability right until someone hits a length constraint and had to either touch every line in order to fix the alignment, causing weird conflicts in VCS, or ignore the alignment and it's slow decay into a mess begins.

so you're basically saying "look this is neat and I like it, but since we cannot prevent some future chap come along and make a mess of it, let's stop this nonsense, now, and throw our hands up in the air—thoughts and prayers is what I say!"?

Re: Formatting code should be unnecessary

#465

Earlier quoted context omitted.

setup_spi( &adc, mode=SPI_01, rate=15, cs_control=CS_MUXED, cs=0x01 ); setup_spi( &eeprom, mode=SPI_10, rate=13, cs_control=CS_MUXED, cs=0x02 ); setup_spi( &mram, mode=SPI_10, rate=50, cs_control=CS_DIRECT, cs=0x08 ); ftfy

This is good, and objectively better than letting the random unbounded length of the function name define and inflate and randomize the indentation. It also makes it easier to use long descriptive function names without fucking up the indentation. setup_spi(&adc, mode=SPI_01, rate=15, cs_control=CS_MUXED, cs=0x01 ); setup_spoo(&adc, mode=SPI_01, rate=15, cs_control=CS_MUXED, cs=0x01 ); setup_s(&adc, mode=SPI_01, rate…

Here, fixed it for you:

    setup_spi(
      &adc,
      mode        = SPI_01,
      rate        = 15,
      cs_control  = CS_MUXED,
      cs          = 0x01 );
    setup_spoo(
      &adc,
      mode        = SPI_01,
      rate        = 15,
      cs_control  = CS_MUXED,
      cs          = 0x01 );
    setup_s(
      &adc,
      mode        = SPI_01,
      rate        = 15,
      cs_control  = CS_MUXED,
      cs          = 0x01 );
    validate_and_register_spi_spoo_s(
      &adc,
      mode        = SPI_01,
      rate        = 15,
      cs_control  = CS_MUXED,
      cs          = 0x01 );

Re: Formatting code should be unnecessary

#466

Earlier quoted context omitted.

> I've never understood why people care so much about the linter settings. Source code formatting programs are not the same as lint[0] programs. The former rewrites source code files such that the output is conformant with a set of layout rules without altering existing logic. The latter is a category of idempotent source code analysis programs typically used to identify potential implementation errors within otherwi…

Thank you! I am almost going out of my mind reading this ~200 comment thread with everyone just casually saying "linter" when they mean "formatter". Do people really not distinguish between these two very different programs?

many people use the prettier plugin for eslint, for example, so in that case they're one and the same!

Re: Formatting code should be unnecessary

#467
post #65

Earlier quoted context omitted.

Thats a slippery slope towards storing semantics and displaying locally preferred syntax ;)

That's why Python should have gone all-in on significant spaces: tabs for blocks, spaces after tabs for line continuation

Mixing spaces and tabs is a surefire way to ruin everything.

Re: Formatting code should be unnecessary

#468
The main selling point for source code in plain text files is compatibility. You can use whatever tool you wish. Yes, it's not ideal, and yes, we are still using non-semantic diffs in these days, even though it should have been a solved problem by now. I'd still argue that even if all the editing/VCS tools start working in a structured way, the storage format should be plain text.

Re: Formatting code should be unnecessary

#469

Earlier quoted context omitted.

Those kind of tables improve readability right until someone hits a length constraint and had to either touch every line in order to fix the alignment, causing weird conflicts in VCS, or ignore the alignment and it's slow decay into a mess begins.

so you're basically saying "look this is neat and I like it, but since we cannot prevent some future chap come along and make a mess of it, let's stop this nonsense, now, and throw our hands up in the air—thoughts and prayers is what I say!"?

At best I'd say it's ok to use it sparingly, in places where it really does make an improvement in readability. I've seen people use it just to align the right hand side of a list of assignments, even when there is no tabular nature to what they are assigning.

Re: Formatting code should be unnecessary

#470

Earlier quoted context omitted.

That’s seems like a genious remark actually. If you store the abstract objects and have the mechanism to transform to whatever the desired output form is, it’s almost trivial to expose a version as files and text rendering for tools that are thus oriented, isn’t it?

Originally my fathers idea from back in the 90s to create a language with a whole suite of syntactic representations to suit your preferences. Want it to look like C? Lisp? Pascal? Why not!

Do you have more references about what your fathers did back then?
Post reply on HN