User:JulienDethurens/Guide/Chapter 4: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>JulienDethurens
Created page with "This page talks about some subjects that could be useful to know about. You can read these at any time, there is no specific moment to read them, so you don't need to read the..."
 
>JulienDethurens
No edit summary
Line 1: Line 1:
This page talks about some subjects that could be useful to know about. You can read these at any time, there is no specific moment to read them, so you don't need to read them completely at the end. However, some of these assume you have some prerequisite knowledge, so you might only be able to understand some of these after reading a certain part of the guide.
This page talks about some subjects that could be useful to know about. You can read these at any time, there is no specific moment to read them, so you don't need to read them completely at the end. However, some of these assume you have some prerequisite knowledge, so you might only be able to understand some of these after reading a certain part of the guide.
==Indentation==
Indenting code means using tabulations (or spaces, but I prefer tabulations) to indent code, to make it more organized.
Usually, a new level of indentation is added on every new block of code, or every scope, if you prefer. Some also do it for tables and in long comments.
Here is an example of indented code:
<code lua>
for i = 1, 50 do
if math.random(5) == 3 then
print(string.format("The number is %d.", i))
elseif math.random(15) == math.random(10) then
print(math.random(5) + i)
break
end
end
</code>
And here is the same code, without indentation:
<code lua>
for i = 1, 50 do
if math.random(5) == 3 then
print(string.format("The number is %d.", i))
elseif math.random(15) == math.random(10) then
print(math.random(5) + i)
break
end
end
</code>
Indented code looks much better and indenting your code will make it much more organized and will be extremly helpful. Trust me, you should '''always''' indent code, even if you think it's not worth it.

Revision as of 20:32, 22 January 2012

This page talks about some subjects that could be useful to know about. You can read these at any time, there is no specific moment to read them, so you don't need to read them completely at the end. However, some of these assume you have some prerequisite knowledge, so you might only be able to understand some of these after reading a certain part of the guide.

Indentation

Indenting code means using tabulations (or spaces, but I prefer tabulations) to indent code, to make it more organized.

Usually, a new level of indentation is added on every new block of code, or every scope, if you prefer. Some also do it for tables and in long comments.

Here is an example of indented code:

for i = 1, 50 do if math.random(5) == 3 then print(string.format("The number is %d.", i)) elseif math.random(15) == math.random(10) then print(math.random(5) + i) break end end

And here is the same code, without indentation:

for i = 1, 50 do if math.random(5) == 3 then print(string.format("The number is %d.", i)) elseif math.random(15) == math.random(10) then print(math.random(5) + i) break end end

Indented code looks much better and indenting your code will make it much more organized and will be extremly helpful. Trust me, you should always indent code, even if you think it's not worth it.