Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
BlackSmith
Apprentice


Joined: 08 Dec 2002
Posts: 152

PostPosted: Mon Aug 07, 2006 11:22 am   

#Comment, allow /** or make // as a standard
 
I would like to get a clear way to comment my code.
#Noop does the trick for now but i would like to use // to comment my code without worrying that if someone has the // commenting off as then the code would not work.
New command #Comment or making /** commenting work would do the trick too.
_________________
BatMUD Best MMORPG around since 1990 telnet://bat.org:23
~ Magic & Mind beats Chrome & Meat anytime ~
Pattern(s) in PERL. Using Cmud 1.34/2.09 & BatClient.
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Mon Aug 07, 2006 5:26 pm   
 
CMUD will be removing the // comment option so that it is always on for scripts. The only reason for having the option in the first place was meant to just deal with the command line. But with CMUD I'm trying to remove options that might effect shared scripts like this.

Every language has it's own commenting syntax. Delphi uses {} and (* *) while other languages use ; or // or /* */

For now I'll stick with // in CMUD since it works both at the beginning of a line and in the middle of a line. The obscure case where // doesn't work requires that the comment is in a place where a variable name is expected (without the @) and there is another / before any other non-alphanumeric character. This should be a pretty rare situation. And it can't ever happen if the // is at the beginning of a line.

The ; comment for an entire line will still work, but we've seen in the past how this can sometimes get confused with the ; command separator, so // is preferred.

The trouble with stuff like /* */ is that it requires parsing across multiple lines, and doing a /* without a closing comment can cause it to get locked into comment mode. Usually this kind of comment is used for commenting out large sections of code, and that is less necessary in CMUD since scripts are already broken into pieces like aliases, triggers, etc...we aren't talking about hundreds of lines of code like in traditional programming languages.

So anyway, go ahead and use //
Reply with quote
Rorso
Wizard


Joined: 14 Oct 2000
Posts: 1368

PostPosted: Mon Aug 07, 2006 6:15 pm   
 
Zugg wrote:

The trouble with stuff like /* */ is that it requires parsing across multiple lines, and doing a /* without a closing comment can cause it to get locked into comment mode. Usually this kind of comment is used for commenting out large sections of code, and that is less necessary in CMUD since scripts are already broken into pieces like aliases, triggers, etc...we aren't talking about hundreds of lines of code like in traditional programming languages.

So anyway, go ahead and use //

/* */ comments are usually, as far as I know, actually not "parsed" but removed in the lexer stage. For example most C/C++ compilers don't support nested /* */ comments:

/*
Comment

/*
Super clever nested comment.
*/
*/ <--- syntax error. Comment was already closed above.
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Mon Aug 07, 2006 6:41 pm   
 
Rorso, yes, that is true. Existing // and ; comments are already handled at the "lex" stage in CMUD also. But zMUD (and CMUD to some extent) also parse some things on a line by line level (for handling the old text import and the #read command where scripts can be read in line by line). This has been mostly phased out in CMUD, but I still try not to do too much stuff that requires spanning multiple lines.

Maybe sometime down the line...this is a pretty minor issue to be worrying about at this stage.
Reply with quote
Rainchild
Wizard


Joined: 10 Oct 2000
Posts: 1551
Location: Australia

PostPosted: Mon Aug 07, 2006 10:47 pm   
 
I can see one need for maybe having a variable at the start of the line -

//blahmodule/myvar = 2

but I would never use that syntax - I would use

#var //blahmodule/myvar 2

but thats not to say someone wouldn't want it to work

and take for example the line

myclass/myvar = 2

then you want to comment that

//myclass/myvar = 2

would assume it was a variable in a different module, so you would need to put an extra space to make the comment happen

// myclass/myvar = 2

that's the only spot that I can think it might get confusing (unless of course you want to comment out the //blahmodule/myvar in which case it would be // //blahmodule/myvar hehe).
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Mon Aug 07, 2006 10:55 pm   
 
Rainchild, you are actually correct. The line

//modulename/varname = value

already works to assign a variable. It is not interpreted as a comment. I forgot about this case, so my statement above about // always working at the beginning of the line is incorrect. You still need some non-alphanumeric character before the next / character.

I think maybe we can just tell people to always put a space after // if they want it as a comment. I'll have to test the syntax highlighting to see what it does and maybe fix that. The syntax highlighting isn't true syntax "checking" and it's pretty dump. So maybe I'll make the syntax highlighter only highlight something as a comment if there is a space after the // to remind people that it's better programming practice.
Reply with quote
edb6377
Magician


Joined: 29 Nov 2005
Posts: 482

PostPosted: Tue Aug 08, 2006 12:59 am   
 
yeah id be happy with //<SPACEHERE>Comment as this is what i do anyways. I think you discussed most of this change in the other thread though :)
_________________
Confucious say "Bugs in Programs need Hammer"
Reply with quote
BlackSmith
Apprentice


Joined: 08 Dec 2002
Posts: 152

PostPosted: Sun Aug 13, 2006 11:54 pm   
 
Zugg wrote:
But with CMUD I'm trying to remove options that might effect shared scripts like this.
Thank you, and keep up the good work.
_________________
BatMUD Best MMORPG around since 1990 telnet://bat.org:23
~ Magic & Mind beats Chrome & Meat anytime ~
Pattern(s) in PERL. Using Cmud 1.34/2.09 & BatClient.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net