Author Topic: REALbasic 5.5.5 pitfalls  (Read 2418 times)

Offline OS923

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 518
REALbasic 5.5.5 pitfalls
« on: March 18, 2019, 03:45:46 AM »
Pitfall #1

x/y is floating point division.
x\y is integer division.

Offline OS923

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 518
Re: REALbasic 5.5.5 pitfalls
« Reply #1 on: March 18, 2019, 03:46:26 AM »
Pitfall #2

Item(), Child() and GetFolderItem() resolve aliases.

TrueItem(), TrueChild() and GetTrueFolderItem() don't resolve aliases.

Offline OS923

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 518
Re: REALbasic 5.5.5 pitfalls
« Reply #2 on: March 18, 2019, 03:47:58 AM »
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.

Offline OS923

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 518
Re: REALbasic 5.5.5 pitfalls
« Reply #3 on: March 18, 2019, 03:49:34 AM »
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.

Offline OS923

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 518
Re: REALbasic 5.5.5 pitfalls
« Reply #4 on: March 18, 2019, 03:50:59 AM »
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.

Offline OS923

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 518
Re: REALbasic 5.5.5 pitfalls
« Reply #5 on: March 18, 2019, 03:51:30 AM »
Pitfall #6

Code: [Select]
for i=x to y
is like

Code: [Select]
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

Code: [Select]
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

Code: [Select]
for i=1 to 5
  if i=3 then
    i=10
  end
next

then i=11.
« Last Edit: March 18, 2019, 04:01:59 AM by OS923 »

Offline OS923

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 518
Re: REALbasic 5.5.5 pitfalls
« Reply #6 on: March 21, 2019, 06:42:23 AM »
Pitfall #7

The methods of the Bitwise class are very slow in REALbasic compared to C++.

Offline OS923

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 518
Re: REALbasic 5.5.5 pitfalls
« Reply #7 on: October 11, 2019, 08:41:18 AM »
Pitfall #8

If you declare or resize an array, then you have to use the highest index, not the number of elements.

Offline OS923

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 518
Re: REALbasic 5.5.5 pitfalls
« Reply #8 on: October 11, 2019, 08:41:35 AM »
Pitfall #9

Concatenation of strings by means of + is slow. It's better to append every string to an array and then use Join.

Offline OS923

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 518
Re: REALbasic 5.5.5 pitfalls
« Reply #9 on: October 11, 2019, 08:41:59 AM »
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.

Offline OS923

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 518
Re: REALbasic 5.5.5 pitfalls
« Reply #10 on: October 11, 2019, 08:42:31 AM »
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
Code: [Select]
c=x.creationDate
t=c.totalSeconds

Offline OS923

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 518
Re: REALbasic 5.5.5 pitfalls
« Reply #11 on: October 11, 2019, 08:42:54 AM »
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.

Offline OS923

  • Platinum Member (500+ Posts)
  • *****
  • Posts: 518
Re: REALbasic 5.5.5 pitfalls
« Reply #12 on: October 11, 2019, 08:43:11 AM »
Pitfall #13

Before you use "for each" you have to verify that the array is not empty.