maildev@lists.thunderbird.net

Thunderbird email developers

View all threads

Fwd: Upcoming changes to our JS coding style

BB
Ben Bucksch
Wed, Aug 28, 2019 11:08 PM

Paul Morris wrote on 20.08.19 20:19:

I believe all the things you mentioned are the result of how Prettier re-formats lines that are longer than the 80 character default. (The exact line width is configurable.

Maybe we should configure the line width to be 120, for all lines. 80 should still be the goal, but a little leeway helps a lot, in cases like the mentioned one. After all, we're not working on 80x25 char green monitors anymore, but on HD screens or more. I don't want this extra space to be eaten by long lines and variable names, but a little leeway is reasonable. So, I'd say "Try to stay within 80 chars" to humans, and "120 chars max" to the computer formatter.

For example, if statements are always broken up with one conditional expression per line. The idea is that having that consistency improves overall readability because you always know what to expect.

I understand the idea. I just strongly disagree that this is true.

Style based on code logic is an important way to convey semantics at first glance and help readability a lot. Reformatting destroys that.

Semantics over form. (In other words, if I have the choice between a pretty wife and a smart one, and cannot have both, I choose smart.)

I gave an example where such "consistency" is outright destructive to readability, and esp. in if expressions, that's particularly important.

For the same reason, the "lonely else" rule is often making code much harder to read.

Since we don't have a lot of options, here is where I make an appeal for flexibility on code style preferences so we can get the benefits of auto-formatting.

You're asking for that the developers are flexible, or the program? I'm for humans ruling over computers, not the other way around :) .

I'm sure everything that I mentioned can easily be configured globally, by disabling certain overzealous rules (like "lonely else") completely, and making some others less strict. We'd still get the benefit of most rules, without having to suffer from the questionable ones that destroy existing good style.

Ben

JK
Jörg Knobloch
Thu, Aug 29, 2019 6:59 AM

On 29 Aug 2019 01:08, Ben Bucksch wrote:

So, I'd say "Try to stay within 80 chars" to humans, and "120 chars
max" to the computer formatter.

