Programmer

How to handle errors using Boolean flags

This error handling method may be the most ancient. Boolean flags were used by many programming languages, and PHP will not be an exception. Even though they are very simple to apply, the main negative aspect is that they were not very informative about the mistake that happened and its perspective. Here is an unsophisticated implementation of the FileReader class, which make use of Boolean flags:

[php]
class FileReader{
var $file;
var $fileDir=’fileDir/’;
function FileReader($file){
if(!@file_exists("{$this->fileDir}{$file}.php")){
return false;
}
$this->file=$file;
}
function getContent(){
if(!@$content=file_get_contents("{$this->fileDir}{$this->file}.php")){
return false;
}
return $content;
}
}
[/php]

Bearing in mind about the explanation for the above example, class errors might be handled as follows:

[php]
$fr=new FileReader(‘inexistent_file’);
if(!$fr->getContent()){
die(‘Unable to read file contents’);
}
else{
echo $fr->getContent();
}
[/php]

In the example, @ error suppression operator is intentionally used, so as to stay away from the complaints of the PHP interpreter and return a false value (or 0 or -1) when a failure happens. At first look, you can observe the incompetence of this method, plus its restricted flexibility. On the other hand, this approach has established to be quite victorious in procedural applications, or when client code is able to handle straightforward errors without corrupting the entire application.

Nowadays, we have investigated the pros and cons of common error handling approaches in PHP 4. Certainly, in huge web applications, a set of error controlling classes is preferred, so you are able to handle errors through a centralized point. Conversely, the trigger_error () / set_error_handler () combination may suit the requirements of small projects, so it is worth considering.

Tags: ,

Guidelines to handle Db connection

Please confirm that you close the original connection to a database all the time and that you are using connection pooling to get better processing speed of database connection creation etc. Here are some tips for you:

1. Use web.config to store up the connection string:

2. Use this connection string forever and do not make any changes to it. If you were not doing this (for example using different DSNs) you will disable the connection pooling feature:
string dsn = System.Configuration.ConfigurationSettings.AppSettings[“dsn”];

3. Do not perform any tricks to try to deal with connections etc, just proceed and use it (no wrapper classes or so involved):
SqlConnection conn = new SqlConnection(dsn);

4. Formulate the time between conn.Open() and conn.Close() as small as possible. E.g. don’t do this:
SqlConnection conn = new SqlConnection(dsn);
Conn.Open();
SqlCommand cmd = new SqlCommand(query, conn);
cmd.Parameters.Add(…);

//and further cmd parameters actions and so on

SqlDataReader reader = cmd.ExecuteReader();

//use the reader and do a bundle of additional tasks, not relying on the database

conn.Close();

But rather, use:
SqlConnection conn = new SqlConnection(dsn);
SqlCommand cmd = new SqlCommand(query, conn);
cmd.Parameters.Add(…);

//and more cmd parameters actions etc

conn.Open();
SqlDataReader reader = cmd.ExecuteReader();

//use the reader
conn.Close();
//perform a batch of other work, not relying on the database

5. Always close the connection when you are done, even when an exception occurs. To do this, use the try…finally pattern:
SqlConnection conn = new SqlConnection(dsn);
try
{
//some init depending on conn
conn.Open();
//minimum number of lines of code depending on the open connection
}
finally
{
if (conn.ConnectionState == ConnectionState.Open)
conn.Close();
}
or the using pattern in C#:
using (SqlConnection conn = new SqlConnection(dsn))
{
//…
conn.Open();
}
This will close the db connection repeatedly while leave from the using block.

Tags:

Local Host in Mozilla or Netscape browsers

Most of the users who are using local host in IIS are known to work only in Internet Explorer (IE) browser.

However, you may also browse your Localhost in both the Mozilla and in Netscape Browsers also. To browse your localhost in Mozilla and Netscape browsers just follow the simple steps provided below:

1) Type about:config in your address bar
2) In Mozilla it will prompt an alert message click the button “I’ll be careful, I promise”
3) Now in the filter box search for “network.automatic-ntlm-auth.trusted-uris
4) Double click on the Preference Name.
5) Enter the value “localhost” and click OK.
6) That’s it.. Your browser is now configured to use localhost.

Hope this is so helpful for many users.

Tags:

Fixing bugs in CSS

A high-quality web designer has to undergo every time he or she codes a page using CSS for design. Web Standards is the only way to go and it must be an obvious option when you take your job serious.

Confirm your markup is well structured

Make sure your markup is finely ordered, in other words make use of the suitable markup for the appropriate content. Apply headings for titles, paragraphs for blocks of text, ordered and unordered lists to sum things up in list form or for your navigation, field sets in combination with legend and label elements for forms… Finally, use tables only for what they are used for, tabular data.

