vBulletin Modifications

Coding style

Welcome to vBHackers.com! - vBHackers Updates:

Go Back   vBulletin Modifications > General Discussions > Off Topic

Reply
 
LinkBack Thread Tools
Old 06-05-2006, 06:50 AM   #1
Coder
bairy's Avatar
Join Date: Jun 2006
Real Name: Chris
Location: Birmingham, UK
bairy is on a distinguished road

Default Coding style && releasability

This is on topic but doesn't really fit any of the vb-specific forums.

I have my own slightly lazy, slightly more efficient-for-me style of coding and I was firstly wondering what you guys thought of it and if you had any styles that break the "how to write neat code" rules yourselves.

I use 5 things I can remember:
1. I omit unnecessary curly braces
2. Shorthand ifs
3. I don't use switch_exec_bg()
4. I don't always use templates. I never use phrases.
5. Simplify the damn queries!


1. I don't use curly braces for single commands, e.g.
You must first be a registered member to view any code.
No reason other than it's a lot quicker to type and I find the code is easier to read.


2. I find shorthand ifs much nicer than longhand
You must first be a registered member to view any code.
rather than
You must first be a registered member to view any code.

3. I don't see why people use switch_exec_bg (it's the function that switches a row background color from alt1 to alt2 (light to darker)).
I use
You must first be a registered member to view any code.
which seems more logical because it saves time looking up the function.
The function's description says it can support > 1 background set at the same time, but since you only create one set of rows at any time, I don't see the point.


4. Okay I know this one is laziness
I don't always use templates in my scripts.
Sometimes I'll put things like row content directly within the php file. Sometimes it's just a hassle to create a new template, figure out all the row variables you have to put in it etc. Plus I read somewhere that eval() is quite slow.


5. Example:
You must first be a registered member to view any code.
I use
You must first be a registered member to view any code.
For one thing, $row is quicker to type than $currentthread.
For another it's always the same so I can type new queries easier.

For queries that need to stay open and can't be freed, I can understand the unique name. For the rest, I struggle to see why.
Probably more of a pet peeve than anything.



And now a mini rant:
Why doesn't vb include a print_r() function. I use
You must first be a registered member to view any code.
It's one of the most useful debugging tools out there.
Come to think of it, why isn't there a hook in functions.php so you can make your own functions. grr.



Anyway,
Any other interesting coding habits I could adopt that break all the rules?
Is it really important to have coding style that follows all the rules before it's released? I've got a couple I'd like to release but they basically use the above.

Last edited by bairy; 06-05-2006 at 07:03 AM..




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
Old 06-05-2006, 08:47 AM   #2
vBulletin Guru
Arnoud's Avatar
Join Date: Nov 2004
Real Name: Arnoud Kuipers
Location: Europe, Flanders
Arnoud is on a distinguished road

Default

Some good points you made there ;).

Generally when I code a private project which doesn't need configurability (for my own site, or a site I run) it sometimes gets pretty messy :p. However, when I code a public hack I generally tend to code 'by the book' so its easy to make modifications for and to learn from the hack.

Also, when making commercial products I always code 'by the book', because this simply looks a lot better and the customer can easily make modifications him-/herself.




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 06-05-2006, 12:19 PM   #3
Coder
Code Monkey's Avatar
Join Date: May 2006
Code Monkey is on a distinguished road

Default

Well, there is no "book". But generally, you should always code to the standards that is most acceptable. Otherwise, you will have a hard time coding with others. Curly brases are not an option if you want your code to be readable.

Keep in mind, if you are refering to vb's so called coding standard,well, that is just their oppinion. They have a standard for their own workgroup. However, we are not part of that workgroup. It's best to stick to the norm that the vast array of coders use.

This is not the best use of the ternary.
You must first be a registered member to view any code.
It should be like this.
You must first be a registered member to view any code.
Now that is short.




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
which style use in this forum gamblertr Off Topic 3 04-18-2006 06:31 PM
New Style Ken Iovino Announcements 24 08-19-2005 08:42 AM
Choose a style for vBhacks Ken Iovino Site Feedback 12 05-02-2005 10:41 PM


All times are GMT -3. The time now is 10:08 PM.

Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 ©2008, Crawlability, Inc. (Patent Pending)