SRL Archive - Senior News and General

SRL Standards.


Nava2

2009-12-14 08:07:44

I think a new list needs to be created, I'll start with the old ones, editted:

[INDENT]
  • Indenting will be two spaces per level. You can indent by selecting text in Simba and pressing Ctrl+Tab and move backwards by hitting Ctrl+Shift+Tab.
  • Margins will be set to 80 characters. Try not to make too long lines. This is because of general codings standards set by the Unix Terminal.
  • The begin statement appears on its own line. The end statement always
  • matches the begin statement by columns. Example:
    begin
    if (condition) then
    begin
    DoStuff();
    end else
    begin
    DoDifferentStuff();
    end;
    end.
  • Do not combine two or more statements on a single line. Write each on its own line.
  • Use semicolons at the end of the lines where appropriate. Simba allows lines without semicolons but you should use them everywhere, except after var, begin, then, else repeat, do and before else.
  • Use spaces after commas and arithmetical signs.
  • Example:
    x := (4 * y) - z + 3;
  • There shall never be white space between an open parenthesis and the next character. As well, there will be a space between logical operators and conditions in conditional statements.
  • Example:
    if ((x = 5) and (y = 5)) then
    DoThis();
  • Object Pascal language reserved words and key words shall always be completely lowercase. Never capitalize words that Simba displays in bold. It's completely unnecessary and looks ugly!
  • Routine names shall always begin with a capital letter and be camel-capped for readability.
  • Example:
    function DeleteVariableFromArray(var theArr: TIntegerArray): Boolean;
  • Routines shall be given names meaningful to their content. Routine name DoStuffWithSyAndSx is not meaningful, but name OutputProgressReport is.
  • Where possible, procedure and function formal parameters of the same type shall be combined into one statement
  • Example:
    procedure Foo(bar1, bar2, bar3, bar4: Integer; bar5: String);
  • All formal procedure and function parameter names will be meaningful to their purpose.
  • All functions should always return some value. Do not rely on SCAR initializing procedure return value automatically! This means: If its a boolean result, set it to false initially, if its an integer set it to 0/-1, and a string would be ''.
  • Variables will be given names meaningful to their purpose. These names will start with a lowercase letter and be Camel Capped for readability. That includes local and loop control variables, although in this case single character names are acceptable. For loop control variables, try to use the variables: i, j, k, l, and h.
  • Boolean variable names must be descriptive enough so that their meanings of True and False values will be clear.
  • Variable declarations start in next line after var statement and are indented.
  • Example:
    var
    x, y: Integer;
    foo: string;
  • Use of global variables is discouraged. However, they may be used when necessary. Global variable naming rules are as follow:
  • Forms and controls are prefixed with their individual prefixes. Examples: frmMainForm, lblUser, txtPassword, imgPreview etc. DTMs will be marked with dtm prefix as in dtmFeather. Character sets will be marked with chr prefix as in chrChatChars. Bitmaps will be marked with bmp prefix as in bmpFishingNet. Include global variables will be marked with g prefix then include initials as in gSRLStartTime. Normal global variables will be marked with g prefix as in gNumFishCaught.
  • Type names that are reserved words shall be completely lowercase as in string. For other variable names, the first letter shall be uppercase, and the rest shall be camel-capped for clarity as in Integer.
  • The most likely case to execute in an if/then/else statement shall be placed in the then clause, with less likely cases residing in the else clause(s). This improves performance as well as readability.
  • For all condition statements, conditions will be encased in a set of parenthesis. This is general coding standard and allows for more obvious reading.
  • If multiple conditions are being tested in an if statement, conditions should be arrange from left to right in order of least to most computation intensive. If condition statement is complex, replace it with function or Boolean variable with a meaningful name. This improves readability and makes code self-documenting.
  • Use of informational file header is encouraged for all script and include files.
  • Use Script > Script Properties from SCAR menu to enter script information.
  • All variables, functions, procedures, and constants should be properly commented. One can choose their own style, but use of {} should be put forward over //.
  • Constants Constants should be used as often as possible. This allows for easier readability and self-explanatory code. Constants should be prefixed with a descriptive meaning, usually associated with the File or the Function. They will follow the format: *FILE*_*FUNCTION*_*VALUE*. They will be camel capped, and the *FILE* token can be left out if it is part of a script and only if it a local constant. If the Constant is used globally in a script it will be prefixed with "gbl".


[/INDENT]

Comments, ideas?

Bobarkinator

2009-12-14 08:14:04

