Discussions related to Visual Prolog
User avatar
Tonton Luc
VIP Member
Posts: 204
Joined: 16 Oct 2001 23:01

Code optimization

Unread post by Tonton Luc »

Hi,

How to optimize this following code ?

Code: Select all

constants %    contenu_visible = b_true.     contenu_visible = b_false.     clauses start():-     if contenu_visible = b_true then         Win = getVpiWindow() % here is TaskWindow\frm1.pro(52,15)     else         Win = applicationWindow::get():getVpiWindow()     end if,     Container = activeXContainer::new(Win),     ...
TaskWindow\frm1.pro(52,15) warning c651: Unreachable or excessive code (removed by the optimization)
User avatar
George
Active Member
Posts: 47
Joined: 19 Sep 2011 8:54

Unread post by George »

constants
% contenu_visible = b_true.
contenu_visible = b_false.


clauses
start():-
if contenu_visible = b_true then
Win = getVpiWindow() % here is TaskWindow\frm1.pro(52,15)
else
Win = applicationWindow::get():getVpiWindow()
end if,
Container = activeXContainer::new(Win),
First of all,

You have used the constants value

Code: Select all

constants contenu_visible = b_false.
You can't change a constant value anywhere in the code - It is the one time initialization

The value for the constant variable is " b_false" - So, It always move to else loop - As a result, there is no use of "contenu_visible = b_true" condition which always fail..

Now see your code :

Code: Select all

clauses start():-     %No use of If clause - it will always fail and move to else loop     %Because you are  using the constant variable that never change during run time     if contenu_visible = b_true then           Win = getVpiWindow() % here is TaskWindow\frm1.pro(52,15)     else         Win = applicationWindow::get():getVpiWindow()     end if,     Container = activeXContainer::new(Win)
If you want to make the contenu_visible variable to change during run time, you may use,
fact variable or properties and make use that for the if loop comparison

example

Code: Select all

facts     contenu_visible : boolean := true.
Ex:
Kind Regards,
George Ananth. S | Prolog Developer
georgeananth.prolog@gmail.com
+91 9791499282
User avatar
Tonton Luc
VIP Member
Posts: 204
Joined: 16 Oct 2001 23:01

Unread post by Tonton Luc »

Hi,

Tks for your help.
I've changing my code as follow and now, any warning message at compile time :

Code: Select all

constants % contenu_visible = b_true. contenu_visible = b_false.   predicates get_win:()-> vpiDomains::windowHandle procedure(). #if contenu_visible = b_true #then clauses     get_win() = getVpiWindow(). #else clauses     get_win() = applicationWindow::get():getVpiWindow(). #endif   clauses start():-     Win = get_win(),     Container = activeXContainer::new(Win),     ...
:wink:
User avatar
George
Active Member
Posts: 47
Joined: 19 Sep 2011 8:54

Unread post by George »

You are trying through conditional compilation

Code: Select all

#if contenu_visible = b_true #then clauses     get_win() = getVpiWindow(). #else clauses     get_win() = applicationWindow::get():getVpiWindow(). #endif

Code: Select all

constants % contenu_visible = b_true. contenu_visible = b_false.
Since you have used conditional compilation, application never compile the "contenu_visible = b_true" block until you manually going to change the constant value

According to your coding, application always compile the else block and again, no use of "If block" -

And it will not give you any compilation error.

If you have true intention of two different branches in your project where user need to change the constant value - then use conditional compilation

: Else, go for the fact variable or properties and do the run time dynamic changes
Kind Regards,
George Ananth. S | Prolog Developer
georgeananth.prolog@gmail.com
+91 9791499282
User avatar
Tonton Luc
VIP Member
Posts: 204
Joined: 16 Oct 2001 23:01

Unread post by Tonton Luc »

Hi,

The user never need to change the constant value => only me, sometime I need to change it manually before to compile my project.
User avatar
George
Active Member
Posts: 47
Joined: 19 Sep 2011 8:54

Unread post by George »

It upto your call,

Depends upon the requirement, you can setup the constants value and build the new setup - The final setup will use only the last modified constant value -

If you need to change the value, every time you have to do it manually which is really not good..

So, play with that depends upon the requirements..
Kind Regards,
George Ananth. S | Prolog Developer
georgeananth.prolog@gmail.com
+91 9791499282
Post Reply