[aur-dev] AUR Coding recomendations IMPORTANT

Angel Velásquez angvp at archlinux.com.ve
Fri Jun 20 01:54:24 EDT 2008


Hi, I am writing this e-mail after reviewing the AUR code and some patches
that people have been sending.

As we know, AUR (like many applications) is still in development, and many
of the things that are actually working weren't coded by any of us, and I
can understand this.

The purpose of my e-mail is to give some recommendations that should be
adopted by everyone, I don't want to be arrogant or force you to do
something without knowing why, so I will explain the reasons behind my
recommendations and then you will probably agree with me.



Singles quotes vs Doubles quotes
=====================

Problem:

In the past I sent an e-mail about this topic, but I think I was
misunderstood. The correct way should be using singles quotes when you don't
need to parse any kind of variable, that applies in any case.

Examples:

1.-
include "lib/whatever.inc.php"; // why double quotes ? just to waste
resources and no more..

2.-
function myFunction($var) {
   return "Hello ".$var; // wrong concatenation AND using double quotes ?!
  # return 'Hello '.$var; // this is the correct use

}
echo myFunction("world"); // wrong
# echo myFunction('world'); // Oh nice you know what i'm talking about.

3.-
$_SESSION["myName"] = "MyNameIsWrong"; // and it certainly is wrong, thanks
for wasting resources with double quotes!

# $_SESSION['myName'] = 'Foo Bar'; // that's the way

4.-
// the last example of a block of HTML
print "<table>\n";
print "<tr>\n";
print "<td>".$title."</td>\n";
print "</tr>\n";
print "</table>\n";
// Come on!!!!, the following line does the same.


echo "<table>\n<tr>\n<td>$title</td>\n</tr>\n</table>";
// Yes I know that placing plenty of \n's would render the code unreadable,
but you can do it in one line with a simple echo.

Overview:

I recommend the use of double quotes in the case that you need to parse many
variables so that the code doesn't become unreadable, or if you want to
output HTML code in a sorted way.

print vs echo
========

Problem:

Many of us usually prefer to use print because we are used to the function
name similarities from languages other than PHP, and we can't get used to
*not* using it.


Examples:

1.- print 'echo is ugly!'; // assuming that you've learned about singles and
doubles quotes :D

Overview:

Print outputs the string and has an actual return value of TRUE or FALSE, so
that converts print in a function slower than echo.


See this thread for more information:
http://codingforums.com/archive/index.php?t-41745.html

To wrap this up, I just want to emphasize the fact that whereas this might
look trivial and nearly irrelevant to some of you, it is important in order
to make AUR a better tool.

Cheers.


-- 
Angel Velásquez
angvp @ irc.freenode.net
Linux Counter: #359909
Arch Linux Trusted User
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://archlinux.org/pipermail/aur-dev/attachments/20080620/1e6eece2/attachment.htm>


More information about the aur-dev mailing list