Jump to content
  • 0

Double slash comments as a source of errors


Kisvakond

Question

Hi all,

 

I've been doing my studies in scripting and I ran into a general issue when copying code from forums or pdfs (which is most of the admins doing).

 

If you have a line of comment with the // comment in a code snippet you wish to copy, it might be that due to a line wrap, something from the comment line might end up in the beginning of the next line. sometimes the end of the has valid keywords by coincidence and, and there you go, clusterfuck.

 

I was running into the issue again yesterday with this post:

...

//fnc_usec_selfActions = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\fn_selfActions.sqf"; // Checks which actions for 
selffnc_usec_selfActions =  compile preprocessFileLineNumbers "fn_selfActions.sqf"; // Checks which custom actions for self

...

 

The last word from the comment went in the next line -> selffnc_usec_selfActions instead of fnc_usec_selfActions.

 

A newline character gone missing in action or inserted by the code snippet frame and you wonder why it failed, although you did everything right and that very same stuff worked for others (displaying the code snippets may be well browser and settings-specific).

Most tutorials encourage scripters to use the line C++ style comments, although the old-fashioned C-style comment work as well (based on the ARMA2 Scripting Guide by Taurus, it's supported ).

 

With the /*..*/ comments such an error could have never happened, e.g. in the mentioned example:

/*fnc_usec_selfActions = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\fn_selfActions.sqf";*/ /* Checks which actions for 
self*/fnc_usec_selfActions =  compile preprocessFileLineNumbers "fn_selfActions.sqf"; /* Checks which custom actions for self */

In this case the original intent of the coder is visible (what's meant to be comment and what's not) and more error tolerant/defensive, as the compiler is not at the mercy of the newline CRLFs.

IMHO, most of the time when a copy-paste code is not working or emits side-effects, it's a missing or  re-located newline character ruining the next line of code.

 

Hopefully no one gets the impression that the problem is having comments (there can't be enough of them). The point is that we should use /*..*/ comments whenever possible.

 

Thank you for reading! :)

 

Cheers

 

Kisvakond

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...