[thelist] RE: functions tip (was RE: Spammers' keywords)

Ben Gustafson Ben_Gustafson at lionbridge.com
Mon Feb 11 11:16:02 CST 2002


This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
--
[ Picked text/plain from multipart/alternative ]

> <tip type="programming" author="benji">
> Use functions whenever you can. I know this is a simple idea, but it's
> amazing how many times I have tidied up my code and made it
> easier to read
> and document by 'functionising' common code fragments.
> </tip>
>
> benji
> inchima.com

+1 to that, benji, and with another:

<tip type = "Programming" author="Ben G.">
Use objects or classes (depending on your language's support) whenever you
can. They provide the clean-code benefits of "functionizing", with the added
benefits of increased readability. In JavaScript, for example, you can use
custom objects to package the attributes and methods that refer to an
object, thus making references to that object logical, compact and easy to
read.

Example:

<SCRIPT LANGUAGE="JavaScript1.2"><!--
	var ben = new person("Ben Gustafson", "Webmaster", false);
	if (!ben.hasCoffee)
		ben.getCoffee();
	alert(ben.name + " has coffee? " + ben.hasCoffee + "!");

	function person(name, occupation, hasCoffee)
	{
		this.name = name;	// attribute of person object
		this.occupation = occupation;
		this.hasCoffee = hasCoffee;
		this.getCoffee = getCoffee; // method of person object
	}

	function getCoffee()
	{
		this.hasCoffee = true;
	}
//--></SCRIPT>

</tip>



More information about the thelist mailing list