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

No style given for try..catch #141

Open
a613 opened this issue Sep 9, 2016 · 6 comments
Open

No style given for try..catch #141

a613 opened this issue Sep 9, 2016 · 6 comments

Comments

@a613
Copy link

a613 commented Sep 9, 2016

Two styles I have seen:

(try (f)
  (catch E e
    (g))
(try
  (f)
  (catch E e
    (g))
@arrdem
Copy link
Contributor

arrdem commented Sep 9, 2016

2nd style should be preferred. try is like do or let in that all body forms should be broken onto the next line(s).

@bbatsov
Copy link
Owner

bbatsov commented Oct 6, 2016

@arrdem is completely right. Guess we should add a rule about this.

@MicahElliott
Copy link

Oh no, the style I've seen/am used to is:

(try (f)
     (catch E e
       (g))

That's the Emacs default!

It's also similar to the way it's done with do blocks.

It would be great to get this settled/codified.

@bbatsov
Copy link
Owner

bbatsov commented Feb 26, 2020

@MicahElliott Well, both are standard Emacs indentations - the first layout is wider, the second is narrower (and I believe way more common). The second layout has the distinct advantage that it highlights better the special nature of do and try.

@MicahElliott
Copy link

MicahElliott commented Feb 26, 2020

I guess I'd argue that a try is ideally a single expression, though I know there are cases where you do use multiple. As a single, it's a nice pattern to say (try (something) ... on a single line, but I know that's not the rule, so let's ignore my first suggestion. But it does feel wrong to prescribe that try should always be alone on its own line. We wouldn't want to say that for do I'd think (and certainly not when or let etc), since I've seen that very commonly as one-line.

My point was probably more to the notion that if you do a one-line try, you should indent the catch to match what's being tryd.

So my vote would be to not capture a prescription here for the style guide. It is an interesting case, though, where we could capture that there are a couple acceptable ways to do it, so as to avoid people changing existing code that's one or the other.

@a613
Copy link
Author

a613 commented Feb 26, 2020

If I remember correctly, when I filed this issue I was thinking of a full-sized nested (f), not a short thing that could fit on one line. If the form being tried is short, indeed it could be written on one line, and the catch indented an extra 3 spaces to line up. If the form is longer, though, I wonder if it is ever acceptable to do the same? That's the question I believe I was aiming at, and apologies for that not being obvious due to my over-simplified example.

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

4 participants