<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Software engineering &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/software-engineering/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>on web development</description>
	<lastBuildDate>Tue, 13 Feb 2018 08:18:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.3</generator>
	<item>
		<title>PHP Strings Don&#8217;t Need Quotes</title>
		<link>/2012/04/26/php-strings-dont-need-quotes/</link>
		<comments>/2012/04/26/php-strings-dont-need-quotes/#comments</comments>
		<pubDate>Thu, 26 Apr 2012 13:52:53 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Cross-platform software]]></category>
		<category><![CDATA[Curly bracket programming languages]]></category>
		<category><![CDATA[PHP interpreter]]></category>
		<category><![CDATA[PHP programming language]]></category>
		<category><![CDATA[Procedural programming languages]]></category>
		<category><![CDATA[Programming language]]></category>
		<category><![CDATA[Scripting languages]]></category>
		<category><![CDATA[Social Issues]]></category>
		<category><![CDATA[Software engineering]]></category>
		<category><![CDATA[String]]></category>

		<guid isPermaLink="false">/?p=3017</guid>
		<description><![CDATA[I bet you didn&#8217;t know that PHP strings don&#8217;t need quotes! Indeed PHP developers work with strings with either single or double quotes, but actually in some cases you don&#8217;t need them. PHP by Book Here&#8217;s how PHP developer declare a string, which is something very common in any programming language. $my_var = 'hello world'; &#8230; <a href="/2012/04/26/php-strings-dont-need-quotes/" class="more-link">Continue reading <span class="screen-reader-text">PHP Strings Don&#8217;t Need Quotes</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2011/07/12/a-javascript-trick-you-should-know/" rel="bookmark" title="A JavaScript Trick You Should Know">A JavaScript Trick You Should Know </a></li>
<li><a href="/2010/03/10/php-if-else-endif-statements/" rel="bookmark" title="PHP if-else-endif Statements">PHP if-else-endif Statements </a></li>
<li><a href="/2011/08/18/powerful-php-less-known-string-manipulation/" rel="bookmark" title="Powerful PHP: Less Known String Manipulation">Powerful PHP: Less Known String Manipulation </a></li>
<li><a href="/2010/06/10/json-and-zend-framework-zend_json/" rel="bookmark" title="JSON and Zend Framework? &#8211; Zend_Json">JSON and Zend Framework? &#8211; Zend_Json </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>I bet you didn&#8217;t know that PHP strings don&#8217;t need quotes! Indeed PHP developers work with strings with either single or double quotes, but actually in some cases you don&#8217;t need them.</p>
<h2>PHP by Book</h2>
<p>Here&#8217;s how PHP developer declare a string, which is something very common in any programming language.</p>
<pre lang="PHP">
$my_var = 'hello world';
// or
$my_var = "hello world";
</pre>
<h2>PHP Tricks</h2>
<p>What if you do the following:</p>
<pre lang="PHP">
echo hello;
</pre>
<p>That appears to be correct &#8230; Well, it&#8217;s not absolutely correct. You&#8217;ll be &#8220;noticed&#8221;.</p>
<pre lang="PHP">
// Notice: Use of undefined constant hello
echo hello;
</pre>
<p>However if you disable error reporting, the code will be completely fine.</p>
<pre lang="PHP">
error_reporting(0);

// no problem now
echo hello;
</pre>
<h2>Variations</h2>
<p>What follows from the thing above is that you can use strings without quotes:</p>
<pre lang="PHP">
// hello
echo hello;

// hello world (concatenated)
echo hello . ' world';

// helloworld
echo hello . world;
</pre>
<p>However you can&#8217;t have spaces and most of the &#8220;special&#8221; symbols.</p>
<pre lang="PHP">
// syntax error
echo hello world;

// syntax error
echo hello!;
</pre>
<h2>Final Words</h2>
<p>Although you can do this in PHP, that is completely wrong. The code becomes more difficult to read and understand. In the second place you can miss a $ sign in front of a variable declaration and thus the PHP interpreter will assume this is a string. So disable error reporting isn&#8217;t so great sometimes.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2011/07/12/a-javascript-trick-you-should-know/" rel="bookmark" title="A JavaScript Trick You Should Know">A JavaScript Trick You Should Know </a></li>
<li><a href="/2010/03/10/php-if-else-endif-statements/" rel="bookmark" title="PHP if-else-endif Statements">PHP if-else-endif Statements </a></li>
<li><a href="/2011/08/18/powerful-php-less-known-string-manipulation/" rel="bookmark" title="Powerful PHP: Less Known String Manipulation">Powerful PHP: Less Known String Manipulation </a></li>
<li><a href="/2010/06/10/json-and-zend-framework-zend_json/" rel="bookmark" title="JSON and Zend Framework? &#8211; Zend_Json">JSON and Zend Framework? &#8211; Zend_Json </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2012/04/26/php-strings-dont-need-quotes/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>JavaScript Performance: for vs. while</title>
		<link>/2012/01/24/javascript-performance-for-vs-while/</link>
		<comments>/2012/01/24/javascript-performance-for-vs-while/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 14:20:05 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Control flow]]></category>
		<category><![CDATA[firebug]]></category>
		<category><![CDATA[Increment]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[Software engineering]]></category>
		<category><![CDATA[software/hardware]]></category>
		<category><![CDATA[Technology/Internet]]></category>
		<category><![CDATA[While loop]]></category>

		<guid isPermaLink="false">/?p=2635</guid>
		<description><![CDATA[JavaScript Loops If you have read some preformance tests on JavaScript loops, you may have heard that &#8220;while&#8221; is faster than &#8220;for&#8221;. However the question is how faster is &#8220;while&#8221;? Here are some results, but first let&#8217;s take a look on the JavaScript code. The for experiment console.time('for'); for (var i = 0; i < &#8230; <a href="/2012/01/24/javascript-performance-for-vs-while/" class="more-link">Continue reading <span class="screen-reader-text">JavaScript Performance: for vs. while</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/02/02/firebugs-console-time-accuracy/" rel="bookmark" title="Firebug&#8217;s console.time() accuracy">Firebug&#8217;s console.time() accuracy </a></li>
<li><a href="/2010/02/02/profiling-javascript-with-firebug-console-profile-console-time/" rel="bookmark" title="Profiling JavaScript with Firebug. console.profile() &#038; console.time()!">Profiling JavaScript with Firebug. console.profile() &#038; console.time()! </a></li>
<li><a href="/2010/08/11/quick-look-at-javascript-objects/" rel="bookmark" title="Quick Look at JavaScript Objects">Quick Look at JavaScript Objects </a></li>
<li><a href="/2010/06/02/detecting-pressed-key-with-e-which-in-javascript/" rel="bookmark" title="Detecting Pressed Key with e.which in JavaScript">Detecting Pressed Key with e.which in JavaScript </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>JavaScript Loops</h2>
<p>If you have read some preformance tests on JavaScript loops, you may have heard that &#8220;while&#8221; is faster than &#8220;for&#8221;. However the question is how faster is &#8220;while&#8221;? Here are some results, but first let&#8217;s take a look on the JavaScript code. </p>
<h4>The <strong>for</strong> experiment</h4>
<pre lang="javascript">
console.time('for');
for (var i = 0; i < 10000000; i++) {
	i / 2;
}
console.timeEnd('for');
</pre>
<h4>The <strong>while</strong> experiment</h4>
<pre lang="javascript">
console.time('while');
var i = 0;
while (i++ < 10000000) {
	i / 2;
}
console.timeEnd('while');
</pre>
<p>Note - these tests are performed and measured with Firebug on Firefox.</p>
<h2>Results</h2>
<p>It's a fact, that you'll get different results as many times as you run this snippet. It depends also on the enviroment and software/hardware specs. That is why I performed them 10 times and then I took the average value. Here are the values of my performance tests. Note that both <strong>for</strong> and <strong>while</strong> perform 10,000,000 iterations.</p>
<p><iframe width='576' height='263' frameborder='0' src='https://docs.google.com/spreadsheet/pub?hl=en_US&#038;hl=en_US&#038;key=0Avxdu4aY4-UGdDktZEJHYUh5RWFLd1prOG52dDdTdUE&#038;single=true&#038;gid=0&#038;output=html&#038;widget=true'></iframe></p>
<h2>And the Winner Is</h2>
<p><strong>While</strong> is the winner with an average result of 83.5 milliseconds, while "for" result is 88 average milliseconds.</p>
<p>As the diagram bellow shows, <strong>the while loop is slightly faster</strong>. However we should be aware that these performance gains are significant for large number of iterations!</p>
<figure id="attachment_2668" style="width: 600px" class="wp-caption alignnone"><a href="/wp-content/uploads/2012/01/chart_1-1.png"><img src="/wp-content/uploads/2012/01/chart_1-1.png" alt="JavaScript Performance: for vs. while" title="JavaScript Performance: for vs. while" width="600" height="371" class="size-full wp-image-2668" srcset="/wp-content/uploads/2012/01/chart_1-1.png 600w, /wp-content/uploads/2012/01/chart_1-1-300x185.png 300w" sizes="(max-width: 600px) 100vw, 600px" /></a><figcaption class="wp-caption-text">JavaScript Performance: for vs. while</figcaption></figure>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/02/02/firebugs-console-time-accuracy/" rel="bookmark" title="Firebug&#8217;s console.time() accuracy">Firebug&#8217;s console.time() accuracy </a></li>
<li><a href="/2010/02/02/profiling-javascript-with-firebug-console-profile-console-time/" rel="bookmark" title="Profiling JavaScript with Firebug. console.profile() &#038; console.time()!">Profiling JavaScript with Firebug. console.profile() &#038; console.time()! </a></li>
<li><a href="/2010/08/11/quick-look-at-javascript-objects/" rel="bookmark" title="Quick Look at JavaScript Objects">Quick Look at JavaScript Objects </a></li>
<li><a href="/2010/06/02/detecting-pressed-key-with-e-which-in-javascript/" rel="bookmark" title="Detecting Pressed Key with e.which in JavaScript">Detecting Pressed Key with e.which in JavaScript </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2012/01/24/javascript-performance-for-vs-while/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Object Cloning and Passing by Reference in PHP</title>
		<link>/2011/10/27/object-cloning-and-passing-by-reference-in-php/</link>
		<comments>/2011/10/27/object-cloning-and-passing-by-reference-in-php/#comments</comments>
		<pubDate>Thu, 27 Oct 2011 14:25:17 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Clone]]></category>
		<category><![CDATA[Cloning]]></category>
		<category><![CDATA[Comparison of programming languages]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Curly bracket programming languages]]></category>
		<category><![CDATA[Java programming language]]></category>
		<category><![CDATA[PHP programming language]]></category>
		<category><![CDATA[Procedural programming languages]]></category>
		<category><![CDATA[Scripting languages]]></category>
		<category><![CDATA[Software engineering]]></category>

		<guid isPermaLink="false">/?p=2408</guid>
		<description><![CDATA[In PHP everything&#8217;s a reference! I&#8217;ve heard it so many times in my practice. No, these words are too strong! Let&#8217;s see some examples. Passing Parameters by Reference Clearly when we pass parameters to a function it&#8217;s not by reference. How to check this? Well, like this. function f($param) { $param++; } $a = 5; &#8230; <a href="/2011/10/27/object-cloning-and-passing-by-reference-in-php/" class="more-link">Continue reading <span class="screen-reader-text">Object Cloning and Passing by Reference in PHP</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2012/08/17/its-not-true-that-php-arrays-are-copied-by-value/" rel="bookmark" title="It&#8217;s Not True that PHP Arrays are Copied by Value">It&#8217;s Not True that PHP Arrays are Copied by Value </a></li>
<li><a href="/2012/04/26/php-strings-dont-need-quotes/" rel="bookmark" title="PHP Strings Don&#8217;t Need Quotes">PHP Strings Don&#8217;t Need Quotes </a></li>
<li><a href="/2011/10/20/some-notes-on-the-object-oriented-model-of-php/" rel="bookmark" title="Some Notes on the Object-oriented Model of PHP">Some Notes on the Object-oriented Model of PHP </a></li>
<li><a href="/2010/06/11/friday-algorithms-quicksort-difference-between-php-and-javascript/" rel="bookmark" title="Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript">Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>In <a href="/category/php/" title="PHP at stoimen.com">PHP </a>everything&#8217;s a reference! I&#8217;ve heard it so many times in my practice. No, these words are too strong! Let&#8217;s see some examples.<br />
<figure id="attachment_2432" style="width: 480px" class="wp-caption alignnone"><a href="/wp-content/uploads/2011/10/ampersand.jpg"><img src="/wp-content/uploads/2011/10/ampersand.jpg" alt="Passing by reference in PHP can be tricky!" title="ampersand" width="480" height="480" class="size-full wp-image-2432" srcset="/wp-content/uploads/2011/10/ampersand.jpg 480w, /wp-content/uploads/2011/10/ampersand-150x150.jpg 150w, /wp-content/uploads/2011/10/ampersand-300x300.jpg 300w" sizes="(max-width: 480px) 100vw, 480px" /></a><figcaption class="wp-caption-text">Some developers think that everything&#039;s passed by reference in PHP.</figcaption></figure></p>
<h2>Passing Parameters by Reference</h2>
<p>Clearly when we pass parameters to a function it&#8217;s not by reference. How to check this? Well, like this.</p>
<pre lang="PHP">
function f($param)
{
	$param++;
}

$a = 5;
f($a);

echo $a;
</pre>
<p>Now the value of $a equals 5. If it were passed by reference, it would be 6. With a little change of the code we can get it.</p>
<pre lang="PHP">
function f(&$param)
{
	$param++;
}

$a = 5;
f($a);

echo $a;
</pre>
<p>Now the variable&#8217;s value is 6. </p>
<p>So far, so good. Now what about copying objects?<br />
<span id="more-2408"></span></p>
<h2>Objects: A Copy or a Cloning?</h2>
<p>We can check whether by assigning an object to a variable a reference or a copy of the object is passed.</p>
<pre lang="PHP">
class C
{
	public $myvar = 10;
}

$a = new C();
$b = $a;

$b->myvar = 20;

// 20, not 10
echo $a->myvar;
</pre>
<p>The last line outputs 20! This makes it clear. By assigning an object to a variable PHP pass its reference. To make a copy there&#8217;s another approach. We need to change $b = $a, to $b = clone $a;</p>
<pre lang="PHP" escaped="true">
class C
{
	public $myvar = 10;
}

$a = new C();
$b = clone $a;

$b->myvar = 20;

// 10
echo $a->myvar;
</pre>
<h2>Arrays by Reference</h2>
<p>What about arrays? What if I assign an array to a variable?</p>
<pre lang="PHP">
$a = array(20);

$b = $a;
$b[0] = 30;

var_dump($a);
</pre>
<p>What do you think is the value of $a[0]? Well, the answer is: 20! So $b is a copy of the array &#8220;a&#8221;. Instead you should assign explicitly its reference to make &#8220;b&#8221; point to &#8220;a&#8221;.</p>
<pre lang="PHP">
$a = array(20);

$b = &$a;
$b[0] = 30;

var_dump($a);
</pre>
<p>Now $a[0] equals 30!</p>
<p>I think this could be useful!</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2012/08/17/its-not-true-that-php-arrays-are-copied-by-value/" rel="bookmark" title="It&#8217;s Not True that PHP Arrays are Copied by Value">It&#8217;s Not True that PHP Arrays are Copied by Value </a></li>
<li><a href="/2012/04/26/php-strings-dont-need-quotes/" rel="bookmark" title="PHP Strings Don&#8217;t Need Quotes">PHP Strings Don&#8217;t Need Quotes </a></li>
<li><a href="/2011/10/20/some-notes-on-the-object-oriented-model-of-php/" rel="bookmark" title="Some Notes on the Object-oriented Model of PHP">Some Notes on the Object-oriented Model of PHP </a></li>
<li><a href="/2010/06/11/friday-algorithms-quicksort-difference-between-php-and-javascript/" rel="bookmark" title="Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript">Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2011/10/27/object-cloning-and-passing-by-reference-in-php/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Does JavaScript undefined Equals undefined?</title>
		<link>/2011/10/21/does-javascript-undefined-equals-undefined/</link>
		<comments>/2011/10/21/does-javascript-undefined-equals-undefined/#comments</comments>
		<pubDate>Fri, 21 Oct 2011 11:36:01 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Curly bracket programming languages]]></category>
		<category><![CDATA[ecmascript]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[Procedural programming languages]]></category>
		<category><![CDATA[Scripting languages]]></category>
		<category><![CDATA[Software engineering]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>
		<category><![CDATA[typeof]]></category>
		<category><![CDATA[undefined]]></category>

		<guid isPermaLink="false">/?p=2416</guid>
		<description><![CDATA[Weird JS As you know sometimes JavaScript can be weird. Let&#8217;s see the following example and let&#8217;s try to answer the question: does &#8220;undefined&#8221; equals &#8220;undefined&#8221;. What do I mean? First take a look at the following code. var a; var b = undefined; // alerts "false" alert(b == a); Both a and b are &#8230; <a href="/2011/10/21/does-javascript-undefined-equals-undefined/" class="more-link">Continue reading <span class="screen-reader-text">Does JavaScript undefined Equals undefined?</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/02/12/how-to-detect-a-variable-existence-in-javascript/" rel="bookmark" title="How to detect a variable existence in JavaScript?">How to detect a variable existence in JavaScript? </a></li>
<li><a href="/2011/07/28/oop-javascript-accessing-public-methods-in-private-methods/" rel="bookmark" title="OOP JavaScript: Accessing Public Methods in Private Methods">OOP JavaScript: Accessing Public Methods in Private Methods </a></li>
<li><a href="/2010/05/24/javascript-objects-coding-style/" rel="bookmark" title="JavaScript Objects Coding Style">JavaScript Objects Coding Style </a></li>
<li><a href="/2011/05/30/object-oriented-javascript-inheritance/" rel="bookmark" title="Object Oriented JavaScript: Inheritance">Object Oriented JavaScript: Inheritance </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>Weird JS</h2>
<figure id="attachment_2419" style="width: 480px" class="wp-caption alignnone"><a href="/wp-content/uploads/2011/10/question.mark_.jpg"><img src="/wp-content/uploads/2011/10/question.mark_.jpg" alt="Does &quot;undefined&quot; equals &quot;undefined&quot;?" title="question.mark" width="480" height="624" class="size-full wp-image-2419" srcset="/wp-content/uploads/2011/10/question.mark_.jpg 480w, /wp-content/uploads/2011/10/question.mark_-230x300.jpg 230w" sizes="(max-width: 480px) 100vw, 480px" /></a><figcaption class="wp-caption-text">Does JavaScript &quot;undefined&quot; equals &quot;undefined&quot;?</figcaption></figure>
<p>As you know sometimes JavaScript can be weird. Let&#8217;s see the following example and let&#8217;s try to answer the question: does &#8220;undefined&#8221; equals &#8220;undefined&#8221;. What do I mean?</p>
<p>First take a look at the following code.</p>
<pre lang="javascript">
var a;
var b = undefined;

// alerts "false"
alert(b == a);
</pre>
<p>Both <strong>a</strong> and <strong>b</strong> are <strong>undefined</strong>, but they are <strong>NOT</strong> equal. Now let&#8217;s see where it can become a problem.</p>
<p>We have an object with one member variable that is not defined.</p>
<pre lang="javascript">
var f1 = function()
{
	this.myvar;
};

var obj1 = new f1();
</pre>
<p>Now you&#8217;d like to know whether the object &#8220;b&#8221; has the property &#8220;myvar&#8221;. There are lots of examples online, but what&#8217;s the right way?<br />
<span id="more-2416"></span></p>
<h2>Wrong</h2>
<p>Appearantly the value of b.myvar should be undefined.</p>
<pre lang="javascript">
alert(obj1.myvar); // undefined
</pre>
<p>But that doesn&#8217;t mean that it is the same value if the object was declared this way:</p>
<pre lang="javascript">
var f2 = function()
{
	this.myvar = undefined;
};

var obj2 = new f2();
</pre>
<p>This is a completely different thing. Why? In the first case if we try to check whether the property myvar belongs to obj1 we can go wrong with:</p>
<pre lang="javascript">
if (obj1.myvar) // false
</pre>
<p>This is false simply because obj1.myvar is undefined</p>
<pre lang="javascript">
if (obj2.myvar) // false
</pre>
<p>Again is false, because obj2.myvar is undefined.</p>
<p>The same thing happen when using the other &#8220;famous&#8221; approach.</p>
<pre lang="javascript">
if (typeof obj1['myvar'] != 'undefined') // false
if (typeof obj2['myvar'] != 'undefined') // false
</pre>
<p>Clearly this is not the right answer, becase even it is undefined <strong>myvar </strong>belongs to <strong>obj2</strong>!</p>
<h2>Right</h2>
<p>Now let&#8217;s try with <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/hasOwnProperty" title="hasOwnProperty on MDN" target="_blank">hasOwnProperty</a> supported by almost every modern browser.</p>
<pre lang="javascript">
if (obj1.hasOwnProperty('myvar')); // false
if (obj2.hasOwnProperty('myvar')); // true
</pre>
<p>Here you can see that when the member variable is explicitly defined as &#8220;undefined&#8221; the object &#8220;has the property&#8221; and hasOwnProperty returns true. Yet again, &#8220;undefined&#8221; does not always equal to &#8220;undefined&#8221;.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/02/12/how-to-detect-a-variable-existence-in-javascript/" rel="bookmark" title="How to detect a variable existence in JavaScript?">How to detect a variable existence in JavaScript? </a></li>
<li><a href="/2011/07/28/oop-javascript-accessing-public-methods-in-private-methods/" rel="bookmark" title="OOP JavaScript: Accessing Public Methods in Private Methods">OOP JavaScript: Accessing Public Methods in Private Methods </a></li>
<li><a href="/2010/05/24/javascript-objects-coding-style/" rel="bookmark" title="JavaScript Objects Coding Style">JavaScript Objects Coding Style </a></li>
<li><a href="/2011/05/30/object-oriented-javascript-inheritance/" rel="bookmark" title="Object Oriented JavaScript: Inheritance">Object Oriented JavaScript: Inheritance </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2011/10/21/does-javascript-undefined-equals-undefined/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Some Notes on the Object-oriented Model of PHP</title>
		<link>/2011/10/20/some-notes-on-the-object-oriented-model-of-php/</link>
		<comments>/2011/10/20/some-notes-on-the-object-oriented-model-of-php/#comments</comments>
		<pubDate>Thu, 20 Oct 2011 15:08:15 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[abstract classes]]></category>
		<category><![CDATA[Abstract type]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Class]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Education]]></category>
		<category><![CDATA[experiment]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[iheritance]]></category>
		<category><![CDATA[Interfaces]]></category>
		<category><![CDATA[Java programming language]]></category>
		<category><![CDATA[Method]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[Object-oriented programming]]></category>
		<category><![CDATA[php 5]]></category>
		<category><![CDATA[php class definition]]></category>
		<category><![CDATA[php experiment]]></category>
		<category><![CDATA[php tutorial]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[Polymorphism in object-oriented programming]]></category>
		<category><![CDATA[Software design patterns]]></category>
		<category><![CDATA[Software engineering]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[Virtual function]]></category>

		<guid isPermaLink="false">/?p=2401</guid>
		<description><![CDATA[PHP 5 introduces interfaces and abstract classes. To become a little clearer, let us see their definitions. Interfaces Object interfaces allow you to create code which specifies which methods a class must implement, without having to define how these methods are handled. Interfaces are defined using the interface keyword, in the same way as a &#8230; <a href="/2011/10/20/some-notes-on-the-object-oriented-model-of-php/" class="more-link">Continue reading <span class="screen-reader-text">Some Notes on the Object-oriented Model of PHP</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2011/05/30/object-oriented-javascript-inheritance/" rel="bookmark" title="Object Oriented JavaScript: Inheritance">Object Oriented JavaScript: Inheritance </a></li>
<li><a href="/2011/07/28/oop-javascript-accessing-public-methods-in-private-methods/" rel="bookmark" title="OOP JavaScript: Accessing Public Methods in Private Methods">OOP JavaScript: Accessing Public Methods in Private Methods </a></li>
<li><a href="/2011/10/27/object-cloning-and-passing-by-reference-in-php/" rel="bookmark" title="Object Cloning and Passing by Reference in PHP">Object Cloning and Passing by Reference in PHP </a></li>
<li><a href="/2011/11/14/php-dont-call-the-destructor-explicitly/" rel="bookmark" title="PHP: Don&#8217;t Call the Destructor Explicitly">PHP: Don&#8217;t Call the Destructor Explicitly </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>PHP 5 introduces interfaces and abstract classes. To become a little clearer, let us see their definitions.</p>
<h2>Interfaces</h2>
<blockquote><p>Object interfaces allow you to create code which specifies which methods a class must implement, without having to define how these methods are handled.<br />
Interfaces are defined using the interface keyword, in the same way as a standard class, but without any of the methods having their contents defined.<br />
All methods declared in an interface must be public, this is the nature of an interface. </p>
<p>To implement an interface, the implements operator is used. All methods in the interface must be implemented within a class; failure to do so will result in a fatal error. Classes may implement more than one interface if desired by separating each interface with a comma. </p></blockquote>
<h2>Abstract Classes</h2>
<blockquote><p>PHP 5 introduces abstract classes and methods. Classes defined as abstract may not be instantiated, and any class that contains at least one abstract method must also be abstract. Methods defined as abstract simply declare the method&#8217;s signature &#8211; they cannot define the implementation.</p>
<p>When inheriting from an abstract class, all methods marked abstract in the parent&#8217;s class declaration must be defined by the child; additionally, these methods must be defined with the same (or a less restricted) visibility. For example, if the abstract method is defined as protected, the function implementation must be defined as either protected or public, but not private. Furthermore the signatures of the methods must match, i.e. the type hints and the number of required arguments must be the same. This also applies to constructors as of PHP 5.4. Before 5.4 constructor signatures could differ. </p></blockquote>
<h2>Some Cases</h2>
<p>Now let&#8217;s do a quick experiment. According to the definition of interfaces we can define an interface and than an abstract class can implement this interface.<br />
<span id="more-2401"></span></p>
<pre lang="PHP">
interface A
{
	public function a();
}

abstract class B implements A
{
	public function a()
	{
		return 10;
	}
}
</pre>
<p>However the abstract class cannot be instantiated so we need to extend it.</p>
<pre lang="PHP">
interface A
{
	public function a();
}

abstract class B implements A
{
	public function a()
	{
		return 10;
	}
}

class C extends B
{
	...
}
</pre>
<p>In the first place is completely OK to define an abstract class that does not contain any abstract method. TUsually if a class has one or more abstract methods <em>(Methods defined as abstract simply declare the method&#8217;s signature &#8211; they cannot define the implementation, according to the docs)</em>, it must be defined as abstract. But we can also define an abstract class which has no abstract methods.</p>
<pre lang="PHP">
abstract class B
{
	public function a()
	{
		return 5;
	}
}

class C extends B
{
	public function a()
	{
		return 10;
	}
}

$c = new C();
echo $c->a();
</pre>
<p>OK then what would happen if we had an interface that is implemented by an abstract class, which in turn is extended by a given class. First of all if a class implements an interface, even if it is an abstract class, it must implement all methods defined in the interface. So if the predefined method in the abstract class is marked as abstract, it would result into a fatal error.</p>
<pre lang="PHP">
interface A
{
	public function a();
}

abstract class B implements A
{
	abstract public function a();
}

class C extends B
{
	public function a()
	{
		return 5;
	}
}

$c = new C();
echo $c->a();
</pre>
<p>This is perfectly logical, because in fact each method of the interface must be implemented by his children.</p>
<p><em>&#8220;All methods in the interface must be implemented within a class; failure to do so will result in a fatal error.&#8221;<br />
</em><br />
Fine, but we can have abstract classes with no abstract methods, let&#8217;s try this:</p>
<pre lang="PHP">
interface A
{
	public function a();
}

abstract class B implements A
{
	public function a()
	{
		return 10;
	}
}

class C extends B
{
	public function a()
	{
		return 5;
	}
}

$c = new C();
echo $c->a();
</pre>
<p>This code is working and the result is the returned value from C::a(). However class B is abstract so let&#8217;s go even further. Let&#8217;s define an abstract method, different from the method B::a().</p>
<pre lang="PHP">
interface A
{
	public function a();
}

abstract class B implements A
{
	public function a()
	{
		return 10;
	}
	
	abstract public function b();
}

class C extends B
{
	public function a()
	{
		return 5;
	}
	
	public function b()
	{
		return "hello world!";
	}
}

$c = new C();
echo $c->a();
echo $c->b();
</pre>
<p>Now there&#8217;s a fatal error. Why?</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2011/05/30/object-oriented-javascript-inheritance/" rel="bookmark" title="Object Oriented JavaScript: Inheritance">Object Oriented JavaScript: Inheritance </a></li>
<li><a href="/2011/07/28/oop-javascript-accessing-public-methods-in-private-methods/" rel="bookmark" title="OOP JavaScript: Accessing Public Methods in Private Methods">OOP JavaScript: Accessing Public Methods in Private Methods </a></li>
<li><a href="/2011/10/27/object-cloning-and-passing-by-reference-in-php/" rel="bookmark" title="Object Cloning and Passing by Reference in PHP">Object Cloning and Passing by Reference in PHP </a></li>
<li><a href="/2011/11/14/php-dont-call-the-destructor-explicitly/" rel="bookmark" title="PHP: Don&#8217;t Call the Destructor Explicitly">PHP: Don&#8217;t Call the Destructor Explicitly </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2011/10/20/some-notes-on-the-object-oriented-model-of-php/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Powerful PHP: Less Known String Manipulation</title>
		<link>/2011/08/18/powerful-php-less-known-string-manipulation/</link>
		<comments>/2011/08/18/powerful-php-less-known-string-manipulation/#comments</comments>
		<pubDate>Thu, 18 Aug 2011 14:01:51 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Data types]]></category>
		<category><![CDATA[Hello world program]]></category>
		<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[Software engineering]]></category>
		<category><![CDATA[String]]></category>

		<guid isPermaLink="false">/?p=2343</guid>
		<description><![CDATA[Yet another thing that&#8217;s great in PHP is the power you have when doing some string manipulation/operation. Here&#8217;s something that is really useful, but I think it remains a bit unknown. Let&#8217;s imagine you need to take the first (or whatever) character of a string. Most developers go to the obvious: $str = 'hello world'; &#8230; <a href="/2011/08/18/powerful-php-less-known-string-manipulation/" class="more-link">Continue reading <span class="screen-reader-text">Powerful PHP: Less Known String Manipulation</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/08/27/php-what-is-more-powerful-than-list/" rel="bookmark" title="PHP: What is More Powerful Than list()">PHP: What is More Powerful Than list() </a></li>
<li><a href="/2011/07/12/a-javascript-trick-you-should-know/" rel="bookmark" title="A JavaScript Trick You Should Know">A JavaScript Trick You Should Know </a></li>
<li><a href="/2010/09/17/5-php-string-functions-you-need-to-know/" rel="bookmark" title="5 PHP String Functions You Need to Know">5 PHP String Functions You Need to Know </a></li>
<li><a href="/2010/08/31/php-what-is-more-powerful-than-list-perhaps-extract/" rel="bookmark" title="PHP: What is More Powerful Than list() &#8211; Perhaps extract()">PHP: What is More Powerful Than list() &#8211; Perhaps extract() </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>Yet another thing that&#8217;s great in PHP is the power you have when doing some string manipulation/operation. Here&#8217;s something that is really useful, but I think it remains a bit unknown. Let&#8217;s imagine you need to take the first (or whatever) character of a string. Most developers go to the obvious:</p>
<pre lang="PHP">
$str = 'hello world';
echo substr($str, 0, 1); // outputs "h"
</pre>
<p>But here&#8217;s something better and cleaner.</p>
<pre lang="PHP">
echo $str{0}; // outputs "h"
</pre>
<p>This code chunk return the first character of $str, but it can be used with the same success for any other character of the string. In my opinion this is more cleaner and its really syntactically self documented.</p>
<p>This approach can be useful when trying to check whether the first symbol for instance is &#8220;?&#8221; or &#8220;/&#8221;.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/08/27/php-what-is-more-powerful-than-list/" rel="bookmark" title="PHP: What is More Powerful Than list()">PHP: What is More Powerful Than list() </a></li>
<li><a href="/2011/07/12/a-javascript-trick-you-should-know/" rel="bookmark" title="A JavaScript Trick You Should Know">A JavaScript Trick You Should Know </a></li>
<li><a href="/2010/09/17/5-php-string-functions-you-need-to-know/" rel="bookmark" title="5 PHP String Functions You Need to Know">5 PHP String Functions You Need to Know </a></li>
<li><a href="/2010/08/31/php-what-is-more-powerful-than-list-perhaps-extract/" rel="bookmark" title="PHP: What is More Powerful Than list() &#8211; Perhaps extract()">PHP: What is More Powerful Than list() &#8211; Perhaps extract() </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2011/08/18/powerful-php-less-known-string-manipulation/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>OOP JavaScript: Accessing Public Methods in Private Methods</title>
		<link>/2011/07/28/oop-javascript-accessing-public-methods-in-private-methods/</link>
		<comments>/2011/07/28/oop-javascript-accessing-public-methods-in-private-methods/#comments</comments>
		<pubDate>Thu, 28 Jul 2011 12:05:42 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[Accessing Private]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Class]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Curly bracket programming languages]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[Object-oriented programming]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[private]]></category>
		<category><![CDATA[public]]></category>
		<category><![CDATA[Scripting languages]]></category>
		<category><![CDATA[Software engineering]]></category>
		<category><![CDATA[Subroutine]]></category>

		<guid isPermaLink="false">/?p=2339</guid>
		<description><![CDATA[As you know in JavaScript when you define a variable with the special word &#8220;var&#8221; the scope of this variable is within the function. So when you simply wite &#8220;var a = 5&#8221; the variable named &#8220;a&#8221; has a global scope and can be accessed in any function in the global scope. var a = &#8230; <a href="/2011/07/28/oop-javascript-accessing-public-methods-in-private-methods/" class="more-link">Continue reading <span class="screen-reader-text">OOP JavaScript: Accessing Public Methods in Private Methods</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2011/05/30/object-oriented-javascript-inheritance/" rel="bookmark" title="Object Oriented JavaScript: Inheritance">Object Oriented JavaScript: Inheritance </a></li>
<li><a href="/2011/10/20/some-notes-on-the-object-oriented-model-of-php/" rel="bookmark" title="Some Notes on the Object-oriented Model of PHP">Some Notes on the Object-oriented Model of PHP </a></li>
<li><a href="/2010/08/11/quick-look-at-javascript-objects/" rel="bookmark" title="Quick Look at JavaScript Objects">Quick Look at JavaScript Objects </a></li>
<li><a href="/2010/03/09/what-make-javascript-closures-work/" rel="bookmark" title="What make JavaScript closures work?">What make JavaScript closures work? </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>As you know in JavaScript when you define a variable with the special word &#8220;var&#8221; the scope of this variable is within the function. So when you simply wite &#8220;var a = 5&#8221; the variable named &#8220;a&#8221; has a global scope and can be accessed in any function in the global scope. </p>
<pre lang="javascript">
var a = 5;

function f() { return a; } // returns 5
</pre>
<p>Thus f will return the value of &#8220;a&#8221; which equals to 5. You can also change the value of the global variable in the function body.</p>
<pre lang="javascript">
var a = 5;
function f() { a = 10; return a; }
console.log(a); // equals to 10
</pre>
<p>Now after we call the function f the value of &#8220;a&#8221; will equal to 10. This is because we reference the global variable &#8220;a&#8221; into the function body without using the keyword &#8220;var&#8221;. This means that if you put the &#8220;var&#8221; keyword the variable &#8220;a&#8221; inside the function body is no longer the same variable as the variable defined outside the body. It becames &#8220;local&#8221; and it&#8217;s visible only inside the function.<br />
<span id="more-2339"></span></p>
<h2>Objects &#038; JavaScript</h2>
<p>Actually in JavaScript functions can be also objects. Any variable defined with the &#8220;var&#8221; keyword becomes private, because it&#8217;s only visible inside the function body, while by using the &#8220;this&#8221; keyword we can define global variables visible outside the function body. Let&#8217;s see na example.</p>
<pre lang="javascript">
var f = function() 
{
	var a = 10;
	this.b = 5;
}

var myfunc = new f();
myfunc.a; // is undefined because a is private
myfunc.b; // equals to 5 because b is public
</pre>
<h2>Public and Private Methods in JavaScript</h2>
<p>As you may know in JS you can define functions inside other functions. Actually this is how you can define classes in JavaScript.</p>
<pre lang="javascript">
var myClass = function() 
{
	var f = function() {
		return 10;
	}
}
</pre>
<p>But this in fact defines a local (private) function into myClass and we cannot access it from the outside world. Here&#8217;s a fully functional class with one public and one private method.</p>
<pre lang="javascript">
var myClass = function()
{
	// public method
	this.a = function() {
		return 10;
	}
	
	// private method
	var b = function() {
		return 5;
	}
}

var c = new myClass();
c.a(); // will return 10
c.b(); // is undefined, because is private
</pre>
<h2>Accessing Private Methods from Public Methods</h2>
<p>Easily we can access private methods from public ones.</p>
<pre lang="javascript">
var myClass = function()
{
	// public method
	this.a = function() {
		return b();
	}
	
	// private method
	var b = function() {
		return 5;
	}
}
</pre>
<p>However accessing public mtehods in private ones is more difficult. That&#8217;s because we cannot use &#8220;this&#8221; into the private methods, just because &#8220;this&#8221; refers to the private method<br />
itself and not to the global method, which is &#8220;myClass&#8221; in our case.</p>
<pre lang="javascript">
var myClass = function()
{
	// public method
	this.a = function() {
		return 10;
	}
	
	// private method
	var b = function() {
		return this.a(); // this will result in an error
	}
}
</pre>
<h2>Accessing Public Methods from Private Methods</h2>
<p>To access public methods in private methods you need to define a variable that points to the global &#8220;this&#8221; object.</p>
<pre lang="javascript">
var myClass = function()
{
	var self = this; 
	
	// public method
	this.a = function() {
		return 10;
	}
	
	// private method
	var b = function() {
		return self.a(); // this will return 10
	}
}
</pre>
<p>This variable gives you the bridge between private methods and global &#8220;this&#8221; pointer.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2011/05/30/object-oriented-javascript-inheritance/" rel="bookmark" title="Object Oriented JavaScript: Inheritance">Object Oriented JavaScript: Inheritance </a></li>
<li><a href="/2011/10/20/some-notes-on-the-object-oriented-model-of-php/" rel="bookmark" title="Some Notes on the Object-oriented Model of PHP">Some Notes on the Object-oriented Model of PHP </a></li>
<li><a href="/2010/08/11/quick-look-at-javascript-objects/" rel="bookmark" title="Quick Look at JavaScript Objects">Quick Look at JavaScript Objects </a></li>
<li><a href="/2010/03/09/what-make-javascript-closures-work/" rel="bookmark" title="What make JavaScript closures work?">What make JavaScript closures work? </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2011/07/28/oop-javascript-accessing-public-methods-in-private-methods/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>A JavaScript Trick You Should Know</title>
		<link>/2011/07/12/a-javascript-trick-you-should-know/</link>
		<comments>/2011/07/12/a-javascript-trick-you-should-know/#comments</comments>
		<pubDate>Tue, 12 Jul 2011 14:49:46 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Brace notation]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Concatenation]]></category>
		<category><![CDATA[Data types]]></category>
		<category><![CDATA[Formal languages]]></category>
		<category><![CDATA[heredoc]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[JavaScript syntax]]></category>
		<category><![CDATA[js solution]]></category>
		<category><![CDATA[possible solution]]></category>
		<category><![CDATA[Software engineering]]></category>
		<category><![CDATA[String]]></category>

		<guid isPermaLink="false">/?p=2333</guid>
		<description><![CDATA[JavaScript Strings You should know that in JavaScript you cannot simply write a multilined code chunk, i.e. something like this: var str = 'hello world'; This will result in an error, which can be a problem when you deal with large strings. Imagine a string containing some HTML that should be injected via innerHTML. Now &#8230; <a href="/2011/07/12/a-javascript-trick-you-should-know/" class="more-link">Continue reading <span class="screen-reader-text">A JavaScript Trick You Should Know</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2011/08/18/powerful-php-less-known-string-manipulation/" rel="bookmark" title="Powerful PHP: Less Known String Manipulation">Powerful PHP: Less Known String Manipulation </a></li>
<li><a href="/2010/08/26/javascript-flexibility-regex-match/" rel="bookmark" title="JavaScript Flexibility &#8211; Regex match()">JavaScript Flexibility &#8211; Regex match() </a></li>
<li><a href="/2010/08/24/flexible-javascript-splitting-strings/" rel="bookmark" title="Flexible JavaScript &#8211; Splitting Strings">Flexible JavaScript &#8211; Splitting Strings </a></li>
<li><a href="/2010/08/25/flexible-javascript-replace-in-a-string/" rel="bookmark" title="Flexible JavaScript &#8211; Replace in a String">Flexible JavaScript &#8211; Replace in a String </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>JavaScript Strings</h2>
<p>You should know that in JavaScript you cannot simply write a multilined code chunk, i.e. something like this:</p>
<pre lang="javascript">
var str = 'hello
world';
</pre>
<p>This will result in an error, which can be a problem when you deal with large strings. Imagine a string containing some HTML that should be injected via innerHTML. Now one possible solution is to concatenate two or more strings, by splitting the initial string.</p>
<pre lang="javascript">
var str = 'hello'
        + 'world';
</pre>
<p>Howerver this solution result in some additional operations like concatenation. It can be very nice if there was something like the PHP multiline string format.</p>
<h2>The PHP Example</h2>
<p>In PHP you have the same use case with strings. You can have a string concatenated over multiple lines, but you cannot split lines like so:</p>
<pre lang="php">
// the following line is wrong
$str = 'hello
world'; 

// a possible solution to the line above is
$str = 'hello'
     . 'world';
// which is very similar to the js solution in the second example

// ... but in PHP there is the so called HEREDOC
$str = <<<EOD
hello
world
EOD;
</pre>
<p>The heredoc gives us the power to write multiline strings. </p>
<h2>The JavaScript Trick</h2>
<p>Actually in JavaScript there is something that's exactly what Heredoc is meant to be for PHP. Take a look at the last example:</p>
<pre lang="javascript">
var text = <>
this <br />
is
my
multi-line
text
</>.toString();

document.body.innerHTML = text;
</pre>
<p>Thus you can write multiline strings in the JavaScript code.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2011/08/18/powerful-php-less-known-string-manipulation/" rel="bookmark" title="Powerful PHP: Less Known String Manipulation">Powerful PHP: Less Known String Manipulation </a></li>
<li><a href="/2010/08/26/javascript-flexibility-regex-match/" rel="bookmark" title="JavaScript Flexibility &#8211; Regex match()">JavaScript Flexibility &#8211; Regex match() </a></li>
<li><a href="/2010/08/24/flexible-javascript-splitting-strings/" rel="bookmark" title="Flexible JavaScript &#8211; Splitting Strings">Flexible JavaScript &#8211; Splitting Strings </a></li>
<li><a href="/2010/08/25/flexible-javascript-replace-in-a-string/" rel="bookmark" title="Flexible JavaScript &#8211; Replace in a String">Flexible JavaScript &#8211; Replace in a String </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2011/07/12/a-javascript-trick-you-should-know/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Object Oriented JavaScript: Inheritance</title>
		<link>/2011/05/30/object-oriented-javascript-inheritance/</link>
		<comments>/2011/05/30/object-oriented-javascript-inheritance/#comments</comments>
		<pubDate>Mon, 30 May 2011 09:43:53 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[web development]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[Class]]></category>
		<category><![CDATA[code sample]]></category>
		<category><![CDATA[code snippet]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Curly bracket programming languages]]></category>
		<category><![CDATA[Education]]></category>
		<category><![CDATA[Inheritance]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Literal]]></category>
		<category><![CDATA[object oriented]]></category>
		<category><![CDATA[Object-oriented programming]]></category>
		<category><![CDATA[objects]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[oop javascript]]></category>
		<category><![CDATA[Scripting languages]]></category>
		<category><![CDATA[Software engineering]]></category>

		<guid isPermaLink="false">/?p=2314</guid>
		<description><![CDATA[Objects and JavaScript JavaScript, being a functional language, differs from most of the procedural/object oriented languages we know. The object oriented approach in JavaScript is rather strange. However there is much power in making objects! The syntax is really odd and there are several approaches. Literal Notation As many of you may know the most &#8230; <a href="/2011/05/30/object-oriented-javascript-inheritance/" class="more-link">Continue reading <span class="screen-reader-text">Object Oriented JavaScript: Inheritance</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2011/07/28/oop-javascript-accessing-public-methods-in-private-methods/" rel="bookmark" title="OOP JavaScript: Accessing Public Methods in Private Methods">OOP JavaScript: Accessing Public Methods in Private Methods </a></li>
<li><a href="/2011/10/20/some-notes-on-the-object-oriented-model-of-php/" rel="bookmark" title="Some Notes on the Object-oriented Model of PHP">Some Notes on the Object-oriented Model of PHP </a></li>
<li><a href="/2010/08/11/quick-look-at-javascript-objects/" rel="bookmark" title="Quick Look at JavaScript Objects">Quick Look at JavaScript Objects </a></li>
<li><a href="/2010/03/02/javascript-inheritance-example/" rel="bookmark" title="JavaScript inheritance example">JavaScript inheritance example </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>Objects and JavaScript</h2>
<p><a href="/tag/javascript/" title="JavaScript on Stoimen.com">JavaScript</a>, being a functional language, differs from most of the procedural/object oriented languages we know. The object oriented approach in JavaScript is rather strange. However there is much power in making objects! The syntax is really odd and there are several approaches.</p>
<h2>Literal Notation</h2>
<p>As many of you may know the most used notation is the JSON (JavaScript Object Notation).</p>
<pre lang="javascript">
{ 'key1' : 'val1'
, 'key2' : 'val2'
, 'key3' : 'val3'
}
</pre>
<p>Of course this is the very basic example. You can use as value any JavaScript object &#8211; another similar object or a function.</p>
<pre lang="javascript">
{ 'key1' : 'val1'
, 'key2' : { 'inner_key1' : 'inner_val1' }
, 'key3' : function() {
			return 10 + 5;
		 }
}
</pre>
<p>The two examples above are showing an anonymous object in JavaScript, but you can assign this code to some variable.</p>
<pre lang="javascript">
var myObject = 
	{ 'key1' : 'val1'
	, 'key2' : 'val2'
	, 'key3' : 'val3'
	}
</pre>
<p>or </p>
<pre lang="javascript">
var myObject =
	{ 'key1' : 'val1'
	, 'key2' : { 'inner_key1' : 'inner_val1' }
	, 'key3' : function() {
				return 10 + 5;
			 }
	}
</pre>
<p>and then you can call the properties of these objects with the &#8216;.&#8217; operator:</p>
<pre lang="javascript">
myObject.key1;
myObject.key2.inner_key1;
myObject.key3();
</pre>
<p>So far so good &#8211; this is the literal object notation in JavaScript. However there is another &#8220;objects&#8221; in JavaScript.<br />
<span id="more-2314"></span></p>
<h2>Objects and Functions in JavaScript</h2>
<p>Actually in JS the functions are also objects (classes). So you can define a function and then define another function inside or use the &#8220;this&#8221; operator.</p>
<pre lang="javascript">
var a = function(name)
{
	this.name = name;
	
	this.print = function() {
		alert(this.name);	
	}
}
</pre>
<p>Then you can make a new instance of this &#8220;class&#8221;.</p>
<pre lang="javascript">
var myObject = new a('hello world');
var anotherObject = new a('some test');

myObject.print(); // will print the string "hello world"
anotherObject.print(); // will print the string "some test"
</pre>
<p>Thus the function <strong>&#8220;a&#8221;</strong> defined within the code <strong>&#8220;var a = function(name) &#8230;&#8221;</strong> is a class in JavaScript. You can make instances (objects) of this class with the &#8220;new&#8221; operator.</p>
<p>You can use another notation for defining the function &#8220;a&#8221;, so both can be used and it&#8217;s up to you to decide which one is more convenient.</p>
<pre lang="javascript">
function a(name) 
{
	this.name = name;
	
	this.print = function() {
		alert(this.name);	
	}	
}
</pre>
<h2>Prototypes</h2>
<p>JS gives you more power. In most of the languages you&#8217;ve to define the class first and then make objects. In JS you can define a &#8220;class&#8221; then make some objects and then add some properties to the class by using the prototype.</p>
<pre lang="javascript">
var a = function(name) 
{
	this.name = name;
}

var myObj = new a('hello world');

a.prototype.print = function() {
	alert(this.name);	
}

myObj.print();
</pre>
<p>So you can see how you can add functions and properties to an already defined class using the prototype. Thus you can call the &#8220;print&#8221; function on the myObj object.</p>
<h2>Inheritance</h2>
<p>The prototype built-in property can be used to make use of one of the main OOP features &#8211; inheritance. </p>
<pre lang="javascript">
var SuperClass = function()
{
	this.superFunction = function() {
		return 'function in Super Class';	
	}
}

var sup = new SuperClass();
sup.superFunction(); // will return the string "function in Super Class"
</pre>
<p>Now you can add one more class and set its prototype to the SuperClass</p>
<pre lang="javascript">
var SubClass = function()
{
	this.subFunction = function() {
		return 'function in Sub Class';	
	}	
}

SubClass.prototype = new SuperClass();
</pre>
<p>Thus you make SubClass inherit from SuperClass. Now you can call the SuperClass properties from any SubClass object.</p>
<pre lang="javascript">
var sub = new SubClass();
sub.superFunction(); // will return the string "function in Super Class"
sub.subFunction(); // will return the string "function in Sub Class"
</pre>
<p>Even more! You can add properties to the super class with prototype.</p>
<pre lang="javascript">
SuperClass.prototype.myFunc = function() {
	return 'my new function';	
}
</pre>
<p>And then call it from the sub class:</p>
<pre lang="javascript">
sub.myFunc(); // will return the string "my new function"
</pre>
<h2>Override a Function</h2>
<p>What happens if you have the same function name in both classes. Actually this overrides the method in the sub class.</p>
<pre lang="javascript">
var SuperClass = function()
{
	this.myFunc = function() {
		return 'function in Super Class';	
	}
}

var SubClass = function()
{
	this.myFunc = function() {
		return 'function in Sub Class';	
	}	
}

SubClass.prototype = new SuperClass();

var sub = new SubClass();
sub.myFunc(); // will return the string "function in Sub Class"
</pre>
<p>while </p>
<pre lang="javascript">
var sup = new SuperClass();
sup.myFunc(); // will return the string "function in Super Class"
</pre>
<h2>Conclusion</h2>
<p>Now you know there are classes, inheritance and overrides in JavaScript &#8211; thus you can improve your object oriented JavaScript!</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2011/07/28/oop-javascript-accessing-public-methods-in-private-methods/" rel="bookmark" title="OOP JavaScript: Accessing Public Methods in Private Methods">OOP JavaScript: Accessing Public Methods in Private Methods </a></li>
<li><a href="/2011/10/20/some-notes-on-the-object-oriented-model-of-php/" rel="bookmark" title="Some Notes on the Object-oriented Model of PHP">Some Notes on the Object-oriented Model of PHP </a></li>
<li><a href="/2010/08/11/quick-look-at-javascript-objects/" rel="bookmark" title="Quick Look at JavaScript Objects">Quick Look at JavaScript Objects </a></li>
<li><a href="/2010/03/02/javascript-inheritance-example/" rel="bookmark" title="JavaScript inheritance example">JavaScript inheritance example </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2011/05/30/object-oriented-javascript-inheritance/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Main Features of the Traditional Software Development Methodologies</title>
		<link>/2011/04/19/main-features-of-the-traditional-software-development-methodologies/</link>
		<comments>/2011/04/19/main-features-of-the-traditional-software-development-methodologies/#comments</comments>
		<pubDate>Tue, 19 Apr 2011 07:39:26 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[agile]]></category>
		<category><![CDATA[Business]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[John Wiley & Sons Inc]]></category>
		<category><![CDATA[Management]]></category>
		<category><![CDATA[methodology]]></category>
		<category><![CDATA[Project management]]></category>
		<category><![CDATA[software development]]></category>
		<category><![CDATA[Software development methodology]]></category>
		<category><![CDATA[Software development process]]></category>
		<category><![CDATA[Software engineering]]></category>
		<category><![CDATA[Software prototyping]]></category>
		<category><![CDATA[Systems Development Life Cycle]]></category>
		<category><![CDATA[Technology/Internet]]></category>

		<guid isPermaLink="false">/?p=2307</guid>
		<description><![CDATA[This article is a continuation of my previous post! The stages of analysis and design are the main stages in the traditional approaches. Of course the focus of the whole project is there and therefore the effort at these stages is very important. They are methodology-centric &#8211; this means that the methodology is very extensive &#8230; <a href="/2011/04/19/main-features-of-the-traditional-software-development-methodologies/" class="more-link">Continue reading <span class="screen-reader-text">Main Features of the Traditional Software Development Methodologies</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2011/04/15/traditional-software-development-methodologies/" rel="bookmark" title="Traditional Software Development Methodologies">Traditional Software Development Methodologies </a></li>
<li><a href="/2011/04/06/an-introduction-to-the-agile/" rel="bookmark" title="An Introduction to the Agile">An Introduction to the Agile </a></li>
<li><a href="/2010/07/27/are-you-agile/" rel="bookmark" title="Are You Agile?">Are You Agile? </a></li>
<li><a href="/2010/01/08/jquery-vs-pure-javascript/" rel="bookmark" title="jQuery vs. pure JavaScript">jQuery vs. pure JavaScript </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p><em>This article is a continuation of my previous <a title="Traditional Software Development Methodologies" href="/2011/04/15/traditional-software-development-methodologies/">post</a>!</em></p>
<p>The stages of analysis and design are the main stages in the traditional approaches. Of course the focus of the whole project is there and therefore the effort at these stages is very important. They are methodology-centric &#8211; this means that the methodology is very extensive and the right application of the method is a warranty for a successful project.</p>
<figure id="attachment_2316" style="width: 500px" class="wp-caption aligncenter"><a href="/wp-content/uploads/2011/04/plan.jpg"><img class="size-full wp-image-2316" title="Traditional Software Development Methodologies" src="/wp-content/uploads/2011/04/plan.jpg" alt="Traditional Software Development Methodologies" width="500" height="375" srcset="/wp-content/uploads/2011/04/plan.jpg 500w, /wp-content/uploads/2011/04/plan-300x225.jpg 300w" sizes="(max-width: 500px) 100vw, 500px" /></a><figcaption class="wp-caption-text">The stages of plan and design are the most imporant for the traditional methodologies</figcaption></figure>
<p>It&#8217;s not far from the truth that the methodology is more important factor than the human factor.<span id="more-2307"></span></p>
<p>All these traditional approaches are systematic methods of software development where the building phase always follows the stage of design. Most of the important decisions are made during the stage of design and once the product is well designed the project can be continued with the phase of building &#8211; which is supposed to be very predictable. Thus the stage of building the product only follows the &#8220;perfect&#8221; design of the system.</p>
<figure id="attachment_2317" style="width: 500px" class="wp-caption aligncenter"><a href="/wp-content/uploads/2011/04/brainstorm.jpg"><img class="size-full wp-image-2317" title="Traditional Software Development Methodologies" src="/wp-content/uploads/2011/04/brainstorm.jpg" alt="Traditional Software Development Methodologies" width="500" height="334" srcset="/wp-content/uploads/2011/04/brainstorm.jpg 500w, /wp-content/uploads/2011/04/brainstorm-300x200.jpg 300w" sizes="(max-width: 500px) 100vw, 500px" /></a><figcaption class="wp-caption-text">Most of the important decisions are made during the stage of design and once the product is well designed the project can be continued with the phase of building.</figcaption></figure>
<p>In that scenario we can see two main activities: <strong>design</strong>, which is highly creative activity, it is difficult to predict and needs high qualification, and <strong>build</strong> in other hand, which is simple to predict and doesn&#8217;t need high qualification [1].</p>
<p>All these facts can be summarized into the following conclusions:</p>
<ul>
<li>When building a software product &#8211; the stage of building is a small piece of the whole process.</li>
<li>The stage of &#8220;design&#8221; remains the main part of the software construction process.</li>
<li>It is very difficult to plan and predict processes with high level of creativity.</li>
</ul>
<p>This is why the traditional methodologies of software development are very useful in some and unsuccessful in other types of projects. Because their main feature is the detailed planning and designing phase they are useful when the project is said to be very large and the level of risk is high. Some project that are estimated to last very long is often developed with some traditional methodology [2].</p>
<figure id="attachment_2318" style="width: 339px" class="wp-caption aligncenter"><a href="/wp-content/uploads/2011/04/risk.jpg"><img class="size-full wp-image-2318" title="Traditional Software Development Methodologies" src="/wp-content/uploads/2011/04/risk.jpg" alt="Traditional Software Development Methodologies" width="339" height="450" srcset="/wp-content/uploads/2011/04/risk.jpg 339w, /wp-content/uploads/2011/04/risk-226x300.jpg 226w" sizes="(max-width: 339px) 100vw, 339px" /></a><figcaption class="wp-caption-text">The traditional approaches are useful when the project is said to be very large and the level of risk is high.</figcaption></figure>
<p>The traditional approaches, in general, can be described by their main features as follows:</p>
<ol>
<li>They are relevant when the project is very large and the building team is also very large and not always geographically collocated;</li>
<li>The stage of planning is very detailed;</li>
<li>The documentation is very large and describes all the features of the system;</li>
<li>They are used for projects where the main requirements are defined early and doesn&#8217;t change often;</li>
<li>The phases of analysis, planning, design, build and deploy are consecutive;</li>
</ol>
<p>[1] Fowler M. <a title="Martin Fowler - The New Methodology" href="http://www.martinfowler.com/articles/newMethodology.html" target="_blank">The New Methodology</a>, 2005<br />
[2] Wysocki R. K., McGary R., Effective Project Management, Third Edition, John Wiley &amp; Sons © 2003</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2011/04/15/traditional-software-development-methodologies/" rel="bookmark" title="Traditional Software Development Methodologies">Traditional Software Development Methodologies </a></li>
<li><a href="/2011/04/06/an-introduction-to-the-agile/" rel="bookmark" title="An Introduction to the Agile">An Introduction to the Agile </a></li>
<li><a href="/2010/07/27/are-you-agile/" rel="bookmark" title="Are You Agile?">Are You Agile? </a></li>
<li><a href="/2010/01/08/jquery-vs-pure-javascript/" rel="bookmark" title="jQuery vs. pure JavaScript">jQuery vs. pure JavaScript </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2011/04/19/main-features-of-the-traditional-software-development-methodologies/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
