# Scripting - Best Practices

This topic covers best practices when implementing scripts in a project.

- Data Change Scripts are executed as a blocking function on a thread that changes a tag's value. For example, if a tag is in a Task, and the tag's value changes in the Task, the Data Change Script will block the Task while the script executes.

- Make sure to utilize Using statements to help keep your script text readable. Using statements allow the compiler to automatically attempt to prefix your code.

  For example, instead of the following code:

      Cognex.VisionPro.Display.CogRecordDisplay display2 = $System.GetInternalObject("Pages.Page.ImageDisplay") as Cognex.VisionPro.Display.CogRecordDisplay;
      Cognex.VisionPro.ICogRecord currentRecord = $Tasks.Task.Task.VisionProToolBlock.CogPMAlignTool.CreateCurrentRecord();

  Add Cognex.VisionPro and Cognex.VisionPro.Display as Using statements, the code can be rewritten as follows:

      CogRecordDisplay display2 = $System.GetInternalObject("Pages.Page.ImageDisplay") as CogRecordDisplay;
      ICogRecord currentRecord = $Tasks.Task.Task.VisionProToolBlock.CogPMAlignTool.CreateCurrentRecord();

  Note: For more information, see the Calling External Code and Using Statements topic.
- Most global static functions (e.g. $System.Log.Write) are thread safe.

- In a "void" script, if you attempt to "return;" before the last line of code, you must instead use "return null;". Simply using "return;" in this scenario will result in a compile error (e.g. "Line 3: An object of a type convertible to 'object' is required.").