I want capitalized reserved words.

Nava2

2009-12-14 08:16:19

From: Bobarkinator
I want capitalized reserved words.


I say no. NEVER! But, I guess it should be put to a vote. I really really really am against it. It creates UGLY code and is an eye-sore.. literally.

E: Added Placing brackets around all conditional statements.

marpis

2009-12-14 08:59:55

I think until should be treated like a function, with brackets.
I think it's somehow a lot cleared, dunno about you guys. What do you think?

Repeat
Until(False); // Good

Repeat
Until False; // Bad

E: I don't think you should forbid capitalizing, because many think it looks cool :rolleyes:

Nava2

2009-12-14 09:22:59

From: marpis
I think until should be treated like a function, with brackets.
I think it's somehow a lot cleared, dunno about you guys. What do you think?

Repeat
Until(False); // Good

Repeat
Until False; // Bad

E: I don't think you should forbid capitalizing, because many think it looks cool :rolleyes:


Capitalizing is silly, and I added conditionals should have braces around them, so things like case..of, while..do, repeat..until, if..then etc.

Naike

2009-12-14 09:42:11

There should be no forbid for capitalizing, having it forbidden would be silly.

Method

2009-12-14 09:55:27

From: N1ke!
There should be no forbid for capitalizing, having it forbidden would be silly.


It needs to be standardized when developing the include for consistency, though.

Otherwise people should be able to use whatever they want for their own scripts.

Naike

2009-12-14 09:58:43

I always capitalize these, in or outside the include..?


Function
Procedure
Procedure Nameofprocedure
For
Const
Integer
String
Boolean
Array

As they look horrible without it.

n3ss3s

2009-12-14 09:59:31

Object Pascal language reserved words and key words shall always be completely lowercase. Never capitalize words that SCAR displays in bold. It's completely unnecessary and looks ugly!


l0l u wish

ZephyrsFury

2009-12-14 10:28:14


with (Players[0]) do
begin
Name := 'poo';
end;

Doesn't compile while


with Players[0] do
begin
Name := 'poo';
end;


does.

Wizzup?

2009-12-14 11:17:17

Is this really necessary?
Let everyone code the way they want. As long as the indenting doesn't jump from 2 spaces to 8 spaces, I could care less.

Bobarkinator

2009-12-14 11:26:00

It does make the include easier to read if a set of standards are adopted throughout it. I also never put brackets around conditional statements unless there is more than one and it needs it.

Wanted

2009-12-14 11:27:16

Imo standards are never gonna stick, as long as everyone is readable and consistant with themselfs I can live

Wizzup?

2009-12-14 11:48:56

From: Bobarkinator
It does make the include easier to read if a set of standards are adopted throughout it. I also never put brackets around conditional statements unless there is more than one and it needs it.


I always put ( and ) around if statements these days, cause it is what all other languages force you to do. So it's more of a habit.

E: And ( and ) make code more readable, not less. :)

Nava2

2009-12-14 12:07:01

From: ZephyrsFury

with (Players[0]) do
begin
Name := 'poo';
end;

Doesn't compile while


with Players[0] do
begin
Name := 'poo';
end;


does.


Thats why it states ``conditionals'' :)

From: Wizzup?
Is this really necessary?
Let everyone code the way they want. As long as the indenting doesn't jump from 2 spaces to 8 spaces, I could care less.


I think that standards allow code to be read by anyone. Without some form of a standardized code, it can be confusing as to whats going on. Much of this is from the *old* standards, I merely tossed some reasoning etc behind them.

From: Wizzup?
I always put ( and ) around if statements these days, cause it is what all other languages force you to do. So it's more of a habit.

E: And ( and ) make code more readable, not less. :)


Heh, thats why I do it as well, I think that it should be practice since it would help people in converting between languages, and in reality, how hard is it to type two chars? :)

Bobarkinator

2009-12-14 12:13:51

I've never had a problem switching between writing java and SCAR having a habit of doing something. I just put them in in Java and leave them out in SCAR because I think it looks better. Talking about ( and ) here.

mastaraymond

2009-12-14 13:36:08

Stop using caps in reserved words.. Looks silly.

Sir R. M8gic1an

2009-12-14 15:44:45


const
gbl_No_Way !

~RM

Coh3n

2009-12-15 10:06:01

To everyone who says capitalizing bold words is ugly, I agree, but it's going to be different for every person. I just depends on their preferences. I agree that it should be consistent throughout the include, it just makes it neater. Perhaps a vote isn't such a bad idea…