Yes, please, don't compress it down to 80 chars from the TTY days of the
1980ies :-( - I'd go for at least 100 chars.

On 29 Aug 2019 01:08, Ben Bucksch wrote: > So, I'd say "Try to stay within 80 chars" to humans, and "120 chars > max" to the computer formatter. Yes, please, don't compress it down to 80 chars from the TTY days of the 1980ies :-( - I'd go for at least 100 chars.
MM
Magnus Melin
Thu, Aug 29, 2019 7:01 AM

I think we want to use the same rules as mozilla-central, and they use
80ch, just like Thunderbird has always used. You'd have major problems
otherwise especially comparing/maintaining semi-forked files that would
have to look totally different just because they were copied.

It looks like we have pretty good unification coming now, basically
removing special formatting rules for all Thunderbird code, including
Lightning which has been different.

 -Magnus

On 29-08-2019 02:08, Ben Bucksch wrote:

Paul Morris wrote on 20.08.19 20:19:

I believe all the things you mentioned are the result of how Prettier
re-formats lines that are longer than the 80 character default.  (The
exact line width is configurable.

Maybe we should configure the line width to be 120, for all lines. 80
should still be the goal, but a little leeway helps a lot, in cases
like the mentioned one. After all, we're not working on 80x25 char
green monitors anymore, but on HD screens or more. I don't want this
extra space to be eaten by long lines and variable names, but a little
leeway is reasonable. So, I'd say "Try to stay within 80 chars" to
humans, and "120 chars max" to the computer formatter.

For example, if statements are always broken up with one
conditional expression per line.  The idea is that having that
consistency improves overall readability because you always know what
to expect.

I understand the idea. I just strongly disagree that this is true.

Style based on code logic is an important way to convey semantics at
first glance and help readability a lot. Reformatting destroys that.

Semantics over form. (In other words, if I have the choice between a
pretty wife and a smart one, and cannot have both, I choose smart.)

I gave an example where such "consistency" is outright destructive to
readability, and esp. in if expressions, that's particularly important.

For the same reason, the "lonely else" rule is often making code much
harder to read.

Since we don't have a lot of options, here is where I make an appeal
for flexibility on code style preferences so we can get the benefits
of auto-formatting.

You're asking for that the developers are flexible, or the program?
I'm for humans ruling over computers, not the other way around :) .

I'm sure everything that I mentioned can easily be configured
globally, by disabling certain overzealous rules (like "lonely else")
completely, and making some others less strict. We'd still get the
benefit of most rules, without having to suffer from the questionable
ones that destroy existing good style.

Ben


Maildev mailing list
Maildev@lists.thunderbird.net
http://lists.thunderbird.net/mailman/listinfo/maildev_lists.thunderbird.net

I think we want to use the same rules as mozilla-central, and they use 80ch, just like Thunderbird has always used. You'd have major problems otherwise especially comparing/maintaining semi-forked files that would have to look totally different just because they were copied. It looks like we have pretty good unification coming now, basically removing special formatting rules for all Thunderbird code, including Lightning which has been different.  -Magnus On 29-08-2019 02:08, Ben Bucksch wrote: > > > Paul Morris wrote on 20.08.19 20:19: >> I believe all the things you mentioned are the result of how Prettier >> re-formats lines that are longer than the 80 character default.  (The >> exact line width is configurable. > > > Maybe we should configure the line width to be 120, for all lines. 80 > should still be the goal, but a little leeway helps a lot, in cases > like the mentioned one. After all, we're not working on 80x25 char > green monitors anymore, but on HD screens or more. I don't want this > extra space to be eaten by long lines and variable names, but a little > leeway is reasonable. So, I'd say "Try to stay within 80 chars" to > humans, and "120 chars max" to the computer formatter. > >> For example, `if` statements are always broken up with one >> conditional expression per line.  The idea is that having that >> consistency improves overall readability because you always know what >> to expect. >> > > I understand the idea. I just *strongly* disagree that this is true. > > Style based on code logic is an important way to convey semantics at > first glance and help readability a lot. Reformatting destroys that. > > Semantics over form. (In other words, if I have the choice between a > pretty wife and a smart one, and cannot have both, I choose smart.) > > I gave an example where such "consistency" is outright destructive to > readability, and esp. in `if` expressions, that's particularly important. > > For the same reason, the "lonely else" rule is often making code much > harder to read. > > >> Since we don't have a lot of options, here is where I make an appeal >> for flexibility on code style preferences so we can get the benefits >> of auto-formatting. > > > You're asking for that the developers are flexible, or the program? > I'm for humans ruling over computers, not the other way around :) . > > I'm sure everything that I mentioned can easily be configured > globally, by disabling certain overzealous rules (like "lonely else") > completely, and making some others less strict. We'd still get the > benefit of most rules, without having to suffer from the questionable > ones that destroy existing good style. > > Ben > > > _______________________________________________ > Maildev mailing list > Maildev@lists.thunderbird.net > http://lists.thunderbird.net/mailman/listinfo/maildev_lists.thunderbird.net
JK
Jörg Knobloch
Thu, Aug 29, 2019 8:51 AM

On 29 Aug 2019 09:01, Magnus Melin wrote:

I think we want to use the same rules as mozilla-central, and they use
80ch, just like Thunderbird has always used. You'd have major problems
otherwise especially comparing/maintaining semi-forked files that
would have to look totally different just because they were copied.

There are very few "semi-forked" files, mostly in the area of
preferences and the about:* pages.

If you really need to compare, you can format the M-C page to C-C
standards first.

We have many lines exceeding 80 chars in JS code, so there well be a lot
of unnecessary churn to reach a design of the TTY era of the 1980s.

Hands up who is still using vi in a terminal window ;-)

Jörg.

On 29 Aug 2019 09:01, Magnus Melin wrote: > I think we want to use the same rules as mozilla-central, and they use > 80ch, just like Thunderbird has always used. You'd have major problems > otherwise especially comparing/maintaining semi-forked files that > would have to look totally different just because they were copied. There are very few "semi-forked" files, mostly in the area of preferences and the about:* pages. If you really need to compare, you can format the M-C page to C-C standards first. We have many lines exceeding 80 chars in JS code, so there well be a lot of unnecessary churn to reach a design of the TTY era of the 1980s. Hands up who is still using vi in a terminal window ;-) Jörg.
MM
Magnus Melin
Thu, Aug 29, 2019 8:58 AM

I won't go into debate on why each setting is useful or not.

It's all about consistency. If you pick and choose, you don't get that.

 -Magnus

On 29-08-2019 11:51, Jörg Knobloch wrote:

On 29 Aug 2019 09:01, Magnus Melin wrote:

I think we want to use the same rules as mozilla-central, and they
use 80ch, just like Thunderbird has always used. You'd have major
problems otherwise especially comparing/maintaining semi-forked files
that would have to look totally different just because they were copied.

There are very few "semi-forked" files, mostly in the area of
preferences and the about:* pages.

If you really need to compare, you can format the M-C page to C-C
standards first.

We have many lines exceeding 80 chars in JS code, so there well be a
lot of unnecessary churn to reach a design of the TTY era of the 1980s.

Hands up who is still using vi in a terminal window ;-)

