Non-Strict Vs Strict

Monkey Forums/Monkey Programming/Non-Strict Vs Strict

therevills(Posted 2011) [#1]
Just a few quick examples of Non-Strict and Strict Code:

*** Non-Strict: ***

This fails with "Identifier 'x' not found":
Function Main()
	x = 1
End


This compiles:
Function Main()
	local x
	x = 1
End


*** Strict: ***

This fails with "Syntax error":
Strict

Function Main() ' <--- Error here
	x = 1
End


This fails with "Identifier 'x' not found":
Strict

Function Main:Int()
	x = 1
End


This fails with "Syntax error":
Strict

Function Main:Int()
	local x ' <--- Error here
	x = 1
End


This fails with "Missing return expression":
Strict

Function Main:Int()
	local x:Int
	x = 1
End


This compiles:
Strict

Function Main:Int()
	local x:Int
	x = 1
	return 0
End



matt(Posted 2011) [#2]
Very useful post, thanks for taking the time


Loofadawg(Posted 2011) [#3]
Much obliged.

I am wanting to stay within the restrictions of Strict, so yes, very useful.