Page 2 of 2

Re: code style for Torque3D

Posted: Sun Jul 16, 2017 8:02 pm
by Duion
Well there can be slight differences within coding styles, for example the preferred indend length, from 1 - 8 spaces/tabs everything exists.

Are the any inconsistencies in the code? I did not notice much.

And do automatic tools exist that can restyle the entire code automatically?

Re: code style for Torque3D

Posted: Tue Jul 18, 2017 12:03 am
by Bloodknight
yes, but they can break code, depending on what gets changed

Re: code style for Torque3D

Posted: Wed Jul 19, 2017 12:00 pm
by Timmy
It's pretty trivial to correct anything if one of these automatic tools killed any code.

Re: code style for Torque3D

Posted: Sat Dec 02, 2017 6:14 pm
by Duion
I did some more research into coding style and found K&R seems to be considered the best amongst experts, as it is used in the Linux kernel and many more big popular projects: ... style.html also interesting to read the other style recommendations.

The main difference are the placement of the braces and the spaces, the Linux kernel uses 8 spaces for indentation and they argue that it enhances readability and that if you need more than 3 levels of indentation your code is bad anyway.

However Torque3D seems to use the Allman style variant which puts the opening braces all in their own lines and first I thought K&R was better, but now I see that Allman style enhances readability and the only disadvantage is using more lines, which is not that big of a problem.

I mean you could argue about some details like how many spaces to use, since 3 are less than the commonly used 4 or even 8 spaces per line, but as game code tends to have a lot of indentations often, 3 lines is a fine choice, so the code does not move too far to the right and 2 spaces would be too little for a significant visual separation.

There seem to be some inconsistencies in the Torque code since .gui and .mis files use a different brace style having the opening brace at the end of the first line instead of using a separate line for them, no idea what the intend behind this is, but as those files are mostly autogenerated from the engine and hardly edited by hand and only a list of items, it would not add much benefit changing it anyway.

So I tend to agree to the way it already is now and suggest not to change Torque3D coding style at all.