Skip to content

Readability of switch statement with long lines #1922

Closed

Description

@richb-hanover

The following code using switch works fine, but it's hard to read because of the long lines:

from sd=foo
select [
  CorrectedAssmt = switch [
  sd.SD_Appraisal2021 == sd.SD_Assessment2021 -> sd.SD_Assessment2021,
  sd.SD_Appraisal2021 != sd.SD_Assessment2021 and sd.SD_Appraisal2021 < 500000 -> sd.SD_Ass_Land2021+sd.SD_Ass_Imp2021/loVal,
  sd.SD_Appraisal2021 != sd.SD_Assessment2021 and sd.SD_Appraisal2021 >= 500000 -> sd.SD_Ass_Land2021+sd.SD_Ass_Imp2021/hiVal,
  ],
]

I was tempted to break the lines at and and -> to look something like this:

from sd=foo
select [
  CorrectedAssmt = switch [
  sd.SD_Appraisal2021 == sd.SD_Assessment2021 
    -> sd.SD_Assessment2021,
  sd.SD_Appraisal2021 != sd.SD_Assessment2021 and
  sd.SD_Appraisal2021 < 500000
    -> sd.SD_Ass_Land2021+sd.SD_Ass_Imp2021/loVal,
  sd.SD_Appraisal2021 != sd.SD_Assessment2021 and 
  sd.SD_Appraisal2021 >= 500000 
    -> sd.SD_Ass_Land2021+sd.SD_Ass_Imp2021/hiVal,
  ],
]

but this gives errors: apparently the entire clause must be on the same line.

I'm not sure if I consider this to be a language design problem: I just note the awkwardness in this situation.

Activity

  1. max-sixty commented on Feb 22, 2023

    @max-sixty
    Member

    Yes this is a good case.

    IIRC we have an existing issue for linebreaks — could we add it to that if we do?

  2. richb-hanover commented on Feb 22, 2023

    @richb-hanover
    ContributorAuthor

    By all means. I am simply reporting an interesting use case, to be considered in the broader scope of the language. Thanks.

  3. max-sixty commented on Feb 22, 2023

    @max-sixty
    Member

    OK, closing as dupe of #819, this can serve as a good case of that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions