Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should match cases use a keyword instead of pipe? #38

Closed
andymcn opened this issue Sep 22, 2014 · 5 comments
Closed

Should match cases use a keyword instead of pipe? #38

andymcn opened this issue Sep 22, 2014 · 5 comments

Comments

@andymcn
Copy link
Contributor

andymcn commented Sep 22, 2014

Currently each case in a match is indicated with a pipe symbol, eg:

match _first
| None => _first = ex'
| as ex: Exchange =>
  _first = None
end

It has been suggested that starting lines with a pipe makes it look like the continuation of an expresison on the previous line, especially to those of us used to C. Using a keyword instead may reduce this problem.

match _first
case None => _first = ex' // store this, wait for another submission
case as ex: Exchange =>
  _first = None // reset the stored submission to None
end
@andymcn
Copy link
Contributor Author

andymcn commented Sep 22, 2014

Another option would be to indent the cases:

match _first
  | None => _first = ex'
  | as ex: Exchange =>
    _first = None
end

This makes things clearer to me, but then has the problem that it looks like there's an end mssing after the last case.

@sylvanc
Copy link
Contributor

sylvanc commented Sep 26, 2014

I prefer the pipe symbol, possibly because it's familiar from OCaml, etc. The only concrete reason I have for preferring it is for cases like this:

match x % 100
| 11 | 12 | 13 => "th"
else
  match x % 10
  | 1 => "st"
  | 2 => "nd"
  | 3 => "rd"
  else
    "th"
  end
end

Note the combination of the initial 11, 12 and 13 cases.

@andymcn
Copy link
Contributor Author

andymcn commented Sep 29, 2014

Let's try the same example with a keyword, I'm using case because I'm lazy.

One case per line option:

match x % 100
case 11
case 12
case 13 => "th"
else
  match x % 10
  case 1 => "st"
  case 2 => "nd"
  case 3 => "rd"
  else
    "th"
  end
end

And the same with case indentation:

match x % 100
  case 11
  case 12
  case 13 => "th"
else
  match x % 10
    case 1 => "st"
    case 2 => "nd"
    case 3 => "rd"
  else
    "th"
  end
end

Cases grouped on a line option:

match x % 100
case 11 case 12 case 13 => "th"
else
  match x % 10
  case 1 => "st"
  case 2 => "nd"
  case 3 => "rd"
  else
    "th"
  end
end

And the same with case indentation:

match x % 100
  case 11 case 12 case 13 => "th"
else
  match x % 10
    case 1 => "st"
    case 2 => "nd"
    case 3 => "rd"
  else
    "th"
  end
end

I think that works well either on separate lines or grouped on a line, but it's definitely better with cases indented

@sophiaIC
Copy link

sophiaIC commented Oct 4, 2014

I agree with Andy that indentation is good. After all, you also use indentation for the two branches of an if-statement.

@sylvanc
Copy link
Contributor

sylvanc commented Nov 18, 2014

We've decided to keep the pipe and not replace it with a keyword.

@sylvanc sylvanc closed this as completed Nov 18, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants