code style for Torque3D

Friendly conversations, and everything that doesn't fit into the other forums.
  • 1
  • 2
14 posts Page 2 of 2
Duion
Posts: 844
Joined: Sun Feb 08, 2015 1:51 am
 
by Duion » Sun Jul 16, 2017 8:02 pm
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?
Bloodknight
Posts: 96
Joined: Tue Feb 03, 2015 8:58 pm
by Bloodknight » Tue Jul 18, 2017 12:03 am
yes, but they can break code, depending on what gets changed
Timmy
Posts: 308
Joined: Thu Feb 05, 2015 3:20 am
by Timmy » Wed Jul 19, 2017 12:00 pm
It's pretty trivial to correct anything if one of these automatic tools killed any code.
Duion
Posts: 844
Joined: Sun Feb 08, 2015 1:51 am
 
by Duion » Sat Dec 02, 2017 6:14 pm
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: https://www.kernel.org/doc/html/v4.10/p ... 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.
  • 1
  • 2
14 posts Page 2 of 2

Who is online

Users browsing this forum: No registered users and 1 guest