Page 1 of 1

Nicer than Disable...()

Posted: Thu Sep 27, 2012 9:44 am
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)

Re: Nicer than Disable...()

Posted: Thu Sep 27, 2012 10:21 am
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

Re: Nicer than Disable...()

Posted: Thu Sep 27, 2012 10:35 am
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.

Re: Nicer than Disable...()

Posted: Thu Sep 27, 2012 10:43 am
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 !

Re: Nicer than Disable...()

Posted: Thu Sep 27, 2012 11:51 am
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

Re: Nicer than Disable...()

Posted: Thu Sep 27, 2012 12:28 pm
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

Re: Nicer than Disable...()

Posted: Thu Sep 27, 2012 1:58 pm
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

Re: Nicer than Disable...()

Posted: Thu Sep 27, 2012 2:22 pm
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)

Re: Nicer than Disable...()

Posted: Thu Sep 27, 2012 4:26 pm
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.

Re: Nicer than Disable...()

Posted: Thu Sep 27, 2012 5:25 pm
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 :)

Re: Nicer than Disable...()

Posted: Thu Sep 27, 2012 10:59 pm
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.