Issue in PostEffect.cpp... Cause TorqueScript lets you...
by Vince Gee · in Torque 3D Professional · 04/16/2013 (6:19 am) · 2 replies
Here is another winner, that goes along the lines of, well TorqueScript lets you... so it must be good practice to use this coding method.
So we have a function and a variable both called "isEnabled". So you might say, "Whats wrong with that?"
Beyond confusion of usaged since:
Good programming practice as well as those pesky "Standards" again usually rule that a member property and a member method should not have the same name. Why? well to avoid confusion and also in some more advanced languages,
I know most of you won't see the problem w/ this, since torquescript allows it, but try doing it in a real object oriented language and see how far you will get.
Besides, don't cha think that
Oh, did I mention it already exposes two functions:
addProtectedField( "isEnabled", TypeBool, Offset( mEnabled, PostEffect),
&PostEffect::_setIsEnabled, &defaultProtectedGetFn,
"Is the effect on." );DefineEngineMethod( PostEffect, isEnabled, bool, (),,
"@return True if the effect is enabled." )
{
return object->isEnabled();
}So we have a function and a variable both called "isEnabled". So you might say, "Whats wrong with that?"
Beyond confusion of usaged since:
if (PostEffect.isEnabled) if (posteffect.isEnabled())
Good programming practice as well as those pesky "Standards" again usually rule that a member property and a member method should not have the same name. Why? well to avoid confusion and also in some more advanced languages,
I know most of you won't see the problem w/ this, since torquescript allows it, but try doing it in a real object oriented language and see how far you will get.
Besides, don't cha think that
PostEffect.SetEnabled(true);or
PostEffect.Enabled = true;is easier to read?
Oh, did I mention it already exposes two functions:
DefineEngineMethod( PostEffect, enable, void, (),,
"Enables the effect." )
{
object->enable();
}
DefineEngineMethod( PostEffect, disable, void, (),,
"Disables the effect." )
{
object->disable();
}
DefineEngineMethod( PostEffect, toggle, bool, (),,
"Toggles the effect between enabled / disabled.n"
"@return True if effect is enabled." )
{
if ( object->isEnabled() )
object->disable();
else
object->enable();
return object->isEnabled();
}About the author
www.winterleafentertainment.com
#2
04/16/2013 (9:54 am)
Indeed that is definitely a mess and begging to be cleaned up. void SetEnable(bool enable); and bool GetEnable();, and just an associated enable field as an alternative to using the function calls would be good enough to me.
Associate David Wyand
Gnometech Inc.
- Dave