1. Ankur Patel
  2. PowerBuilder
  3. Monday, 2 March 2020 05:22 AM UTC

Hello,

I have a simple problem and we get this bug once/twice in a year but the impact of this bug is always huge. The problem is the following.

When we create a new function in PowerBuilder, it automatically sets the return value as integer, which the developers forget to change once in a while. Now they do declare a variable to return as long/double/decimal but seem to forget changing the return value. Let's consider the following example.

public function integer of_get_maxid ();

long ll_max_id

Select MAX(tran_id) into :ll_max_id From table_name;

//check whether value is null
If ll_max_id = 0 OR Isnull(ll_max_id) Then
ll_max_id = 0 
End If

Return ll_max_id

end function

Now, the function will work fine until the records in table will reach more than 32767. And the records in table never reach to that level during the developer unit testing or during in-house QA. The issue comes into light when a client reaches more than 32767 records and then it starts corrupting the data because now the variable overflows which gives a negative number.

What I want to know is if there a tool which can detect such possible integer overflows as it seems like this is something which an automated tool can easily catch. 

I think the best solution to this problem would be if PowerBuilder compiler would show a warning for such mistakes.

 

Thanks,

Ankur Patel

Who is viewing this page
David Peace Accepted Answer Pending Moderation
  1. Wednesday, 4 March 2020 11:18 AM UTC
  2. PowerBuilder
  3. # 1
0
Votes
Undo

Hi

We always had a code review process, our development manager was responsible for code qualty and would review everyones code before it was released for build. This quick glance approach would pick up these sorts of sillies and ensures that standards are met. It's a simple approach but works very effectivly.

I also think a compiler warning for moving different numeric types not just function returns. Setting a int = long could give a datatype missmatch warning. Just a thought.

Cheers

David

Comment
There are no comments made yet.
Michael Kramer Accepted Answer Pending Moderation
  1. Tuesday, 3 March 2020 20:18 PM UTC
  2. PowerBuilder
  3. # 2
2
Votes
Undo

How to find ALL INT-returning functions across an entire PB workspace!

  1. Prerequisite! :: This "script" expects you have all source under "native source control" so that all PB source files reside in folder = ws_objects in your workspace root folder.
  2. Download attached ZIP archive = PowerSmells.zip
    Copy contained file = PowerSmells.ps1 to your PB workspace root folder
    File contains PowerShell script to find all INTEGER returning functions across all targets in current PB workspace.
    View the file for comments on what + how.
    1. You may need to "unblock" the script before Windows trusts the downloaded file.
    2. You may need to change PowerShell execution policy to RemoteSigned to execute the script.

  3. In command prompt in your workspace root folder, execute this command.
    Example here has root folder = D:\Code
    D:\Code> PowerShell .\PowerSmells.ps1 [Enter]​

     

You can copy the script-block and do as many code "auto reviews" as you like. The "Pattern" and "NotMatch" texts are traditional "regular expressions."

Enjoy! /Michael

 

UPDATED => Fixed typo in original attached file.

Attachments (1)
Comment
There are no comments made yet.
Michael Kramer Accepted Answer Pending Moderation
  1. Tuesday, 3 March 2020 11:39 AM UTC
  2. PowerBuilder
  3. # 3
1
Votes
Undo

I use PowerShell to search for "code smells" like:

  • Text = "<start of line>public function int "
  • Likewise for protected and private.

I run my PowerShell script containing set of such smell-searches on the ws_objects folder and all subfolders.
PowerShell is fast - and it works. Not fancy in any way but very practical.

HTH /Michael

Comment
I had to lookup the RegEx character. I meant "^public function int " >>> Read: Line starts "public function int ".
  1. Michael Kramer
  2. Tuesday, 3 March 2020 18:14 PM UTC
Ah ok, now I get it! Thanks
  1. Miguel Leeuwe
  2. Wednesday, 4 March 2020 02:36 AM UTC
I added sample PowerShell script in a new, separate reply. It takes a few seconds to scan complete code base of large PB workspace - and list exactly which PBL + CLASS + FUNCTION has unwanted = "smelly" definition.

Searching for "PowerSmells in PowerScript"...
  1. Michael Kramer
  2. Wednesday, 4 March 2020 04:40 AM UTC
There are no comments made yet.
Olan Knight Accepted Answer Pending Moderation
  1. Monday, 2 March 2020 15:20 PM UTC
  2. PowerBuilder
  3. # 4
0
Votes
Undo

I never use integers.
Well, fine....ALMOST never.

Integers are far too prone to blow up in a data-intensive environment, and I've been using LONG values since the first time I ran into this issue back in the day.

For me it's easy to remember to change integers to LONGs becausae I always do that - it's a habit. Perhaps this is a habit your developers adopt?


Later -

Olan

Comment
There are no comments made yet.
mike S Accepted Answer Pending Moderation
  1. Monday, 2 March 2020 14:24 PM UTC
  2. PowerBuilder
  3. # 5
3
Votes
Undo

put in an IDE enhancement request to change the default from integer to long for default function return values for new functions

 

It is a PITA to change it every single time you create a new function.

Comment
I agree with having it default to (none) and it should be at the top of the drop-down, not the bottom.

I also think that the compiler should flag data type mismatches.
  1. Roland Smith
  2. Monday, 2 March 2020 16:23 PM UTC
Can someone guide me how to put in an IDE enhancement request for setting the return value to "(None)" by default or should I just raise it as a bug on the appeon bug page?
  1. Ankur Patel
  2. Tuesday, 3 March 2020 08:26 AM UTC
Just add a bug and they will change it to enhancement when it gets moved to the internal bugzilla.
  1. Roland Smith
  2. Tuesday, 3 March 2020 14:36 PM UTC
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Monday, 2 March 2020 08:33 AM UTC
  2. PowerBuilder
  3. # 6
0
Votes
Undo

Hi,

AFAIK, there's no such tool, unless "Visual Expert" has included something like this in the latest years.

You could write something yourself maybe.

I'm not trying to be arrogant, but my message is that if your developers make "this kind of mistakes frequently", than you'd be better off to make sure that your Q&A team does test with values higher than integer. All you'd have to do is insert a record in the DB with an id with max integer value.

If you want a simple but tedious solution (not 100%):

Select your target in the library painter and do a search on "return ll_", after that check all of the functions / events listed.

 

NOTE: to prevent / avoid errors like this, make your developers do some unit testing and give them a checklist on which one of the mandatory checks is to check on return types. Maybe even have them document the functions / events.

I "now no longer have to do any documentation", but in the past, there hasn't been a single window which I did have to document, which would not prove it had small errors or could be improved.

 

regards,

MiguelL

Comment
You took the words right out of my keyboard, Miguel!
  1. John Fauss
  2. Monday, 2 March 2020 14:48 PM UTC
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.