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 12:25

ternary operators are very useful: there places in the code where they come handy like:

 printf("The buffer is allocated %u bytes with %s",bufbytes,is_set?"content_str":gen(new_content));
--instead of
if(is_set){
 printf("The buffer is allocated %u bytes with content_str",bufbytes);
}else{  printf("The buffer is allocated %u bytes with %s",bufbytes,gen(new_content));}



______________________________________________
http://xs135.xs.to/xs135/09042/av922.jpg
When despotism has established itself for ages in a country, as in France, it is not in the person of the king only that it resides. It has the appearance of being so in show, and in nominal authority; but it is not so in practice and in fact. It has its standard everywhere. Every office and department has its despotism, founded upon custom and usage. Every place has its Bastille, and every Bastille its despot. The original hereditary despotism resident in the person of the king, divides and sub-divides itself into a thousand shapes and forms, till at last the whole of it is acted by deputation. This was the case in France; and against this species of despotism, proceeding on through an endless labyrinth of office till the source of it is scarcely perceptible, there is no mode of redress. It strengthens itself by assuming the appearance of duty, and tyrannises under the pretence of obeying.

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