Wizzup?

2009-12-15 11:42:01

From: Coh3n
To everyone who says capitalizing bold words is ugly, I agree, but it's going to be different for every person. I just depends on their preferences. I agree that it should be consistent throughout the include, it just makes it neater. Perhaps a vote isn't such a bad idea…


Yeah. Let 51% of the users decide for the other 49%.

ZephyrsFury

2009-12-15 12:44:58

As long as the code is readable why do we need everyone to have identical standards? Just makes it harder for everyone to code…

Nava2

2009-12-15 13:17:57

From: ZephyrsFury
As long as the code is readable why do we need everyone to have identical standards? Just makes it harder for everyone to code…


How does it make it harder?

nielsie95

2009-12-15 13:31:26

From: Wizzup?
Yeah. Let 51% of the users decide for the other 49%.


That's democracy, I believe?

I agree that code in the include should be consistent. It always annoys me when people do not use lowercase reserved words. But, on the other hand, I also find it annoying when people do not use spaces in statements, which according to the standards is correct (if I recall correctly).


from left to right in order of least to most computation intensive


It should be the other way around.

And type names should start with a T?

Wizzup?

2009-12-15 13:38:34

From: nielsie95
That's democracy, I believe?


Doesn't mean it fits.

From: nielsie95

I agree that code in the include should be consistent. It always annoys me when people do not use lowercase reserved words. But, on the other hand, I also find it annoying when people do not use spaces in statements, which according to the standards is correct (if I recall correctly).


If you really care that much, throw SRL in an auto formatter on your local copy. (I believe you made one)


From: nielsie95

And type names should start with a T?


Yeah, Types should usually start with a T.

Coh3n

2009-12-15 14:44:16

From: Wizzup?
Yeah. Let 51% of the users decide for the other 49%.

I meant just in SRL. I couldn't care less what people do in their own script (to a certain standard). You may as well be consistent in SRL. Either capitalize the words or not, not both.

Wanted

2009-12-15 16:42:28

I might kill someone if uppercase bold letters are considered standard.

Bobarkinator

2009-12-15 16:59:45

From: IceFire908
I might kill someone if uppercase bold letters are considered standard.


They're so pretty!!!

Naike

2009-12-15 17:38:52


Function FindNewAlchObject: Boolean;
var
I, X, Y: Integer;
S: TBox;
C: Boolean;


function FindNewAlchObject: boolean;
var
I, X, Y: integer;
S: TBox;
C: boolean;

How is there a difference in reading that? If it annoys you so much I would consider getting glasses or possibly check for dyslexia.

Wanted

2009-12-15 17:47:24

From: N1ke!

Function FindNewAlchObject: Boolean;
var
I, X, Y: Integer;
S: TBox;
C: Boolean;


function FindNewAlchObject: boolean;
var
I, X, Y: integer;
S: TBox;
C: boolean;

How is there a difference in reading that? If it annoys you so much I would consider getting glasses or possibly check for dyslexia.


Hahaha, if I coded that it would be

[PHP]function FindNewAlchObject: Boolean;
var
B: Boolean;
P: TPoint;
Box: TBox;
I: Byte;[/PHP]

To answer your question, both of those bother me haaha

Nava2

2011-11-07 00:23:39

Bump.

Updated the first post.

Coh3n

2011-11-07 00:28:03

"One can choose their own style, but use of {} should be put forward over //." I think for one-lined comments // is just fine.

Everything else looks fine to me.

BraK

2011-11-07 00:28:11

You know you put this in the SSRL area right? :p

Nava2

2011-11-07 00:30:38

From: BraK
You know you put this in the SSRL area right? :p


Yeah :)

To push it to the masses sooner than later.

From: Coh3n
"One can choose their own style, but use of {} should be put forward over //." I think for one-lined comments // is just fine.

Everything else looks fine to me.


True, also I do not think that PS supports nested comments.. thus the use of // is sometimes necessary.. I will change this.

BraK

2011-11-07 00:32:08

Why not just update Shuts it's already pretty good tutorial.

Nava2

2011-11-07 01:01:09

From: BraK
Why not just update Shuts it's already pretty good tutorial.


I'm good with that, I just want to see the updated standards implemented.

BraK

2011-11-07 01:05:42

http://villavu.com/forum/showthread.php?t=60288

This one ^

Coh3n

2011-11-07 01:07:13

I'm pretty sure by Beginner's tutorial also has a section on standards. Would probably be better to update that one as I'm more likely to keep it up to date than Shut.