Mac OS 9 Lives
Mac OS 9 Discussion => Development & Programming => Topic started by: OS923 on March 18, 2019, 03:45:46 AM
-
Pitfall #1
x/y is floating point division.
x\y is integer division.
-
Pitfall #2
Item(), Child() and GetFolderItem() resolve aliases.
TrueItem(), TrueChild() and GetTrueFolderItem() don't resolve aliases.
-
Pitfall #3
If a function returns a boolean, but you forget to write "return true" or "return false", for example in a menu handler, then it returns false.
"return false" can have a special meaning like this doesn't have to be processed anymore.
-
Pitfall #4
If you use Dictionary's "value" property but the key is not in the dictionary then you get an exception and the program is suddenly very slow. You should first test with the "HasKey" method whether the key is in the dictionary.
-
Pitfall #5
Some string functions have a "B" variant to treat the string as a series of bytes instead of a series of Unicode characters.
Len(s)=number of Unicode characters in s.
LenB(s)=number of bytes in s.
AscB, ChrB, InStrB, LeftB, MidB, RightB.
-
Pitfall #6
for i=x to y
is like
i=x;
j=y;
while (i<=j)
{
// Changing y here doesn't change the loop.
// Changing i to > y stops the loop.
i++;
}
and not like
i=x;
while (i!=y)
{
// Changing y here changes the loop.
// Changing i to > y doesn't stop the loop.
i++;
}
If the following program runs
for i=1 to 5
if i=3 then
i=10
end
next
then i=11.
-
Pitfall #7
The methods of the Bitwise class are very slow in REALbasic compared to C++.
-
Pitfall #8
If you declare or resize an array, then you have to use the highest index, not the number of elements.
-
Pitfall #9
Concatenation of strings by means of + is slow. It's better to append every string to an array and then use Join.
-
Pitfall #10
Appending many items to an array is slow. It's better to use redim to append many places at the end of the array if all places are in use.
-
Pitfall #11
If x is a FolderItem, then x.creationDate.totalSeconds and x.modificationDate.totalSeconds cause a memory leak of a Date. You have to write
c=x.creationDate
t=c.totalSeconds
-
Pitfall #12
If you define a file type, and you enable "Document icon", then it will add this Type to the 'BNDL' resource, even if you don't define icons.
For example, if the Creator is 'Cret' and you want that your program can open folders, then you need to add file type "special/folder" / 'MACS' / 'fold' with "Document icon" disabled and file type "folder" / 'Cret' / 'fold' with "Document icon" enabled.
-
Pitfall #13
Before you use "for each" you have to verify that the array is not empty.