Follow us on...
Follow us on Twitter Follow us on Facebook
Register

User Tag List

Results 1 to 6 of 6
  1. #1
    Newbie
    Join Date
    21 Jun 2012
    Posts
    15
    Threads
    1

    My User Ranks

    My Reputation

    Enclosing code in quotes.

    While working on my newest client's site I noticed that most (almost all) of the code I saw in the files was formatted like this:
    PHP Code:
    if($_POST[attribute]
    function();

    if(!
    $_POST[attribute]
    function(); 
    No braces, no quotes. Although somewhat functional, there were more errors when I set the ini to display all errors than I care to mention. As I closed tags, removed print and changed it to echo I noted that all the errors cleared out. This is truly a sign of not only a beginning programmer, but a lazy one as well. Quotes are your friend, as are braces (and include files). 153 files in the root with no include files. Quite frustrating to say the least.

    Secondary rant: indenting. Indent your code, people. It makes going back over your code at a later date and makes your (or the next programmer's) life much easier.

    Yet another rant: comments. Comments are your friend.

    Yep, one more: non-escaped $_GET and $_POST. $_GET is fine if you HAVE to make the URL show data (user profiles and search results are a good example), but $_POST is best. It's harder to hijack, looks nicer when the whole site isn't set with ?action and ?id tags on the end of the URL.

    Source: 16 years as a programmer in Python, RoR, PHP/MySQL/MySQLi, ASSEMBLY, PERL, HTML/XHTML, CSS, Java, Javascript and BASIC (yes, BASIC).
    Last edited by SpotOnTech; 06-28-2012 at 03:34 AM.

  2. #2
    VPL Supporter Avalanche's Avatar
    Join Date
    30 May 2011
    Location
    USA
    Posts
    428
    Threads
    20
    Blog Entries
    3

    My User Ranks


    My Reputation

    Re: Enclosing code in quotes.

    I've only been programming for a little over four years. And I'll admit I'm self taught. But it was interesting to see the turning point where I felt as though I was no longer a newbie at programming. When I started fixing code that was terrible. I not only could recognize it, I could fix it. When I first realized that it was a big deal and I was so proud that I was better at someone else in programming.

    Now, I wish all programmer's were perfect gods so I wouldn't have to fix all their dumbass mistakes. >.> Amazing how the times change.

  3. #3
    Member ThomasMosey's Avatar
    Join Date
    05 Feb 2012
    Location
    Coventry, UK
    Posts
    183
    Threads
    22
    Blog Entries
    2

    My Social Networking

    Follow ThomasMosey On Twitter Add ThomasMosey on Facebook
    Visit ThomasMosey's Youtube Channel

    My User Ranks

    My Reputation

    Re: Enclosing code in quotes.

    I've been programming a little over 6 years now, and to all the people who code like the example given in the OP:



    It just simply should not be done, especially if it's for commercial purposes.
    Kind Regards,

    Thomas Mosey
    Web Developer & Programmer


    http://thomasmosey.com/
    tom@thomasmosey.com

    Follow me on Twitter!
    @ThomasMosey


  4. #4
    Newbie
    Join Date
    21 Jun 2012
    Posts
    15
    Threads
    1

    My User Ranks

    My Reputation

    Re: Enclosing code in quotes.

    Here's a snippet of code from the contact form that I haven't gone over yet. By the time you read this, it'll be fixed since it's open in Notepad++, but this is as it stands as of posting:

    PHP Code:
    <?php
    $loggedin
    =notnecessary;
    include 
    "header.php";

    if(isset(
    $_GET['email'])){
    $name=$_POST['name'];
    $subject=$_POST['subject'];
    $emailaddy=$_POST['emailaddy'];
    $email=$_POST['email'];

    $to="[REDACTED]";
    $subject "Contact Form";
    $body "From: $name\nSubject: $subject\nEmail Address: $emailaddy\n\n

    $email";
    $from_header="From: [REDACTED]";
    mail($to,$subject,$body,$from_header);

    print 
    "Email successfully sent.";
    include 
    "footer.php";
    exit;
    }

    print 
    "<form method=post action=contact.php?email=yes>
    Your Name: <input type=text name=name><br>
    Your Email: <input type=text name=emailaddy><br>
    Subject: <input type=text name=subject><br>
    <textarea rows=20 cols=30 name=email>Email content here.</textarea><br>
    <input type=submit name=submit value='Send Email'></form>"
    ;

    include 
    "footer.php";
    ?>
    Oh, and no, it was not indented. Personally I enclose all my functions with parentheses to make it explicit. aka: echo("foo"); include("foo"); and I don't use print for anything.

  5. #5
    Approved Programmer
    Join Date
    23 Jan 2011
    Posts
    754
    Threads
    34
    Blog Entries
    2

    My User Ranks




    My Reputation

    Re: Enclosing code in quotes.

    Not only will it throw warning, but it also executes a lot slower (approximately 4x).

    Speed test ... http://lnked.me/x9idd

    isset / empty should be used instead of forcing a hard read of the variable (i.e. isset($_POST['foo']) instead of $_POST['foo']). This is just wrong ...

    ~judda
    Personal Site, Blog, Development Projects all wrapped up into one convenient location. Click here to begin. I am very straight to the point ... if you don't like it ...just feel free to ignore me.

    Blog :: Development Blog :: Resume




    Virtual Pet News - Aggregator of all pet site News Feeds
    SQL Blog Feed - Aggregator of several SQL blog sites
    PHP Blog Feed - Aggregator of several PHP blog sites

  6. #6
    Newbie
    Join Date
    21 Jun 2012
    Posts
    15
    Threads
    1

    My User Ranks

    My Reputation

    Re: Enclosing code in quotes.

    Quote Originally Posted by judda View Post
    Not only will it throw warning, but it also executes a lot slower (approximately 4x).

    Speed test ... http://lnked.me/x9idd

    isset / empty should be used instead of forcing a hard read of the variable (i.e. isset($_POST['foo']) instead of $_POST['foo']). This is just wrong ...

    ~judda
    ...and that's exactly what I'm running into with over 20k lines of code in this site. I should have charged my per/hr rate instead of a flat fee.

    Edit: Also, since there are multiple arrays being passed, I usually cross-check it since say, if(isset($_GET['foo']) && $_GET['foo'] == "bar"). I'm not sure who the coders were of this site, but I'd like to hit them with my old Windows 3.11 manual.
    Last edited by SpotOnTech; 06-28-2012 at 07:57 AM.

 

 

Similar Threads

  1. Favourite Quotes
    By Lion in forum General Discussion
    Replies: 2
    Last Post: 06-16-2012, 11:41 AM
  2. Flash game price quotes?
    By Ardy in forum Programming General
    Replies: 4
    Last Post: 12-30-2011, 11:46 AM
  3. Favorite Quotes.
    By FaTaLiTy in forum General Discussion
    Replies: 9
    Last Post: 12-12-2011, 03:19 PM
  4. Looking for quotes for a Sidscroller
    By Teshia in forum Programming Marketplace
    Replies: 0
    Last Post: 07-05-2011, 07:35 AM
  5. Quotes
    By adbrad in forum Updates and Feedback
    Replies: 1
    Last Post: 02-17-2011, 11:40 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •