<?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>Cameron McKay &#187; Programming Languages</title>
	<atom:link href="http://cdmckay.org/blog/category/programming-languages/feed/" rel="self" type="application/rss+xml" />
	<link>http://cdmckay.org/blog</link>
	<description>Programming and Game Development</description>
	<lastBuildDate>Mon, 14 May 2012 21:11:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Things I miss from Java while programming in C#</title>
		<link>http://cdmckay.org/blog/2011/05/02/things-i-miss-from-java-while-programming-in-c/</link>
		<comments>http://cdmckay.org/blog/2011/05/02/things-i-miss-from-java-while-programming-in-c/#comments</comments>
		<pubDate>Mon, 02 May 2011 22:19:17 +0000</pubDate>
		<dc:creator>cdmckay</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Programming Languages]]></category>

		<guid isPermaLink="false">http://cdmckay.org/blog/?p=1841</guid>
		<description><![CDATA[One of the perks of being a freelance programmer is that I get to program in a lot of different languages, either because the client has dictated a certain language, has left the choice up to me, or limited me by what is supported by a host (Hi PHP!). As fate would have it, I [...]]]></description>
			<content:encoded><![CDATA[<p>One of the perks of being a freelance programmer is that I get to program in a lot of different languages, either because the client has dictated a certain language, has left the choice up to me, or limited me by what is supported by a host (Hi PHP!).</p>
<p>As fate would have it, I have had the good fortune to have extensive experience with both C# and Java.  While many articles will list things a programmer misses from C# while coding in Java (properties, LINQ, reified generics, type inference, named and optional parameters, closures, continuations), this post intends to look at things a Java programmer might miss while coding in C#.</p>
<p><span id="more-1841"></span></p>
<h3>1. Method return type covariance</h3>
<p>Covariant method return types are one of the lesser known Java features (see <a href="http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.4.5">Section 8.4.5 in the JLS</a>).  Basically, Java allows you to narrow the return type of a method when overriding it in a sub-class.  For example:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Foo <span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SubFoo <span style="color: #000000; font-weight: bold;">extends</span> Foo <span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Bar <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">final</span> Foo foo <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Foo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> Foo getFoo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> foo<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SubBar <span style="color: #000000; font-weight: bold;">extends</span> Bar <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">final</span> SubFoo subFoo <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SubFoo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> SubFoo getFoo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> subFoo<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Although situations where this is needed are seldom, it is a nice feature to have when you need it.  An good example of its usage is in the <a href="http://wicket.apache.org">Apache Wicket framework</a>.  All pages in Wicket typically derive from the <a href="http://wicket.apache.org/apidocs/1.4/org/apache/wicket/markup/html/WebPage.html">WebPage</a> class.  Thus, when you want to access information from a custom Wicket session you need to do something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> UserInfoPage <span style="color: #000000; font-weight: bold;">extends</span> WebPage <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> UserInfoPage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        FooSession session <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>FooSession<span style="color: #009900;">&#41;</span> getSession<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">String</span> userName <span style="color: #339933;">=</span> session.<span style="color: #006633;">getUserName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        ...
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>However, if you add a class above <code>UserInfoPage</code> called <code>FooPage</code>, you can use a covariant return type to eliminate the unsightly cast:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> FooPage <span style="color: #000000; font-weight: bold;">extends</span> WebPage <span style="color: #009900;">&#123;</span>
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> FooSession getSession<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>FooSession<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">getSession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> UserInfoPage <span style="color: #000000; font-weight: bold;">extends</span> FooPage <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> UserInfoPage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        FooSession session <span style="color: #339933;">=</span> getSession<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">String</span> userName <span style="color: #339933;">=</span> session.<span style="color: #006633;">getUserName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        ...
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>To me this is preferable to adding another method called <code>getFooSession()</code>.  Having two methods can be confusing to a future maintainer (do I want <code>getFooSession()</code> or <code>getSession()</code>? What&#8217;s the difference?) and needlessly clutters your IDE&#8217;s code completion.</p>
<p>There is no equivalent in C#, short of adding a method.  Will C# ever support such a feature?   It&#8217;s hard to say, but probably not anytime soon.  There has been <a href="http://connect.microsoft.com/VisualStudio/feedback/details/90909/need-covariant-return-types-in-c-all-net-langage">a request for covariant method return types since 2004</a>.  Microsoft response then was:</p>
<blockquote><p>We hear this request a lot. We&#8217;ll consider it for the next release.</p></blockquote>
<p>After seven years and three major C# releases, it looks like they&#8217;re still considering it.</p>
<h3>2. Class-like enums</h3>
<p>This one is not a big surprise, as it is typically mentioned as one of the few things that Java has done better that C#.  In C#, enums are basically glorified integral types.  As such, they can&#8217;t contain any extra data without using attributes.  While attributes are nice, accessing them requires quite a bit of boilerplate.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">enum</span> MotionType <span style="color: #008000;">&#123;</span>
    Stationary,
    Walking,
    Running,
    <span style="color: #008000;">&#91;</span>Description<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Time Travelling&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>,
    TimeTravelling
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #008000;">...</span>
&nbsp;
<span style="color: #0000FF;">MotionType</span> type <span style="color: #008000;">=</span> MotionType<span style="color: #008000;">.</span><span style="color: #0000FF;">TimeTravelling</span><span style="color: #008000;">;</span>
var description <span style="color: #008000;">=</span> type
    <span style="color: #008000;">.</span><span style="color: #0000FF;">GetType</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">.</span><span style="color: #0000FF;">GetField</span><span style="color: #008000;">&#40;</span>type<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">.</span><span style="color: #0000FF;">GetCustomAttributes</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>DescriptionAttribute<span style="color: #008000;">&#41;</span>, <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">.</span><span style="color: #0000FF;">Cast</span><span style="color: #008000;">&lt;</span>DescriptionAttribute<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">.</span><span style="color: #0000FF;">First</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">.</span><span style="color: #0000FF;">Description</span><span style="color: #008000;">;</span>
Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span>description<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>A further restriction of C# enums if that they can&#8217;t be used as a generic constraint.  For example, the following code would not compile:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> Monster<span style="color: #008000;">&lt;</span>TMotionType<span style="color: #008000;">&gt;</span> <span style="color: #0600FF; font-weight: bold;">where</span> TMotionType <span style="color: #008000;">:</span> <span style="color: #6666cc; font-weight: bold;">enum</span> <span style="color: #008000;">&#123;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p><a href="https://msmvps.com/blogs/jon_skeet/archive/2009/09/10/generic-constraints-for-enums-and-delegates.aspx">According to C# MVP Jon Skeet</a>, this is not a restriction of the CLR, but is actually a restriction of the Microsoft C# compiler.  The best you can do to work around this is to use the broader constraint <code>where : struct</code>, or the <a href="http://code.google.com/p/unconstrained-melody/">Unconstrained Melody library</a>.</p>
<p>Java enums, on the other hand, are specialized classes.  Like C# enums, Java enums can be used with <code>switch</code> statements and be converted to integral types.  However, Java enums go far beyond these simple uses.  Java enums can have instance fields, instance methods and even per-constant methods.    Java generics can also be constrained to take only enums.  </p>
<p>Here&#8217;s how the <code>MotionType</code> enum could be written in Java (notice how easy it is to get the description in this case):</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">enum</span> MotionType <span style="color: #009900;">&#123;</span>
    STATIONARY<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Stationary&quot;</span><span style="color: #009900;">&#41;</span>,
    WALKING<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Walking&quot;</span><span style="color: #009900;">&#41;</span>,
    RUNNING<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Running&quot;</span><span style="color: #009900;">&#41;</span>,
    TIME_TRAVELLING<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Time Travelling&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> description<span style="color: #339933;">;</span>
    MotionType<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> description<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">description</span> <span style="color: #339933;">=</span> description<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
...
&nbsp;
<span style="color: #006633;">MotionType</span> type <span style="color: #339933;">=</span> MotionType.<span style="color: #006633;">TIME_TRAVELLING</span><span style="color: #339933;">;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>type.<span style="color: #006633;">description</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This is just scratching the surface of Java enum capabilities.  I highly recommend reading Chapter 6 of Effective Java or <a href="http://download.oracle.com/javase/1.5.0/docs/guide/language/enums.html">the Oracle enum documentation</a>.</p>
<h3>3. Anonymous inner classes</h3>
<p>This is another it&#8217;s-useful-when-you-need-it feature of Java that C# mostly addresses with events and delegates.  The most common situation for anonymous inner classes in Java is for listeners:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">Widget widget <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Widget<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onInteraction<span style="color: #009900;">&#40;</span>WidgetState state<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        ...
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>In C#, this is handled using events and delegates:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Widget widget <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Widget<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
widget<span style="color: #008000;">.</span><span style="color: #0000FF;">Interaction</span> <span style="color: #008000;">+=</span> state <span style="color: #008000;">=&gt;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #008000;">...</span>
<span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span></pre></div></div>

<p>The C# approach is superior in most cases.  There&#8217;s far less clutter and it&#8217;s a lot easier to add listener support to a class in C#.  Furthermore, since it&#8217;s a language feature, you can count on it being more or less the same everywhere.  However, it&#8217;s not without drawbacks.  You&#8217;ll notice in the previous Java example, we can guarantee that there is only one listener.  Furthermore, if we declare <code>onInteraction</code> as abstract, we can also ensure that all concrete implementations of <code>Widget</code> have an <code>onInteraction</code> handler.  The event/delegate approach as written cannot make the same guarantees.</p>
<p>Since C# does not support anonymous inner classes, the best we can do to emulate them is something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Widget widget <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Widget<span style="color: #008000;">&#40;</span>state <span style="color: #008000;">=&gt;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #008000;">...</span>
<span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>&#8230;or, if we wanted to make it a little more clear, we could use named parameters:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Widget widget <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Widget<span style="color: #008000;">&#40;</span>onInteraction<span style="color: #008000;">:</span> state <span style="color: #008000;">=&gt;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #008000;">...</span>
<span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<h3>Locally scoped final/readonly variables</h3>
<p><a href="http://www.cc2e.com/">In the book Code Complete 2</a>, Steve McConnell recommends that you use final keyword whenever possible.  The justification for this being that less mutable code is easier to keep track of mentally and less likely to be accidentally modified.  Although the practice of making everything final can be weird at first, you eventually become so used to using final that you start to feel a little bit exposed whenever a variable isn&#8217;t marked final.</p>
<p>C# has a nearly equivalent keyword to <code>final</code>: <code>readonly</code>.  However, for some reason, readonly is only usable on the field level.  In the local scope, there is no direct equivalent to final in C#.  The best you can do is use <code>const</code>, but this only works with compile-time constants, so</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">string</span> foo <span style="color: #008000;">=</span> Foo<span style="color: #008000;">.</span><span style="color: #0000FF;">getString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>&#8230;won&#8217;t work.</p>
<h3>Conclusion</h3>
<p>In this article we looked at four features of Java that lack direct C# equivalents: covariant method return types, class-like enums, anonymous inner classes and locally-scoped final/readonly keywords.  C# is often thought of as a &#8220;better Java&#8221;.  However, as this article has shown, this is not true.  Java may not have as many bells and whistles as its newer cousin, but it still offers some compelling features that may never find their way into C#.</p>
]]></content:encoded>
			<wfw:commentRss>http://cdmckay.org/blog/2011/05/02/things-i-miss-from-java-while-programming-in-c/feed/</wfw:commentRss>
		<slash:comments>41</slash:comments>
		</item>
		<item>
		<title>Anders Hejlsberg talks about C# 4.0</title>
		<link>http://cdmckay.org/blog/2010/04/18/anders-hejlsberg-talks-about-c-4-0/</link>
		<comments>http://cdmckay.org/blog/2010/04/18/anders-hejlsberg-talks-about-c-4-0/#comments</comments>
		<pubDate>Mon, 19 Apr 2010 01:46:37 +0000</pubDate>
		<dc:creator>cdmckay</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[.net 4.0]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://cdmckay.org/blog/?p=1365</guid>
		<description><![CDATA[Channel 9 has posted a great talk by Anders Hejlsberg, the original author of Turbo Pascal, the chief architect of Delphi, and the lead architect of C#. History lesson: Anders was lured away from Borland by Microsoft with a hefty offer of a $1.5 million signing bonus, a base salary of up to $200,000, and [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://channel9.msdn.com/posts/matthijs/C-40-and-beyond-by-Anders-Hejlsberg/">Channel 9 has posted a great talk</a> by <a href="http://en.wikipedia.org/wiki/Anders_Hejlsberg">Anders Hejlsberg</a>, the original author of Turbo Pascal, the chief architect of Delphi, and the lead architect of C#.</p>
<p>History lesson: Anders was <a href="http://news.cnet.com/2009-1023-229218.html">lured away from Borland by Microsoft</a> with a hefty offer of a $1.5 million signing bonus, a base salary of up to $200,000, and options to buy 75,000 shares of Microsoft stock.</p></blockquote>
<p>Looks like it was worth it, as each C# release has added many interesting and powerful features, while maintaining a fine balance between complexity and simplicity.</p>
]]></content:encoded>
			<wfw:commentRss>http://cdmckay.org/blog/2010/04/18/anders-hejlsberg-talks-about-c-4-0/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Fep Section</title>
		<link>http://cdmckay.org/blog/2009/10/16/fep-section/</link>
		<comments>http://cdmckay.org/blog/2009/10/16/fep-section/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 06:06:43 +0000</pubDate>
		<dc:creator>cdmckay</dc:creator>
				<category><![CDATA[Fep]]></category>
		<category><![CDATA[Programming Languages]]></category>

		<guid isPermaLink="false">http://couchware.ca/blogs/cam/?p=1036</guid>
		<description><![CDATA[I just added a new Fep section. I&#8217;m going to try to work on a bit more (just ordered this sucker) as making a programming language has been something I&#8217;ve always had an interest in. First stop: parsers!]]></description>
			<content:encoded><![CDATA[<p>I just added a new <a href="http://cdmckay.org/blog/fep/">Fep section</a>.  I&#8217;m going to try to work on a bit more (just ordered <a href="http://generatingparserswithjavacc.com/">this sucker</a>) as making a programming language has been something I&#8217;ve always had an interest in.  </p>
<p>First stop: parsers!</p>
]]></content:encoded>
			<wfw:commentRss>http://cdmckay.org/blog/2009/10/16/fep-section/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fep Collections</title>
		<link>http://cdmckay.org/blog/2009/07/29/fep-collections/</link>
		<comments>http://cdmckay.org/blog/2009/07/29/fep-collections/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 20:47:57 +0000</pubDate>
		<dc:creator>cdmckay</dc:creator>
				<category><![CDATA[Fep]]></category>
		<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[collections]]></category>
		<category><![CDATA[dictionaries]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[lists]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://couchware.ca/blogs/cam/?p=863</guid>
		<description><![CDATA[As I was working on the PHP classes that Fep was to map to, I realized that it was rather silly for me to re-invent an API for lists since there were already many well-designed ones in existence. In particular, I&#8217;ve found that the .NET 3.5 collections API to be particularly nice to use. Moreover, [...]]]></description>
			<content:encoded><![CDATA[<p>As I was working on the PHP classes that Fep was to map to, I realized that it was rather silly for me to re-invent an API for lists since there were already many well-designed ones in existence.  In particular, I&#8217;ve found that the .NET 3.5 collections API to be particularly nice to use.  Moreover, since everyone and their dog and using .NET now, it would also be familiar to most programmers.  Thus, I&#8217;ve decided to use a subset of the .NET collections API for Fep collections.</p>
<p><span id="more-863"></span></p>
<p>Furthermore, after some thought, I&#8217;ve decided to split up Fep arrays.  In PHP arrays aren&#8217;t really arrays in the traditional sense, but more like array/associate array hybrids (JavaScript uses a similar concept).  This can be confusing, error-prone and I don&#8217;t think that the benefits of having an hybrid array system outweighs the complexity.</p>
<p>Thus, in Fep, there will be two main collection types: lists and dictionaries.  Here&#8217;s how a Fep list will look like:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Fep</span>
fep <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span> <span style="color: #0000ff;">&quot;foo&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;bar&quot;</span> <span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
fep<span style="color: #339933;">.</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// == 4</span>
fep<span style="color: #339933;">.</span>add<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;baz&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
fep<span style="color: #339933;">.</span>find<span style="color: #009900;">&#40;</span> x <span style="color: #339933;">=&gt;</span> x <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// == 2</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Will compile into this PHP</span>
<span style="color: #000088;">$fep</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FepList<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;foo&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;bar&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$fep</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$fep</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;baz&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$fep</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$x</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">return</span> x <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>And here&#8217;s how a Fep dictionary will look:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Fep</span>
fep <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> blah<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;blah&quot;</span><span style="color: #339933;">,</span> foo<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;bar&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;zero&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
fep<span style="color: #339933;">.</span>keys<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// == [ &quot;blah&quot;, &quot;foo&quot;, 0 ]</span>
fep<span style="color: #339933;">.</span>containsKey<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;foo&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// == true</span>
fep<span style="color: #339933;">.</span>remove<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;foo&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// == true</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// PHP</span>
<span style="color: #000088;">$fep</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FepDict<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;blah&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;blah&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;foo&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;bar&quot;</span><span style="color: #339933;">,</span> 
         <span style="color: #cc66cc;">0</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;zero&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$fep</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">keys</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$fep</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">containsKey</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;foo&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$fep</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">remove</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;foo&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://cdmckay.org/blog/2009/07/29/fep-collections/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fep Arrays</title>
		<link>http://cdmckay.org/blog/2009/07/24/fep-arrays/</link>
		<comments>http://cdmckay.org/blog/2009/07/24/fep-arrays/#comments</comments>
		<pubDate>Sat, 25 Jul 2009 01:39:55 +0000</pubDate>
		<dc:creator>cdmckay</dc:creator>
				<category><![CDATA[Fep]]></category>
		<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://couchware.ca/blogs/cam/?p=827</guid>
		<description><![CDATA[Disclaimer: This is not the way Fep arrays will work. Refer to the new article on Fep collections for more information. In this article, I&#8217;ll write a bit about how I think Fep arrays will look. Keep in mind this a work in progress and is by no means comprehensive. Without further ado&#8230; In PHP, [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Disclaimer:</strong> <em>This is not the way Fep arrays will work.  <a href="/blogs/cam/2009/07/29/fep-collections/">Refer to the new article on Fep collections for more information</a>.</em></p>
<p>In this article, I&#8217;ll write a bit about how I think Fep arrays will look.  Keep in mind this a work in progress and is by no means comprehensive.  Without further ado&#8230;</p>
<p>In PHP, you define an array using the <code>array()</code> construct.  Fep will follow the lead of languages like JavaScript, Python, Ruby and Groovy and use the square bracket </code>[]</code> notation.</p>
<h3>Initialization</h3>
<p>For example, a simple array in PHP is creating like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>In Fep, this would be done like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">arr <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span></pre></div></div>

<p><span id="more-827"></span></p>
<p>There are actually three things to notice here.  First, Fep uses square brackets.  Second, Fep has optional semicolons (similar to JavaScript and Scala).  Third, Fep doesn't prefix all variables with <code>$</code>.  This should give your pinky finger a bit of rest and de-noise-ify your Fep code.</p>
<p>How about associative arrays?  In this case, I don't want to deviate too much from PHP, so I'm going to go with the same syntax:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// PHP</span>
<span style="color: #000088;">$fruits</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
  <span style="color: #0000ff;">&quot;fruits&quot;</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;a&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;orange&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;b&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;banana&quot;</span><span style="color: #339933;">,</span> 
                     <span style="color: #0000ff;">&quot;c&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;apple&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
  <span style="color: #0000ff;">&quot;numbers&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">6</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
  <span style="color: #0000ff;">&quot;holes&quot;</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;first&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;second&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;third&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Fep</span>
fruits <span style="color: #339933;">=</span> 
<span style="color: #009900;">&#91;</span>
  <span style="color: #0000ff;">&quot;fruits&quot;</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;a&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;orange&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;b&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;banana&quot;</span><span style="color: #339933;">,</span> 
                <span style="color: #0000ff;">&quot;c&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;apple&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
  <span style="color: #0000ff;">&quot;numbers&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">6</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
  <span style="color: #0000ff;">&quot;holes&quot;</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;first&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;second&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;third&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#93;</span></pre></div></div>

<h3>Decomposition</h3>
<p>What about that convenient <code>list</code> construct?  In Fep, we'll try again to reduce the typing and improve readability by introducing this syntax:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// PHP</span>
<span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$a</span><span style="color: #339933;">,</span> <span style="color: #000088;">$b</span><span style="color: #339933;">,</span> <span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;a&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;b&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;c&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Fep</span>
a<span style="color: #339933;">,</span> b<span style="color: #339933;">,</span> c <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;a&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;b&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;c&quot;</span><span style="color: #009900;">&#93;</span></pre></div></div>

<h3>Accessors</h3>
<p>To fetch a value from a Fep array, the regular PHP-style accessors will be used, with the main difference being that Fep will support negative indexing.  That is, <code>$array[-1]&nbsp;==&nbsp;$array[$array.length&nbsp;-&nbsp;1]</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">arr <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span>
println <span style="color: #000088;">$arr</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span>    <span style="color: #666666; font-style: italic;">// 1</span>
println <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">6</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #666666; font-style: italic;">// 5</span>
println <span style="color: #000088;">$arr</span><span style="color: #009900;">&#91;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span>   <span style="color: #666666; font-style: italic;">// 3</span>
&nbsp;
mixed <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;a&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;b&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;foo&quot;</span><span style="color: #009900;">&#93;</span>
println arr<span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;a&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #666666; font-style: italic;">// b</span>
println arr<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span>   <span style="color: #666666; font-style: italic;">// foo</span></pre></div></div>

<h3>API</h3>
<p>All arrays in Fep will be <code>Array</code> objects.  As such, they'll have access to all the PHP array functions in an object-oriented way.  Here's a few examples:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// PHP</span>
<span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;x&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$len</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$arr</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">array_push</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$arr</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;y&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;z&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$arr</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$merged</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_merge</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$arr</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;a&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;b&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;c&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Fep</span>
arr <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;x&quot;</span><span style="color: #009900;">&#93;</span>
len <span style="color: #339933;">=</span> arr<span style="color: #339933;">.</span>length
arr<span style="color: #339933;">.</span>push<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;y&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;z&quot;</span><span style="color: #009900;">&#41;</span>
arr<span style="color: #339933;">.</span>contains<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
merged <span style="color: #339933;">=</span> arr <span style="color: #339933;">+</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;a&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;b&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;c&quot;</span><span style="color: #009900;">&#93;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://cdmckay.org/blog/2009/07/24/fep-arrays/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fep: A cleaner PHP</title>
		<link>http://cdmckay.org/blog/2009/07/24/fep-a-cleaner-php/</link>
		<comments>http://cdmckay.org/blog/2009/07/24/fep-a-cleaner-php/#comments</comments>
		<pubDate>Fri, 24 Jul 2009 22:35:57 +0000</pubDate>
		<dc:creator>cdmckay</dc:creator>
				<category><![CDATA[Fep]]></category>
		<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://couchware.ca/blogs/cam/?p=817</guid>
		<description><![CDATA[PHP bugs me. It&#8217;s a language with so many inconsistencies, it&#8217;s just screaming to be cleaned up. I&#8217;m surprised it hasn&#8217;t happened yet. That&#8217;s why I&#8217;m starting a series of articles on Fep, a cleaned up version of PHP. Fep has the following goals: Eliminate many of the inconsistencies of PHP while maintaining the core [...]]]></description>
			<content:encoded><![CDATA[<p>PHP bugs me.  It&#8217;s a language with so many inconsistencies, it&#8217;s just screaming to be cleaned up.  I&#8217;m surprised it hasn&#8217;t happened yet.  That&#8217;s why I&#8217;m starting a series of articles on <strong>Fep</strong>, a cleaned up version of PHP.  </p>
<p><span id="more-817"></span></p>
<p>Fep has the following goals:</p>
<ul>
<li>Eliminate many of the inconsistencies of PHP while maintaining the core <em>feel</em> of the language.  For example, why is there <code>print</code> and <code>echo</code>? Answer: <a href="http://www.faqts.com/knowledge_base/view.phtml/aid/1/fid/40">it&#8217;s complicated</a>.  But it doesn&#8217;t have to be!  <code>isset()</code> is a language construct that requires brackets but <code>require</code> doesn&#8217;t.  These are the types of things I&#8217;d like to fix.</li>
<li>PHP has a ton of <a href="http://ca2.php.net/manual/en/ref.strings.php">string functions</a> that are just screaming to be separated into classes.  Fep will do this.  This will be also done to groups of functions in a similar state.</li>
<li>PHP isn&#8217;t the nicest language, but it&#8217;s easy and familiar.  It also has a ton of support.  Fep will be a sort of meta-language.  Fep code will be converted to PHP code before it is run in order to maintain compatibility with the PHP ecosystem.</li>
<li>PHP&#8217;s OO model is a bit strange.  Why is the constructor called <code>__construct</code>?  To me that&#8217;s ugly as shit.  I&#8217;m also not a big fan of using <code>-></code> to access methods and attributes.  I&#8217;d much rather use <code>.</code>, but in order to do that, we&#8217;ll probably need to stop using <code>.</code> for concatenation.  I&#8217;m ok with doing that.</li>
</ul>
<p>That&#8217;s just a few of the things of the top of my head.  The development process will follow this pattern:</p>
<ol>
<li>write a series of articles to map out the language (maybe even write a <a href="http://docs.python.org/reference/">language reference like Python</a>),</li>
<li>write a compiler that&#8217;ll convert Fep code into PHP code,</li>
<li>write a module for Apache that&#8217;ll convert <code>.fep</code> files to <code>.php</code> files and then feed them to the PHP module.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://cdmckay.org/blog/2009/07/24/fep-a-cleaner-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

