Author Topic: Making script admin-only?  (Read 10029 times)

Someone who earns money through knowing how to program well. Who are you?


im waffles who are you?????

Grats on Thread 666?

Brackets shouldn't be on the same line as anything else generally, and you should really indent.
You should get into the habit of doing these things, for readability's sake:
QFT

The whole purpose is to be able to read it and understand the code.  If you ever plan to professionally program, you will be expected to use formatting techniques.  It's just better when you make code readable.
« Last Edit: March 29, 2008, 12:52:11 AM by Irk89 »

It is perfectly readable with braces on the same lines, here's an experiment I did.



Contents of short.cs:


Long.cs wouldn't fit in one screenie so here's the code:
Code: [Select]
if(Something)
{
//dosomething
if(AnotherSomething)
{
//yey
return AnotherSomething;
}
else
{
//boo
if(Blah)
{
//omg
//do something now.
}
}

if(Blah != omgwtfbbq)
{
//om nom nom
//yey for cake
if(cake)
{
cake = win;
//yey
}
else
{
cake = lose;
//boo

}
}

if(cake == win)
{
//do something celebratory
return cake;
}
else
{
//this suck.
return blah;
}
}


Long.cs not fitting shows why putting braces on the same line, again is an advantage, it allows you to fit more code into one page allowing you to read all your code faster for bugs, etc.

Which one of these is easier to find the error in and debug?
Code: [Select]
if(%testing)
{
 %n = 15;
 while(%n > 2)
 {
  %n--;
  echo(%n);
 }
 if(%x < 3)
 {
  commandtoserver('love');
  if(%y)
  {
   echo("!!");
  }
 }
 else
 {
  %x = 3;
  if(%y)
  {
   echo("Why?");
  }
}

Code: [Select]
if(%testing){
%n = 15;
while(%n > 2){
%n--;
echo(%n);}
if(%x < 3){
commandtoserver('love');
if(%y){
echo("!!");
}}else{
%x = 3;
if(%y){
echo("Why?");}}
In the first one, you can see the gap in the indents and the whitespace. If I'd used Tab. With no indents and compressed lines in the second, it is a lot harder to find the source of the error.


Pickle, use 3 spaces on long.cs :cookieMonster:

I think you'll find any professional programming organization will pick readability over file size. Stop being ignorant.

And just for further evidence, 90% of mods you've released have notably huge bugs in them. Meanwhile me and Space Guy who program properly have been able to release reliable and fully working mods. Coincidence? I think not.
« Last Edit: March 29, 2008, 01:30:35 PM by Ephialtes »

I would argue to just use whichever way you prefer:
Code: [Select]
function X() {
or
Code: [Select]
function X()
{
or even
Code: [Select]
function X ()
{

It's all perfectly readable... no need to whine about where the brackets are unless it looks like this:
Quote from: Space Guy
Code: [Select]
if(%testing){
%n = 15;
while(%n > 2){
%n--;
echo(%n);}
if(%x < 3){
commandtoserver('love');
if(%y){
echo("!!");
}}else{
%x = 3;
if(%y){
echo("Why?");}}

But you should always indent.


And to Mr Pickle, the whole point of source code is to be readable, not compact. You compile it if you want it to be small.
« Last Edit: March 29, 2008, 03:16:21 PM by exidyne »

Yes, this was about the brackets, not indenting, therefore you should keep the indents in the second code space guy.

The thing is that even if brackets aren't on their own lines, you can't see if everything is properly indented.

Code: [Select]
function X() {
   if( a ) {
      Y();
      return b;
   } else {
      Z();
      return c;
   }
}


function X()
{
   if( a )
   {
      Y();
      return b;
   }
   else
   {
      Z();
      return c;
   }
}

It's ridiculous to whine about how either of the above examples isn't readable, or that you "can't see if everything is properly indented", because you can.
« Last Edit: March 29, 2008, 03:19:39 PM by exidyne »

It is perfectly readable with braces on the same lines, here's an experiment I did.
<Pic>
What is that skin called? Looks nice. :cookieMonster:

As functions grow and become more layered (and line lengths may become longer), it would be much more advantageous to have brackets on separate lines.

Referring to use of brackets on the same line as other things:
Wiki Link: http://en.wikipedia.org/wiki/Indent_style#K.26R_style

Quote from: Wiki
Advantages of this style are that the beginning brace does not require an extra line by itself; and the ending brace lines up with the statement it conceptually belongs to. One disadvantage of this style is that the ending brace of a block takes up an entire line by itself, which can be partially resolved in if/else blocks and do/while blocks:

Code: [Select]
if (x < 0) {
    printf("Negative");
    negative(x);
} else {
    printf("Positive");
    positive(x);
}

This style makes it difficult to scan any source code for the opening brace of a block; however, it is otherwise as easy to find the beginning of the block by locating first line where the block 'pulls left' (where the indentation level decreases).