Loading... Cancel

EiD recipe special : few conventions and best practice for software developer R

October 15th, 2007

i just gathered a few of my known conventions and best practices. i belief this will help many of us.

few of my previously written posts -
usages of “final” keyword in java -
http://www.somewhereinblog.net/blog/hasan/28708715

usages of comment and coding
http://www.somewhereinblog.net/blog/hasan/28704020

let’s check out my recipes -

1. code from your peer developer perspective view.
while you writing your code, always think your code will be reviewed by some other developers, who is not like you,
who is very serious in simple fault and ignorance in writing code. your code will reflect who you are, so better be careful while you exposing yourselves (through writing code).

2. variable convention -
never write short variable name, always write variable which reflects it usages.
for example -

$user = new User() instead of $u = new User(). follow same convention when you have nested “loop”

3. source file naming convention (except java)
set your file name in such a way that will reflect the usages of the file.
for example -

verify_user_authentication.php (or in a packaging manner - user_util_verify_authentication.php). in java you better know how to write package.


4. keep your url domain centric

all urls should be inherited by some specific problem domain for example -

http://abc.com/user/login
http://abc.com/user/register
http://abc.com/user/update

here “user” is problem domain and “login|register|update” are actions or you could say problem.

5. method naming convention -
write method name in such a format that will reflect it usages. or simply make it self describing.
for example -

function verify_user_credentials() {}
def verify_whether_user_profile_is_complete() {}
private void checkUserFlyLimit() {}

6. don’t write query from controller:
build or execute query from DAO or helper or utility or domain itself. don’t put it over controller which limits the reuability and later extendability and interception

7. single concern
while coding, keep your method slim and less concerned about other implementation. for example -

private void isAuthorizedUser(pUser, pAction) {
if (userAlreadyLoggedOn(pUser) && userIsNotBlocked(pUser) && userHasPermission(pUser, pAction)) {
// boooooooooooooooomm…
}
}

8. think from testability
while writing your code always think from testable perspective view. this means, how you could testify your work or module
or bunch of code which your company is paying for.

9. follow coding norms -
i. think before coding

whatever you want to put on your code try to think or imagine before start coding.

ii. dump your think in comment

whatever you thought just write it down over comment or paper or in a common place where you or future developers could have look on. (better place in comment)

iii. write your algorithm in comment.

whatever you planned write in comment before kick start your coding.

iv. set up your unit test case.

find all probable assertion points from use case, put them over your unit test case.

v. write your code
vi. coding routine -

(1) test -> (2) code - go to > (1) [recursively]

10. always put your tag over the source file,
whatever you wrote, that reflects your confident and work efficiency, so better you tag your name over every source code you have written or modified. good for tech lead or project manager, because tagging each file with author name, it creates a hidden responsibility for the author :) good for both parties.
for example -

/**
* @author someone
*/

My adds on - “Just PHP will give you nothing… unless you upgrade yourself” R

January 26th, 2007

Recently i was reading an article from Hasin bhai,
which is titled “Just PHP will give you nothing, unless you upgrade yourself”
here is my comment on hasin bhai’s post

wow hasin bhai, nice write up.
Bro i wanna add up few topics which are leaking in most of the php developers. i belief most of the PHP developers are producing dirty fast code (not 30th first night ;) ) it is because of the following reasons:
(my suggestion are enclosed with in ‘–>’ context)

1. less concentration of DRY (Don’t Repeat Yourself)
–> Create each fragment as reusable module (for example: latest_comments.php, latest_user.php, latest_news.php etc..)

2. Search those code which u have written more than once
–> Separate them. (keep them in separate reusable file)

3. Keep your business logic away from presentation layer
–> you don’t need to follow any strict design pattern like MVC, MVP. just plain solution is enough. Use php class to manage your business rules.

4. Use any good framework, it doesn’t mean you have to use java or Ruby on rails like framework. Better go for simple and productive framework.

5. Use library from trusted parties (hope zend is growing up its huge libraries on many aspect), PEAR is obviously great choice.

6. Don’t think all running web application is 100% accurate, and never ever grab their design and code. Better use your own sense and create a colorful stuff… meet your own client requirements.

7. Don’t mix up PHP with java or these kinda technologies
–> The way php works and the way Java works are not same, and better not compare both. Never ever try to implement all design patterns which are successful on Java EE platform. PHP is great for its simplicity. Java is great for its complexity.

8. Go for better object orientation, but it doesn’t mean you have to restrict everything with in a bunch of classes.
–> PHP is not intended to develop for this purpose. Rather follow php related performance tuning stuff.

9. Always keep your data access layer separate from raw or presentational php coding

10. Always go through open source projects, where you can learn how big projects are managed by human beings.

My few suggestions:
1. Keep a separate file for all SQL queries. for example:
(#) file: sql_index.php
——————
$select_users = ’select * from User’;
$delete_user_by_id = ‘delete from User where userID=?’;

$select_comments = ’select * from Comment’;
$delete_comments = ‘delete from Comment’;

(#) file: sample_usages.php
———————
…..
$result = mysql_query( $select_user);
…..

—> Benefit is, when you want to solve cross database related issue, you can resolve it very frequently (though you can write Data Abstraction Layer dependent code)

2. Presentational files (which files are used to render web UI) should keep their logic through few helper functions (rather hard embedded code). For example:
(#) File: test.php
——————
< div >
< ? foreach ($post in $posts) echo $post->title ? >
< /div>

(#) File: replace_test.php
—————-
< div >
< ?= render_posts() ? >
< /div>

3. Limit frequent database access.
–> Go for caching system, use PEAR cache or any cache solution from PECL. For more optimized and challenging solution go for DSO related caching solution, whenever you will need multiple server It will give you a big hug. Go for MemCache, as it has been proven for several years.

4. Grow your knowledge on Software engineering.

5. Explore your idea, you can become a good developer but you can’t become a good idea creator unless you explore and dive inside the deep sea of knowledge.

6. Travel as much place as you like, it will help you to grow up a good sense of creativity. (I have to start it … :D )

7. Don’t forget to adopt little stuff from TDD (Test driven development), dig these terms: unit test, fixture etc…

8. Try to work on agile team. Enforce your PM to learn about agile related stuff. Select the best agile methodologies which are most suitable for your company. (Agile comes with a bunch of options, scrum, XP, rup and many stuff)

9. While you writing your code, always think, your code will be verified by some guy, who is very strict and who will surly scream because of your poor writing… :p (anyway, if u feel your code is nice … just send me. during my week ends I will check it up… obviously I will come with a set of good criticize :) )

10. Learn, Dig, Seek and Dive in “KnowSea”

11. Use change management tools, (Subversion, bug tracking system and project planning tools)

(hasin bhai apologized for Big comment :p)

Best regards,

Posted in PHP, comment

ajax-new-color version 1.0-2 R

December 9th, 2006

Credit goes to John (http://red-star.nl/blog)

here is change logs:

version 1.0-2
(thanks goes to Jon)
1. added style on button
2. fixed IE related side bar bug

version 1.0
(thanks goes to John)

1. added cookies support for comment box
2. updated css files
3. added optional plugin support
4. gravatar support added
5. Fitness indicator support added

version 0.2
1. Fixed real link

Download link

Usually hosting issues donít arise with godaddy or even dotster. If you want your business opportunity at the internet to grow and burgeon, try a reliable name like anhosting.

Wordpress Plugin: Fitness Indicator version 1.0 R

November 27th, 2006

Plugin Name: Fitness Indicator (contributed by samiha esha)
Version: 1.0
Description:
Let your visitor know about your physical condition, your fitness indicator will show your up to date physical status. if you were sick, and how u are recovering you can display over your fitness indicator.
10% fitness means you are too sick similarly 100% fitness means you are in good mood with good fitness.

Usages:
in your template use <? show_health_meter()?>

Download link: here

fitness indicator in action:
wordpress template integration

administration panel

Download link: here

PHP Fragment cache solution R

September 26th, 2006

PHP Fragment cache solution Sometimes we want to cache a part php script rather caching the whole page.

dyanmic_updated_part.gif

For example above right side list is updating after 1 hour, so why not cache it for 1 hour rather shooting database for each request.

My illustration will cache a time stamp (so when can verify when it was updated lastly):

Read the rest of this blog »

Posted in PHP, tutorial

For old Fan!!! R

September 17th, 2006

hi, i am getting some request for my previous “ajax-new-color” theme.

i have changed my file system thats why previous files are lost.

please find out this attachment…. ajax-new-color
thank u :D

Posted in PHP

upload_max_filesize related problem R

January 3rd, 2006

I have heard and faced this problem several times when i need to upload more than 2M file using my php script….

-> “upload_max_filesize” is one php.ini defined property… this propery limits the maximum uploadable content size…

-< !>- PHP manual described this propery as “PHP_INI_PERDIR”…

-< ?>- PHP_INI_PREDIR means “Entry can be set in php.ini, .htaccess or httpd.conf “…

-

- You need to upload more than 2M file

->> You can do it just change php.ini “upload_max_filesize” propery …
-- Example: upload_max_filesize=100M

-

- When you dont have php.ini access….

->> You can change this property using .htaccess file…

(#)File: .htaccess
————————————————–
php_value upload_max_filesize 100m
————————————————–

*NOTE: (—-) this signed used for indicating start and end of file…

Save in your php web root directory…

Thats it…

Thank you

NHM Tanveer Hossain KHan (h asan)
http://hasan.we4tech.com [Ajax based WP template]

http://www.somewherein.net
http://www.somewherein.net/blog

Posted in PHP

PHP and PHP R

August 27th, 2005

Corporate world always concerned about scalable/reliable/secure solution. Java EE, .NET these are the common example among other successful technologies. “Java EE”, “.NET” seems the relief for many enterprise solution..

V(ery). Big echo system always backup these technologies.. Java EE and .NET has introduced many coolest success factors for the real enterprise solution.

Microsoft considers the general developer, they provide strong RAD tool. Microsoft never belief “…developer by born get the programming skill…”. They promote people to be programmer…

Open source technologies are supporting many corporate for a long time.. corporate world rather wasting money they are selecting the right technologies.

“Open source” brought a baby named “PHP” which is proving its simplicity in every steps. From the early stage PHP is injecting the RAD (Rapid Application Development) concept. At the beginning, PHP was aimed only for form processing. Day by day many Open minded and talented developers are contributing to give maturity in PHP.

PHP is gradually developing the best community among other technology communities. PHP has become the standard for web site development. Many successful web application for instance CMS, Blog engine etc.. are freely available. Which gives more pleasure in development rather starting from scratch.

“PHP is RAD”..
You may ask why RAD, because when you close your eyes you can see some visual components and you know them as RAD.. PHP is RAD from the sense of its simple API set.

PHP requires very minimum development time that’s exactly appropriate for Agile methodology. TDD (Test Driven Development) is now the common practice in PHP based development.

…..it is a long journey…
When OS brought the great technology “PHP”, OS developers really have foreseen. PHP started with very silly coding standard… because PHP is moving with small step. Two guys redesigned the PHP engine and they shaped PHP as a multi featured scripting environment for Web application development. People never mind to checkout the FUN.. PHP gave the FUN… that’s brought PHP as the number one web development environment.
……..
Many developers interested to develop PHP based web application… PHP became more mature.. whenever its main contributors determined on its strength.. PHP gained more strength when contributors released Zend Engine II…. OOP programming is now more strength that’s really great fun for other OOP developers…

That’s why I enrolled myself…..
Hasan
http://hasan.we4tech.com

Posted in PHP

Password protected secure web application with design patterns R

August 22nd, 2005

Probably you want to develop password protected web application using PHP…

Make a php driven web site with FrontController approach….

I think FrontController pattern has good solution for this type of problem…

If you follow Front Controller pattern u can easily restrict any pages
from your centralize controller….
for more reading
http://www.phppatterns.com/index.php/article/articleview/81/1/1/

let’s see how Front Controller will work with your user security

public interface PHPFrontController extends BaseController {
// …..
public function isAccessible();
public function getCurrentView();
// …..
}

etc…. you can fun…..

for instance while your index.php is running…
it will cosider:

// Singleton pattern
$frontController=PHPFrontController::newInstance();

// check valid user….
if($frontController->isAccessible()) {
View::generateView(View::HTML, $frontController->getCurrentView());
}

……..

For more details information…

// example implementation of accessible method....
public function isAccessible() {
$state=false;

try {
// you can check through your DAO
if($userDAO->isValideUser(
HttpRequest::getParam(
array(”txtUser”,”txtPassword”))))
$state=true;

}
catch($frameworkException ) {}

return $state;
}

Thank you..

Posted in PHP

AJAX( ASync. JavaScript And XML) R

June 18th, 2005

Why do you need AJAX instead of your traditional Web designing/Developing method??
———————————————————————————————
How easy to surf one 100% data driven web site? I think its not so easy because it take too time to load every module when I press each link. That’s the great problem. You need only details information or one article but your web browser is loading every modules as well as graphics. How funny things. You want to know one’s name but he will give you all of his history as well as his Grand grand father information @-)

I think some people have some know how about game programming or animation programming etc… or concept..

Think you are designing one game or something animation related program. But when your end user run this game every time (for refreshing each motion) it loads every module to represent changes. Can you imagine how disgusting program that will??..

That’s the same thing happing for web technologies. You are developing one 100% data driven web site but how its possible without refreshing web pages to load dynamic content??

Of course its one great question.
To resolve this problem you should use the concept of AJAX.

Read the rest of this blog »