SRL Archive - Outdated Tutorials

Standards demystified


Raskolnikov

2008-12-16 16:07:22

Okay, I am going to break it out. The appliances for members lately h
ave had amazingly bad standards. I want to fix that. Here are some tips on what standards are so you aren't confused.

Begins and Repeats:

procedure Hello;
begin
DoWhatever; //There are always two spaces on the line after the begin.
end;

When I say always I mean ALWAYS. There is no exception to this rule

repeat
DoWhatever;
until(SomethingHappens);

There are always two spaces on the line after a repeat too.

Let's review…

procedure Hello;
begin
DoWhatever;
end;

IS NOT CORRECT. The correct standards are:

procedure Hello;
begin
DoWhatever;
end;

More review:

repeat
DoWhatever;
until(SomethingHappens);

IS NOT CORRECT. The correct standards are:

repeat
DoWhatever; //Two spaces!!!
until(SomethingHappens);

Okay, on to the next section

If then boolean statements:

if Something then
DoWhatever; //Two spaces!!!

Is correct. When using a begin the following is correct:

if Something then
begin //no spaces on the begin
DoWhatever; //Then we swoop in for the two spaces...
end; //then our end

if Something then
begin
DoWhatever;
end;

IS NOT CORRECT.

Another thing about if…or…then statements is this:

if (x < 7) or (SomeBoolean) then //is correct

if (SomeBoolean) or (x < 7) then //is incorrect

The reason for this is the statement that has the greatest chance of being correct is placed before the or, and the one with the least chance of being correct, is placed after the or.

Loops (while..do, for…to…do)

Most of the same rules stated above apply.

while SomethingIsTrue do //no capitalization of the bolded words.
DoSomething; //same two space rule

while SomethingIsTrue do
begin //no spaces on the begin
DoSomething;
Writeln('hello this is correct');
end;

for i:=0 to 5 do
begin //no spaces on the begin
DoSomething; //same two space rule applies
Writeln('this is correct');
end;

There are really no big exceptions to go over here.

Capitalization:

When Kaitneiks wrote down the standards, there is to be no unnecessary capitalization. For example:

Procedure Hello;

Is not correct.

procedure Hello;

Is correct. Different people have different personal styles about capitalization, which is why I am going to brisk over it. I would recommend leaving anything in bold lowercase. If you develop your own style over time, go ahead.

Commas, Spaces, and Declaring Variables

Whenever you are declaring a variable, such as:

var
Hello: string;

There must always be two spaces after the var! Also with a constant:

const
WhatDoWeDo := 'mine';

The same rules apply.

There must always be spaces after commas and arithmetic signs:

Mouse(x,y,2,2,true);

Is not correct.

Point(5+4,9+2);

Is not correct.

Mouse(x, y, 2, 2, true); //is correct
Point(5 + 4, 9 + 2); //is correct

Get the idea?

Semicolons:

DoSomeStuff; //is correct

There should always be semicolons where they apply

if Something then; //is not correct!

There are never semicolons after bolded words, with the exception of end (which always has a semicolon or period to end the script)

DoSomeStuff //is incorrect, you need a semicolon!

After procedures/functions there must always be a semicolon. The only exception to this rule is the following:

if Something then //no begin, if there is a begin after this line, then there is a semicolon (on next line)
DoSomething //no semicolon!!!
else
DoSomethingElse; //now we can have a semicolon

Procedures/Functions

All procedures/functions should have names meaningful to their purpose:

procedure CutTheWood; //is correct

procedure DoSomething; //is not correct

For procedures/functions with parameters, the parameters of the same type should be lined up in one declaration on the line if possible. For example:

procedure CutTheWood(Amount: integer; WaitTime: integer;);

Is not correct. The correct thing is:

procedure CutTheWood(Amount, WaitTime: integer);

Do you see what I mean? There should be one declaration for all parameters belonging to one type.

All functions should return a result, or else they should be a procedure:

function Hello: integer;
begin
Result := 5;
end;

Is correct, we are actually returning something.

function Hello: integer;
begin
Mouse(x, y, 1, 1, true);
end;

We aren't returning a result. The above should be:

procedure Hello;
begin
Mouse(x, y, 1, 1, true);
end;

Variables

Global variables (x, y, etc.) are frowned upon because they cause a longer waiting time. When you are able to, don't use global variables.

As well as global variables are frowned upon, so are one letter variables. Put some variety into your variables.

Some Tips:

Always include your standards while you script, it is a big time saver!
If you do have slightly varying standards then what I have posted, be sure that they are consistent!!!

Conclusion:

Good luck with standards. I know we can be picky arses about standards, so this is why I want to teach you so you don't get put down by others. When in doubt, ask an SRL member and they will help you :D. Please post suggestions, criticism, anything about this tutorial! Please rep ++ too please :D

Cut em2 it

kitchenrange

2008-12-16 22:57:59

Thx alot man, Im pretty sure that was mostly directed at my application so I had to thank you personally lol.

Kyle Undefined

2008-12-16 23:09:11

Nice, not a bad tut. It explains the basics without going over anyone's head.

~Camo

Raskolnikov

2008-12-17 00:28:59

From: kitchenrange
Thx alot man, Im pretty sure that was mostly directed at my application so I had to thank you personally lol.


It was directed at a lot of people's applications. No problem, I just want to decrease the amount of awful standard applications we get.

From: Camo¤Kyle
Nice, not a bad tut. It explains the basics without going over anyone's head.

~Camo


Thanks camo :D


Cut em2 it

senrath

2008-12-17 00:36:13

You might want to add in a note that it's usually easier to add standards as you program, rather than come back in later to fix them.

Raskolnikov

2008-12-17 00:42:02

Thank you :D Going to be added along with some suggestions from Method.

Cut em2 it

Raskolnikov

2008-12-18 14:33:56

Updated, added a whole new array of explanation!

Cut em2 it

Gu3st...

2008-12-19 15:39:45

if Condition then
DoStuff // Notice: No ';' at the end of the line.
else
DoSt0ff;

Mario

2008-12-19 16:30:59

Correct me if I'm wrong. But shouldn't

procedure CutTheWood(Amount, WaitTime: integer;);
be a function, not a procedure, because a function will return amounts and such.

senrath

2008-12-19 18:06:55

From: Mario
Correct me if I'm wrong. But shouldn't

procedure CutTheWood(Amount, WaitTime: integer;);
be a function, not a procedure, because a function will return amounts and such.


But it's not returning anything.

Raskolnikov

2008-12-20 01:18:10

From: NaumanAkhlaQ
Good tut:

procedure CutTheWood(Amount: integer;, WaitTime: integer;);

You know that wouldn't work??


I didn't know that???? Anyways, if it does work, then it isn't correct standards anyways.

From: Zytex!
if Condition then
DoStuff // Notice: No ';' at the end of the line.
else
DoSt0ff;


This is correct standards? I always use semicolon there but thanks.

From: senrath
But it's not returning anything.


Right, it isn't, so hence it should be a procedure.

Cut em2 it

Gu3st...

2008-12-20 02:21:47

From: Cut em2 it
This is correct standards? I always use semicolon there but thanks.

Try running this script:
const
Condition = True;

procedure DoSomething;
begin
WriteLn('Condition is True');
end;

procedure DoSomethingElse;
begin
WriteLn('Condition is False');
end;

begin
if Condition then
DoSomething;
else
DoSomethingElse;
end.
You will get an 'Identifier expected' error.
Delete the semicolon after ' DoSomething;' at line 16. Now it works! :)

If you use a begin after the 'if … then' then you do use semicolons after the procedures.
If you do not use a begin after the 'if … then' and uses 'else' after the procedure you want called then you do not use a semicolon after the procedure (the one between 'if … then' and 'else').

I am not very good in explaining things, but I hope you get it :p

Raskolnikov

2008-12-20 12:17:43

I get it thanks :D I will add after I get home from Tae Kwon Do

Cut em2 it

Nava2

2008-12-20 12:40:04

You forgot while loops! :)

Great tut, maybe mention to put the most likely/least computer intensive piece of a strand of an if or while statement first.

Like:
if (x < 3) or (IAmAFunctionThatReturnsABoolean) then
begin
...

You put the X < 3 because it is more likely true.

Also, one letter vars / functions are frowned upon unless appropriate. :)

Raskolnikov

2008-12-20 17:04:45

From: Nava2
You forgot while loops! :)

Great tut, maybe mention to put the most likely/least computer intensive piece of a strand of an if or while statement first.

Like:
if (x < 3) or (IAmAFunctionThatReturnsABoolean) then
begin
...

You put the X < 3 because it is more likely true.

Also, one letter vars / functions are frowned upon unless appropriate. :)


Thanks, also global vars were going to be my next addition too.

From: Zytex!
Try running this script:
const
Condition = True;

procedure DoSomething;
begin
WriteLn('Condition is True');
end;

procedure DoSomethingElse;
begin
WriteLn('Condition is False');
end;

begin
if Condition then
DoSomething;
else
DoSomethingElse;
end.
You will get an 'Identifier expected' error.
Delete the semicolon after ' DoSomething;' at line 16. Now it works! :)

If you use a begin after the 'if … then' then you do use semicolons after the procedures.
If you do not use a begin after the 'if … then' and uses 'else' after the procedure you want called then you do not use a semicolon after the procedure (the one between 'if … then' and 'else').

I am not very good in explaining things, but I hope you get it :p


Doing that right now!

Cut em2 it

Edit: for to do/while do loops added and variables added. Btw, did I get a tutorial cup for this tutorial?!!! If so I am excited!

Raskolnikov

2008-12-20 19:28:39

Yay I did get a tut cup, and I added the following:

  • Global Variables
  • Other variable things
  • For to do loops
  • While Do loops
  • more notes

Cut em2 it

Gu3st...

2008-12-21 13:34:58

Gz on tut writer cup :D
How many tutorials have you wrote?

Raskolnikov

2008-12-21 14:10:45

Er.. 4 or five, but this was my best by far.

Cut em2 it

Floor66

2009-01-22 14:01:44



procedure CutTheWood(Amount: integer;, WaitTime: integer;);

Is not correct. The correct thing is:


procedure CutTheWood(Amount, WaitTime: integer;);



Still the SCAR code is incorrect :p
it's

procedure CutTheWood(Amount: integer; WaitTime: integer;); //wrong standards, but it compiles

Correct:

procedure CutTheWood(Amount, WaitTime: integer);

You had 1 semicolon too much at the end.

Awesome tut btw.

Raskolnikov

2009-01-26 17:28:05

Thanks floor, never learned that :o


Cut em2 it

Raskolnikov

2009-03-22 20:33:30

I want this thread to have more activity, and to get the link for my signature.

Cut em2 it

ian.

2009-03-22 20:53:27

const
WhatDoWeDo := 'mine';

should be

const
WhatDoWeDo = 'mine';
;)

Raskolnikov

2009-03-23 00:03:06

whoops, thanks 99 :D

Cut em2 it