Nucleus Support Forum Index

Find on the forum:
any terms  all terms  Advanced Search

RSS 2.0
Browse posts: Unanswered | Mark all read

« »
Loading Nucleus FAQ ticker...
Post new topic Reply to topic
Author Message
gRegor
Nucleus PhD


Joined: 14 May 2002
Posts: 715
Location: Indianapolis, IN USA

Post Posted: Tue Nov 23, 2010 6:48 pm   Post subject:
Reply with quote

After many years, I guess I'm back at it. At least for a little bit. Smile

I was committing a change I had discussed on the mailing list in COMMENT.php and since it's a short file I went ahead and made a subsequent commit cleaning it up.

I added backtick characters around the field names in the query `like this`, capitalized the SQL keywords, then added braces for all if conditions and made their format uniform.

_________________
gRegor
"Live free or die; death is not the worst of evils." .. John Stark

Back to top

View user's profile Send private message Visit poster's website AIM Address ICQ Number
Wild Soundscape
Nucleus Disciple


Joined: 24 Aug 2010
Posts: 127

Post Posted: Wed Nov 24, 2010 2:23 pm   Post subject:
Reply with quote

Could I suggest a major improvement would be proper layout of nested braces?

Code:
if (x)
  {
  something=1;
  }


rather than

Code:
if (x) {
something=1;
}


The latter, although I know originated by K&R around 1979, is really difficult to follow, particularly when deeply nested.

Back to top

View user's profile Send private message
ftruscot
Nucleus Guru
Nucleus Guru


Joined: 22 Feb 2006
Posts: 7449
Location: Massachusetts

Post Posted: Wed Nov 24, 2010 4:13 pm   Post subject:
Reply with quote

It would be good to be consistent on braces. Everyone seems to have their own preference. It doesn't matter to me much since my editor helps identify brace pairs with red highlighting and dotted connecting lines.
_________________
Is your question not solved yet?
Search our FAQ,
read the Documentation, or
browse the list of available plugins.

Check out my plugins

Back to top

View user's profile Send private message Visit poster's website
gRegor
Nucleus PhD


Joined: 14 May 2002
Posts: 715
Location: Indianapolis, IN USA

Post Posted: Wed Nov 24, 2010 6:54 pm   Post subject:
Reply with quote

Heh, yeah that can be its own holy war. Smile

My preference is the latter method, which is what I've been using when cleaning up.

I've seen this in a fair bit of Nucleus code:
Code:

if (x)
{
   something=1;
}

// note: braces at same indentation as 'if'


and I guess I don't mind doing it that way if that's the consensus. Indenting the braces further than the 'if' doesn't make sense to me, though.

Personally, I've not found my method hard to follow. I usually have a blank line between anything nested, and of course the indentation.

Example:
Code:

if (x) {

   something = 1;

   if (y) {
      something_else = 1;
   }

}

_________________
gRegor
"Live free or die; death is not the worst of evils." .. John Stark

Back to top

View user's profile Send private message Visit poster's website AIM Address ICQ Number
gRegor
Nucleus PhD


Joined: 14 May 2002
Posts: 715
Location: Indianapolis, IN USA

Post Posted: Wed Nov 24, 2010 6:58 pm   Post subject:
Reply with quote

Probably more important is making sure all control structures are using braces. There's a lot of simple if / else structures that don't have braces at all. Smile
_________________
gRegor
"Live free or die; death is not the worst of evils." .. John Stark

Back to top

View user's profile Send private message Visit poster's website AIM Address ICQ Number
ftruscot
Nucleus Guru
Nucleus Guru


Joined: 22 Feb 2006
Posts: 7449
Location: Massachusetts

Post Posted: Wed Nov 24, 2010 7:01 pm   Post subject:
Reply with quote

Yes. That is pretty random, too. I'm guilty of not using them sometimes if the if only executes one statement, but other times I use the braces in the same situation. It would be good to have some conventions written out. Maybe they exist and I've missed them...
_________________
Is your question not solved yet?
Search our FAQ,
read the Documentation, or
browse the list of available plugins.

Check out my plugins

Back to top

View user's profile Send private message Visit poster's website
gRegor
Nucleus PhD


Joined: 14 May 2002
Posts: 715
Location: Indianapolis, IN USA

Post Posted: Wed Nov 24, 2010 8:00 pm   Post subject:
Reply with quote

I thought there were some for plugins - I referenced that in the first post in this thread. That's been years ago. Smile I don't remember.

Perhaps PHPBB's guidelines would be a good place to start / copy:

http://area51.phpbb.com/docs/coding-guidelines.html#code

_________________
gRegor
"Live free or die; death is not the worst of evils." .. John Stark

Back to top

View user's profile Send private message Visit poster's website AIM Address ICQ Number
ftruscot
Nucleus Guru
Nucleus Guru


Joined: 22 Feb 2006
Posts: 7449
Location: Massachusetts

Post Posted: Wed Dec 01, 2010 7:08 pm   Post subject:
Reply with quote

I found this list of guidelines for core coding in the wiki: http://wakka.xiffy.nl/contributing:codingguidelines

We should probably do any cleaning up to match to these guidelines. It's funny how much they differ from the phpbb3 guidelines in certain aspects. The phpbb3 guidelines also touch on more things than the nucleus ones.

_________________
Is your question not solved yet?
Search our FAQ,
read the Documentation, or
browse the list of available plugins.

Check out my plugins

Back to top

View user's profile Send private message Visit poster's website
gRegor
Nucleus PhD


Joined: 14 May 2002
Posts: 715
Location: Indianapolis, IN USA

Post Posted: Wed Dec 01, 2010 10:19 pm   Post subject:
Reply with quote

I'm going to be bold (Wikipedia language) and suggest updating those guidelines to be more in line with phpBB's guidelines. I'll work on this on a new wiki page, but summary:

- variable names all lowercase, separate words by underscore (I really don't like lowerCamelCase for variables, easily confused with functions)

- lowerCamelCase for functions / methods

- braces on their own line, in line with the control structure (I concede readability and easier brace-matching)

- single space between tokens

- single quote strings unless variable interpolation is necessary

- other things as I think of them / review the phpBB guidelines

_________________
gRegor
"Live free or die; death is not the worst of evils." .. John Stark

Back to top

View user's profile Send private message Visit poster's website AIM Address ICQ Number
ftruscot
Nucleus Guru
Nucleus Guru


Joined: 22 Feb 2006
Posts: 7449
Location: Massachusetts

Post Posted: Wed Dec 01, 2010 10:41 pm   Post subject:
Reply with quote

I can go with whatever. I agree that consistency is important.

It will be hard to change function names and even variable names is some cases (like global variables where they are used in plugins and other external code). But it's worth trying.

I think we can continue on this and agree on some standards, but I suggest we don't try to clean up the code until after the release of 3.60 in the next few weeks. One thing to consider going forward is incorporating some PHP5-specific standards, particularly in classes, since we no longer officially support php4.

_________________
Is your question not solved yet?
Search our FAQ,
read the Documentation, or
browse the list of available plugins.

Check out my plugins

Back to top

View user's profile Send private message Visit poster's website
Post new topic Reply to topic
Display posts from previous:   

Goto page Previous  1, 2, 3, 4  Next

Page 3 of 4

All times are GMT + 1 Hour

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2001, 2002 phpBB Group