-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
New comment syntax. #1535
Comments
Yes for the pound and square bracket. Looks like it has the best tradeoff for cleanliness and noticeability. |
No for Yes for |
I personally don't see the need for a multi-line comment syntax. "when false" and "discard" are perfectly fine for temporarily commenting out multiple lines of code, not to mention that any editor more modern than edlin should make it easy to use "#" to comment out a block of code. If you insist, then an empty pseudo-procedure should also do the trick: comment """
This is a comment.
""" I'm mostly not sure what functionality multi-line comments would add; an actual use case would be nice to see. (I could see the case for commenting part of the line, e.g. to annotate individual procedure parameters, but that's a different use case.) In my experience, these types of comments tend to also get turned into something like this, anyway:
At which point there's no real difference compared to using single line comments. |
template c(comment: string) = discard comment
c"""
Nimrod
is
awesome
""" |
@kirbyfan64 I should mention that with the @gradha hrm, that looks tolerable actually. I wonder if we could get away with using an operator instead of the |
@dom96 I was guessing that. It's just that the
Using |
@kirbyfan64 Yeah, I agree. I'm starting to like |
I agree with rbehrends; not sure about the pseudo procedure though. I like the mantra that there should only be one way to do things. |
I'd definitely like a multi-line comment syntax. Not a fan of the {- -} and (* *) ideas though, and I agree with kirbyfan64 about how confusing the ### ### style could get. #[ ]# looks the best to me. |
I have to say that I am wondering what it is that other people use multi-line comments for? I mean, if I want to comment multiple lines, I mark a block, hit |
I suppose it is true that as long as your text editor/IDE supports that then there is no issue. |
@rbehrends @dom96 Why not have the new multi-line comments become doc-comments? Currently, typing doc-comments requires adding a |
@rbehrends @Varriount That reminds me: you would need two separate key bindings one to add |
@dom96 That's a different issue. If you really only insert a multi-line comment marker at the beginning and end, it'd save you some typing for new comments. But in reality, you still want a visual hint on each line: for example, try to make sense out of a |
For actual comments, I usually use single line comments on every line. However, when I port code from another language or another program, I like to copy the foreign code into the area I am working on. A multiline comment comes in handy there. Single line comments get in the way even if you use a powerfull editor. |
Lua uses I suggest |
Why not #*..... *# for consistency. |
#*..... *# +1 |
I like #[ ... #] or #[ ... ]#. |
I really don't see the point in a block comment syntax, not once have I been like "boy I wish nim had block comments". I see the point for porting code, but discard """ """ works really well there. For the cases where discard """ """ is not a good solution I think that editors that just add a # if you press the return key on a line that has a # should do fine, and that is all editors ever. Also I don't understand how #* and *# is more consistent than anything else, or is it just that code that looks like C must be fast and good? Understand that C started with ONLY /* and / (and indeed it still has only those if you are using C89 as god intended) and only later did it get //, because people found / and / annoying even with editors. I have never found // annoying with editors and only really use / and */ because Microsoft's C computer does not support //. |
@barcharcraz Your comment formatting got goofed up. Escape your asterisks. |
How about no block comments and repeat the single line comment escape? Does the AST look different in each case? I'm influenced by ruby, where there are no multiline comments and I don't see what multiline comments provide over just repeating the single-line comment escape. |
I don't know why we're discussing this after the #[ .. ]# if we have to use something ridiculous. |
I think we need to decide what to do about this before the release of 1.0 so I will mark it as a Showstopper. |
No, the compiler warns about `#[``already, so we can make that an error for 1.0 and then later have a multiline comment without breaking anything. So no showstopper. |
I know that this is an old discussion, but I took quick stab at creating a nim syntax highlighting file for Kate, and it looks like there is no convenient way to look ahead more than two characters. While #[ .. ]# for multiline comments would be fine, something like ##[ .. ]## or ### ... ### could be problematic. I also agree with @rbehrends that there is not really a need for multiline comments. However, when commenting out portions of code, the 'when false' approach - while syntactically sufficient - may not provide enough visual clues about the code inside being excluded from compilation. That would require evaluation of the 'when' expression, which is probably deseriable, but may also not be easy to integrate in some text editors. |
I don't know about highlighting the entire block of code inside the 'when false' block, but highlighting 'when false' itself can be done quite easily in sublime text. |
Yeah, but if 'when false' is being highlighted then other expressions that evaluate to false should probably be highlighted as well (for consistency). I think that greying out inactive code would be a desirable feature in any text editor. By the way, I was wrong about the two character look ahead in Kate. Besides regular expressions there is also a way to look ahead by string matching, so no problem there. That doesn't mean those long comment patterns would be a good idea though. If it looks or feels awkward, then it probably is :) |
I don't see the need of yet another syntax for comments, as both Is there a non-aesthetical reason for @gmpreussner: kate highlights |
No |
I think Nim should definitely have a multiple comment levels; Lua does and I find it to really good for productivity. code
broken code 1
#[
commented code A
#]
broken code 2 In C/C++, you'd need to individual comment the broken code sections, or remove the multiline comment terminator of code
#[[
commented broken code 1
#[
commented code A
#]
commented broken code 2
#]] I suggest the terminator be a[0] = b[0]
#[
a[1] = b[1]# this is a comment, note that it accidentally terminates the multiline comment!
a[2] = b[2]
]#
a[3] = b[3] Also +1 for |
Why does a language need multi-line comments? 👎
although clever, ### could get out of hand. |
Single line comments makes for better code documentation. The present syntax is alright. |
Since there seems to be an abundance of opinions on this subject, I propose that anyone who really wants another comment type write up something akin to Python's PEP's, rather than simply stating opinion. |
I mainly need inline comments. Don't care about multiline to much but |
@keyle Araq has said that modern tools should be embraced, which I agree with, and programmers really ought to rely on capable editors. I'm not sure where the line is drawn though, but batch commenting doesn't exactly rely on complex technology. Chances are there's something I'm not taking into account, but I'm sure there are people who want it specifically for the sake of convenience, and it would be good to know exactly what kind of tools we expect users to have. I see that Aporia supports batch commenting, which is nice. However, it doesn't really seem like a complex thing to implement, and if it doesn't imply some kind of tradeoff then there's no need to consider all these things. |
Yes for
I do like multiline comments in cases where I want complete text editor freedom for documentation purposes. Some advantages of multiline comments:
|
I've suddenly seen some scala example that brought me to the following "why nots":
|
@yglukhov Scala is an excellent example of what not to do. :) Really, though, I think this needs to be in Nim before 1.0. |
@kirbyfan64 What I'm still not seeing for this particular use case is why this isn't something that an editor cannot do for you. I hit map ,c :Comment<CR>
map ,u :Uncomment<CR>
com! -range Comment <line1>,<line2>s/^/# /
com! -range Uncomment <line1>,<line2>s/^# // The other use case where you may need comments with a begin and end are inline comments, e.g. something like this (borrowing Haskell syntax for inline comments): proc foo(arg1: Type1 {-comment1-}, arg2: Type2 {-comment2-}) = ... I'd argue that this is a much less important use case and can easily wait until after 1.0. |
Yeah, IDEs can definitely do it. Which is great. When you use an IDE. |
@kirbyfan64 I do not use an IDE. Any editor more advanced than edlin should be able to do it. |
I still really just want some inline comments... block and line comments are simply not enough. And comments should nest. #[ ... #[ ... #] #[ ... #] ... #]... |
@oderwat Give me a use case. |
proc doSomething(a: int, b: string, c: int) = ...doit...
doSomething(1543231#[1544291#]#[996584#],"bla"#["blub"#],3#[or any prime#]) let x=y*1.14#[was 1.16 till yesterday#]*123.4#[should be calculated#]+100
let z=doSomething#[or doOtherthing#](1,2,3) #[ need to fix that proc
proc ohMy(y: float): float =
y*1.14#[was 1.16 till yesterday#]*123.4#[should be calculated but how?#]+100
#]
proc ohMy(y: float): float = 1234.5 # just use that for now I would also prefer |
I think now that the lack of inline comments is against Nim's design philosophy. We support #[comment here]
#[[comment here]]
#[[[comment here]]]
#[[[[comment here]]]] With the level of [] up to 4. This means that regex based syntax highlighters can still process them properly (it adds 4 new regexes to the highlighter) and yet is flexible enough to allow for nesting in practice as well as crazy stuff like code here
#]]] # end marker here left for easy code section deactivations |
Implemented multi-line comments. |
For reference: the syntax for multi-line comments we settled on is On Monday, 18 January 2016, Andreas Rumpf notifications@github.com wrote:
|
Let's implement a new comment syntax for 0.10.0. Current syntax
discard """ ... """
is too ugly and too much hassle to write. It's about time I make this feature request official and create an issue for it. So here it is.@Araq's suggestion on IRC was
#[ ... ]#
.Other possible contenders:
### ... ###
,{- ... -}
,(* ... *)
.Suggestions and discussion encouraged.
Also, let's be democratic: so in your reply tell us if you think this is a good idea or not with a unambiguous
Yes
orNo
.Forum discussion here.
The text was updated successfully, but these errors were encountered: