urbit / arvo

https://github.com/urbit/urbit
110 stars 58 forks source link

add runes for 'commenting out' subhoons #1190

Closed pilfer-pandex closed 5 years ago

pilfer-pandex commented 5 years ago

By analogy to clojure https://clojuredocs.org/clojure.core/comment or #_, we add runes for commenting out code.

The effect of =_ is to discard its first subhoon and return the second. That is,

=_  p
    q

is equivalent to

q

The only restriction imposed on p is that it parse. It need not, for example, type check.

For convenience, we also provide a !_ rune such that

!_  p

is equivalent to

=_  p
    !!
pilfer-pandex commented 5 years ago

The clojure equivalent of my =_ actually deletes its children from the ast, leaving nothing in their place. The code that comes to replace the removed code in clojure is the subsequent sibling of the comment node, not its child. It wasn't immediately (~2m) obvious to me how to do this for hoon, nor did it strike me as particularly necessary. I could look into this more if people have a stronk preference for it though.

ohAitch commented 5 years ago

Minor suggestion: how hard would it be for ! to print p in a ~|? I'm thinking in particular of usages like !("Can't implement this case until the eschaton merge") or !_(%bad-width)

On Wed, Jun 12, 2019 at 1:14 PM pilfer-pandex notifications@github.com wrote:

By analogy to clojure https://clojuredocs.org/clojure.core/comment or #_, we add runes for commenting out code.

The effect of =_ is to discard its first subhoon and return the second. That is,

=_ p q

is equivalent to

q

The only restriction imposed on p is that it parse. It need not, for example, type check.

For convenience, we also provide a !_ rune such that

!_ p

is equivalent to

=_ p !!


You can view, comment on, or merge this pull request online at:

https://github.com/urbit/arvo/pull/1190 Commit Summary

  • add runes for 'commenting out' subhoons

File Changes

Patch Links:

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/urbit/arvo/pull/1190?email_source=notifications&email_token=AAOFPBSN7C654YWL72JMKODP2FKKVA5CNFSM4HXQ5PE2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4GZE43PQ, or mute the thread https://github.com/notifications/unsubscribe-auth/AAOFPBVJHTFSVHDKYKGTSSTP2FKKVANCNFSM4HXQ5PEQ .

belisarius222 commented 5 years ago

Why do we want this? I detest commented-out code, and I worry this rune would legitimize and encourage it.

If this rune did require the commented-out code to typecheck, I would be less vehemently opposed to it, since at least the comment would be forced to stay up-to-date as the code around it changes.

pilfer-pandex commented 5 years ago

Oftentime in the course of debugging code, you need to comment out parts. But using :: to do this can be quite cumbersome. This is a direct need I came upon in doing work on test, where I want to progressively strip out sections of hall to get to a minimal repro.

pilfer-pandex commented 5 years ago

It seems useful to have this as an affordance, and just reject code that has commented out parts in review, if that's your taste.

ohAitch commented 5 years ago

Add it to CI, even!

Fang- commented 5 years ago

Oftentime in the course of debugging code, you need to comment out parts. But using :: to do this can be quite cumbersome.

Sounds like you want block comments (boo!), or just to git gud at editing .hoon files?
It seems very weird to me to solve this using language, especially if we're gonna say "code that contains this is not space-rated/approvable".

belisarius222 commented 5 years ago

Oftentime in the course of debugging code, you need to comment out parts. But using :: to do this can be quite cumbersome. This is a direct need I came upon in doing work on test, where I want to progressively strip out sections of hall to get to a minimal repro.

This is better solved by Vim than by Hoon. Here's how I comment out a block of code, which, as you correctly point out, is frequently needed for debugging:

0 <Ctrl-V> <bunch of down arrow> I :: <Esc>

0 goes to the beginning of the line. Ctrl-V starts a rectangular selection. Down extends the selection to the next line. I enters insert at the beginning of each selected line. :: inserts the comment. Esc exits insert mode, completing the command.

Works every time! Takes a second or two, and there are probably Vim wizards who know faster incantations.

jtobin commented 5 years ago

Works every time! Takes a second or two, and there are probably Vim wizards who know faster incantations.

No wizardry here, but one time saver is to insert an exact or rough count of the number of lines to descend before hitting the down button (by which I mean j, of course 😝).

e.g., for twenty lines:

0 <Ctrl-V> 20 j I :: <Esc>

(Often you may just want to ballpark a number like 20, and then adjust manually with j and k.)

jtobin commented 5 years ago

This one has been sitting without any action for over a week, so I'm going to close it for the time being. I suspect it's a bit too contentious a feature to get merged as-is (aside from the complaints above, I'm also not keen on it myself). Maybe worth taking to the mailing list?

cgyarvin commented 5 years ago

Conditional compilation is actually already in there... perhaps you just have to find it!

Sent from my iPhone

On Jun 20, 2019, at 9:12 PM, Jared Tobin notifications@github.com wrote:

This one has been sitting without any action for over a week, so I'm going to close it for the time being. I suspect it's a bit too contentious a feature to get merged as-is (aside from the complaints above, I'm also not keen on it myself). Maybe worth taking to the mailing list?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

philipcmonk commented 5 years ago

FWIW, after using it with @pilfer-pandex, I'm in favor of !_. It's quite ergonomic for debugging and refactoring. I think =_ is a bridge too far, and certainly it shouldn't use a = rune slot since it's only for debugging.