I know this question is going to be…weird and…odd. I have programmed stuffs for around 4 years until now, since I was 14. I found out that I have changed my ways of writing script quite many times and I don’t know which way is better, is there any standard for writing and displaying a script?
Ok, this is how I write when I started [I will make an example with long, deep [whatever] so you can see how I display a script]:
$(document).ready(function()
{
odd=0; even=0;
for(i=0; i<10; i++)
{
for(j=0; j<10; j++)
{
if((i+j)%2==0)
{
even++;
alert(i+j);
}
else
{
odd++;
alert(i+j);
}
}
}
});
And then, when I started some more complex script, I found out that the way above is completely stupid, so I changed several times the way to write it, and about 2 years ago, I found out a way to write script for myself:
$(document).ready(function()
{
odd=0; even=0;
for(i=0; i<10; i++)
{
for(j=0; j<10; j++)
{
if((i+j)%2==0)
{
even++;
alert(i+j);
}
else
{
odd++;
alert(i+j);
}
}
}
});
Well, it looks more clearly right? But recently, I found out that many programmers write script in this way:
$(document).ready(function() {
odd = 0;
even = 0;
for (i = 0; i < 10; i++) {
for (j = 0; j < 10; j++) {
if ((i + j) % 2 == 0) {
even++;
alert(i + j);
}
else {
odd++;
alert(i + j);
}
}
}
});
And I am confused now. I want to have myself a way that will last forever. So I am asking if there is any standard of how to display your script so that it will be easy to keep track of for everyone else?
Thanks for any idea. 😛
[x]
The last two ways you show are quite literally religious totems for two opposing camps. You will find people on both sides vigorously supporting their style. Don’t get sucked into the fight. Use whichever you like, be consistent, and don’t worry about it.