Page 1 of 1

scripting standards

Posted: Wed May 06, 2009 9:00 am
by pritam79
Hi everyone,
I would like to know if programming for the web using PHP needs some language standards to be maintained. Do I need to use high end PHP scripting or simple scripting to perform the same task. What should a inexperienced programmer opt for to develop for the web?

thanks

Re: scripting standards

Posted: Wed May 06, 2009 10:02 am
by Zyxist
Well, it depends on the kind of the task :). Nobody will use Zend Framework just to write a visit counter for private use, as well as nobody creates Yahoo-size websites, writing plain PHP files without any form of engine, libraries, structure... The standards depend on solution, but unsually they are only implementations of widely known techniques that do not refer only to PHP, but are common in other languages, too. For example, the very popular MVC pattern is implemented in most of the today's PHP frameworks, but each implementation is different. Moreover, similar MVC design can be found in Python frameworks and even GUI libraries for desktop applications.

However, we can find some techniques that could be considered as "standards", such as using object-oriented programming or frameworks. You will find them in most of the projects.

Re: scripting standards

Posted: Thu May 07, 2009 6:01 am
by papa
Here is some useful information as well: http://pear.php.net/

Re: scripting standards

Posted: Sat May 23, 2009 1:46 am
by pritam79

Code: Select all

<?php
 include "header2.php";
 ?>
 <div id="content">
 <?php
 session_start();
 global $valid_user;
 //include function files for this application
   require("PDMS_fns.php");
   check_valid_user();
   if(!filled_out($_POST))
    {
      echo "<br><br><center>You have not filled out the form completely-<a href='add_appointment_form.php'>retry</a></center>.";
      exit;
    }
  
   $conn = db_connect();
      if(!$conn)
      {
          echo "<br><center>Could not connect to database server- retry</center>";
          exit;
      }
      $sql = mysql_query("SELECT * FROM appointments WHERE username='$valid_user'");
  
      $result = mysql_query("SELECT * FROM appointments WHERE username='$valid_user'");
        if(!$result)
         {
          echo "<br><center>Could not execute query</center>";
          exit;
         }
     // if ok put in db
      
      $result = mysql_query("INSERT into appointments(A_ID, username, a_date, a_time, a_notes) values('', '$valid_user','$_POST[a_date]', '$_POST[a_time]', '$_POST[a_notes]')");
      
        if(!$result)
         {
          echo "<br><br><center>Could not add-try again</center>";
          exit;
         }
        if($result)
         {
          echo "<br><b><center>Appointment added successfully<br></center></b><br>";
          echo "<HTML><body><table><tr>";
          echo "<td style=\"height: 66px; width: 860px; text-align: center\"><b>Date</b>: $_POST[a_date]</td>";
          echo "<td style=\"height: 66px; width: 860px; text-align: center\"><b>Time</b> : $_POST[a_time]</td></tr>";
          echo "<tr><td style=\"height: 73px; width: 860px; text-align: center\" colspan=\"2\"><b>Notes</b> : $_POST[a_notes]</td></tr>";
          echo "</table></body></html>";
         }  
        else
         {
           // otherwise, provide link back,  tell them to try again
         echo "<p><br><br><center>Addition failed- <a href='add_appointment_form.php'>Retry</a></center></p>";
    exit;
   }
 ?>
 </div>
Most of the sites coded in php use high end coding, i would like to know if the sites developed using simple scripting like the above code would work on the web or there is lot to be done with this simple coding. Are there any loopholes with the code.Please suggest something and the steps to be taken to use high end php coding. What is the proper learning resource one should use in order to learn and use php for the web? What are the tutorials? thanks

Re: scripting standards

Posted: Sat May 23, 2009 2:15 am
by Christopher
pritam79 wrote:Most of the sites coded in php use high end coding, i would like to know if the sites developed using simple scripting like the above code would work on the web or there is lot to be done with this simple coding. Are there any loopholes with the code.Please suggest something and the steps to be taken to use high end php coding. What is the proper learning resource one should use in order to learn and use php for the web? What are the tutorials? thanks
The truth about the question you are asking is that you will only improve if you have to improve. You ask about "simple scripting" and "high end coding". Those terms have no real meaning. There is a lot of information about solving software problems. If you want to know if there is a better way to program than how you are currently programming -- the answer is yes. If you are looking for an excuse to keep programming the way you are currently programming -- the answer is yes too. If you want to learn state-of-the-art in PHP programming, I would recommend learning Zend framework.

Re: scripting standards

Posted: Sun May 24, 2009 12:00 am
by pritam79
Thanks

Re: scripting standards

Posted: Sun May 24, 2009 12:46 am
by AGISB
I have to admit, that I am a fan of easy coding. As I am ostly programming for my own projects or projects I am the only programmer in, it doesn't matter how my code looks.

If someone would have to work with my code he will get mad. I hardly do Objects as I don't like to have to look for the code in various places. I like to use my functions and rework them in every new project. I know that there are downfalls to this, but my programms do exactly what they should do and nothing more. Most class oriented stuff or frameworks do so much more that is not needed. If you use code, classes or frameworks that are written by others you never really know where possible security leaks are but of course more people look for them. So basically there is good and evil to every approach and there is no 'the right' way but the way you can get things done.

Re: scripting standards

Posted: Mon May 25, 2009 12:24 am
by pritam79
OK.... but I would like to know what the best resource for learning professional PHP(used on the web) is. I have been through many
tutorials, but all of them give just a basic grounding of the language including coding that is there in my previous post. I have seen that sites on the web use some high-end PHP code.

Re: scripting standards

Posted: Mon May 25, 2009 4:14 am
by Christopher
AGISB wrote:So basically there is good and evil to every approach and there is no 'the right' way but the way you can get things done.
This is an often stated argument and it is erroneous. There are approaches that are have more good and less evil that other approaches. Many of them are long agreed to. Saying that 'the way you can get things done' is 'the right way' is the same as saying that any way is the right way. That is obviously not true. Worse, it ignores all of the work that people have done to show us better approaches to developing software.

Re: scripting standards

Posted: Mon May 25, 2009 8:06 am
by alex.barylski
In software, there is good code, bad code, and wrong code...

Bad code stinks, is really buggy, consumes mreo resources than needed, unstable, full of holes, breaks all the time but it 'works' and lets the client get the job done (ie: WordPress, Joomla, etc).

Wrong code, is what every peice of software starts out as, code that doesn't work and no one is happy with the result.

Good code, is code that has been polished, refined, refactored and redesigned in some cases.

Every developer writes bad code, and most start their careers writing bad code, but some eventually learn and move towards writing good code. Which side of the fence you sit on really depends on your genuine interest in software development. If your just a career programmer, you'll probably write bad code for the rest of your days. If you write software because your passionate about what you do and would do it for free in your spare time anyways, then you best be looking into improving your code.

Re: scripting standards

Posted: Mon May 25, 2009 8:56 am
by Yossarian
It can be really difficult to get a handle on what you should be doing, or the incremental steps you ought to be making as you move from project to project.

I think some universal danger signs that creep up on you and eventually might sound bells in your head are: Deja vu (haven't I already written this?) Cut and paste (I know where that is kept in a previous project, I'll just go and copy it) occasionally asking yourself "Isn't there a better way of doing this?" and experiencing a slight sense of trepidation when asked, or forced, to go back and alter some code you wrote in the past to, say, add new functionality to it.

There is nothing concrete in those feelings, but if you do start to recognise them then it is probably a good sign you need to step back, and seek out the advice of cleverer people that you (and I) who similarly dealt with them and for one reason or another documented methodologies to :

a) promote their own code reuse
b) generate more robust and comprehensible code for themselves.

Lets call these methodologies "Professional Coding Practices", and seeking out one naturally leads to becoming aware of a raft of others. You only adopt the ones that you feel apply to you, when you are ready for them.

A word of warning though, it can be very time consuming to learn this stuff - but ultimately extremely rewarding.

PCSpectra: If you write software because your passionate about what you do and would do it for free in your spare time anyways, then you best be looking into improving your code.
Nicely put.

Re: scripting standards

Posted: Tue May 26, 2009 2:03 pm
by kaisellgren
PCSpectra wrote:Every developer writes bad code,
I have noticed that people tend to write the same bad code until someone else points out the problem. Usually, someone handles one situation better and someone else handles another situation better. There are so many topics and everyone have their own strengths. A team of coders, imo, can produce pretty much well coded applications.

Re: scripting standards

Posted: Tue May 26, 2009 2:17 pm
by alex.barylski
Usually, someone handles one situation better and someone else handles another situation better.
I would say so, it's the whole idea behind two heads are better than one.
There are so many topics and everyone have their own strengths. A team of coders, imo, can produce pretty much well coded applications.
While I agree to some degree, I also disagree. Just look at the proof, it's splattered all over the open source (and closed source) world. WordPress has thousands of contributors, yet a horrible codebase...

Two heads are always better than one, certainly, but a team is also only as strong as it's weakest link. ;)