Talk:AI:Introduction

From OpenTTD
Jump to: navigation, search

Follow OpenTTD C++ coding style?

The OpenTTD coding style specifies open braces should have thier own line. I think we should follow the same guidlines in sample code for the AI's.

so this:

class MyNewAI extends AIController 
{
  function Start();
}

Not this:

class MyNewAI extends AIController {
  function Start();
}
Please read the coding style again. It specifies open braces should go on a new line for functions. They should not for classes, enums and control statements. Yexo 19:32, 14 August 2009 (UTC)

Prototypes not needed?

The page has this example:

class MyNewAI extends AIController 
{
  function Start();
}

However, the function prototype doesn't seem to be needed, and has proven confusing to people on the boards. I recomend removing them from examples in the wiki. That is unless someone has a better reason for including them then they "provide a nice looking list of functions". You could do the same thing in comments and not be confusing to squirrel newbies. Dustin (Sign your posts with ~~~~ in future)

Using prototyping is very widely accepted amongst developers and also acts as a placeholder for functions that have not yet been implemented. There's no need for it like in C++ but it's still a very good habit to get into. Xmakina 10:06, 10 August 2009 (UTC)


I have no evidence that they are "a good habit". More like a holdover from less capable compilers that couldn't deal with forward references. Code Complete (my style guide) doesn't advocate them. The Squirrel docementation doesn't even mention them that I could find. Further, I think they are confusing to people new to squirrel, since we have had some questions on the forums. What happens in squirrel if you call a prototped function without an implementation? Basically, I am not sold and I think they are confusing in this example. For now I plan to mark them with a comment in the example. --Dustin 16:14, 14 August 2009 (UTC)
Personal tools