I now and then see people posting scripts without indents and it is really a pain in the *ss to read such code.
Please remember to create proper indents, it makes a difference!
There is a reason for the [
code] function. It is there to preserve the indents.
Look for example at this: (note: do NOT use this script. It is for demonstration only)
#******************************************************************
# Author: Zeriab Date: 28-01-2006
#
# Class_Name.class:
# -----------------
# The header should have no indents at all
# This should contain information about
# Don't implement this class as it most likely won't work
# This is just to illustrate the use of indents
#******************************************************************
class Class_Name
# one indent (= 2 spaces) after the class declaration
@data # object data
@@special = object # class data
# another indent in the constructor
def initialize(data)
# another for loops
for s in something...otherthing
# and for if's
data = data + @@special
if (data=somthing)
#something here
data = somethingnew
end
end
#going back down
@data = min + 60*hours
end
# indents in other methods
def getData()
# return function(@data)
return function(@data)
end
end
If I see something like that. I just skip it.
If it's working, great! But if there is a bug in it, or if one want to modify it...
Anyway what I want is something like this:
#******************************************************************
# Author: Zeriab Date: 28-01-2006
#
# Class_Name.class:
# -----------------
# The header should have no indents at all
# This should contain information about
# Don't implement this class as it most likely won't work
# This is just to illustrate the use of indents
#******************************************************************
class Class_Name
# one indent (= 2 spaces) after the class declaration
@data # object data
@@special = object # class data
# another indent in the constructor
def initialize(data)
# another for loops
for s in something...otherthing
# and for if's
data = data + @@special
if (data=somthing)
# something here
data = somethingnew
end
end
# going back down
@data = min + 60*hours
end
# indents in other methods
def getData()
# return function(@data)
return function(@data)
end
end
You see the difference?
Let's say you've forgotten an
end. In which of the 2 cases is it easiest to discover where to place the missing
end?
The answer is of course the second case where you can see which line belongs to which block due to the indents.
Note: The standard indent in RMXP is 2 spaces. I think you can use any reasonable amount of spaces per indent as long as the indents are proportional.
Basically the system is.
Class definition is at 0-indents. Likewise the the comments before the class at 0-indents
Instance data, method declaration and so on is at 1-indent.
The block in the method starts at 2-indents and goes one indent up for every loop, if, and so on.
Another way to say this is: If you insert block A into block B, then the indent for block A is the indent for block B + 1. Ignore this line if you don't understand what it means.
You might have noticed that I haven't said anything about comments. That's because I don't see lack of comment in the scripts I read, so I thought there was no need to write about that, but that might be related to the fact that I don't read scripts without indents. But you are right. Comments certainly are of importance. They are of as much if not of more importance than indents.
If you have anything to add, please do so.