Jump to content

help


jwilson122

Recommended Posts

Just bear in mind that a) clean, b) secure, c) easy to read, and d) powerful might not play well together.  Are you having any particular problems with any of those topics or have you just heard that your code should have those attributes and you want to fit in and be cool?

Link to comment
Share on other sites

Just bear in mind that a) clean, b) secure, c) easy to read, and d) powerful might not play well together.  Are you having any particular problems with any of those topics or have you just heard that your code should have those attributes and you want to fit in and be cool?

 

not really... but why cant secure, clean code be powerful?

Link to comment
Share on other sites

So you're not having any particular problems, and you're not trying to be cool. What do you want?

 

Um?? not trying to be "cool"? LOL.. Dude, I'm cooler than you, and im also calm too bro! BUT, My question was, for tips and advice on creating clean, secure code. :)

Link to comment
Share on other sites

Just bear in mind that a) clean, b) secure, c) easy to read, and d) powerful might not play well together.  Are you having any particular problems with any of those topics or have you just heard that your code should have those attributes and you want to fit in and be cool?

 

?? Maybe he should do what the rest do and completely ignore the quality of his work and get on with it. You should be very receptive to people who are trying to become better developers - that's what this forum is all about.

 

wilson, what you're looking for is php best practices. Search in google, there are tons of websites about this. Then, search on each specific item again to validate cause just in case. Here are a few links:

 

http://pear.php.net/manual/en/standards.bestpractices.php

http://cyrilmazur.com/2010/10/proposal-best-practices-for-writing-php.html

 

In fact, here's the search link:

 

http://www.google.co.uk/search?q=php+best+practices+readability&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-GB:official&client=firefox-a

 

Some excellent links there. Got me fired up now to do some improving! :)

 

Keep it cool.

Link to comment
Share on other sites

Firstly, this is such a broad question and cannot possibly be answered in a single reply.

Secondly, the OP should have Googled and came back with specific questions.

 

@OP, if you have specific questions we don't mind helping, after all, that's why we're here.

Link to comment
Share on other sites

Thanks a lot Anti-Moronic! ;) Will take a look at your links.

 

Firstly, this is such a broad question and cannot possibly be answered in a single reply.

Secondly, the OP should have Googled and came back with specific questions.

 

@OP, if you have specific questions we don't mind helping, after all, that's why we're here.

 

Well, I dont have any :) So can you be helpful and tell me tricks and techniques you do? Thats ALL I want!

Link to comment
Share on other sites

Indenting and spacing:

 

$var = 0;

for($i = 0; $i <= 100; $i++){
       $var++;
       echo $var;
}

 

Realising the best way of doing something

 


if($var==0){
    echo "boo";
}elseif($var == 1){
    echo "bies";   
}elseif($var == 2){
    echo "are";   
}elseif($var == 3){
    echo "always";   
}elseif($var == 4){
    echo "fun";   
}elseif($var == 5){
    echo "to";   
}else($var == 6){
    echo "squeeze";   
}

 

Can be changed to:

 

switch($var){
    case 0:
        echo "boo";
        break;
    case 1:
        echo "bies";
        break;
    case 2:
        echo "are";
        break;
    case 3:
        echo "always";
        break;
    case 4:
        echo "fun";
        break;
    case 5:
        echo "to";
        break;
    default:
        echo "squeeze";
}

 

Learning different ways to structure code in your head:

 


function do(){
   function this(){
       echo "this";    
   }

   function that(){
       echo "that";
   }
}


that();

 

can be layed out like:

 

class do{
    public $this = "this";
    public $that = "that";
    
    public function this(){
        echo $this->this;    
    }
    
    public function that(){
        echo $this->that;    
    }
}    

$do = new do();
$do->that();

 

Lots more.. Looking at how others lay their code out is always a good start.

 

In a  job, commenting is a MUST. so always comment your stuff really clearly. Also use full words rather than abbreviations a - z lol.

Link to comment
Share on other sites

God point made above. I'd certainly suggest you download some highly regarded opensource frameworks/apps and read the code. Look at the readability - but more importantly try to understand some of the advanced abstract methods. It can be a real eye opener and if you analyze modern frameworks/apps, you'll learn modern techniques!

 

To be honest, I'm very surprised there isn't a sticky here for this kind of thing. Solving other people's problems is one thing, but teaching them how to be better developers can only make all our lives better.

 

More from that search list:

 

http://www.phpvs.net/2008/06/04/ten-php-best-practices-tips-that-will-get-you-a-job/

http://www.mikebernat.com/blog/My_PHP_Best_Practices

http://www.odi.ch/prog/design/php/guide.php

 

Another great idea is to find amateur code and try to improve it to the best of your ability. Make it more readable, more abstract and flexible (search DNR or DIE principle), less lines, faster, whatever. It will truly help you become a better programmer...and *always* search google if you want to know if php can do _____ and how ____ THEN check the manual for ______.

 

Hope that helps! I'm not sure how far into php you are, but it's start to get really really addictive about a month or two in.

Link to comment
Share on other sites

The code snippets posted by jimmyt1988 can hardly be considered the cleanest way to do things, nor "best practices".  I'd love to go into depth on one or more subjects that the OP might like to know more about, but can see the dangers already (from posts above) that he might very well take what is said as "gospel" and not take the time to learn the subject.

Link to comment
Share on other sites

Thanks a lot Anti-Moronic! ;) Will take a look at your links.

 

Firstly, this is such a broad question and cannot possibly be answered in a single reply.

Secondly, the OP should have Googled and came back with specific questions.

 

@OP, if you have specific questions we don't mind helping, after all, that's why we're here.

 

Well, I dont have any :) So can you be helpful and tell me tricks and techniques you do? Thats ALL I want!

 

Then you haven't put any time or research into your own question.  If you have, then I'm sure you would have plenty of questions.  The only advice I can give you is that PHP doesn't have a set standard for code formatting or indenting, so be consistent and, if using a framework, use their style.

Link to comment
Share on other sites

Lol okay well, thanks and good point @ salathe! :) If you could please show me your style, that would be great ;)

 

@Maq, well 1. I don't use any frameworks since I develop sites for people freelancing. So, I'm asking others to show me code sniplets if they could.. my code needs to be clean enough another programmer can edit it since my customers gets the script. ;) Anyways, thanks for your help!

 

Anyone else, if you can provide me with code sniplets or something, it would be great! Thanks tons.

Link to comment
Share on other sites

I'm a freelancer and frequently use frameworks.

 

You'll find the more high paying clients and projects (i.e. $3000+) expect you to work with a well designed framework and design pattern. Whether that be your own or otherwise. Because they might then hire other people to amend later, it is usually required that you develop using a framework. What's the use in using your own framework if somebody had to learn it..there are plenty of frameworks out there which are maintained and studied by tons of professionals. Far more than your own framework can attract.

 

If you want to see code snippets - check the other threads or look at anybody's profile here and check their latest posts. Should be plenty of snippets. First though, I'd advise you read *every* link I sent before. There is a link which shows you how to make your code more readable and maintainable.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.