Topic: A tool that helps you write better code (Read 2058 times)
I am a metal monkey!
Administrator Community Supporter?
Jedai Sword Master
Gender:
Posts: 5772
46229 credits Members referred : 3
« on: Sep 21, 2006, 10:42:22 am »
Just read here about CodeSniffer, a PEAR package that parses the code of your scripts, and creating a report regarding it.
Typical reports can show up like this :
Quote
[LINE 62] WARNING: Equals sign not aligned with surrounding assignments. Expected 3 spaces, but found 1 space. [LINE 99] WARNING: Line exceeds 85 characters. It is recommended that this be shortened. [LINE 101] WARNING: Equals sign not aligned with surrounding assignments. Expected 4 spaces, but found 1 space. [LINE 145] WARNING: Equals sign not aligned with surrounding assignments. Expected 2 spaces, but found 1 space. [LINE 156] WARNING: Line exceeds 85 characters. It is recommended that this be shortened.
Seems like a good tool to optimize scripts and learn how to write better code. I think it is time to install PEAR in my development server
But I guess having your personal style is ok with php, as there is no standard editor that edits your coding (microsoft's languages automatically change your code to what they want...)
/* * obtiene el número de identificación del paciente */ $id=$_GET['identificacion'];
/* * si el número de identificación fué asignado mediante * la forma en html abajo incluida, entonces ejecutamos.. */ if($id) { /* * hacemos la conexión a la base de datos */ $conn = mysql_connect("localhost", "root", "");
if (!$conn) { echo "La contraseña de la base de datos o el usuario pueden no existir, error: " . mysql_error(); exit; }
if (!mysql_select_db("auto_mantenimiento")) { echo "Puede no existir la base de datos, error: " . mysql_error(); exit; }
/* * este query busca los resultados que tengan el username * asignado en la forma en html abajo incluida.. */ $sql = "SELECT * FROM auto_mtto WHERE identificacion=$id";
$result = mysql_query($sql);
if (!$result) { echo "No se pudo correr el query ($sql) en la base de datos, error: " . mysql_error(); exit; }
if (mysql_num_rows($result) == 0) { echo "No hubo resultados que mostrar."; exit; }
/* * imprime los resultados obtenidos (pudiendo incluso ser más de un row) */ while ($row = mysql_fetch_assoc($result)) { echo "el artículo número: "; echo $row["identificacion"]; echo "<BR>tiene una hora de ejecución a las: "; echo $row["hora_ejecucion"]; }
mysql_free_result($result); } ?>
<!--- la forma que trae los resultados mediante el numero de identificacion ---> <form name="search" action="show.php" method="GET"> Elegir un ID:<BR> <input type="text" name="identificacion" value=""> <input type="submit" name="submit" value="Buscar"><BR> </form> </font>
Global Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6691
34714 credits Members referred : 374
OMG!I am geek
Gender:
Posts: 55
366 credits Members referred : 0
my day will come..
« Reply #8 on: Oct 30, 2006, 11:41:47 pm »
thanks man n_n it takes a little bit more of space in the physical file but oh well.. it's clearer than other formats because of the break lines and everything.. im learning a lot from this forums!!
Global Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6691
34714 credits Members referred : 374
thanks man n_n it takes a little bit more of space in the physical file but oh well.. it's clearer than other formats because of the break lines and everything.. im learning a lot from this forums!!
absolutly code must be easy to read and clear (always think about that you need to change/and understand the code also 2 years later)
OMG!I am geek
Gender:
Posts: 55
366 credits Members referred : 0
my day will come..
« Reply #10 on: Oct 31, 2006, 08:05:46 am »
There's always that... I wouldn't need 2 years to forget what a function does.. considering my short memory it would take a couple of weeks haha.. probably way less than 2 week.. commenting it is very important. I just wonder if there's any way to encrypt my scripts via a password or something so no one read my comments and steal my code. I'm trying to make money of it sometimes.
I am a metal monkey!
Administrator Community Supporter?
Jedai Sword Master
Gender:
Posts: 5772
46229 credits Members referred : 3
« Reply #11 on: Oct 31, 2006, 06:45:29 pm »
eliezer, this is good when you just "scripting". If you have an application envirenment it should be more than that, and have modules/template system to help you write code more organized and easy.
Anyway regarding your encode question, you can try a compiler like eAccelerator (which is not so good - many times can crash the system) or the Zend encoder which is a little expensive, but does great job
OMG!I am geek
Gender:
Posts: 55
366 credits Members referred : 0
my day will come..
« Reply #12 on: Oct 31, 2006, 10:26:25 pm »
Hey Nikolas! Yeaaah, I had the chance to work for one month at Woodwing (www.woodwing.net) and everything we programmed had to use templates and everything because the programs were translated into about 10-13 languages. So we always used templates, css, includes, etc..
That's the best way to do programming, you change just one or two files and see how all the scripts change. Very useful huh?
I can't afford right now to buy an encoder, but I'll google for free encoders and see if I'm lucky.. Greetings man!!!
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=4197