Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Is cleaner always better?

Name: Anonymous 2009-07-22 10:22

Well, I make a student in web development, and my professor insists on using the longer version of things when writing PHP simply because he is used to it. Now, I have kind of gotten used to writing redundant code.

Here's an example of Me vs. My Professor:

Him


   if(!get_magic_quotes_gpc()) {
    $username = addslashes($username);
   }

   $q = "select password from users where username = '$username'";
   $result = mysql_query($q,$conn);
   if(!$result || (mysql_numrows($result) < 1)){
      return 1; //Indicates username failure
   }


Me


    !get_magic_quotes_gpc() ? $username = addslashes($username) : TRUE;

    $query = "SELECT password FROM users WHERE username = '$username'";
    $result = mysql_query($query,$connection);
   
    !$result || (mysql_num_rows($result) < 1) ? '1' : '2';


Which way do you prefer writing it in?

Note

If you see any errors, please feel free to correct them.

Name: =+=*=F=R=O=Z=E=N==V=O=I=D=*=+= !frozEn/KIg 2009-07-22 17:00

"Semantically they are the same."
Except you can't use if(){}else{} in many places where choices can be made.



______________________________________
http://xs135.xs.to/xs135/09042/av922.jpg
Compiler: A program which produces executables.
Runtime:A program which loads another program as top execution layer
Virtual machine:A program which executes bytecode
Interpreter:A Virtual Machine which runs scripts
JIT:A program which runs scripts and temporary compiles them into memory
It is indeed a precious gift to understand the forces that guide oneself.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List