Jörg.


Maildev mailing list
Maildev@lists.thunderbird.net
http://lists.thunderbird.net/mailman/listinfo/maildev_lists.thunderbird.net

I won't go into debate on why each setting is useful or not. It's all about consistency. If you pick and choose, you don't get that.  -Magnus On 29-08-2019 11:51, Jörg Knobloch wrote: > On 29 Aug 2019 09:01, Magnus Melin wrote: >> I think we want to use the same rules as mozilla-central, and they >> use 80ch, just like Thunderbird has always used. You'd have major >> problems otherwise especially comparing/maintaining semi-forked files >> that would have to look totally different just because they were copied. > > There are very few "semi-forked" files, mostly in the area of > preferences and the about:* pages. > > If you really need to compare, you can format the M-C page to C-C > standards first. > > We have many lines exceeding 80 chars in JS code, so there well be a > lot of unnecessary churn to reach a design of the TTY era of the 1980s. > > Hands up who is still using vi in a terminal window ;-) > > Jörg. > > > _______________________________________________ > Maildev mailing list > Maildev@lists.thunderbird.net > http://lists.thunderbird.net/mailman/listinfo/maildev_lists.thunderbird.net >
GL
Geoff Lankow
Thu, Aug 29, 2019 9:01 AM

I'd prefer 100-character lines over consistency with m-c.

GL

On 29/08/19 20:58, Magnus Melin wrote:

I won't go into debate on why each setting is useful or not.

It's all about consistency. If you pick and choose, you don't get that.

 -Magnus

On 29-08-2019 11:51, Jörg Knobloch wrote:

On 29 Aug 2019 09:01, Magnus Melin wrote:

I think we want to use the same rules as mozilla-central, and they
use 80ch, just like Thunderbird has always used. You'd have major
problems otherwise especially comparing/maintaining semi-forked
files that would have to look totally different just because they
were copied.

There are very few "semi-forked" files, mostly in the area of
preferences and the about:* pages.

If you really need to compare, you can format the M-C page to C-C
standards first.

We have many lines exceeding 80 chars in JS code, so there well be a
lot of unnecessary churn to reach a design of the TTY era of the 1980s.

Hands up who is still using vi in a terminal window ;-)

Jörg.


Maildev mailing list
Maildev@lists.thunderbird.net
http://lists.thunderbird.net/mailman/listinfo/maildev_lists.thunderbird.net

I'd prefer 100-character lines over consistency with m-c. GL On 29/08/19 20:58, Magnus Melin wrote: > I won't go into debate on why each setting is useful or not. > > It's all about consistency. If you pick and choose, you don't get that. > >  -Magnus > > On 29-08-2019 11:51, Jörg Knobloch wrote: >> On 29 Aug 2019 09:01, Magnus Melin wrote: >>> I think we want to use the same rules as mozilla-central, and they >>> use 80ch, just like Thunderbird has always used. You'd have major >>> problems otherwise especially comparing/maintaining semi-forked >>> files that would have to look totally different just because they >>> were copied. >> >> There are very few "semi-forked" files, mostly in the area of >> preferences and the about:* pages. >> >> If you really need to compare, you can format the M-C page to C-C >> standards first. >> >> We have many lines exceeding 80 chars in JS code, so there well be a >> lot of unnecessary churn to reach a design of the TTY era of the 1980s. >> >> Hands up who is still using vi in a terminal window ;-) >> >> Jörg. >> >> >> _______________________________________________ >> Maildev mailing list >> Maildev@lists.thunderbird.net >> http://lists.thunderbird.net/mailman/listinfo/maildev_lists.thunderbird.net >> > > _______________________________________________ > Maildev mailing list > Maildev@lists.thunderbird.net > http://lists.thunderbird.net/mailman/listinfo/maildev_lists.thunderbird.net >
PK
Philipp Kewisch
Thu, Aug 29, 2019 9:01 AM

On 8/29/19 10:51 AM, Jörg Knobloch wrote:

Hands up who is still using vi in a terminal window ;-)

o/

(I do prefer 100ch though, this fits comfortably so that I can view two
files next to each other)

The flexibility is on prettier's end afaik. Here is a note on print
width and why they use 80ch:

https://prettier.io/docs/en/options.html#print-width

Philipp

On 8/29/19 10:51 AM, Jörg Knobloch wrote: > Hands up who is still using vi in a terminal window ;-) o/ (I do prefer 100ch though, this fits comfortably so that I can view two files next to each other) The flexibility is on prettier's end afaik. Here is a note on print width and why they use 80ch: https://prettier.io/docs/en/options.html#print-width Philipp
JK
Jörg Knobloch
Thu, Aug 29, 2019 9:51 AM

On 29 Aug 2019 11:01, Philipp Kewisch wrote:

(I do prefer 100ch though, this fits comfortably so that I can view two
files next to each other)

The flexibility is on prettier's end afaik. Here is a note on print
width and why they use 80ch:

https://prettier.io/docs/en/options.html#print-width

Looks like so far we had a few votes for 100 chars, even from a vi user ;-)

I read the linked article, well, I'm not convinced really. Long lines
happen due to indentation, not because there is so much code on one line.

We'd really need to see some formatting examples to compare to see
whether the code would end up "overly compact". Maybe that's really the
case.

Jörg.

On 29 Aug 2019 11:01, Philipp Kewisch wrote: > (I do prefer 100ch though, this fits comfortably so that I can view two > files next to each other) > > > The flexibility is on prettier's end afaik. Here is a note on print > width and why they use 80ch: > > https://prettier.io/docs/en/options.html#print-width Looks like so far we had a few votes for 100 chars, even from a vi user ;-) I read the linked article, well, I'm not convinced really. Long lines happen due to indentation, not because there is so much code on one line. We'd really need to see some formatting examples to compare to see whether the code would end up "overly compact". Maybe that's really the case. Jörg.
PM
Paul Morris
Thu, Aug 29, 2019 12:26 PM

On 8/28/19 7:08 PM, Ben Bucksch wrote:

Maybe we should configure the line width to be 120, for all lines. 80
should still be the goal, but a little leeway helps a lot, in cases
like the mentioned one. After all, we're not working on 80x25 char
green monitors anymore, but on HD screens or more. I don't want this
extra space to be eaten by long lines and variable names, but a little
leeway is reasonable. So, I'd say "Try to stay within 80 chars" to
humans, and "120 chars max" to the computer formatter.

Well, Prettier does not work that way.  If you tell it lines should be
100 or 120 or whatever, it will format the code to use that line width,
no more, and also no less.  That's how it meets its design goal of
consistency.  For example:

https://prettier.io/playground/#N4Igxg9gdgLgprEAuEAdKBLAZgAgBTRwA0OMA7hCTABYBOcxOWEArrSejl0xgG6MBnDAA8SAuPygk4GAObUYJTFEadu8KTjgAbCQipkd-KtQy14CAJQ5ga+jDZQmAQ23iA3OgC+6dL2e0OMI4ALw2OIQGlKR0DCTMbERqWHyCImJ6mjLyijjKqk6k+lq6kgZGcN7uIEQgEAAOMBjQAsigAbQQZAAKAQitKM68EBgAJjUgAEa0zmAA1nAwAMr1sxhQssgwtCzEIAoAttoA6qbwAqtgcEv9GE28dwCeyOACrbXr4ubdM7IHzsgsK5xLUAFYCYQAIRm80WS2cBzgABl1nBAcC9uDhEt1rJdABFFgQeDotx7Va0L4vSbOSaPbTQCb1WjrGDHMY0ZAARgADDzasyIOJjjN6i9mXAvvwJgBHInwH4NAYgZwCAC0Kjgoy1E3ocrMcB+zj+AKQQLJtXEBwwWx2eyEGwJ8rRZoxtRgtPZo05SAATO6ZhhtLiAMIQA7-F5QQgTFjiAAqtIG5vEXi8QA

Or if that doesn't work, paste the following code here:

https://prettier.io/playground/

and set it to 100 character line width in the options.

if (one, two, three, four,
    five, six, seven, eight, nine,
    ten, eleven, twelve, thirteen) {
  return false;
}

var x = {
  one, two, three, four,
  five, six, seven, eight, nine,
  ten, eleven, twelve, thirteen
};

The code is reformatted to use the full line width.

Since we don't have a lot of options, here is where I make an appeal
for flexibility on code style preferences so we can get the benefits
of auto-formatting.

You're asking for that the developers are flexible, or the program?
I'm for humans ruling over computers, not the other way around :) .

What I'm saying is Prettier offers auto-formatting but not the kind of
customizability you want, and the auto-formatting is worth it.  That
means developers will need to be flexible about their preferences, as
they are flexible whenever there is disagreement among developers about
the best code style.

I'm sure everything that I mentioned can easily be configured
globally, by disabling certain overzealous rules (like "lonely else")
completely, and making some others less strict. We'd still get the
benefit of most rules, without having to suffer from the questionable
ones that destroy existing good style.

Well, I'm afraid that is simply not the case.  As I mentioned before,
for better or worse, Prettier is not designed to be configurable in that
way.  See: https://prettier.io/docs/en/why-prettier.html  and
https://prettier.io/docs/en/option-philosophy.html

It has an escape hatch with |// prettier-ignore| comments to allow for
exceptional cases.

I know we could have a long discussion with lots of views shared on code
style.  You've offered some strong arguments for yours here.  We might
even reach a consensus where everyone is happy. But since we want the
benefits of auto-formatting, we will need to work with the tool that
offers it.

(More in another reply.)

-Paul

