GarageGames / Torque2D

MIT Licensed Open Source version of Torque 2D game engine from GarageGames
MIT License
1.67k stars 1.55k forks source link

Inconsistent use of capital letters in functions and properties #144

Open jamesu opened 10 years ago

jamesu commented 10 years ago

This issue has bitten me a few times in the past, and once again now, so I thought I'd bring it up again...

As probably everyone knows, most strings and variable references in Torquescript and Torque2D in general are case insensitive. This means for example:

%object.doThis();
%object.DoThis();
%object.DOTHIS();
%oBJect.dOtHiS();

And

%object.Property
%object.PROPERTY

And also

$variable
$VARIABLE
$vArIaBlE

Are all equivalent.

Since all strings are case insensitive, this also means if you define a string in TorqueScript, you'll be stuck with that version of the capitalized button for the lifetime of a running engine instance. For example if we type this in the console...

PauseSceneModeButton.text = "run"; // not capitalized, better change it...
PauseSceneModeButton.text = "Run";

The text of the button will remain as "run", not "Run". Note though that the text field of a control is set as type TypeCaseString (i.e. case insensitive), but in reality this type is useless in this situation as strings are converted into their case insensitive version in the compilation stage. Thankfully though this problem does not occur when grabbing values from text boxes, file objects, etc.

Since I'm interested in incorporating alternative scripting languages into the Torque2D core, this central issue becomes a big problem as nothing is consistent in the code - one minute a property or function might be using a capital letter to start off with, the other no capital letter, etc.

Setting "caseSens" to false by default in StringTable reveals the full scale of this problem. Nothing loads properly until you change a whole bunch of field and class names in script to their correctly cased versions. For whatever reason, a lot more of the object property names in Torque2D (e.g. in GuiControl) start with capital letters (although in Torque3D this is not the case). The serialized versions of the gui controls in the taml files seem to use whatever random case they were in when last saved, meaning for instance the text is blank for most of the buttons.

Examples of general case inconsistencies in code:

text and Text command and Command buttonType and ButtonType minExtent and MinExtent sceneObject and SceneObject white and White class and Class toolTip and ToolTip getWord and GetWord toggleConsole and ToggleConsole moduleId and ModuleId versionId and VersionId $Gui::fontCacheDirectory and $GUI::fontCacheDirectory %touchId and %touchID

Oddly enough in the coding guidelines section in the wiki, it mentions "Be Consistent". But in this case, the code is anything but consistent.

lilligreen commented 10 years ago

Agreed. We need to come up with a set of guidelines for naming folders/files, classes, fields, methods, etc. And then the fun work of going through all the code and applying that standard. Something to look at post 3.0 release.