The RPG Maker Resource Kit

RMRK RPG Maker Creation => RPG Maker General => General Scripting => Topic started by: Zeriab on January 28, 2006, 03:21:04 PM

Title: Indents! Please use them!
Post by: Zeriab on January 28, 2006, 03:21:04 PM
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)
Code: [Select]
#******************************************************************
# 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:

Code: [Select]
#******************************************************************
# 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.
Title: Indents! Please use them!
Post by: ahref on January 28, 2006, 03:40:18 PM
indents are a pain

the make documents look wierd there not required and i dont plan on using them
Title: Indents! Please use them!
Post by: blueXx on January 28, 2006, 03:55:44 PM
it's fairly annoying enough to write a script, well assuming you actually made something of use
adding those dumb stuff will be just extra work , i would only add any of those if the player needs to edit it to use it , only at the point of editing and only the way i want it to be
Title: Indents! Please use them!
Post by: Tsunokiette on January 28, 2006, 05:44:08 PM
Uh dudes, idents aren't a pain they take, well a milisecond to create one, two, they are required in every job or community that involves programming.

When you don't use indents you are but a lazy scripter. :wink:

Rmxp.net is the exception, because thier forum software isn't working properly yet.
Title: Indents! Please use them!
Post by: blueXx on January 28, 2006, 06:04:08 PM
a sec each line.. X say 100 lines = pain

ok so i am lazy so what?
Title: Indents! Please use them!
Post by: helipluis on January 28, 2006, 06:07:00 PM
Quote from: blueXx
a sec each line.. X say 100 lines = pain

ok so i am lazy so what?


So nothing!  8)
Title: Indents! Please use them!
Post by: Zeriab on January 28, 2006, 06:18:48 PM
Quote from: blueXx
a sec each line.. X say 100 lines = pain

You are in luck. It have been accounted for in the script editor:
You make 1 indent, type the line and press enter.
New line, Script Editor automatically creates 1 indent for you.

In fact you only have to make or remove an indent when you should change the amount of indents.
If you look at the indented code I've made I should only have to change the indent 10-12 times. It's really no problem doing this while writing the code.
I can however be a pain to indent an entire script after it were made.
You really just have to make it a habbit.

Quote from: blueXx
ok so i am lazy so what?

It makes me think your script sucks.

If you want to learn how to space your script properly, look at some of Tsunokiette's scripts. I really like those.

Edit: Corrected some spelling errors
Title: Indents! Please use them!
Post by: blueXx on January 28, 2006, 06:28:50 PM
while making X amount of scripts, i only posted 1, which worked and was better than any script i was capable of finding to that subject
so.. my scripting sux?

i am having a little problem pointing at the reason for your pointless comment

one can be lazy, though his stuff will work while tsu is more than just well knowen to post scripts before he finished them
not that it makes his scripts bad, just makes your hard worker quite rushy.

and seriously i don't see what greatness it gives you to see me explain every god damn action, you will never see an event being explained like that, even if it had an option to add comments at the end of every line.

the way i see it- if you can read the script itself, like you can easily read an event then you don't need comments.
if you can't , what the hell are you doing editing the script?
Title: Indents! Please use them!
Post by: Zeriab on January 28, 2006, 07:37:41 PM
I realized I've written It makes me think your scripting sucks.
What I meant was: It makes me think your script sucks.
There's also a difference between me thinking it being thus and it actually being thus. Like I wrote before. Looking at unstructured scripts makes me think that they either suck or have not been copied properly.


Quote from: blueXx
one can be lazy, though his stuff will work while tsu is more than just well knowen to post scripts before he finished them
not that it makes his scripts bad, just makes your hard worker quite rushy.

You seem to have missed my point. I am not referring you to Tsu's scripts because of the functionality. I want you to look at the structure of Tsu's scripts. In this context I don't care about how well the script works when you run the game.


If you still wonder why you should indents I hope looking at the Planner-class I've created sometime ago in Java with and without spacing will clarify why one would use indents:
With Spacing (http://www28.websamba.com/Vobbys/Planner.txt)
Without Spacing (http://www28.websamba.com/Vobbys/BadPlanner.txt)


About all the comments stuff you've wrote. I've never written anything about commenting every line about it's action. In fact I didn't write much more, than they are important to make. How should one make comments? I did not answer this and I do not believe this topic to be the place for such an answer as I've created this topic on the purpose of showing how to indenting your script.
Title: Indents! Please use them!
Post by: ahref on January 28, 2006, 09:37:12 PM
whenever i open a complicated html source of a website there is indents everyhwere and i constantly have to scroll accross

they dont affect the programing so i dont think there needed for companies
if they are then meh!
Title: Indents! Please use them!
Post by: blueXx on January 28, 2006, 10:36:00 PM
well everyone with their own taste.. personally i like your bad planner , he looks pro

why?
cause making all the stuff close to each other makes it look harder to make and makes me think "oh wow he is a pro"
while your good planner looks empty and makes me think "lol anybody can do that.. what a noob.."

then again.. some will say it's the other way around Oo

well.. that's getting pointless anyways Xx
Title: Indents! Please use them!
Post by: Zeriab on January 28, 2006, 11:00:41 PM
Quote from: blueXx
well.. that's getting pointless anyways Xx

Meh, agreed. There would properly not get anything good out of continuing this.

@ahref The site you're looking at might be computer generated, like this page.
If you look at the source of the page it would properly not look too nice. That's basically because the computer don't care if the lines can't fit on the screen, and why should it?
I remember loong ago playing with a programming language called Delphi. The max amount of data a String (text) could contain was 2 GB. <-- That's very very very much!
The source of any page here at crankeye would not be anywhere near that, but still, a line of only 1 KB is long. It's about 1000 letters!
Remember the computer would have no problems reading that, but it might look crazy when viewed.
Title: Indents! Please use them!
Post by: Tsunokiette on January 29, 2006, 01:37:45 AM
Quote from: Zeriab
Quote from: blueXx
one can be lazy, though his stuff will work while tsu is more than just well knowen to post scripts before he finished them
not that it makes his scripts bad, just makes your hard worker quite rushy.

You seem to have missed my point. I am not referring you to Tsu's scripts because of the functionality.


Lol, this is true. It's not that I rush to post the scripts, it's that I post scripts before I  fully test them, simply because I'm only able to access RMXP once a week at the most, causing me to miss completely unforseen errors. (usualy syntax/mystery Oo)

But I'll take responsibility, most of my scripts don't work *cries* but that's changed, I havn't released any scripts for a while, because I'm still de-bugging them. But when they don't work constantly, it discourages me and I stop for a while, then again, do you really expect more to come from a 14 year old boy? lol.
Title: Indents! Please use them!
Post by: Zeriab on January 29, 2006, 09:38:57 PM
What I expect really depends on the specific boy.
You are however not any 14 year old boy, you are a 14 year old boy who know how to create those indents (and good comments) I treasure so much.
That I naturally expect more from you is just my own fault, not yours.