Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Clean Coding - Common Sense (https://forums.graalonline.com/forums/showthread.php?t=73158)

xXziroXx 04-10-2007 05:36 PM

Quote:

Originally Posted by JkWhoSaysNi (Post 1298731)
Me either. The spaces inside the ( brackets offend me too ;)

Heres how I do it:

PHP Code:

if (var) {
       ...


i guess if (var) has more meaning if you name your boolean variables as verbs as I tend to do e.g. if (finished)

Same as me then, although I would do:

PHP Code:

if (var == true) {
       ...



Skyld 04-10-2007 05:43 PM

PHP Code:

if (var)
{
  
// ...


I don't see the point in putting var == true when that's already implied, and I prefer brackets on their own line. It improves spacing and clarity.

Crow 04-10-2007 06:21 PM

Quote:

Originally Posted by Skyld (Post 1298760)
PHP Code:

if (var)
{
  
// ...


I don't see the point in putting var == true when that's already implied, and I prefer brackets on their own line. It improves spacing and clarity.

Lines++ ;/

Skyld 04-10-2007 06:27 PM

Quote:

Originally Posted by Crow (Post 1298768)
Lines++ ;/

Doesn't really matter. The script will be folded into the same amount of bytecodes with new lines as it is with brackets on the same lines.

The fact is that it's clearer when I'm editing the script.

JkWhoSaysNi 04-10-2007 07:11 PM

That's not a fact it's entirely subjective :P

I think less lines is clearer. I think it's easier to see which statement a block belongs to when the opening bracket is on the same line.

xXziroXx 04-10-2007 08:02 PM

Quote:

Originally Posted by JkWhoSaysNi (Post 1298782)
That's not a fact it's entirely subjective :P

I think less lines is clearer. I think it's easier to see which statement a block belongs to when the opening bracket is on the same line.

Agreed.

Novo 04-10-2007 09:01 PM

PHP Code:

function onKilled()
  {
  var;
  } 

I r bestest in Teh World!

Skyld 04-11-2007 12:09 AM

Quote:

Originally Posted by JkWhoSaysNi (Post 1298782)
That's not a fact it's entirely subjective :P

Quote:

Originally Posted by Skyld
The fact is that it's clearer when I'm editing the script.

I.

Novo 04-11-2007 12:51 AM

Quote:

Originally Posted by Skyld (Post 1298907)
I.

I.

cbk1994 04-11-2007 01:05 AM

Quote:

Originally Posted by Novo (Post 1298945)
I.

I.
--
Less lines? Really.

PHP Code:

//#CLIENTSIDE
function onCreated() { dothis(); thendothis(); thenletthis "foo"thendosomethingelse(); timetomilkthecow();doOTHERSTUFF()} function doOTHERSTUFF() { noWAI(); } function noWAI() { player.chat "MUAHAHAHAHAHAHAH!"; } 

Whoah you're right, that's really neat and clean!

Kristi 04-13-2007 03:36 PM

Quote:

Originally Posted by Twinny (Post 1299409)
I. (Question how long this thread will survive :whatever:)

I (decided it will go on no longer)

Sam 04-13-2007 03:56 PM

Next time I see people power spamming a serious thread like this, I will spread also power infraction points for each spam post. x_x

Quote:

3) SPAM

a) Posting of spam is not allowed. Spam is defined as any irrelevant or inappropriate message. Due to the nature of the forums, what is considered spam varies between threads. In other words: in some threads, small posts such as "..." are perfectly valid responses, whereas in other threads it is inappropriate. The context of the message is very important in this regard. It is the right and responsibility of the administrators or moderators to determine whether or not a message is spam and to take appropriate action if it is.


Kristi 04-14-2007 08:50 PM

I am reopening this for the sake of clean coding discussion. No spam tolerence here!

cbk1994 04-15-2007 04:41 AM

Quote:

Originally Posted by Novo (Post 1298799)
PHP Code:

function onKilled()
  {
  var;
  } 

I r bestest in Teh World!

The brackets really need to be on their own line ...

What do you people mean you only give brackets a new line for functions? How are functions any different in that structure than an if () or while (), or w/e?

xXziroXx 04-15-2007 04:42 AM

Quote:

Originally Posted by cbkbud (Post 1300082)
The brackets really need to be on their own line ...

What do you people mean you only give brackets a new line for functions? How are functions any different in that structure than an if () or while (), or w/e?

Example:

PHP Code:

function BLAH()
{  
// See? NEW LINE!
  
if (lawl == "xXx") {  // See? NO NEW LINE!
  
}



Twinny 04-15-2007 11:06 AM

PHP Code:

function blah()
{
  if (
this.condition)
  {
    if (
this.completelydifferentcondition)
      
blah2();
    else
      
blah3();
  }  


My general stylings. I normally have brackets around all conditions and events but when i'm finished and there is only one statement, I generally remove them.

Like

PHP Code:

function Dosomething()
  return 
this.something.index();

public function 
yay()
  return 
localfunction(); 


Skyld 04-15-2007 11:07 AM

Quote:

Originally Posted by xXziroXx (Post 1300085)
Example:

PHP Code:

function BLAH()
{  
// See? NEW LINE!
  
if (lawl == "xXx") {  // See? NO NEW LINE!
  
}



Eh. That sorta screams 'inconsistency'.

cbk1994 04-15-2007 02:21 PM

Quote:

Originally Posted by xXziroXx (Post 1300085)
Example:

PHP Code:

function BLAH()
{  
// See? NEW LINE!
  
if (lawl == "xXx") {  // See? NO NEW LINE!
  
}



Any logic behind that? Seems a little hard to follow.

Twinny -- why don't you use brackets for one statement? They make it a lot cleaner, and neater, and if you need to adjust something it looks better.
PHP Code:

if ( foo )
{
  
doSomething();



xXziroXx 04-15-2007 04:42 PM

Quote:

Originally Posted by Skyld (Post 1300117)
Eh. That sorta screams 'inconsistency'.

It can scream whatever it wants, aslong as I like to script like that. :)

cbk1994 04-15-2007 05:38 PM

Quote:

Originally Posted by xXziroXx (Post 1300163)
It can scream whatever it wants, aslong as I like to script like that. :)

That's one way to think about it.


All times are GMT +2. The time now is 12:51 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.