Nicer than Disable...()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Nicer than Disable...()

Post by djes »

Disable...() functions should be renamed, mixed with "state" functions, or joined with Enable...() functions. For example, DisableWindow() syntax is not clear :
DisableWindow(#Window, State);
'State' can take the following values:
1: The window is disabled.
0: The window is enabled.
is giving this crappy code

Code: Select all

DisableWindow(#MyWindow, #Disabled)
DisableWindow(#MyWindow, #Enabled)
It would be nicer to have

Code: Select all

DisableWindow(#MyWindow)
EnableWindow(#MyWindow)
and much better (because programmable)

Code: Select all

SetWindowState(#Fenetre, #Disabled)
SetWindowState(#Fenetre, #Enabled)
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: Nicer than Disable...()

Post by Josh »

Code: Select all

DisableWindow(#MyWindow)
EnableWindow(#MyWindow)
Not good. In this case you couldn't set the state by parameter.

Code: Select all

SetWindowState(#Fenetre, #Disabled)
SetWindowState(#Fenetre, #Enabled)
Also not good. In this case you get a conflict with #PB_Window_Maximize etc

Code: Select all

DisableWindow(#MyWindow, #True)
DisableWindow(#MyWindow, #False)
This i'm using
sorry for my bad english
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Nicer than Disable...()

Post by IdeasVacuum »

Code: Select all

DisableWindow(#MyWindow, #True)
DisableWindow(#MyWindow, #False)
That's how I use the existing functions, I think it's absolutely fine.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Re: Nicer than Disable...()

Post by djes »

Josh wrote:

Code: Select all

SetWindowState(#Fenetre, #Disabled)
SetWindowState(#Fenetre, #Enabled)
Also not good. In this case you get a conflict with #PB_Window_Maximize etc
Think a bit more :)
Josh wrote:Code:
DisableWindow(#MyWindow, #True)
DisableWindow(#MyWindow, #False)
That's how I use the existing functions, I think it's absolutely fine.
It's not because it works that it's fine. Using a negative word to do a positive action is just... Crappy !
User avatar
idle
Always Here
Always Here
Posts: 5844
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Nicer than Disable...()

Post by idle »

I have to agree with djes, It's just not good form to invoke a double negative conundrum

EnableFoo(object)
DisableFoo(object)

and additionally

SetFoo(object,state)
GetFoo(object,state)

would make a whole lot more sense
Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: Nicer than Disable...()

Post by Josh »

djes wrote:
Josh wrote:

Code: Select all

SetWindowState(#Fenetre, #Disabled)
SetWindowState(#Fenetre, #Enabled)
Also not good. In this case you get a conflict with #PB_Window_Maximize etc
Think a bit more :)
Maybe you think a bit more :) In this case you have a problem, because the parameter has to been used as a flag. If not, you have a problem with GetWindowState(MyWindow)

djes wrote:
Josh wrote:Code:
DisableWindow(#MyWindow, #True)
DisableWindow(#MyWindow, #False)
That's how I use the existing functions, I think it's absolutely fine.
It's not because it works that it's fine. Using a negative word to do a positive action is just... Crappy !
Where do you see a negative word to do a positive action? The action is Disable
sorry for my bad english
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: Nicer than Disable...()

Post by MachineCode »

Code: Select all

DisableWindow(#MyWindow)
EnableWindow(#MyWindow)
No way! I use flags to toggle the state, and the above way makes much more coding. Compare which is shorter and easier:

Code: Select all

If WinDisabled=1
  DisableWindow(#MyWin)
Else
  EnableWindow(#MyWin)
EndIf

Code: Select all

WinDisabled=1-WinDisabled
DisableWindow(WinDisabled)
You can always write your own macros to do it the way you like, but don't force others to change their coding preferences.
djes wrote:DisableWindow() syntax is not clear
In your opinion. It's crystal-clear to me. I don't want to change my sources just because you don't like it. :P
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
User avatar
Dadido3
User
User
Posts: 54
Joined: Sat Jan 12, 2008 11:50 pm
Location: Hessen, Germany
Contact:

Re: Nicer than Disable...()

Post by Dadido3 »

Here's the solution ;)

just define these macros:

Code: Select all

Procedure DisableWindow_(Window, State)
  DisableWindow(Window, State)
EndProcedure

Macro DisableWindow(Window, State=#True)
  DisableWindow_((Window), (State))
EndMacro

Macro EnableWindow(Window, State=#True)
  DisableWindow_((Window), ~(State))
EndMacro
And then you can do something like:

Code: Select all

DisableWindow(123) ; to disable it
DisableWindow(123, #True) ; to disable it
DisableWindow(123, #False) ; to enable it

EnableWindow(123) ; to enable it
EnableWindow(123, #True) ; to enable it
EnableWindow(123, #False) ; to disable it
and its completly backwards compatible...
It coul'd be built into purebasic this way and everyone would be happy ;)

(I haven't tested the macros, but i hope you can see what they should do)
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: Nicer than Disable...()

Post by Tenaja »

MachineCode wrote:You can always write your own macros to do it the way you like, but don't force others to change their coding preferences.
I always find it interesting when someone suggests a feature that could easily be implemented as backwards compatible to all existing code, and helpful to many coders, but just because there is code that does not use the new feature someone always screams "don't make me change!"

This happens regularly...it is very unfortunate. (And MachineCode, please do not take this as a personal attack, or a comment on you specifically--your post is just the most recent of many similar posts, so my comment is to "all of us". Also, realize that this is NOT my first post to go back and edit...)

Everybody (i.e. the "regulars") knows that it is highly unlikely that Fred will ever implement a feature that would break existing code, unless he is making a major core upgrade, such as the 3.x to 4.0 upgrade. Everybody also knows that Fred is bright enough to come up with a way to implement almost EVERY feature request using a method that maintains backwards compatibility. It is pretty safe to assume that Fred would not force us to change.
Last edited by Tenaja on Thu Sep 27, 2012 9:30 pm, edited 1 time in total.
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Re: Nicer than Disable...()

Post by djes »

MachineCode wrote: You can always write your own macros to do it the way you like, but don't force others to change their coding preferences.
I don't force anyone, I'm suggesting, and I know that it can be done easily :)
Dadido3 wrote:Here's the solution ;)

just define these macros:

Code: Select all

Procedure DisableWindow_(Window, State)
  DisableWindow(Window, State)
EndProcedure

Macro DisableWindow(Window, State=#True)
  DisableWindow_((Window), (State))
EndMacro

Macro EnableWindow(Window, State=#True)
  DisableWindow_((Window), ~(State))
EndMacro


And then you can do something like:

Code: Select all

DisableWindow(123) ; to disable it
DisableWindow(123, #True) ; to disable it
DisableWindow(123, #False) ; to enable it

EnableWindow(123) ; to enable it
EnableWindow(123, #True) ; to enable it
EnableWindow(123, #False) ; to disable it
and its completly backwards compatible...
It coul'd be built into purebasic this way and everyone would be happy ;)

(I haven't tested the macros, but i hope you can see what they should do)
Great, and totally backward compatible :D The same thing could apply to SetWindowState(), with a new constant to Enable|Disable OR'D with the existing constants, giving the possibility to alter the window with only one command (and so, reducing code size).
There's also a lot of other "Disable***()" everywhere in the language.

Tenaja> Agree with you :)
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: Nicer than Disable...()

Post by MachineCode »

Tenaja wrote:MachineCode, please do not take this as a personal attack
It's okay, I didn't. :) And I know nobody is "forcing" any changes at this time. I just wanted to nip it in the bud, if it were needed.
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
Post Reply