DragonPrime - LoGD Resource Community
Welcome Guest
  • Good morning, Guest.
    Please log in, or register.
  • May 24, 2019, 10:24:33 AM
Home Forums News Downloads Login Register Advanced Search
* * *
DragonPrime Menu
Resource Pages

Pages: 1 2 [3]   Go Down
Author Topic: Coding Tips  (Read 24682 times)
0 Members and 1 Guest are viewing this topic.
iMod God
SVN Users
Mod God
Offline Offline

Posts: 3458

If ya didn't get it by now... you're hopeless...

View Profile WWW
« Reply #30 on: March 14, 2008, 12:24:04 AM »

I have to disagree.

In my opinion (That may very well be influenced by the Java Conventions) the first code is much simpler to read.
Opening brackets in their own line always keep my from reading code smoothly.

I agree. Put the open braces on the line where the statement begins, then the end brace on its own line at the end of the statement, followed by another (if necessary, ex: else, elseif). Also, proper tabbing is key. I feel that opening braces and closing them on their own lines makes the script not as smooth as it could be.

If you didn't understand anything in the above post, don't try to attempt anything suggested.

White Knight
Mod God
Offline Offline

Posts: 1030

For the truth!

View Profile
« Reply #31 on: March 14, 2008, 03:34:37 AM »

There really isn't a "correct" style, as many exist and people tend to use one or another based on their own experience with them.  Personally, I use a modified Allman's for procedural and modified K&R for object-oriented code.  It's important to find a style you find easily readable and stick with it throughout a project.  Which to choose or how many is your decision (unless, of course, a project requires a certain style and you have no choice; at the time of this writing, LoGD doesn't force a style on you).
« Last Edit: March 14, 2008, 03:38:41 AM by White Knight » Logged

Helping you help yourself.
Captain of the Guard
Offline Offline

Posts: 102

View Profile
« Reply #32 on: September 05, 2010, 02:05:18 PM »

Test.  And then test.  And test again.

When I download a file that doesn't even run, I often wonder whether the author ever even ran it, even once, and then I wonder what they were thinking.  Yesterday I read a post wherein an admin had sought help because the healer wasn't charging anything to heal.  Talisman I saw appropriately mentioned that they didn't seem any too familiar with playing the game.

To me the most invaluable coding tip is, yes, test.  Don't be afraid to play your own module before you offer it up for others to deal with.  When you've found something wrong with it and don't know how to fix it, then seek help.  Don't keep it a secret or leave it for others to find like some used car that needs work.

My other favorite is try.  I learned quite a bit at first fixing modules I'd downloaded only to find they didn't work or as they were said to be able to do, see above.  Look it over, and over, and over.  Look at working modules to see how they work.  Do these and the rest I'd read elsewhere'll make it easier to debug when it doesn't.  You'll learn some things too I guarantee along the way.

O and this I used to see asked a lot, if you get a bunch of code texted-out across the top of the screen, save time and just add php at the top of the file after where you're probably going to find just <? if you look, again see above.

Test, try, search the forum, and, barring finding any kind of a resolution or a point in the right direction, ask.  Good, organized, technique'll make it easier to debug and find whatever the problem is, or at least help make it quicker.  And, Talisman hates it, by the way, when people post their module rather than attaching it.

Do these and you'll be writing your own working modules soon enough.  Style?  Technique?  Why make it harder on yourself at the absolute very least to follow even your own code?  Yeah, keep it neat.  You'll probably learn a lot quicker that way so to be better able to see what it is you yourself are doing.

My final thought along these lines is this, and I don't do this as often I admit as I used to, and you should, whether it's PhP or any other project you use a computer to facilitate in its design, always backup your work.  Then, if you break it, you've presumably if you've done everything else I've mentioned a working copy from which to start again, rather than trying to get back to one.

Its a process.  Go at it with some tools.  It makes it a lot easier.  You wouldn't build a house without a hammer, or a plan, would you?  Or would you rather try to follow some scriblings on the back of a napkin?
« Last Edit: September 05, 2010, 03:37:49 PM by Wraith » Logged
Old Dog
Mod God
Offline Offline

Posts: 1047

LoGD Buff!

View Profile WWW
« Reply #33 on: May 16, 2011, 06:07:53 AM »

Functions are fun, I really enjoy creating them and their usefulness is undeniable.

I use them all over the place in my 097 game and some in v1x
Functions can cut down on repetitive code; write it once and be done with it

I remember having trouble creating FUNCTIONS, today I whip them out as needed.

To help out someone I am providing a base which I use, it is the foundation needed to create a LoGD function

function nameoffunction($args if any){
     global $session;
     rest of code and args if any

To use the function simply put

into your code where you need it to run.

Seems simple? Well it is.

* Please do not ask about FUNCTIONS by replying to this post
 - DO go to any one of the numerous php code tutoring web sites available
This is only a Code Tip  ...the rest is on you
« Last Edit: May 16, 2011, 06:16:58 AM by robert » Logged

Old Dog
Mod God
Offline Offline

Posts: 1047

LoGD Buff!

View Profile WWW
« Reply #34 on: August 24, 2012, 07:21:01 AM »

Eliminate white space

When I get new code (not only LotGD)
 - I open each and every page with Crimson Editor
 - I then Select: Document > Tabs Spaces > Remove Trailing Spaces
 - Do not forget to 'Save' it ..with the white space eliminated  Wink
 - I do this for each and every page, before it is uploaded to the server

Many times, over and over, authors leave spaces, tab and lines which can trigger/cause some sort of error.
By eliminating white space on each and every page, I run into very few problems.
For me, this habit, is time consuming but time well worth spending!

This is only a Code Tip  ...the rest is on you

Pages: 1 2 [3]   Go Up
Jump to:  

DragonPrime Notices
Welcome to DragonPrime - The LoGD Resource Community!

Support Us
No funds raised yet this year
Your help is greatly appreciated!
Recent Topics
DragonPrime LoGD
Who's Online
129 Guests, 0 Users
Home Forums News Downloads Login Register Advanced Search