On 8/28/19 7:08 PM, Ben Bucksch wrote: > Maybe we should configure the line width to be 120, for all lines. 80 > should still be the goal, but a little leeway helps a lot, in cases > like the mentioned one. After all, we're not working on 80x25 char > green monitors anymore, but on HD screens or more. I don't want this > extra space to be eaten by long lines and variable names, but a little > leeway is reasonable. So, I'd say "Try to stay within 80 chars" to > humans, and "120 chars max" to the computer formatter. > Well, Prettier does not work that way.  If you tell it lines should be 100 or 120 or whatever, it will format the code to use that line width, no more, and also no less.  That's how it meets its design goal of consistency.  For example: https://prettier.io/playground/#N4Igxg9gdgLgprEAuEAdKBLAZgAgBTRwA0OMA7hCTABYBOcxOWEArrSejl0xgG6MBnDAA8SAuPygk4GAObUYJTFEadu8KTjgAbCQipkd-KtQy14CAJQ5ga+jDZQmAQ23iA3OgC+6dL2e0OMI4ALw2OIQGlKR0DCTMbERqWHyCImJ6mjLyijjKqk6k+lq6kgZGcN7uIEQgEAAOMBjQAsigAbQQZAAKAQitKM68EBgAJjUgAEa0zmAA1nAwAMr1sxhQssgwtCzEIAoAttoA6qbwAqtgcEv9GE28dwCeyOACrbXr4ubdM7IHzsgsK5xLUAFYCYQAIRm80WS2cBzgABl1nBAcC9uDhEt1rJdABFFgQeDotx7Va0L4vSbOSaPbTQCb1WjrGDHMY0ZAARgADDzasyIOJjjN6i9mXAvvwJgBHInwH4NAYgZwCAC0Kjgoy1E3ocrMcB+zj+AKQQLJtXEBwwWx2eyEGwJ8rRZoxtRgtPZo05SAATO6ZhhtLiAMIQA7-F5QQgTFjiAAqtIG5vEXi8QA Or if that doesn't work, paste the following code here: https://prettier.io/playground/ and set it to 100 character line width in the options. if (one, two, three, four,     five, six, seven, eight, nine,     ten, eleven, twelve, thirteen) {   return false; } var x = {   one, two, three, four,   five, six, seven, eight, nine,   ten, eleven, twelve, thirteen }; The code is reformatted to use the full line width. >> Since we don't have a lot of options, here is where I make an appeal >> for flexibility on code style preferences so we can get the benefits >> of auto-formatting. > > You're asking for that the developers are flexible, or the program? > I'm for humans ruling over computers, not the other way around :) . > What I'm saying is Prettier offers auto-formatting but not the kind of customizability you want, and the auto-formatting is worth it.  That means developers will need to be flexible about their preferences, as they are flexible whenever there is disagreement among developers about the best code style. > I'm sure everything that I mentioned can easily be configured > globally, by disabling certain overzealous rules (like "lonely else") > completely, and making some others less strict. We'd still get the > benefit of most rules, without having to suffer from the questionable > ones that destroy existing good style. > Well, I'm afraid that is simply not the case.  As I mentioned before, for better or worse, Prettier is not designed to be configurable in that way.  See: https://prettier.io/docs/en/why-prettier.html  and https://prettier.io/docs/en/option-philosophy.html It has an escape hatch with |// prettier-ignore| comments to allow for exceptional cases. I know we could have a long discussion with lots of views shared on code style.  You've offered some strong arguments for yours here.  We might even reach a consensus where everyone is happy. But since we want the benefits of auto-formatting, we will need to work with the tool that offers it. (More in another reply.) -Paul
PM
Paul Morris
Thu, Aug 29, 2019 12:53 PM

Hi all,

Kindly allow me to express some frustration.  I really wish we had had
this discussion about line width sooner than the day that we planned to
start implementing the changes.  Looks like I should have sent the email
sooner to get the ball rolling, knowing how debates on such things take
time.  Hindsight is 20/20, as they say.

Some procedural questions now in my mind:

Can we reach a consensus decision on line width involving everyone on
the team that may want to weigh in, while leaving enough time to do the
work and let reviewers review the work, in order to land the changes
before the merge on Monday?

Should we delay this work 6 weeks until just before the next merge (and
beta release) in order to have more time for discussion to reach a
consensus decision?

We'd really need to see some formatting examples to compare to see
whether the code would end up "overly compact". Maybe that's really

the case.

An easy way to do such a comparison is to cut and paste the contents of
a JS file from the TB code base into the Prettier sandbox here:
https://prettier.io/playground/  and then change the --print-width
option back and forth between 100 and 80.

-Paul

Hi all, Kindly allow me to express some frustration.  I really wish we had had this discussion about line width sooner than the day that we planned to start implementing the changes.  Looks like I should have sent the email sooner to get the ball rolling, knowing how debates on such things take time.  Hindsight is 20/20, as they say. Some procedural questions now in my mind: Can we reach a consensus decision on line width involving everyone on the team that may want to weigh in, while leaving enough time to do the work and let reviewers review the work, in order to land the changes before the merge on Monday? Should we delay this work 6 weeks until just before the next merge (and beta release) in order to have more time for discussion to reach a consensus decision? > We'd really need to see some formatting examples to compare to see > whether the code would end up "overly compact". Maybe that's really the case. An easy way to do such a comparison is to cut and paste the contents of a JS file from the TB code base into the Prettier sandbox here: https://prettier.io/playground/  and then change the --print-width option back and forth between 100 and 80. -Paul