Javascript by Example #13

JavaScript by Example:

JavaScript by Example:

Example 1.1 A simple JavaScript program Run View Source
Example 1.2 An HTML form with a JavaScript event handlerdefined Run View Source
Example 1.3 Estimating Your Taxes with JavaScript Run View Source
Example 6.1 Defining JavaScript Functions ViewSource
Example 6.2 Using Functions as Data ViewSource
Example 6.3 Checking for the Correct Number of Arguments View Source
Example 6.4 A Multi-Argument max() Function ViewSource
Example 6.5 Creating and Initializing an Array ViewSource
Example 6.6 Using Static Variables ViewSource
Example 7.1 A Rectangle Object Constructor Function ViewSource
Example 7.2 Defining and Invoking a Method ViewSource
Example 7.3 Defining Methods in a Constructor ViewSource
Example 7.4 Defining a Class with a Prototype Object View Source
Example 7.5 Defining instance/class variables and methods View Source
Example 7.6 Defining and using the valueOf() method ViewSource
Example 8.1 An Array Constructor ViewSource
Example 9.1 Copying, Passing, and Comparing by Value View Source
Example 9.2 Copying, Passing, and Comparing by Reference View Source
Example 9.3 References Themselves are Passed by Value ViewSource
Example 9.4 Are Strings and Functions Compared by Value orReference? Run View Source
Example 9.5 The assign() Method ViewSource
Example 10.1 A Simple JavaScript Program in an HTML FileRun View Source
Example 12.1 Using the alert(), confirm() and prompt() methodsRun View Source
Example 12.2 Displaying and Reporting JavaScript Errors witha Run View Source
Example 12.3 Displaying a link’s destination in the statusline Run View Source
Example 12.4 A digital clock in the status line Run View Source
Example 12.5 Creating an invisible frame ViewSource
Example 12.6 Dynamically creating and animating framesRun View Source
Example 13.1 Getting Browser Version Information ViewSource
Example 13.2 Extracting Arguments from a URL ViewSource
Example 13.3 A Navigation Bar Using the History and LocationObjects View Source
Example 14.1 Creating a plain-text document Run View Source
Example 14.2 Generating XBM images with JavaScript Run View Source
Example 14.3 Listing the Links in a Document ViewSource
Example 14.4 A Random Hypertext Link ViewSource
Example 14.5 Invoking Methods of a Java applet from JavaScript View Source
Example 15.1 A Utility Class for Working with CookiesRun View Source
Example 16.1 An Animation Using Image Replacement Run View Source
Example 16.2 An Animation Using the onLoad() Event HandlerRun View Source
Example 16.3 Implementing a Toggle Button with Image ReplacementRun View Source
Example 17.1 An HTML Form Containing all Form ElementsRun View Source
Example 17.2 Performing Form Validation Run View Source
Example 18.1 A Script Hidden from Old Browsers ViewSource
Example 18.2 Displaying a Message on non-JavaScript Browsers View Source
Example 18.3 Loading a JavaScript-based page only if JavaScriptis supported View Source
Example 18.4 Displaying a Message with View Source
Example 18.5 Displaying a Message for Browsers that do notSupport JavaScript 1.1 View Source
Example 18.6 A Web Page to test for JavaScript Compatibility View Source
Example 18.7 Displaying a Failure Message when using View Source
Example 19.1 Scripting the built-in Java classes Run View Source
Example 19.2 Controlling an Applet with JavaScript ViewSource
Example 19.3 Controlling a Plug-in from JavaScript Run View Source
Example 19.4 Using JavaScript from an Applet Method ViewSource
Example 19.5 A Java OutputStream for Displaying HTML in aBrowser Window View Source

Reference:

