Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 assert command
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
marz




PostPosted: Thu Jun 12, 2003 4:23 pm   Post subject: assert command

What does the assert command do?
as in:
var text : int
text := Font.New ("Tomaha:14")
assert text > 0
Sponsor
Sponsor
Sponsor
sponsor
Mazer




PostPosted: Thu Jun 12, 2003 4:38 pm   Post subject: (No subject)

assert checks the statement and terminates the program if it's false.
although, it wouldn't work with fonts. when you make a font, the font is made no matter what. if the font you chose doesn't exist, it is replaced with another one, arial i guess. so the font variable will always be greater than 0 (except before you initialize it).

assert is usually used with opening files and loading pictures. so:

code:

var pic : int
pic := Pic.FileNew ("blah.bmp")

assert pic > 0

if the picture "blah.bmp" doesn't exist in the same folder as this program is running in, the picture isn't created and pic would not be greater than 0.
or with files:
code:

var fs : int
open : fs, "blah.txt", get
assert fs > 0

again, if "blah.txt" doesn't exist in that directory, fs will not be greater than 0 and the program will automatically terminate.

i don't really know why people like to use assert. maybe it'd be good for testing your program, but if you have other people using it having your program terminate itself is just as bad as it crashing.
Catalyst




PostPosted: Thu Jun 12, 2003 4:42 pm   Post subject: (No subject)

something like this might be good in a program to stop it from harming your computer or files, but turing isnt really powerful enough to any thing major so there really is no point
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: