[Tutorial] How to indent
#1

Introduction

Time to time, we get the occasional "fix my code" or "what must I do" in Scripting Help, fair enough. One issue that tends to arise though, is the unreadable code that the OP may provide.

PAWN is a free format language. There is no strict way of doing things. Whether you may find this as a blessing or not, it allows you to write code in a way that conforms to your style of scripting (and is syntactically correct).

Better yet, it's also structured. We are allowed to section off or hide necessary information to perform specific tasks (subroutines, code-blocks etc.), hence the idea of compartmentalization.

Why indent?

Clustered code tends to become an unmanageable mess. Here on the forums, most people will have a much easier time helping and solving problems with readable code. Trying to find the underlying cause of some error may also become a hassle when there may visibly be one true culprit.

How to indent

Think of a block of code as a group or section that contains the instructions to perform (if not one) multiple tasks. Each block is defined by an opening and closing brace ( { and } ). Every time you define a code-block, the code within that block is indented.

pawn Код:
doSomething()
{
    /*new block of code, indent*/
   
    for(new i = 0; i < 4; i++)
    {
        /*new block of code, indent*/
       
        printf("%d", i);
    }
}
#pragma tabsize 0

People wanting to get rid of the loose indentation warnings generated by the compiler would often use,
pawn Код:
#pragma tabsize 0
Do note that this is NOT a solution, only a workaround.

Quote:
Originally Posted by Wiki
This is set to 4 in SA:MP as that is the size of a tab in pawno. Setting this to 0 will surpress all your indentation warnings but is highly unadvised as it allows entirely unreadable code.
Reply
#2

Not Bad, newb's should really read this
Reply
#3

Anyway, indent serves to give hierarchy to the Scripts we make, and certain times to avoid confusion. Good job.
Reply
#4

Good job, useful for beginners
Reply
#5

I am just going to quote this:
Quote:
Originally Posted by ******
Посмотреть сообщение
As you correctly point out, the pragma is not recommended, so why mention it in the first place? Just ignore it - the less that people know about it, the less that people can choose to ignore your nice advice and just use it anyway.
Reply
#6

No pragma is not good pragma is not good.
Read the above poster says.
Reply
#7

Quote:
Originally Posted by Romel
Посмотреть сообщение
No pragma is not good pragma is not good.
Read the above poster says.
I think you need to re-read what the above poster says.
Reply
#8

Quote:
Originally Posted by Romel
Посмотреть сообщение
No pragma is not good pragma is not good.
Read the above poster says.
What do you not understand in the tutorial? He clearly states NOT to use it.
Quote:
Originally Posted by arbit
Посмотреть сообщение
Introduction

#pragma tabsize 0
People wanting to get rid of the loose indentation warnings generated by the compiler would often use,
pawn Код:
#pragma tabsize 0
Do note that this is NOT a solution, only a workaround.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)