http://examples.oreilly.com/jscript2/ From: http://sitestree.com/?p=4740
Categories:13
Tags:
Post Data:2013-05-05 02:36:52

    Shop Online: <a href='https://www.ShopForSoul.com/' target='new' rel="noopener">https://www.ShopForSoul.com/</a>
    (Big Data, Cloud, Security, Machine Learning): Courses: <a href='http://Training.SitesTree.com' target='new' rel="noopener"> http://Training.SitesTree.com</a> 
    In Bengali: <a href='http://Bangla.SaLearningSchool.com' target='new' rel="noopener">http://Bangla.SaLearningSchool.com</a>
    <a href='http://SitesTree.com' target='new' rel="noopener">http://SitesTree.com</a>
    8112223 Canada Inc./JustEtc: <a href='http://JustEtc.net' target='new' rel="noopener">http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning) </a>
    Shop Online: <a href='https://www.ShopForSoul.com'> https://www.ShopForSoul.com/</a>
    Medium: <a href='https://medium.com/@SayedAhmedCanada' target='new' rel="noopener"> https://medium.com/@SayedAhmedCanada </a>

Handling Checkbox arrays with Javascript::GetElementsByName:XHTML supported #13

The following code demonstrates how to handle checkboxes with javascript. Note the names of all check boxes are same myInput[]. It could also be myInput. Both works as an array to contain the controls’ values. I prefer myInput[] as you can handle this control in PHP as an array. If you use $arr=$_POST[‘myInput’], $arr will contain the values of the controls.

Note the use of getElementsByName(). It is easy to manipulate javascript controls using this name. You do not need to send a value/control to the function. And in many times, document.myform.control, does not work right, specially if you want to main XHTML standard[i need to check more on this]. getElementById is also very useful. You may use getElementById for most times, but with checkbox arrays getElementsByName is better choice.

Also, note that when a form is submitted only the values of the checked check boxes are submitted to the server. You may wish to use hidden controls to keep the values, so that all values are submitted and based on the checked/non-checked you can ..control your work

                        function getElements()            {           var x=document.getElementsByName("myInput[]");              alert(x.length);            alert(x[0].value);              alert(x[1].value);              alert(x[2].value);              }         10 
20
30

Want to check how the code works, check below

function getElements() { var x=document.getElementsByName(“myInput[]”); alert(x.length); alert(x[0].value); alert(x[1].value); alert(x[2].value); }10
20
30

From: http://sitestree.com/?p=4735
Categories:13
Tags:
Post Data:2009-12-11 16:22:24

    Shop Online: <a href='https://www.ShopForSoul.com/' target='new' rel="noopener">https://www.ShopForSoul.com/</a>
    (Big Data, Cloud, Security, Machine Learning): Courses: <a href='http://Training.SitesTree.com' target='new' rel="noopener"> http://Training.SitesTree.com</a> 
    In Bengali: <a href='http://Bangla.SaLearningSchool.com' target='new' rel="noopener">http://Bangla.SaLearningSchool.com</a>
    <a href='http://SitesTree.com' target='new' rel="noopener">http://SitesTree.com</a>
    8112223 Canada Inc./JustEtc: <a href='http://JustEtc.net' target='new' rel="noopener">http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning) </a>
    Shop Online: <a href='https://www.ShopForSoul.com'> https://www.ShopForSoul.com/</a>
    Medium: <a href='https://medium.com/@SayedAhmedCanada' target='new' rel="noopener"> https://medium.com/@SayedAhmedCanada </a>

How to implement multiple tab webpages in Ajax and Javascript #13

The following two examples will demonstrate how to use javascript and/or ajax to implement multiple tab webpages.http://www.dynamicdrive.com/dynamicindex17/ajaxtabscontent/

http://www.barelyfitz.com/projects/tabber/example2.html

I have used the first code extensively in one of my applications.The basic ides is: you define a div section. On each click, you change the contents of that div section using Ajax concepts. You could also use Iframe and JavaScript. However, if the pages under different tabs require information from the server side then Ajax is the right choice

From: http://sitestree.com/?p=4733
Categories:13
Tags:
Post Data:2011-08-18 06:20:43

    Shop Online: <a href='https://www.ShopForSoul.com/' target='new' rel="noopener">https://www.ShopForSoul.com/</a>
    (Big Data, Cloud, Security, Machine Learning): Courses: <a href='http://Training.SitesTree.com' target='new' rel="noopener"> http://Training.SitesTree.com</a> 
    In Bengali: <a href='http://Bangla.SaLearningSchool.com' target='new' rel="noopener">http://Bangla.SaLearningSchool.com</a>
    <a href='http://SitesTree.com' target='new' rel="noopener">http://SitesTree.com</a>
    8112223 Canada Inc./JustEtc: <a href='http://JustEtc.net' target='new' rel="noopener">http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning) </a>
    Shop Online: <a href='https://www.ShopForSoul.com'> https://www.ShopForSoul.com/</a>
    Medium: <a href='https://medium.com/@SayedAhmedCanada' target='new' rel="noopener"> https://medium.com/@SayedAhmedCanada </a>

What you really need to learn in Javascript? #13

What you really need to learn in Javascript? 
1. Where you can place JavaScript codes?
Anywhere in the web-pages, ideally in the header section, or in an external file. If you keep javascript codes in an external file, the codes will be re-usable from different web-pages2. Some basic programming:



document.write('Hello World');

This will only be displayed in javascript enabled browsers.

document.write('Page Requiring Javascript');

3. Variables and their scopes

var hello = 'Hello World';
document.write(hello);

var mynum = 5;
var smokes = false;
var riches = null;
var today = new Date;
Example use of variables:

var questions = 'If you have any questions about this
please email me.';
document.write(questions);

Another block can refer to questions variables without reassigning the value

document.write(questions);

variables declared within a function is recognized only withing that function. Variables declared outside of a function is recognized anywhere in the webpage within javascript code from the declaration place.
4. Operators
Assignment operators

var rich = 5000;
var lotsOfMoney = 100000;
rich = lotsOfMoney;
document.write(rich);

Arithmetic and concatenation operators
five = two + three;
profit = income - expenses;
income = sales * price;
payment = total / instalments;
option = randnum % choices;
b = ++a;
c = a++;
d = --a;
e = a--;
Combination of Operators like c/c++
joy += happiness;
price -= discount;
capital *= interest;
pie /= slices;
options %= choice;
Example use:

var singlePrice = 8;
var bulkPrice = singlePrice * 9;
document.write('

Buy our Widgets $'
+singlePrice+' for one, $'+bulkPrice+' for ten

');

5. Comparing Variables, Logical statements

var red = 5;
var blue = 3;
var match = null;
if (red == blue)
{
match = 'equal';
}
else
{
match = 'unequal';
}
document.write(red + ' and ' + blue + ' are ' + match);

Other comparison operators:
if (red > blue)
if (red >= blue)
if (red < blue)
if (red < = blue)
if (red != blue)
Combining more than one comparison
if ((red == blue) || (red == green))

var red = 5;
var blue = 3;
var green = 3;
var match = null;
if ((red == blue) && (red == green))
{
match = 'equal';
}
else
{
purple = 'unequal';
}
document.write(red + ' and ' + blue + ' are ' + match);

Comparison in short
red == blue ? match = 'equal' : match = 'unequal';
instead of
if (red == blue)
{
match = 'equal';
}
else
{
match = 'unequal';
}
Example Use:


var discPrice = 25;
var regPrice = 25;
var discount = regPrice - discPrice;
if (discount > 0)
document.write('

Save $'+discount+ ' off the normal price of $' +regPrice+ 'now only $'+discPrice+'.

');
else
document.write('

Buy now at our regular cheap price of $' + regPrice+'.

' );

6. Switch statement in Javascript, very similar to C/C++/Java
use switch instead of multiple if/else if

var red = 1;
var result = null;
switch (red)
{
case 1: result = 'one'; break;
case 2: result = 'two'; break;
default: result = 'unknown';
}
document.write(result);

Example:

var message = 0;
switch (message)
{
case 1: document.write('Merry Christmas'); break;
case 2: document.write('Happy New Year'); break;
case 3: document.write('Happy Easter'); break;
case 4: document.write('Happy Holidays'); break;
default: document.write('Welcome');
}

7. Function
Defining a function
function myCode()
{
document.write('Hello World');
}
calling a function
myCode()
Example:
function displayMessage()
{
switch (message)
{
case 1: document.write('Merry Christmas'); break;
case 2: document.write('Happy New Year'); break;
case 3: document.write('Happy Easter'); break;
case 4: document.write('Happy Holidays'); break;
default: document.write('Welcome');
}
}
var message = 0;
displayMessage();
parameter passing
function writeSentence(argument1,argument2)
{
document.write('The '+argument1+' is '+argument2+'.
');
}
var a = 'table';
var b = 'chair';
var c = 'red';
var d = 'blue';
writeSentence(a,c);
writeSentence(b,c);
b = 'other ' + b;
writeSentence(b,d);
writeSentence('table',b); //passing the value directly
Example:
function displayMessage(m)
{
switch (m)
{
case 1: document.write('Merry Christmas'); break;
case 2: document.write('Happy New Year'); break;
case 3: document.write('Happy Easter'); break;
case 4: document.write('Happy Holidays'); break;
default: document.write('Welcome');
}
}
In Javascript functions can also return values
function validField(fld)
{
if (fld == '') return false;
return true;
}
function validField(fld)
{
return (fld != '');
}
How to receive returned values and process
document.write(myField + ' is ');
if (!validField(myField))
{
document.write('not ');
}
document.write('empty');
8. Alert and confirm
alert('Alert Message');
Will display a message box with the message. Very useful in debugging javascript applications.
use confirm(), when you need user agreement on an issue. like:
if (confirm('Select a button'))
{
alert('You selected OK');
}
else
{
alert('You selected Cancel');
}
9. comments
// Scrolling Ad Javascript
// copyright 3rd September 2004, by Stephen Chapman
// permission to use this Javascript on your web page is
// granted provided that all of the code in this script (including
// these comments) is used without any alteration
or
/* Scrolling Ad Javascript
copyright 3rd September 2004, by Stephen Chapman
permission to use this Javascript on your web page is
granted provided that all of the code in this script (including
these comments) is used without any alteration */

10. Debugging JavaScript
Test in different browsers like IE, Mozilla, Firfox, Netscape
Enable Javascript and script debugging
Script debugging usually reside under tools menu under browsing or web development sub-options

Using alert to check variable values or if you can reach to a particular point of your code
use bookmarklets, these are small scripts that can be used as plug in into browsers to provide error information.
Use firebug in firefox, also use error console under tools menu to debug javascript error.
Visual interdev provides Javascript debugging you may also enable external debugging by such programs
11. External javascript

You can place all of your javascript codes to an external file. and use the file scripts/functions from any webpage.
You just need to provide a reference to that external file.
You can provide reference as follows:
<script language="javascript" type="text/javascript"
src="hello.js">

Note: do not include any or in the external file.
12. Using tag: this tag may help you to provide some information to the visitors
when javascript is disabled or not supported by the browsers.

document.write('Hello Javascript World');

Hello World Without Javascript

This page uses Javascript. Your browser either
doesn't support Javascript or you have it turned off.
To see this page as it is meant to appear please use
a Javascript enabled browser.

13. Objects and properties in Javascript
var strlen = myField.length;
var str = mynum.toString();
function theLetter(num)
{
var str = 'abcdefghijklmnopqustuvwxyz';
return str.substr(num-1,1);
}
document.write(theLetter(5));
14. Arrays in Javascript
var myArray = new Array();
var myArray = new Array('message one',
'message two','message three');
document.write(myArray[0]);
myArray[3] = 'message four';
function displayMessage(m)
{
var greeting = new Array('Welcome','Merry Christmas',
'Happy New Year','Happy Easter','Happy Holidays');
if (m greeting.length) m = 0;
document.write(greeting[m]);
}
15. Loops
for (var i=0; i<10; i++)
{
document.write(i);
}
var x = 0;
while (x<10)
{
document.write(x);
x++;
}
var x = 12;
do
{
document.write(x);
x++;
} while (x<10)
16. Date and Time in Javascript
//current date
var myDate = new Date;
myDate.setDate(15);
myDate.setMonth(3); // January = 0
myDate.setFullYear(2006);
myDate.setDate(myDate.getDate()+7);

From: http://sitestree.com/?p=4732
Categories:13
Tags:
Post Data:2011-02-12 19:58:06

    Shop Online: <a href='https://www.ShopForSoul.com/' target='new' rel="noopener">https://www.ShopForSoul.com/</a>
    (Big Data, Cloud, Security, Machine Learning): Courses: <a href='http://Training.SitesTree.com' target='new' rel="noopener"> http://Training.SitesTree.com</a> 
    In Bengali: <a href='http://Bangla.SaLearningSchool.com' target='new' rel="noopener">http://Bangla.SaLearningSchool.com</a>
    <a href='http://SitesTree.com' target='new' rel="noopener">http://SitesTree.com</a>
    8112223 Canada Inc./JustEtc: <a href='http://JustEtc.net' target='new' rel="noopener">http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning) </a>
    Shop Online: <a href='https://www.ShopForSoul.com'> https://www.ShopForSoul.com/</a>
    Medium: <a href='https://medium.com/@SayedAhmedCanada' target='new' rel="noopener"> https://medium.com/@SayedAhmedCanada </a>

Little note on CVS #14

CVS Version Control System:

  • There will be a repository where the files(of different versions) will be saved. Its just like a central storage of files. You will need a software that will provide this facility.
  • You also need a client software. The client software can get copies of the repository files. After, modifying clients can update/save to the repository. While saving from clients steps are needed so that version control is maintained [no inconsistency arises].
  • Linux has command based clients, also there are CVs servers for linux. Download them from the internet.
  • I have some experience of using WinCVS – a windows based CVS client.
  • In WinCVS, You can set command line parameters using Admin->commandline parameters option. You have to provide some information like: CVS server, repository path, username, password.
  • In WinCVS, you can checkout files from the CVS server using the checkout option from the menu (tools). You need to specify local path to store the files. Also, you need to mention some information like the previous step (or you can copy a string from the previous step and provide here):

From: http://sitestree.com/?p=4777
Categories:14
Tags:
Post Data:2008-07-13 11:35:14

    Shop Online: <a href='https://www.ShopForSoul.com/' target='new' rel="noopener">https://www.ShopForSoul.com/</a>
    (Big Data, Cloud, Security, Machine Learning): Courses: <a href='http://Training.SitesTree.com' target='new' rel="noopener"> http://Training.SitesTree.com</a> 
    In Bengali: <a href='http://Bangla.SaLearningSchool.com' target='new' rel="noopener">http://Bangla.SaLearningSchool.com</a>
    <a href='http://SitesTree.com' target='new' rel="noopener">http://SitesTree.com</a>
    8112223 Canada Inc./JustEtc: <a href='http://JustEtc.net' target='new' rel="noopener">http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning) </a>
    Shop Online: <a href='https://www.ShopForSoul.com'> https://www.ShopForSoul.com/</a>
    Medium: <a href='https://medium.com/@SayedAhmedCanada' target='new' rel="noopener"> https://medium.com/@SayedAhmedCanada </a>

Quick reference to sub version’s repository administration commands #14

Sub version administration related commands

  • svnlook:to examine various revisions and transactions in a repository. No change is made by this command. Just analyze near to commit or committed changes.
  • svnadmin:
  • ls repos: check sub version repository
  • svnadmin create “path to repository”
  • svnadmin create –fs-type fsfs /path/to/repos: creates repository that uses FSFS file system
  • svnadmin create –fs-type bdb /path/to/repos : creates repository that uses BDB in the backend
  • ls repos/hooks/: This displays the hooks for the repository. Hooks are scripts that run in different repository events. You can write or use third party hooks as well
  • svnadmin help: provides information on how to use svnadmin command
  • svnadmin –version
  • Available subcommands of svnadmin: crashtest, create,deltify
  • svnlook info /path/to/repos:
  • svnlook info /path/to/repos -r 19
  • svnlook youngest /path/to/repos: younest revision number
  • svnsync: Creates read only mirror of the sub version repository
  • svnsync:subcommands:synchronize (sync),copy-revprops,help (?, h)
  • svnadmin setlog myrepos newlog.txt -r 388 :
  • svnadmin lstxns myrepos:outlisted transactions
  • svnadmin rmtxns myrepos `svnadmin lstxns myrepos`
  • svnadmin list-unused-dblogs /path/to/repos: display unused log files
  • svnadmin list-unused-dblogs /path/to/repos | xargs rm: restore disk space from unused log files
  • svnadmin recover /path/to/repos : BDB repository recover
  • svnadmin dump myrepos > dumpfile: dump svn repository
  • svnadmin load newrepos < dumpfile :effectively replays those dumped revisions into the targetrepository for that operation
  • svnadmin create newrepos
    $ svnadmin dump myrepos | svnadmin load newrepos
  • svnadmin hotcopy /path/to/repos /path/to/repos-backup:backup repository
  • $ svnadmin hotcopy –clean-logs /path/to/bdb-repos /path/to/bdb-repos-backup

Sub version repository strategies

You may create three folders: trunk, branch, tags. Trunk->main development, bracnch->to create various named brances of the main trunc, tags->collection of free snapshots that are created and destroyed

Subversion repository may make use of backend database like berkeley DB or it can just use a file system like FSFS

From: http://sitestree.com/?p=4736
Categories:14
Tags:
Post Data:2008-05-30 10:27:31

    Shop Online: <a href='https://www.ShopForSoul.com/' target='new' rel="noopener">https://www.ShopForSoul.com/</a>
    (Big Data, Cloud, Security, Machine Learning): Courses: <a href='http://Training.SitesTree.com' target='new' rel="noopener"> http://Training.SitesTree.com</a> 
    In Bengali: <a href='http://Bangla.SaLearningSchool.com' target='new' rel="noopener">http://Bangla.SaLearningSchool.com</a>
    <a href='http://SitesTree.com' target='new' rel="noopener">http://SitesTree.com</a>
    8112223 Canada Inc./JustEtc: <a href='http://JustEtc.net' target='new' rel="noopener">http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning) </a>
    Shop Online: <a href='https://www.ShopForSoul.com'> https://www.ShopForSoul.com/</a>
    Medium: <a href='https://medium.com/@SayedAhmedCanada' target='new' rel="noopener"> https://medium.com/@SayedAhmedCanada </a>

Introduction to software version control #14

Version control software are used to maintain and create different versions of the same software. It allows parallel software development and facilitates collaboration and team based software development. In addition, it provides features so that integration among different people’s work can be made. Also, tracking back to an early stage of the software becomes possible.

Why do software companies need it? Let you may develop a software and release it. Then you may still want to keep the same version along with improving it. You want a new improved version for future release. You may want further improvements, hence further versions. Also, in internal development, several programmer may collaborate to work on different/same parts in parallel. Then they can merge them to a merged and stable/workable/reliable stage. They can create a version of the software at this moment. If any crap happens, they can come back to this stable version and continue improving/re-developing.

Among the version control software some popular ones are CVS,Subversion,Visual Source Safe, and Starteam. I personally have some working experience with starteam and subversion. In subversion, there is a repository of codes. Subversion is totally file system and directory based. Repository needs to be well designed. It may contain all projects in one folder or all projects in separate folder. Both has advantages and disadvantages. A good approach may be using them in mix. Keep similar projects in one folder and create separate folders for non-similar projects. As there are some administrative tasks that can be applied to the root folder/a folder thats why grouping may be need as project requirements may be different. It also affects the version number, usually version number is increased by the base/root folder. Still the increase may be because of another project.

A project usually contains two folders. Trunc folder is the main development folder. Branch folder is the new version/working folder.Each programmer usually creates his own copy of the branch and work on the copy. Sometimes, programmers merge their changes and keep it to the branch. While anyone wants to save his work to the branch, it will display the changes made to the same file by other programmers. Then he/she can decide how to integrate all changes into the file. The branch changes may be transferred to the main trunc folder to create a new version of the software.

From: http://sitestree.com/?p=4734
Categories:14
Tags:
Post Data:2007-07-15 12:24:21

    Shop Online: <a href='https://www.ShopForSoul.com/' target='new' rel="noopener">https://www.ShopForSoul.com/</a>
    (Big Data, Cloud, Security, Machine Learning): Courses: <a href='http://Training.SitesTree.com' target='new' rel="noopener"> http://Training.SitesTree.com</a> 
    In Bengali: <a href='http://Bangla.SaLearningSchool.com' target='new' rel="noopener">http://Bangla.SaLearningSchool.com</a>
    <a href='http://SitesTree.com' target='new' rel="noopener">http://SitesTree.com</a>
    8112223 Canada Inc./JustEtc: <a href='http://JustEtc.net' target='new' rel="noopener">http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning) </a>
    Shop Online: <a href='https://www.ShopForSoul.com'> https://www.ShopForSoul.com/</a>
    Medium: <a href='https://medium.com/@SayedAhmedCanada' target='new' rel="noopener"> https://medium.com/@SayedAhmedCanada </a>

Some random information regarding commenting your code #15

Some random information regarding commenting your codeIs commenting required? or suggested?Simply yes. Always comment your code.Note: Commenting is always useful only when it is done right. Bad commenting is worse than not commenting.What should you write in the comment?--------------------------------------Write why the section of the code is required.write-What does the code section do.Write it in plain english. Don't use any language syntax.If you do not find what to write...then better check did you understand the requirements of the assignment/section? Also check, are you sure your design/logic will work? Also, why your design/code will work -- did you really understand. Do not write how the code works in comments but write why and what it does.Why commenting is useful?-------------------------Commenting will make your code more readable to others.Commenting will help others to find out the right section of code to edit/modify. Also, understand the purpose of the program as well as sequence of the logic.It will also help you to review/(work on) your own code laterIn many or most companies, you will hardly write codes from scratch, you have to work on others' code. So commenting is required.Random:--------Use a clear commenting style - easy to editComment as you go/code - do not leave commenting until the end of writing codeIf you are worried that commenting will reduce performance...rather comment and use tools to create release codes without commentscomment above the code -- not at the rightvariable declaration may have comment at the rightif you use any special trick that is not ovbious from the code -- write it in comments [a trick:we can do a right shift for divide by 2]Comments and Pseudocode Programming Practice (PPP)----------------------------------------------------Comments and Pseudocode Programming Practice (PPP) go hand in hand.what is Pseudocode Programming Practice (PPP)?1. Write your logic in plain english may be as a paragraph2. Decompose it step by step into as fine grained that it can not be decomposed further. (The paragraph will be converted to lines of steps)3. comment each line/step (use comment sign like //)4. After each line/comment write the corresponding code.

From: http://sitestree.com/?p=4786
Categories:15
Tags:
Post Data:2011-10-01 17:18:46

    Shop Online: <a href='https://www.ShopForSoul.com/' target='new' rel="noopener">https://www.ShopForSoul.com/</a>
    (Big Data, Cloud, Security, Machine Learning): Courses: <a href='http://Training.SitesTree.com' target='new' rel="noopener"> http://Training.SitesTree.com</a> 
    In Bengali: <a href='http://Bangla.SaLearningSchool.com' target='new' rel="noopener">http://Bangla.SaLearningSchool.com</a>
    <a href='http://SitesTree.com' target='new' rel="noopener">http://SitesTree.com</a>
    8112223 Canada Inc./JustEtc: <a href='http://JustEtc.net' target='new' rel="noopener">http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning) </a>
    Shop Online: <a href='https://www.ShopForSoul.com'> https://www.ShopForSoul.com/</a>
    Medium: <a href='https://medium.com/@SayedAhmedCanada' target='new' rel="noopener"> https://medium.com/@SayedAhmedCanada </a>

