Show constant as constant name in Variable Viewer

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Korolev Michael
Enthusiast
Enthusiast
Posts: 200
Joined: Wed Feb 01, 2012 5:30 pm
Location: Russian Federation

Show constant as constant name in Variable Viewer

Post by Korolev Michael »

Code: Select all

#Success = 45
var = #Success
It would be groovy, if Variable Viewer will display var as "#Success" in addition to "45".
Can you incarnate this a VERY handy option? :)
Last edited by Korolev Michael on Sat Sep 14, 2013 2:27 pm, edited 3 times in total.
Former user of pirated PB.
Now registered user :].
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Show constant as constant name in debugger

Post by Fred »

Unfortunately, it's not possible as we don't know which constant you assigned to var. Many different constants can have the '45' value.
Korolev Michael
Enthusiast
Enthusiast
Posts: 200
Joined: Wed Feb 01, 2012 5:30 pm
Location: Russian Federation

Re: Show constant as constant name in debugger

Post by Korolev Michael »

You can make possibility for assigning to variables a set of possible constants. And save these assigned values in pb file.
For example, in Variable Viewer, click to variable "var", then choose and bind defined constants #Success and #Failed to it.

Thus, Variable Viewer will always show #Success or #Failed instead of 45 or 47.
Last edited by Korolev Michael on Sat Sep 14, 2013 11:27 am, edited 1 time in total.
Former user of pirated PB.
Now registered user :].
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Show constant as constant name in debugger

Post by Fred »

It won't work everytime and surely don't want the debugger display wrong info ;)
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Show constant as constant name in debugger

Post by PB »

What happens here? ;)

Code: Select all

#Success = 45
#Failure = 45
var = #Success
Debug var ; Does the IDE show #Success or #Failure ?
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Korolev Michael
Enthusiast
Enthusiast
Posts: 200
Joined: Wed Feb 01, 2012 5:30 pm
Location: Russian Federation

Re: Show constant as constant name in debugger

Post by Korolev Michael »

IDE will show "multiple constant matches found". This means, there is a mistake in code, because you bound two equally defined constants.

Does anyone assign two equal values for two constants, in real project? Constant values can coincide if they belongs to different abstraction layers/objects e.t.c.

Edit: I meant not Debugger, but Variable Viewer, sorry. Edited all my messages.
Former user of pirated PB.
Now registered user :].
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Show constant as constant name in debugger

Post by PB »

> Does anyone assign two equal values for two constants, in real project?

Yes. In fact, it's totally normal.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Korolev Michael
Enthusiast
Enthusiast
Posts: 200
Joined: Wed Feb 01, 2012 5:30 pm
Location: Russian Federation

Re: Show constant as constant name in Variable Viewer

Post by Korolev Michael »

No, I meant not two equal constant within all project. I mean two equal constants within one variable.

How one variable can have 45 = #Success OR #Failed at same time, can you explain me?
Last edited by Korolev Michael on Sat Sep 14, 2013 11:48 am, edited 1 time in total.
Former user of pirated PB.
Now registered user :].
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Show constant as constant name in debugger

Post by Little John »

Korolev Michael wrote:This means, there is a mistake in code, because you bound two equally defined constants.
No, not at all.
Korolev Michael wrote:Does anyone assign two equal values for two constants, in real project?
:?:

Code: Select all

#NumberOfWives = 1
#NumberOfChildren = 1
Do you think there is a mistake in this code snippet, or in the life of the respective person?
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Show constant as constant name in Variable Viewer

Post by Fred »

You can imagine such (pseudo) code:

Code: Select all

Select GadgetType()
  Case #PB_GadgetType_Button
    Flags = #PB_Gadget_Toggle
  Case #PB_GadgetType_Tree
    Flags = #PB_Gadget_CheckBoxes
EndSelect
#PB_Gadget_CheckBoxes and #PB_Gadget_Toggle can have the same value in PB because it's not applied to the same gadget. Anyway, there is no reliable ways to revert a numeric value back to a constant at runtime.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Show constant as constant name in Variable Viewer

Post by PB »

> How one variable can have 45 = #Success OR #Failed at same time

It doesn't. The var = 45. So, which 45 constant is it referring to? Nobody knows.

What you're asking is like asking where the water in a hose came from. The hose
is the variable name, and the water is the variable value. So where did the water
come from? Nobody knows.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Show constant as constant name in Variable Viewer

Post by Fred »

PB wrote:What you're asking is like asking where the water in a hose came from. The hose
is the variable name, and the water is the variable value. So where did the water
come from? Nobody knows.
Another similar quote I read somewhere was the following: "It's like trying to get back eggs and flour from a backed cake" :)
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Show constant as constant name in Variable Viewer

Post by PB »

I think this is what the OP wants:

Code: Select all

#alone=1
#one=1
#single=1

var=#one
Debug var ; Shows "#one" instead of "1"
But it just doesn't work like that. var has become 1, but the
debugger doesn't know if it's from #alone, #one or #single.
And for all practical purposes, it doesn't even matter.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Korolev Michael
Enthusiast
Enthusiast
Posts: 200
Joined: Wed Feb 01, 2012 5:30 pm
Location: Russian Federation

Re: Show constant as constant name in Variable Viewer

Post by Korolev Michael »

I know what you are talkin' about, guys. Are you sure that you really got the question?

@PB, I proposed to do something like "binding" variables or "tracking".

Example one
1. In Variable Viewer (VV), click by right button on var, choose "Bind Constants"
2. Window pops up, you type there:

Code: Select all

#one;
And save. OK, VV knows chosen constants for tracking.

When you run:
Image

We got #one, because we bound with var only #one!

Another example.
1. In Variable Viewer (VV), click by right button on var, choose "Bind Constants"
2. Window pops up, you type there:

Code: Select all

#one;
#two
Save.

Run and you'll get:
Image

VV shows #one, step in, then shows #two, because we bound them both!

Yet another example.
1. In Variable Viewer (VV), click by right button on var, choose "Bind Constants"
2. Window pops up, you type there:

Code: Select all

#one;
#alone
Run:
Image

We got this exception because there are too many bound constants that equals to 1.

Bottom line:
Why did I propose this? You got status 4578. What does it mean, do you remember? Sometimes, with raw value of variable we can't say, what really this value means. Especially, when we operating with constants only, not with numbers.

This can be done. We just need to add some additional info for Variable Viewer. Info, what constants it need to track for particular variable. Whew.

I already know, no one supports this request, but I'll try to pose my point, at least.
Last edited by Korolev Michael on Sat Sep 14, 2013 2:17 pm, edited 1 time in total.
Former user of pirated PB.
Now registered user :].
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Show constant as constant name in Variable Viewer

Post by PB »

> You got status 4578. What does it mean, do you remember?

Well, you shouldn't be checking for what 4578 is; you should always
be checking instead for a constant of that value. Like the following:

Code: Select all

#status_ok=1
#status_wrongname=2
#status_filenotfound=4578

[...]

result = CheckSomething()

If result = #status_filenotfound
  MessageRequester("Error","File not found!")
EndIf
Doing this means you never have to remember what 4578 means.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Post Reply