Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Tuesday, April 16, 2013

Validation Email Address: Server side vs Client side

The week ago I was programming my web application using PHP5.

There is two ways to validate email:

  1. On server side (using filter_var from PHP5)
  2. On client side (using input type email from HTML5)

PHP5 example

$email = "xpto@email.com";
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
    echo "This ".$email." email address is considered valid.";
}

HTML5 example

<form action="file.php" method="post">
  E-mail: <input type="email" name="useremail"><br>
  <input type="submit">
</form>

In my opinion it is better validate email on client side instead server side. So don't validate email on server side because it takes a lot work to warn user that has an invalid email address. With client side to validate email, it saves a lot work to warn user that has an invalid email address.

But if you are programming a web application using OOP, it is good idea to validate email from server side because you are not using form to validate email but you are using object, for example:

class User{
  private $name, email;
 
  public function __construct($name,$email){
   $this->name=$name;
   $this->email=validate($email);
  }
  
 private function validate($email){
  $mail = "";
  if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
   $mail = $email;
  }else{
    echo "This $email is not valid!";
   }
  return $mail;
 }
}
$user = new User("Peter","peter@xpto.com");//valid email
$user = new User("Paul","kjfddks");//prints "This kjfddks is not valid!"

Monday, April 2, 2012

The best way to planning software


I believe Use Case diagram, Entity-Relationship model and flowchart to design a software. It is extremely useful because I loose less time to program and correct the mistakes. I would rather planning during two months than programming during two months. Why? Because a software with good planning is cheap, fast and flexible unlike a software with bad planning that is expensive, slow and inflexible to possible changes.


All my academic life, I got used to program more hours than planning. My works were not awesome but also were not bad. It was enough to pass in evaluation. Finishing my course, I did an internship at the software company. Bringing old habits, I programmed more than planned. I had a project to finish in beginning of December but I finished in end of January. Why? Bad planning! My boss was angry with me for I did not meet deadline. I confess that is not good to see my boss angered!


I learned a lot with that mistake. From that, to develop any software, I always make Use Case diagram, Entity-Relationship model and flowchart. Use Case diagram is very abstract and easy to understand what the actor's goal. Entity-Relationship is used to define tables on database. Without this model, I would be lost. The flowchart is used to define software's logic.


With those three tools of planning, I spend less time to program, more time to planning, I am able to meet deadline and my boss will be happy with my work.

Wednesday, March 21, 2012

Communicating between PC and Arduino (Correction)


On March 19th, 2012, a youtube user called Sophie333C found a problem on video "Communicating between PC and Arduino".

Sophie333C's comment:
Hi, There seems to be a problem when you press send the second time around,
it only seems to update every second press of the button!

After two days, she sent me a solution. I tested her solution and it works fine. Now I can receive a answer
when I press the button for first time. Here is code of solution:

  answer = port_arduino.ReadByte()
        TextBox2.Text = Chr(answer)

I would like thank to Sophie333C to found out this problem.