Good Coding Style in PHP + Other languages #15

Style 1.1: Use proper indenting

while ($x < $z) {    if ($a == 1)    {       echo 'A was equal to 1';  }   else    {       if ($b == 2)        {           //do something      }       else        {           //do something else     }   }}

1.2
while ($x < $z) { if ($a == 1) { echo 'A was equal to 1'; } else { if ($b == 2) { //do something } else { //do something else } }}

Style 2.1: Properly indent conditional statements. Always use braces, it will make later additions of more statements easier.

while ($x < $z) {   if ($a == 1)    {       echo 'A was equal to 1';  }   else    {       if ($b == 2)        {           //do something      }       else        {           //do something else     }   }}

Style 2.2

while ($x < $z) {   if ($a == 1) {      echo 'A was equal to 1';  } else {        if ($b == 2) {          //do something      } else {            //do something else     }   }}

3.1 Function Calls
No space between function names and parenthesis.

   $var = myFunction($x, $y);

3.2 Function declarations

Use braces properly, give meaningful names to the parameters, always return values from functions. Avoid printing/echoing inside functions.

function myFunction($province, $city = ''){   //indent all code inside here   return $result;}   

4. Use comments before a function. Also, use comments before a block [especially if it uses some difficult to understand logic]use PHPDoc style comments that may work like Javadoc to create documentation from your source files

/** *  short description of function * *   Optional more detailed description. * * @param $paramName - type - brief purpose *  @param ... *    ... *   @return type and description */

5. Use include_once or require_once instead of include or require to include a file that contains common variables, functions, classes.
6. Php tags: always use

  

instead of

  

7. to enclose strings use single quote ‘ ‘ rather than double quotes ” “. Try to use . to concate string variables. You can use double quote and put variables inside.

 $associative_array['name']; $var='My String';   $var2='Very... long... string... ' . $var . ' ...more string... ';  $sql="INSERT INTO mytable (field) VALUES ('$var')";

8. Follow some conventions for variable and function names

  • Class name start with uppercase letter. Each word should start with uppercase letter
  • Variable and function name may start with lower case letters. Then each word will start with a capital letter
  • give meaningful names to variables and functions
  • Do not make them too lengthy. I prefer less than 12-15 character names
  • Do not abbreviate words in variable or function names. Use $url or $articleUrl as variable names, not $URL or $articleURL as

From: http://sitestree.com/?p=4741
Categories:15
Tags:
Post Data:2006-08-07 13:22:40

    Shop Online: <a href='https://www.ShopForSoul.com/' target='new' rel="noopener">https://www.ShopForSoul.com/</a>
    (Big Data, Cloud, Security, Machine Learning): Courses: <a href='http://Training.SitesTree.com' target='new' rel="noopener"> http://Training.SitesTree.com</a> 
    In Bengali: <a href='http://Bangla.SaLearningSchool.com' target='new' rel="noopener">http://Bangla.SaLearningSchool.com</a>
    <a href='http://SitesTree.com' target='new' rel="noopener">http://SitesTree.com</a>
    8112223 Canada Inc./JustEtc: <a href='http://JustEtc.net' target='new' rel="noopener">http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning) </a>
    Shop Online: <a href='https://www.ShopForSoul.com'> https://www.ShopForSoul.com/</a>
    Medium: <a href='https://medium.com/@SayedAhmedCanada' target='new' rel="noopener"> https://medium.com/@SayedAhmedCanada </a>

IT Startup ideas #155

Some IT startup ideas

From: http://sitestree.com/?p=5338
Categories:155
Tags:
Post Data:2008-12-19 06:44:39

    Shop Online: <a href='https://www.ShopForSoul.com/' target='new' rel="noopener">https://www.ShopForSoul.com/</a>
    (Big Data, Cloud, Security, Machine Learning): Courses: <a href='http://Training.SitesTree.com' target='new' rel="noopener"> http://Training.SitesTree.com</a> 
    In Bengali: <a href='http://Bangla.SaLearningSchool.com' target='new' rel="noopener">http://Bangla.SaLearningSchool.com</a>
    <a href='http://SitesTree.com' target='new' rel="noopener">http://SitesTree.com</a>
    8112223 Canada Inc./JustEtc: <a href='http://JustEtc.net' target='new' rel="noopener">http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning) </a>
    Shop Online: <a href='https://www.ShopForSoul.com'> https://www.ShopForSoul.com/</a>
    Medium: <a href='https://medium.com/@SayedAhmedCanada' target='new' rel="noopener"> https://medium.com/@SayedAhmedCanada </a>