Validate your markup

It’s not pretty much the green check mark in the bottom right hand corner of your browser or 0 errors or warning on the W3C Validator that matters. This is only an additional check and a confirmation that your code validates. The W3C markup validator or W3C CSS validator should be your tools to make your page an error free. Tools that facilitate you to create the right coding, but consider that this is just a machine that runs a test for you. Some coding faults, for instance using the incorrect or structure-less code for certain content will not be seen as an error by this machine, so make sure this is in order. Validate the pages is an absolute necessity before you begin to fix any CSS layout problems.

Tags:

When to hire, and What Size Firm

when a merchant employs an SEO firm, it is more important as which firm they hire. The right moment to outsource SEO help is right before a major site redesign. If a merchant does not appoint an SEO firm until after re-launch, “You were building your troubles in,”.

If you do the site rebuild with the help of a SEO firm, you can stay away from pitfalls like unnecessary use of Flash, HTML frames, or graphics that works in opposition to search visibility. SEO concerns be supposed to be a central driver to a rebuild, not an after-the-fact add-on.

When you rent an SEO specialist, your own site’s size is a key determinant of which company to hire. “There is no ‘one-size-fits-all’ SEO vendor,”. A small SEO shop having three to four-people would be swamped by a massive corporate account, and a best-of-breed 100-person SEO/paid search consultancy would be far too costly for a ‘mom and pop’ site.

However, both of these SEO companies might do high-quality work at a reasonable price for the part of business they are set up to handle.The difficulty is that “a lot of SEO firms sell what they are having, not what is good for you”. In other words, it’s up to the merchant to make a decision if an SEO company is the right size and has the right approach, the firms themselves will always say take the job, apart from this problem, as long as a merchant can compensate their fees.

To be clear in your mind, a good SEO expert will be able to locate or build up terms the business owner won’t think of, but “the more you can be implicated with your own keyword research, the better.”

Tags: ,

Pay for Programmers and reviewers in the video game industry

A survey has been conducted by Game Developer magazine about the pay structure in the field of video game for programmers and the reviewers. The survey result concludes that programmers were making large amount money. According to the sixth annual survey taken by Game Developer magazine, programmers were earning the largest part money with a regular income of more than $80,000 per year for a second year in a row.

Producers were bagged the Second position , who earned an average of $77,000 and Game designers came in after that with an average salary of better than $61,500 although those with three or less years of experience came in much lower at a salary of less than $45,000. Artists came in next with an average salary of about $43,000.

Quality assurance or game testers be paid an average of just under $38,000 per year but again with only three or fewer years of experience, that salary drops to only just over $26,000 per year. Certainly game reviewers are still paid the least and most would not even reveal what little they earn.

The results are in and programmers are still the highest paid in the video game industry and reviewers still are paid the least

Tags:

Smarty for Programmers

The advantage for programmers is that they write the code in a PHP file without having to combine the instructions with HTML. Also, if the designer changes the layout of a page the programmer doesn’t have to change the code to suit the new layout since the functionalities won’t change. You perform your work in your files, assign to the templates all the values needed to print on the site and go out for a beer.

The PHP file you need to include the Smarty class require 'Smarty.class.php'. After that you instantiate the smarty with $smarty = new Smarty.

To assign a variable to the template you need to $smarty->assign('UserName', 'Jeff Adams'). After everything is finished you call the method and to display the template $smarty->display('index.tpl').

A sample code like this (index.php) :

[php]
<code><span style="color: #0000bb; font-size: 10;"><php </span>
<span style="color: #007700; font-size: 10;">require </span><span style="color: #dd0000; font-size: 10;">’Smarty.class.php'</span><span style="color: #007700; font-size: 10;">; </span></code><span>
</span><code><span style="color: #0000bb; font-size: 10;">$smarty </span><span style="color: #007700; font-size: 10;">= new </span><span style="color: #0000bb; font-size: 10;">Smarty</span><span style="color: #007700; font-size: 10;">; </span></code><span>
</span><code><span style="color: #0000bb; font-size: 10;">$smarty</span><span style="color: #007700; font-size: 10;">-></span><span style="color: #0000bb; font-size: 10;">assign</span><span style="color: #007700; font-size: 10;">(</span><span style="color: #dd0000; font-size: 10;">’Username'</span><span style="color: #007700; font-size: 10;">, </span><span style="color: #ff8000; font-size: 10;">’Jeff Adams’); </span></code><span>
</span><code><span style="color: #0000bb; font-size: 10;">$smarty</span><span style="color: #007700; font-size: 10;">-></span><span style="color: #0000bb; font-size: 10;">display</span><span style="color: #007700; font-size: 10;">(</span><span style="color: #dd0000; font-size: 10;">’index.tpl'</span><span style="color: #007700; font-size: 10;">); </span></code><span>
</span><code><span style="color: #0000bb; font-size: 10;">?> </span></code>

[/php]


The template (index.tpl) like this:

[php]
<code><span style="color: #007700; font-size: 10;"><</span><span style="color: #0000bb; font-size: 10;">html</span><span style="color: #007700; font-size: 10;">> </span></code><span>
</span><code><span style="color: #007700; font-size: 10;"><</span></code><code><span style="color: #0000bb; font-size: 10;">body</span><span style="color: #007700; font-size: 10;">> </span></code><span>
<code> </code></span><code><span style="color: #0000bb; font-size: 10;">Welcome </span><span style="color: #007700; font-size: 10;">{</span><span style="color: #0000bb; font-size: 10;">$Username</span><span style="color: #007700; font-size: 10;">} </span></code><span>
<code><!–</code–></code></span><code><span style="color: #007700; font-size: 10;"><</span></code><code><span style="color: #0000bb; font-size: 10;">body</span><span style="color: #007700; font-size: 10;">> </span></code><span>
<code><!–</code–></code></span><code><span style="color: #007700; font-size: 10;"><!–</span–></span></code><code><span style="color: #007700; font-size: 10;"></</span></code><code><span style="color: #0000bb; font-size: 10;">html</span><span style="color: #007700; font-size: 10;">></span></code>

[/php]

Also create an array in PHP an pass it to the template:

[php]
<code><span style="color: #0000bb; font-size: 10;">$tmplate </span><span style="color: #007700; font-size: 10;">= array ( </span><span style="color: #ff8000; font-size: 10;">’UID’=> ’10’, &’Name’ => ‘Jeff Adams’, ‘Address’=>’Home address’); </span></code><span>
</span><code><span style="color: #0000bb; font-size: 10;">$smarty</span><span style="color: #007700; font-size: 10;">-></span><span style="color: #0000bb; font-size: 10;">assign</span><span style="color: #007700; font-size: 10;">(</span><span style="color: #ff8000; font-size: 10;">’info’, $tmplate);</span></code>

[/php]

Tags:

Cron Jobs

Cron is a unix, solaris service that allows tasks to be automatically run at regular intervals by the cron. These tasks are often called as cron jobs in unix and solaris. cron is motivated by a crontab. Crontab is a file which contains the schedule of cron entries to be run and at particular time period.

Early versions of cron, Version 7 Unix and 32V, made their services only to the super-user of the operating system (root). With the release of Unix System V and the multi-user cron, these services were extensive to all account-holding users of the system.

Two different modes you can use the cron job:

  • Standard – This mode provides range of pre-set options we can choose and set the cron job for our need.

  • Advanced (Unix Style) – It provides the regular cron options ie, Unix style cron options to set the cron job.

To add or change a cron job:

  1. On the home page click on the Cron jobs button.
  2. If you desire to use the Standard mode, click on the Standard button.

  • Enter the e-mail address to send the results of the cron job.
  • In run field enter the command the you want to run in the Command.
  • Choose the one option from each of the available lists.
  • Then click on the Save Crontab button now your cron job has now been added or updated.

If you desire to use the Advanced mode, click on the Advanced button.

  • First enter the times for the cron job in the Minute, Hour, Day, Month, or Weekday fields.
  • Then provide the cron job script in the Command field.

  • Then click on the Commit Changes button now your cron job has been added or updated.

Tags: ,

Who is a good Programmer?

One who follow the below mentioned points will become a good programmer.

  • Save your code regularly! You don’t know when the power goes out. Imagine if you working for a long time (say 3 hours) without saving the code, you will lose several hours worth of code.
  • Write down appropriate comments near the coding wherever needed. Comments are very important and useful. If another person happens to go through your code, it will be very easy for him to understand if you provide comments. It will be very helpful for you too, if you visit that code 1 or 2 years later.
  • Your code should be clean and simple. Separate your code into chunks, and use line breaks where you can.
  • Test your code frequently. When you have completed a simple part of code, test it and then proceed to the next part. Don’t wait until you have written five hundred lines of code before testing? If any error occurs, you have to look through all those lines to trace out the error.
  • Back up your code. Because your system may crash or affected by virus or the file may get corrupted. So take a backup every night after a day of coding and always be in the safer side.

Tags:

Request a Free SEO Quote