Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Wednesday, March 17, 2010

Programming: You're doing it wrong

If you're a programmer (as I am), please do yourself a favor and read this post by Marco Tabini in the 20th anniversary of his IT career:
http://www.phparch.com/2010/03/10/programming-youre-doing-it-wrong/

Some highlights of his post:

"Software development is the land of egos and opinions—and it seems that, no matter how bad we try, we're always doing things the wrong way."

"One of the things that I have learned in twenty years of attempting to program is that we’re all doing it wrong. You. Me. Everybody."

"If you’re agonizing over whether you’re writing good code, let me spare you the anguish: you’re doing it wrong—except if your code works, in which case you most definitely are doing it right."


Other posts by Tabini (worth to read):
- Stop Telling People to Optimize, and Start Teaching them to program
- 5 meta skills for the PHP programmer

Friday, February 5, 2010

Get / set generator

I know some IDEs for Java already include this feature, but I was looking something similar for PHP and this is what I found:

http://www.icurtain.co.uk/getset.php

This generator works for any language. It basically gets the variable names (separated by comma) and generates the get and set method for each one.

Helps to save a lot of time!

Monday, January 25, 2010

JS Beautifier

Have some code with no indentation or breaklines? Try this tool:

http://jsbeautifier.org/

It will clean your code ;)

Friday, January 22, 2010

Sphider

Sphider is an open source search engine made in PHP:

http://www.sphider.eu/

It's easy to download and install and works with the same logic as Google: page ranking.

It helped me to understand better how Google ranks the pages and how their database looks like (of course, Google has more sophisticated techniques in their search engine that they won't reveal, but the base has been published and has been used to develop new engines like Sphider).

I recommend you to give it a try if you're involved in Web Development.

Friday, December 5, 2008

PHP cool functions I just found

I know that for some of you this is not new, but for me it is and I found these functions so cool that I want to at least mention them:

DB.class

I created this class to help my self save some time writing code to access a MySQL DB.
It contains all the esential methods to connect to the DB, execute a SELECT, execute a DML (insert, update, delete) and retrieve relevant information about the last query executed (result, number of affected rows, last id inserted).

The idea is to extend this class when you want to access a table of your DB and reuse the methods without re-typing all the lines of code to connect to the DB, fetch the results, evaluate if errors were returned, etc.

///////Put code of the class here



All your now code is reduced to:
- Create a class that extends this one.
- Write your query (simple string).
- Call one of the methods of the DB class that already handles everything else (connection, execution, fetching results, building returning message of OK or ERROR).


//Put example of how to use it here


I hope you find this class useful. Any comments are welcome.

Books I recommend

PHP & MySQL
  • Beginning PHP5 and MySQL5 - From Novice to Professional-2e-2006-APress
  • Professional Ajax Php
  • Professional LAMP - Linux, Apache, MySQL, & PHP5 Web Development (2006)
Javascript
  • Javascript Bible 4th Edition
  • O'reilly - Javascript - The Definitive Guide, 4th Edition
Ajax


HTML, XML and others -ML
  • OReilly XML Pocket Reference 2nd

Class Form

If there is something I "hate" of Web programming with PHP, is the constant mix of HTML with PHP and Javascrip when I have to build a screen.

I start putting the HTML code for the form (text, checkboxes, combos, buttons, etc.). Then I insert the PHP code to set initial values in the fields that -most of the time- come from the DB.

Then I plug all the possible validations I can do on the files using Javascript, such as empty files, numbers, dates, etc.

All this is very repetitive and BORING!

So, in other effort to reduce time programming the same over and over again, I created the class "Form" which:
- Has one method that builds any field you need in your form based on the arguments you pass.
- Sets all the default values for those arguments you don't pass (most of the arguments are optional).
- Builds forms with a uniform look and feel.
- Validates the inputs based on the fields you mark as "mandatory" (argument of the main method).
- Restricts the inputs to numbers if indicated.

This is saving me HOURS of development.

//Put the code here...

Charts in PHP 4 without complicated installations!

You can download the library: jpgraph-1.22.1
From: