Unsatisfying arithmetic sequences e.g. [0 .. n - 1] #104

Closed
opened 2018-01-13 02:10:21 +01:00 by chreekat · 6 comments
chreekat commented 2018-01-13 02:10:21 +01:00 (Migrated from github.com)

I'm not really sure what the best practice for the various cases are. These seems pretty reasonable:

-- 👍 
[1..8]
[0..]

I am less certain about more complex expressions. I personally just remove all whitespace within arithmetic sequences, but I don't feel particularly good about it:

-- ???
[0..n-1]

But like the title says, this is pretty unsatisfying:

-- 👎
[0 .. n - 1]

Have you put any thought into the possibilities here?

I'm not really sure what the best practice for the various cases are. These seems pretty reasonable: ```haskell -- 👍 [1..8] [0..] ``` I am less certain about more complex expressions. I personally just remove all whitespace within arithmetic sequences, but I don't feel particularly good about it: ```haskell -- ??? [0..n-1] ``` But like the title says, this is pretty unsatisfying: ```haskell -- 👎 [0 .. n - 1] ``` Have you put any thought into the possibilities here?
tfausak commented 2018-01-13 15:04:56 +01:00 (Migrated from github.com)

For what it's worth, I like how Brittany currently formats these. I prefer putting spaces around operators, and I consider .. to be an operator of sorts.

For what it's worth, I like how Brittany currently formats these. I prefer putting spaces around operators, and I consider `..` to be an operator of sorts.
chreekat commented 2018-01-13 16:55:58 +01:00 (Migrated from github.com)

@tfausak I can't really argue. I put spaces around operators, in general. I guess I just got used to seeing no spaces in most of the examples I come across.

@tfausak I can't really argue. I put spaces around operators, in general. I guess I just got used to seeing no spaces in most of the examples I come across.
eborden commented 2018-01-15 21:23:44 +01:00 (Migrated from github.com)

Yeah, I'm with @tfausak on this one. I like the way brittany is currently formatting.

Yeah, I'm with @tfausak on this one. I like the way `brittany` is currently formatting.
lspitzner commented 2018-01-16 00:15:47 +01:00 (Migrated from github.com)

Reminds me of #67 (spaces used in sections). More generally, it is again the decision between "shorter" and "more consistent". There are two reasons for brittany sticking to the "consistency" route currently:

  1. It is easier to implement. [0..n-1] would be surprisingly hard to implement, because the layouting of expressions now would be "context sensitive". The simpler cases would still need special-case handling (e.g. if we wanted [literal..literal] but otherwise [expr .. expr]).
  2. Consistency is good for readability, and the two spaces you gain here are not really worth it.

The thought process is

  • n-1 vs n - 1 - use latter because no context sensitive layouting for exprs
  • [0..n - 1] vs [0 .. n - 1] - use latter because former is confusing space-precedence-implication-wise.
  • [0..10] vs [0 .. 10] - use latter because more consistent with [0 .. n - 1]

Is that convincing enough? :) I know in both cases there is a lot of code out there that omits the spaces for certain cases, e.g. for sections (x:) or (20*), and here [1..] or [a..b]. And I still do write [1..10] myself. But I think the current behaviour is the "correct" one.

Reminds me of #67 (spaces used in sections). More generally, it is again the decision between "shorter" and "more consistent". There are two reasons for brittany sticking to the "consistency" route currently: 1) It is easier to implement. `[0..n-1]` would be surprisingly hard to implement, because the layouting of expressions now would be "context sensitive". The simpler cases would still need special-case handling (e.g. if we wanted `[literal..literal]` but otherwise `[expr .. expr]`). 2) Consistency is good for readability, and the two spaces you gain here are not really worth it. The thought process is - `n-1` vs `n - 1` - use latter because no context sensitive layouting for exprs - `[0..n - 1]` vs `[0 .. n - 1]` - use latter because former is confusing space-precedence-implication-wise. - `[0..10]` vs `[0 .. 10]` - use latter because more consistent with `[0 .. n - 1]` Is that convincing enough? :) I know in both cases there is a lot of code out there that omits the spaces for certain cases, e.g. for sections `(x:)` or `(20*)`, and here `[1..]` or `[a..b]`. And I still do write `[1..10]` myself. But I think the current behaviour is the "correct" one.
chreekat commented 2018-01-16 04:23:40 +01:00 (Migrated from github.com)

Thanks for taking the time to list your rationale so clearly! My "issue" is resolved.

Thanks for taking the time to list your rationale so clearly! My "issue" is resolved.
codygman commented 2020-10-30 20:51:00 +01:00 (Migrated from github.com)

FWIW our brittany update just changed [0..5] to [0 .. 5] and to throw my opinion out there:

I dislike it.

I imagine that doesn't mean a lot, but I felt compelled enough to track down this relevant issue and comment this 😅

FWIW our brittany update just changed `[0..5]` to `[0 .. 5]` and to throw my opinion out there: I dislike it. I imagine that doesn't mean a lot, but I felt compelled enough to track down this relevant issue and comment this :sweat_smile:
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: hexagoxel/brittany#104
There is no content yet.