<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Angel "Java" Lopez on Blog</title>
	<atom:link href="http://ajlopez.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://ajlopez.wordpress.com</link>
	<description>Software Development, in the Third Millenium</description>
	<lastBuildDate>Sat, 05 Dec 2009 12:56:00 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='ajlopez.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/6d646a25923112f8b0fb31b77125ff57?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Angel "Java" Lopez on Blog</title>
		<link>http://ajlopez.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://ajlopez.wordpress.com/osd.xml" title="Angel &#8220;Java&#8221; Lopez on Blog" />
		<item>
		<title>People and software</title>
		<link>http://ajlopez.wordpress.com/2009/12/05/people-and-software/</link>
		<comments>http://ajlopez.wordpress.com/2009/12/05/people-and-software/#comments</comments>
		<pubDate>Sat, 05 Dec 2009 12:56:00 +0000</pubDate>
		<dc:creator>ajlopez</dc:creator>
				<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajlopez.wordpress.com/2009/12/05/people-and-software/</guid>
		<description><![CDATA[Every day, as software developers, we are so concentrated in our interests, in software development, that we lost the big picture: software is good for people. Software industry, beyond our crazy love for programming, has big impact on humankind. I could not imagine one human activity that was not be touched by software, in one [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajlopez.wordpress.com&blog=378226&post=308&subd=ajlopez&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Every day, as software developers, we are so concentrated in our interests, in software development, that we lost the big picture: software is good for people. Software industry, beyond our crazy love for programming, has big impact on humankind. I could not imagine one human activity that was not be touched by software, in one or another way.</p>
<p>For me, all started with a tweet by <a href="http://twitter.com/dbasch" target="_blank">@dbasch</a>:</p>
<p><img src="http://www.ajlopez.com/images/articles2/twitterexample35.png" /> </p>
<p>This is the story:</p>
<p><a title="http://www.reddit.com/r/pics/comments/abam0/help_me_fix_my_last_picture_of_mom/" href="http://www.reddit.com/r/pics/comments/abam0/help_me_fix_my_last_picture_of_mom/">http://www.reddit.com/r/pics/comments/abam0/help_me_fix_my_last_picture_of_mom/</a></p>
<p>(read all the comment list)</p>
<p><img src="http://www.ajlopez.com/images/articles2/peoplesoftware.png" /> </p>
<p>This is the power of peole and the web, too.</p>
<p>Angel “Java” Lopez   <br /><a href="http://www.ajlopez.com">http://www.ajlopez.com</a>    <br /><a href="http://twitter.com/ajlopez">http://twitter.com/ajlopez</a></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajlopez.wordpress.com/308/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajlopez.wordpress.com/308/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajlopez.wordpress.com/308/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajlopez.wordpress.com/308/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajlopez.wordpress.com/308/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajlopez.wordpress.com/308/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajlopez.wordpress.com/308/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajlopez.wordpress.com/308/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajlopez.wordpress.com/308/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajlopez.wordpress.com/308/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajlopez.wordpress.com&blog=378226&post=308&subd=ajlopez&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ajlopez.wordpress.com/2009/12/05/people-and-software/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/086e1ed94cfc99c62fa27525e69b1a3b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajlopez</media:title>
		</media:content>

		<media:content url="http://www.ajlopez.com/images/articles2/twitterexample35.png" medium="image" />

		<media:content url="http://www.ajlopez.com/images/articles2/peoplesoftware.png" medium="image" />
	</item>
		<item>
		<title>Generating a model from the Database using AjGenesis</title>
		<link>http://ajlopez.wordpress.com/2009/11/28/generating-a-model-from-the-database-using-ajgenesis/</link>
		<comments>http://ajlopez.wordpress.com/2009/11/28/generating-a-model-from-the-database-using-ajgenesis/#comments</comments>
		<pubDate>Sat, 28 Nov 2009 22:46:07 +0000</pubDate>
		<dc:creator>ajlopez</dc:creator>
				<category><![CDATA[AjGenesis]]></category>
		<category><![CDATA[Code Generation]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajlopez.wordpress.com/?p=304</guid>
		<description><![CDATA[AjGenesis, my code generation open source project, use tasks, templates and a free model, to generate text artifacts, usually source code. Most of the examples use models serialized as XML or text files. But you can use anything as the initial input. Even a model could be the output of this process. Month ago, I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajlopez.wordpress.com&blog=378226&post=304&subd=ajlopez&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>AjGenesis, my code generation open source project, use tasks, templates and a free model, to generate text artifacts, usually source code. Most of the examples use models serialized as XML or text files. But you can use anything as the initial input. Even a model could be the output of this process. Month ago, I wrote about <a href="http://ajlopez.wordpress.com/2008/04/21/ajgenesis-generating-the-model-from-the-database/" target="_blank">generating the model from the database</a>. In my opinion, the database is not the more expressive model to use as starting point, but it is an ubiquitous one (you should admit: I’m improving my English vocabulary…;-)</p>
<p>In my current agile project, the team took the database as the base model. Actually, we are using a more abstract model, but the database was a good asset to use as first model.</p>
<p>So, I back to play with my old example, and improved it. You can download the current example from my Skydrive <a href="http://cid-9f903f3d6db0c176.skydrive.live.com/self.aspx/Examples/AjGenesis/DatabaseExample01.zip" target="_blank">DatabaseExample01.zip</a>. (the code in flux is in the code repository at Codeplex, under examples\DatabaseExamples).</p>
<p>After download and expand it, you have the folders:</p>
<p><img src="http://www.ajlopez.com/images/articles2/ajgenesisdb04.png" /> </p>
<p>The content of Projects\Northwind\Metadata.xml:</p>
<pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas;font-size:12px;margin:0;"><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Metadata</span><span style="color:#0000ff;">&gt;</span>
  <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Project</span><span style="color:#0000ff;">&gt;</span>
    <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Name</span><span style="color:#0000ff;">&gt;</span>Northwind<span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">Name</span><span style="color:#0000ff;">&gt;</span>
  <span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">Project</span><span style="color:#0000ff;">&gt;</span>
  <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Database</span><span style="color:#0000ff;">&gt;</span>
    <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Name</span><span style="color:#0000ff;">&gt;</span>Northwind<span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">Name</span><span style="color:#0000ff;">&gt;</span>
    <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">ConnectionString</span><span style="color:#0000ff;">&gt;</span>server=.\SQLEXPRESS;database=Northwind;Integrated Security=true<span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">ConnectionString</span><span style="color:#0000ff;">&gt;</span>
  <span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">Database</span><span style="color:#0000ff;">&gt;</span>
<span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">Metadata</span><span style="color:#0000ff;">&gt;</span></pre>
</pre>
<p>It describes the connection string to use to connect to example database. It use Northwind database, in SQL Server (full or express). If you don’t have Northwind, the creation scripts are in Sql folder.</p>
<p>To create the project and entities (the model to generate), run:</p>
<p><font face="Consolas">MakeModelFromDatabase.cmd</font></p>
<p>AjGenesis (compiled in Bin folder) begin to work:</p>
<p><img src="http://www.ajlopez.com/images/articles2/ajgenesisdb02.png" /> </p>
<p>The executed commad contains:</p>
<p><font face="Consolas">Bin\AjGenesis.Console Projects\Northwind\Metadata.xml Tasks\DatabaseProcess.ajg</font></p>
<p>This command loads Metadata.xml as model in memory, and executes the AjBasic task DatabaseProcess.ajg. This tasks use <a href="http://msdn.microsoft.com/en-us/library/ms186778.aspx" target="_blank">Information Schema views</a> to obtain information about database structure (using information schema views opens the possibility of database independence).</p>
<p>The task creates Projects\Northwind\Project.xml file:</p>
<pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas;font-size:12px;margin:0;"><span style="color:#0000ff;">&lt;?</span>xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot; standalone=&quot;yes&quot;<span style="color:#0000ff;">?&gt;</span>
<span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Project</span><span style="color:#0000ff;">&gt;</span>
  <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Name</span><span style="color:#0000ff;">&gt;</span>Northwind<span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">Name</span><span style="color:#0000ff;">&gt;</span>
  <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Model</span><span style="color:#0000ff;">&gt;</span>
    <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Entities</span><span style="color:#0000ff;">&gt;</span>
      <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Entity</span> <span style="color:#ff0000;">Source</span>=<span style="color:#0000ff;">&quot;Entities/Customer.xml&quot;</span><span style="color:#0000ff;">/&gt;</span>
      <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Entity</span> <span style="color:#ff0000;">Source</span>=<span style="color:#0000ff;">&quot;Entities/Shipper.xml&quot;</span><span style="color:#0000ff;">/&gt;</span>
      <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Entity</span> <span style="color:#ff0000;">Source</span>=<span style="color:#0000ff;">&quot;Entities/Supplier.xml&quot;</span><span style="color:#0000ff;">/&gt;</span>
      <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Entity</span> <span style="color:#ff0000;">Source</span>=<span style="color:#0000ff;">&quot;Entities/Order.xml&quot;</span><span style="color:#0000ff;">/&gt;</span>
      <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Entity</span> <span style="color:#ff0000;">Source</span>=<span style="color:#0000ff;">&quot;Entities/Product.xml&quot;</span><span style="color:#0000ff;">/&gt;</span>
      <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Entity</span> <span style="color:#ff0000;">Source</span>=<span style="color:#0000ff;">&quot;Entities/OrderDetail.xml&quot;</span><span style="color:#0000ff;">/&gt;</span>
      <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Entity</span> <span style="color:#ff0000;">Source</span>=<span style="color:#0000ff;">&quot;Entities/CustomerCustomerDemo.xml&quot;</span><span style="color:#0000ff;">/&gt;</span>
      <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Entity</span> <span style="color:#ff0000;">Source</span>=<span style="color:#0000ff;">&quot;Entities/CustomerDemographic.xml&quot;</span><span style="color:#0000ff;">/&gt;</span>
      <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Entity</span> <span style="color:#ff0000;">Source</span>=<span style="color:#0000ff;">&quot;Entities/Region.xml&quot;</span><span style="color:#0000ff;">/&gt;</span>
      <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Entity</span> <span style="color:#ff0000;">Source</span>=<span style="color:#0000ff;">&quot;Entities/Territory.xml&quot;</span><span style="color:#0000ff;">/&gt;</span>
      <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Entity</span> <span style="color:#ff0000;">Source</span>=<span style="color:#0000ff;">&quot;Entities/EmployeeTerritory.xml&quot;</span><span style="color:#0000ff;">/&gt;</span>
      <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Entity</span> <span style="color:#ff0000;">Source</span>=<span style="color:#0000ff;">&quot;Entities/Employee.xml&quot;</span><span style="color:#0000ff;">/&gt;</span>
      <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Entity</span> <span style="color:#ff0000;">Source</span>=<span style="color:#0000ff;">&quot;Entities/Category.xml&quot;</span><span style="color:#0000ff;">/&gt;</span>
    <span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">Entities</span><span style="color:#0000ff;">&gt;</span>
  <span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">Model</span><span style="color:#0000ff;">&gt;</span>
<span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">Project</span><span style="color:#0000ff;">&gt;</span>
</pre>
</pre>
<p>The project and entities are similar to the ones I used in <a href="http://ajlopez.wordpress.com/2007/11/12/application-generation-using-ajgenesis/" target="_blank">Application generationg using AjGenesis</a> (but there are not the same). Part of the generated file Projects\Northwind\Entities\Customer.xml:</p>
<pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas;font-size:12px;margin:0;"><span style="color:#0000ff;">&lt;?</span>xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot; standalone=&quot;yes&quot;<span style="color:#0000ff;">?&gt;</span>
<span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Entity</span><span style="color:#0000ff;">&gt;</span>
  <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Name</span><span style="color:#0000ff;">&gt;</span>Customer<span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">Name</span><span style="color:#0000ff;">&gt;</span>
  <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Description</span><span style="color:#0000ff;">&gt;</span>Customer<span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">Description</span><span style="color:#0000ff;">&gt;</span>
  <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">SetName</span><span style="color:#0000ff;">&gt;</span>Customers<span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">Name</span><span style="color:#0000ff;">&gt;</span>
  <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Descriptor</span><span style="color:#0000ff;">&gt;</span>Customer<span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">Descriptor</span><span style="color:#0000ff;">&gt;</span>
  <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">SetDescriptor</span><span style="color:#0000ff;">&gt;</span>Customers<span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">SetDescriptor</span><span style="color:#0000ff;">&gt;</span>
  <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">SqlCatalog</span><span style="color:#0000ff;">&gt;</span>Northwind<span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">SqlCatalog</span><span style="color:#0000ff;">&gt;</span>
  <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">SqlSchema</span><span style="color:#0000ff;">&gt;</span>dbo<span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">SqlSchema</span><span style="color:#0000ff;">&gt;</span>
  <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">SqlName</span><span style="color:#0000ff;">&gt;</span>Customers<span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">SqlName</span><span style="color:#0000ff;">&gt;</span>
  <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Properties</span><span style="color:#0000ff;">&gt;</span>
    <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Property</span><span style="color:#0000ff;">&gt;</span>
      <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Name</span><span style="color:#0000ff;">&gt;</span>CustomerID<span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">Name</span><span style="color:#0000ff;">&gt;</span>
      <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Description</span><span style="color:#0000ff;">&gt;</span>CustomerID<span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">Description</span><span style="color:#0000ff;">&gt;</span>
      <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">SqlName</span><span style="color:#0000ff;">&gt;</span>CustomerID<span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">SqlName</span><span style="color:#0000ff;">&gt;</span>
      <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">SqlLength</span><span style="color:#0000ff;">&gt;</span>5<span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">SqlLength</span><span style="color:#0000ff;">&gt;</span>
      <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">IsKey</span><span style="color:#0000ff;">&gt;</span>True<span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">IsKey</span><span style="color:#0000ff;">&gt;</span>
      <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">SqlType</span><span style="color:#0000ff;">&gt;</span>nchar<span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">SqlType</span><span style="color:#0000ff;">&gt;</span>
      <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">SystemType</span><span style="color:#0000ff;">&gt;</span>String<span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">SystemType</span><span style="color:#0000ff;">&gt;</span>
      <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">IsNullable</span><span style="color:#0000ff;">&gt;</span>False<span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">IsNullable</span><span style="color:#0000ff;">&gt;</span>
    <span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">Property</span><span style="color:#0000ff;">&gt;</span>
....
  <span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">Properties</span><span style="color:#0000ff;">&gt;</span>
<span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">Entity</span><span style="color:#0000ff;">&gt;</span>
</pre>
</pre>
<p>The main logic resides in Tasks\DatabaseProcess.ajg, written in AjBasic dynamic language, fragment:</p>
<pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas;font-size:12px;margin:0;">cmd = <span style="color:#0000ff;">new</span> System.Data.SqlClient.SqlCommand()
cmd.Connection = conn
cmd.CommandText = &quot;<span style="color:#8b0000;">select * from Information_Schema.Tables where Table_Type = 'BASE TABLE'</span>&quot;
conn.Open()
PrintLine &quot;<span style="color:#8b0000;">Reader</span>&quot;
dr = cmd.ExecuteReader()
Tables = CreateList()
<span style="color:#0000ff;">while</span> dr.Read()
  PrintLine &quot;<span style="color:#8b0000;">Table </span>&quot; &amp; dr.Item(&quot;<span style="color:#8b0000;">Table_Name</span>&quot;) &amp; &quot;<span style="color:#8b0000;">: </span>&quot; &amp; dr.Item(&quot;<span style="color:#8b0000;">Table_Type</span>&quot;)
  Table = CreateObject()
  Table.SqlCatalog = dr.Item(&quot;<span style="color:#8b0000;">Table_Catalog</span>&quot;)
  Table.SqlSchema = dr.Item(&quot;<span style="color:#8b0000;">Table_Schema</span>&quot;)
  Table.SqlName = dr.Item(&quot;<span style="color:#8b0000;">Table_Name</span>&quot;)
  Table.Name = Table.SqlName.Replace(&quot;<span style="color:#8b0000;"> </span>&quot;,&quot;<span style="color:#8b0000;"></span>&quot;)

  <span style="color:#0000ff;">if</span> IsPlural(Table.Name) <span style="color:#0000ff;">then</span>
    Table.SetName = Table.Name
    Table.Name = ToSingular(Table.Name)
  <span style="color:#0000ff;">else</span>
    Table.SetName = ToPlural(Table.Name)
  <span style="color:#0000ff;">end</span> <span style="color:#0000ff;">if</span>

  Table.Descriptor = Table.Name
  Table.SetDescriptor = Table.SetName

  Table.Description = Table.Name

  Tables.Add(Table)
<span style="color:#0000ff;">end</span> <span style="color:#0000ff;">while</span>
dr.Close()</pre>
</pre>
<h3>Possible improvements</h3>
<p>This examples is a “proof of concept”. To be used in a more general way, it should be improved. Some points to work:</p>
<p>- Use the generated model to generate a working application, scaffolding or not.</p>
<p>- Support of more meta data obtained via Information Schema</p>
<p>- Try another databases, try a real example</p>
<p>- Relation treatment: detecting cascade and other actions</p>
<p>Another posts about initial models for AjGenesis:</p>
<p><a href="http://ajlopez.wordpress.com/2008/10/02/another-model-for-ajgenesis/" target="_blank">Another model for AjGenesis</a></p>
<p><a href="http://ajlopez.wordpress.com/2008/09/28/textual-model-for-code-generation-in-ajgenesis/" target="_blank">Textual model for code generation in AjGenesis</a></p>
<p><a href="http://ajlopez.wordpress.com/2008/04/23/ajgenesis-generating-the-model-from-assemblies/" target="_blank">AjGenesis: Generating the model from assemblies</a></p>
<p><a href="http://ajlopez.wordpress.com/2008/04/21/ajgenesis-generating-the-model-from-the-database/" target="_blank">AjGenesis: Generating the model from the database</a></p>
<p>Angel “Java” Lopez<br />
  <br /><a href="http://www.ajlopez.com">http://www.ajlopez.com</a></p>
<p><a href="http://twitter.com/ajlopez">http://twitter.com/ajlopez</a></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajlopez.wordpress.com/304/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajlopez.wordpress.com/304/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajlopez.wordpress.com/304/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajlopez.wordpress.com/304/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajlopez.wordpress.com/304/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajlopez.wordpress.com/304/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajlopez.wordpress.com/304/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajlopez.wordpress.com/304/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajlopez.wordpress.com/304/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajlopez.wordpress.com/304/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajlopez.wordpress.com&blog=378226&post=304&subd=ajlopez&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ajlopez.wordpress.com/2009/11/28/generating-a-model-from-the-database-using-ajgenesis/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/086e1ed94cfc99c62fa27525e69b1a3b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajlopez</media:title>
		</media:content>

		<media:content url="http://www.ajlopez.com/images/articles2/ajgenesisdb04.png" medium="image" />

		<media:content url="http://www.ajlopez.com/images/articles2/ajgenesisdb02.png" medium="image" />
	</item>
		<item>
		<title>Generating code with AJGenesis using NHibernate hbm files</title>
		<link>http://ajlopez.wordpress.com/2009/11/22/generating-code-with-ajgenesis-using-nhibernate-hbm-files/</link>
		<comments>http://ajlopez.wordpress.com/2009/11/22/generating-code-with-ajgenesis-using-nhibernate-hbm-files/#comments</comments>
		<pubDate>Sun, 22 Nov 2009 09:50:45 +0000</pubDate>
		<dc:creator>ajlopez</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[AjGenesis]]></category>
		<category><![CDATA[C Sharp]]></category>
		<category><![CDATA[Code Generation]]></category>
		<category><![CDATA[NHibernate]]></category>

		<guid isPermaLink="false">http://ajlopez.wordpress.com/?p=291</guid>
		<description><![CDATA[I was working on generating C# classes, using as starting point .hbm NHibernate mapping files. As usual, I wrote an example with AjGenesis, my open source code generation engine.
You can download a first example from my Skydrive:
Examples &#62; AjGenesis &#62; NHibernateMappingExample01.zip
(the code is in the trunk, in the current change set, under examples\NHibernateMappinp:
 
but if [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajlopez.wordpress.com&blog=378226&post=291&subd=ajlopez&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I was working on generating C# classes, using as starting point .hbm <a href="http://nhforge.org/" target="_blank">NHibernate</a> mapping files. As usual, I wrote an example with <a href="http://ajgenesis.codeplex.com" target="_blank">AjGenesis</a>, my open source code generation engine.</p>
<p>You can download a first example from my Skydrive:</p>
<p><a href="http://cid-9f903f3d6db0c176.skydrive.live.com/self.aspx/Examples/AjGenesis/NHibernateMappingExample01.zip" target="_blank">Examples &gt; AjGenesis &gt; NHibernateMappingExample01.zip</a></p>
<p>(the code is in the trunk, in <a href="http://ajgenesis.codeplex.com/sourcecontrol/changeset/view/61684?projectName=ajgenesis#" target="_blank">the current change set</a>, under examples\NHibernateMappinp:</p>
<p><img src="http://www.todocontenidos.com/images/articles/ajgenesisnh03.png" /> </p>
<p>but if you want to go directly to the example, the Skydrive download I mentioned has all you need to run this demo, including AjGenesis trunk code compiled to binaries).</p>
<p>After expanding the file, you have this content:</p>
<p>&#160;<img src="http://www.todocontenidos.com/images/articles/ajgenesisnh02.png" /> </p>
<p>To create C# classes, execute at command prompt:</p>
<pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas;font-size:10pt;margin:0;">GenerateClasses AjFirstExample
GenerateClasses AjTest</pre>
</pre>
<p>To create a .NET project with the .cs and .hbm files, run:</p>
<pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas;font-size:10pt;margin:0;">GenerateProject AjFirstExample
GenerateProject AjTest</pre>
</pre>
<p>The generated files are created under Build folder.</p>
<p>The two example projects are AjFirstExample, with two simple plain mappings, and AjTest, with a more interesing mapping, with bags and many to one relations.</p>
<p>Currently, each project is described by a simple Project.xml:</p>
<pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas;font-size:10pt;margin:0;"><span style="color:#0000ff;">&lt;</span><span style="color:#800000;">Project</span> <span style="color:#ff0000;">Name</span>=<span style="color:#0000ff;">&quot;AjTest&quot;</span><span style="color:#0000ff;">&gt;</span>
<span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">Project</span><span style="color:#0000ff;">&gt;</span></pre>
</pre>
<p>This is one of the mapping files in Projects\AjTest\Mappings, Department.hbm:</p>
<pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas;font-size:10pt;margin:0;"><span style="color:#0000ff;">&lt;?</span>xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; <span style="color:#0000ff;">?&gt;</span>
<span style="color:#0000ff;">&lt;</span><span style="color:#800000;">hibernate</span>-<span style="color:#ff0000;">mapping</span> <span style="color:#ff0000;">xmlns</span>=<span style="color:#0000ff;">&quot;urn:nhibernate-mapping-2.2&quot;</span>
  <span style="color:#ff0000;">assembly</span>=<span style="color:#0000ff;">&quot;AjTest.Entities&quot;</span>
  <span style="color:#ff0000;">namespace</span>=<span style="color:#0000ff;">&quot;AjTest.Entities&quot;</span>
  <span style="color:#0000ff;">&gt;</span>
  <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">class</span> <span style="color:#ff0000;">name</span>=<span style="color:#0000ff;">&quot;Department&quot;</span> <span style="color:#ff0000;">table</span>=<span style="color:#0000ff;">&quot;departments&quot;</span><span style="color:#0000ff;">&gt;</span>
    <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">id</span> <span style="color:#ff0000;">name</span>=<span style="color:#0000ff;">&quot;Id&quot;</span> <span style="color:#ff0000;">column</span>=<span style="color:#0000ff;">&quot;Id&quot;</span> <span style="color:#ff0000;">type</span>=<span style="color:#0000ff;">&quot;Int32&quot;</span><span style="color:#0000ff;">&gt;</span>
      <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">generator</span> <span style="color:#ff0000;">class</span>=<span style="color:#0000ff;">&quot;native&quot;</span><span style="color:#0000ff;">/&gt;</span>
    <span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">id</span><span style="color:#0000ff;">&gt;</span>
    <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">property</span> <span style="color:#ff0000;">name</span>=<span style="color:#0000ff;">&quot;Description&quot;</span> <span style="color:#ff0000;">type</span>=<span style="color:#0000ff;">&quot;String&quot;</span><span style="color:#0000ff;">/&gt;</span>
    <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">bag</span> <span style="color:#ff0000;">name</span>=<span style="color:#0000ff;">&quot;Employees&quot;</span> <span style="color:#ff0000;">lazy</span>=<span style="color:#0000ff;">&quot;true&quot;</span> <span style="color:#ff0000;">inverse</span>=<span style="color:#0000ff;">&quot;true&quot;</span> <span style="color:#ff0000;">cascade</span>=<span style="color:#0000ff;">&quot;all&quot;</span><span style="color:#0000ff;">&gt;</span>
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas&lt;font-size:12px;margin:0;">      <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">key</span> <span style="color:#ff0000;">column</span>=<span style="color:#0000ff;">&quot;IdDepartment&quot;</span><span style="color:#0000ff;">/&gt;</span>
      <span style="color:#0000ff;">&lt;</span><span style="color:#800000;">one</span>-<span style="color:#ff0000;">to</span>-<span style="color:#ff0000;">many</span> <span style="color:#ff0000;">class</span>=<span style="color:#0000ff;">&quot;AjTest.Entities.Employee, AjTest.Entities&quot;</span><span style="color:#0000ff;">/&gt;</span>
    <span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">bag</span><span style="color:#0000ff;">&gt;</span>
  <span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">class</span><span style="color:#0000ff;">&gt;</span>
<span style="color:#0000ff;">&lt;/</span><span style="color:#800000;">hibernate</span>-mapping<span style="color:#0000ff;">&gt;</span>
</pre>
</pre>
<p>This is the generated code for this mapping, Department.generated.cs:</p>
<pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas;font-size:10pt;margin:0;"><span style="color:#0000ff;">using</span> System;
<span style="color:#0000ff;">using</span> System.Collections.Generic;
<span style="color:#0000ff;">using</span> Iesi.Collections.Generic;
<span style="color:#0000ff;">namespace</span> AjTest.Entities
{
  <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> Department {
    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">int</span> Id { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }
    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">string</span> Description { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }
    <span style="color:#0000ff;">public</span> IList&lt;Employee&gt; Employees { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }
    <span style="color:#0000ff;">public</span> Department()
    {
      <span style="color:#0000ff;">this</span>.Employees = <span style="color:#0000ff;">new</span> List&lt;Employee&gt;();
    }
  }
}
</pre>
</pre>
<p>Lets take a look to generation process. This is GenerateProject.cmd:</p>
<pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas;font-size:10pt;margin:0;">@echo off
<span style="color:#0000ff;">set</span> ProjectName=%1%
<span style="color:#0000ff;">if</span> &quot;<span style="color:#8b0000;">%1%</span>&quot;==&quot;<span style="color:#8b0000;"></span>&quot; <span style="color:#0000ff;">set</span> ProjectName=AjFirstExample
Bin\AjGenesis.Console.exe Projects\%ProjectName%\Project.xml Tasks\AddMappings.ajg Tasks\BuildCSharp.ajg
xcopy Libraries\*.* Build\%ProjectName%\CSharp\Src\Libraries /Y /Q</pre>
</pre>
<p>The main line is the one containing AjGenesis.Console.exe invocation. Project.xml is loaded in memory. The AddMapping.ajg task is loaded and executed, and then, BuildCSharp.ajg task is processed. AddMapping.ajg code (written in AjBasic, the dinamic language currently used by AjGenesis):</p>
<pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas;font-size:10pt;margin:0;"><span style="color:#008000;">' Add mappings from directory if not specified in Project model</span>
Include(&quot;<span style="color:#8b0000;">Utilities/Utilities.tpl</span>&quot;)
<span style="color:#0000ff;">if</span> <span style="color:#0000ff;">not</span> Project.Mappings <span style="color:#0000ff;">then</span>
  Project.Mappings = CreateList()

  di = <span style="color:#0000ff;">new</span> System.IO.DirectoryInfo(&quot;<span style="color:#8b0000;">Projects/${Project.Name}/Mappings</span>&quot;)

  <span style="color:#0000ff;">for</span> <span style="color:#0000ff;">each</span> fi <span style="color:#0000ff;">in</span> di.GetFiles(&quot;<span style="color:#8b0000;">*.hbm.xml</span>&quot;)
    filename = fi.Name
    Project.Mappings.Add(filename.Substring(0, filename.Length - 8))
  <span style="color:#0000ff;">end</span> <span style="color:#0000ff;">for</span>
<span style="color:#0000ff;">end</span> <span style="color:#0000ff;">if</span>
</pre>
</pre>
<p>It adds the name of mapping files contained in the Mapping folder of the project. A more interesing task is GenerateCSharp.ajg. First, it loads the NHibernate library to use its hbm parser:</p>
<pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas;font-size:10pt;margin:0;">include &quot;<span style="color:#8b0000;">Utilities/Utilities.tpl</span>&quot;
include &quot;<span style="color:#8b0000;">Utilities/FileUtilities.tpl</span>&quot;
include &quot;<span style="color:#8b0000;">Utilities/TypeUtilities.tpl</span>&quot;
Include(&quot;<span style="color:#8b0000;">Utilities/NHibernateUtilities.tpl</span>&quot;)
include &quot;<span style="color:#8b0000;">Templates/CSharp/UtilitiesCs.tpl</span>&quot;
include &quot;<span style="color:#8b0000;">Templates/CSharp/CSharpFunctions.tpl</span>&quot;
AssemblyManager.LoadFrom(&quot;<span style="color:#8b0000;">Libraries/NHibernate.dll</span>&quot;)
parser = <span style="color:#0000ff;">new</span> NHibernate.Cfg.MappingSchema.MappingDocumentParser()
</pre>
</pre>
<p>Then, it creates the solution and project objects:</p>
<pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas;font-size:10pt;margin:0;"><span style="color:#0000ff;">if</span> <span style="color:#0000ff;">not</span> Project.BuildDir <span style="color:#0000ff;">then</span>
  Project.BuildDir = &quot;<span style="color:#8b0000;">Build/${Project.Name}/CSharp</span>&quot;
<span style="color:#0000ff;">end</span> <span style="color:#0000ff;">if</span>
message &quot;<span style="color:#8b0000;">Creating Directories...</span>&quot;
FileManager.CreateDirectory(Project.BuildDir)
FileManager.CreateDirectory(&quot;<span style="color:#8b0000;">${Project.BuildDir}/Sql</span>&quot;)
FileManager.CreateDirectory(&quot;<span style="color:#8b0000;">${Project.BuildDir}/Src</span>&quot;)
FileManager.CreateDirectory(&quot;<span style="color:#8b0000;">${Project.BuildDir}/Src/Libraries</span>&quot;)
message &quot;<span style="color:#8b0000;">Defining Solution and Projects...</span>&quot;
Project.Solution = CreateObject()
Project.Solution.Guid = &quot;<span style="color:#8b0000;">FAE04EC0-301F-11D3-BF4B-00C04F79EFBC</span>&quot;
Project.Solution.Projects = CreateList()
message &quot;<span style="color:#8b0000;">Defining Entities Project...</span>&quot;
PrjEntities = CreateObject()
PrjEntities.Includes = CreateList()
PrjEntities.Guid = CreateGuid()
PrjEntities.COMGuid = CreateGuid()
Project.Solution.Projects.Add(PrjEntities)
Project.Entities = CreateList()
</pre>
</pre>
<p>Then, it iterates on each hbm file, to get information about the entities to generate:</p>
<pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas;font-size:10pt;margin:0;"><span style="color:#0000ff;">for</span> <span style="color:#0000ff;">each</span> MappingName <span style="color:#0000ff;">in</span> Project.Mappings
  filename = &quot;<span style="color:#8b0000;">Projects/${Project.Name}/Mappings/${MappingName}.hbm.xml</span>&quot;
  mapping = parser.Parse(OpenAsStream(filename))

  <span style="color:#0000ff;">for</span> <span style="color:#0000ff;">each</span> hbmclass <span style="color:#0000ff;">in</span> mapping.Items where IsType(hbmclass, &quot;<span style="color:#8b0000;">HbmClass</span>&quot;)
    Entity = CreateObject()

    Project.Entities.Add(Entity)

    Entity.ClassName = hbmclass.name
    Entity.<span style="color:#0000ff;">Namespace</span> = mapping.<span style="color:#0000ff;">namespace</span>

    <span style="color:#008000;">' Namespace as default project name for Entities Project</span>
    <span style="color:#0000ff;">if</span> <span style="color:#0000ff;">not</span> PrjEntities.Name <span style="color:#0000ff;">then</span>
      PrjEntities.Name = mapping.<span style="color:#0000ff;">namespace</span>
      PrjEntities.Directory = &quot;<span style="color:#8b0000;">${Project.BuildDir}/Src/${PrjEntities.Name}</span>&quot;
      FileManager.CreateDirectory(PrjEntities.Directory)
    <span style="color:#0000ff;">end</span> <span style="color:#0000ff;">if</span>

    Entity.Properties = CreateList()

    <span style="color:#0000ff;">if</span> hbmclass.Id <span style="color:#0000ff;">then</span>
      <span style="color:#0000ff;">Property</span> = CreateObject()
      <span style="color:#0000ff;">Property</span>.Name = hbmclass.Id.name
      <span style="color:#0000ff;">Property</span>.Type = HbmTypeToCSharp(hbmclass.Id.type1, Entity.<span style="color:#0000ff;">Namespace</span>)
      Entity.Properties.Add(<span style="color:#0000ff;">Property</span>)
    <span style="color:#0000ff;">end</span> <span style="color:#0000ff;">if</span>

    <span style="color:#0000ff;">for</span> <span style="color:#0000ff;">each</span> item <span style="color:#0000ff;">in</span> hbmclass.Items
      <span style="color:#0000ff;">if</span> IsType(item, &quot;<span style="color:#8b0000;">HbmProperty</span>&quot;) <span style="color:#0000ff;">then</span>
        <span style="color:#0000ff;">Property</span> = CreateObject()
        <span style="color:#0000ff;">Property</span>.Name = item.name
        <span style="color:#0000ff;">Property</span>.Type = HbmTypeToCSharp(item.type1, Entity.<span style="color:#0000ff;">Namespace</span>)
        Entity.Properties.Add(<span style="color:#0000ff;">Property</span>)
      <span style="color:#0000ff;">end</span> <span style="color:#0000ff;">if</span>

      <span style="color:#0000ff;">if</span> IsType(item, &quot;<span style="color:#8b0000;">HbmManyToOne</span>&quot;) <span style="color:#0000ff;">then</span>
        <span style="color:#0000ff;">Property</span> = CreateObject()
        <span style="color:#0000ff;">Property</span>.Name = item.name
        <span style="color:#0000ff;">Property</span>.Type = HbmTypeToCSharp(item.<span style="color:#0000ff;">class</span>, Entity.<span style="color:#0000ff;">Namespace</span>)
        Entity.Properties.Add(<span style="color:#0000ff;">Property</span>)
      <span style="color:#0000ff;">end</span> <span style="color:#0000ff;">if</span>
      <span style="color:#0000ff;">if</span> IsType(item, &quot;<span style="color:#8b0000;">HbmSet</span>&quot;) <span style="color:#0000ff;">then</span>
        <span style="color:#0000ff;">Property</span> = CreateObject()
        <span style="color:#0000ff;">Property</span>.Name = item.name
        <span style="color:#0000ff;">Property</span>.IsSet = <span style="color:#0000ff;">true</span>
        <span style="color:#0000ff;">Property</span>.Type = HbmTypeToCSharp(item.Item.<span style="color:#0000ff;">class</span>, Entity.<span style="color:#0000ff;">Namespace</span>)
        Entity.Properties.Add(<span style="color:#0000ff;">Property</span>)
      <span style="color:#0000ff;">end</span> <span style="color:#0000ff;">if</span>
      <span style="color:#0000ff;">if</span> IsType(item, &quot;<span style="color:#8b0000;">HbmBag</span>&quot;) <span style="color:#0000ff;">then</span>
        <span style="color:#0000ff;">Property</span> = CreateObject()
        <span style="color:#0000ff;">Property</span>.Name = item.name
        <span style="color:#0000ff;">Property</span>.IsList = <span style="color:#0000ff;">true</span>
        <span style="color:#0000ff;">Property</span>.Type = HbmTypeToCSharp(item.Item.<span style="color:#0000ff;">class</span>, Entity.<span style="color:#0000ff;">Namespace</span>)
        Entity.Properties.Add(<span style="color:#0000ff;">Property</span>)
      <span style="color:#0000ff;">end</span> <span style="color:#0000ff;">if</span>
    <span style="color:#0000ff;">end</span> <span style="color:#0000ff;">for</span>
  <span style="color:#0000ff;">end</span> <span style="color:#0000ff;">for</span>
<span style="color:#0000ff;">end</span> <span style="color:#0000ff;">for</span>
</pre>
</pre>
<p>You can extend the capabilities, processing more tags (I should write an example using Meta tags), and detecting more NHibernate mapping idioms. Now, the task generates the code:</p>
<pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas;font-size:10pt;margin:0;"><span style="color:#0000ff;">for</span> <span style="color:#0000ff;">each</span> Entity <span style="color:#0000ff;">in</span> Project.Entities
  TransformerManager.Transform(&quot;<span style="color:#8b0000;">Templates/CSharp/Entity.tpl</span>&quot;, &quot;<span style="color:#8b0000;">${PrjEntities.Directory}/${Entity.ClassName}.generated.cs</span>&quot;, Environment)
  PrjEntities.Includes.Add(CreateFileCs(&quot;<span style="color:#8b0000;">${Entity.ClassName}.generated</span>&quot;))
<span style="color:#0000ff;">end</span> <span style="color:#0000ff;">for</span>
</pre>
</pre>
<p>The tasks not only generates the .cs files, but it creates a solution and a C# project, copying and embedding the original mapping files:</p>
<pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas;font-size:10pt;margin:0;"><span style="color:#0000ff;">for</span> <span style="color:#0000ff;">each</span> MappingName <span style="color:#0000ff;">in</span> Project.Mappings
  filename = &quot;<span style="color:#8b0000;">Projects/${Project.Name}/Mappings/${MappingName}.hbm.xml</span>&quot;
  targetfilename = &quot;<span style="color:#8b0000;">${PrjEntities.Directory}/${MappingName}.hbm.xml</span>&quot;
  System.IO.File.Copy(filename, targetfilename, <span style="color:#0000ff;">true</span>)
  PrjEntities.Includes.Add(CreateFileType(MappingName,&quot;<span style="color:#8b0000;">hbm.xml</span>&quot;))
<span style="color:#0000ff;">end</span> <span style="color:#0000ff;">for</span>
<span style="color:#0000ff;">for</span> <span style="color:#0000ff;">each</span> CsProject <span style="color:#0000ff;">in</span> Project.Solution.Projects where CsProject.ProjectType&lt;&gt;&quot;<span style="color:#8b0000;">Web</span>&quot;
  FileManager.CreateDirectory(CsProject.Directory)
  FileManager.CreateDirectory(CsProject.Directory &amp; &quot;<span style="color:#8b0000;">/Properties</span>&quot;)
  TransformerManager.Transform(&quot;<span style="color:#8b0000;">Templates/CSharp/CsProject.tpl</span>&quot;, &quot;<span style="color:#8b0000;">${CsProject.Directory}/${CsProject.Name}.csproj</span>&quot;, Environment)
  TransformerManager.Transform(&quot;<span style="color:#8b0000;">Templates/CSharp/AssemblyInfoCs.tpl</span>&quot;, &quot;<span style="color:#8b0000;">${CsProject.Directory}/Properties/AssemblyInfo.cs</span>&quot;, Environment)
<span style="color:#0000ff;">end</span> <span style="color:#0000ff;">for</span>
TransformerManager.Transform(&quot;<span style="color:#8b0000;">Templates/Solution.tpl</span>&quot;, &quot;<span style="color:#8b0000;">${Project.BuildDir}/Src/${Project.Name}.sln</span>&quot;, Environment)
</pre>
</pre>
<p>This is the generated solution:</p>
<p><img src="http://www.todocontenidos.com/images/articles/ajgenesisnh01.png" /> </p>
<h3>Next steps</h3>
<p>I should work in these point:</p>
<p>- Generate a more complete solution (with NHibernate infrastructure, Web Presentation, etc…) as in others AjGenesis examples. </p>
<p>- Support more NHibernate mapping options</p>
<p>- Use meta tags</p>
<p>But now, you are able to play with this example. You can change the templates to generate more artifacts, as Visual Basic .NET source files.</p>
<p>Thanks to <a href="http://twitter.com/fabiomaulo" target="_blank">@fabiomaulo</a> for pointing me to the NHibernate hbm parser capabilities!</p>
<p>Angel “Java” Lopez<br />
  <br /><a href="http://www.ajlopez.com">http://www.ajlopez.com</a> </p>
<p><a href="http://twitter.com/ajlopez">http://twitter.com/ajlopez</a></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajlopez.wordpress.com/291/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajlopez.wordpress.com/291/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajlopez.wordpress.com/291/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajlopez.wordpress.com/291/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajlopez.wordpress.com/291/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajlopez.wordpress.com/291/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajlopez.wordpress.com/291/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajlopez.wordpress.com/291/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajlopez.wordpress.com/291/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajlopez.wordpress.com/291/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajlopez.wordpress.com&blog=378226&post=291&subd=ajlopez&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ajlopez.wordpress.com/2009/11/22/generating-code-with-ajgenesis-using-nhibernate-hbm-files/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/086e1ed94cfc99c62fa27525e69b1a3b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajlopez</media:title>
		</media:content>

		<media:content url="http://www.todocontenidos.com/images/articles/ajgenesisnh03.png" medium="image" />

		<media:content url="http://www.todocontenidos.com/images/articles/ajgenesisnh02.png" medium="image" />

		<media:content url="http://www.todocontenidos.com/images/articles/ajgenesisnh01.png" medium="image" />
	</item>
		<item>
		<title>The beauty of Twitter: Example 1</title>
		<link>http://ajlopez.wordpress.com/2009/11/21/the-beauty-of-twitter-example-1/</link>
		<comments>http://ajlopez.wordpress.com/2009/11/21/the-beauty-of-twitter-example-1/#comments</comments>
		<pubDate>Sat, 21 Nov 2009 13:17:00 +0000</pubDate>
		<dc:creator>ajlopez</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://ajlopez.wordpress.com/2009/11/21/the-beauty-of-twitter-example-1/</guid>
		<description><![CDATA[I’m an avid user of Twitter. Usually, I use TweetDeck as client. Twitter is a simple idea (short messages, you can follow every user with public profile) that has changed the way we are interacting. In the software development arena, Twitter is a great complement (or complete replacement) to reading feeds. This is an example [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajlopez.wordpress.com&blog=378226&post=289&subd=ajlopez&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I’m an avid user of Twitter. Usually, I use TweetDeck as client. Twitter is a simple idea (short messages, you can follow every user with public profile) that has changed the way we are interacting. In the software development arena, Twitter is a great complement (or complete replacement) to reading feeds. This is an example of its efectiveness.</p>
<p>Today, all begins with a tweet from <a href="http://twitter.com/jfroma" target="_blank">@jfroma</a>, a software developer (he is argentinian, like me:</p>
<p><img src="http://www.todocontenidos.com/images/articles/twitterexample05.png" /> </p>
<p>I didn’t read all his messages, then, I was curious about his comment: Model View View Model pattern. I know José (<a href="http://twitter.com/jfroma" target="_blank">@jfroma</a>) has working examples of <a href="http://jfromaniello.blogspot.com/search/label/WPF" target="_blank">data binding in WPF</a> over models retrieved via NHibernate, so I followed the link and began to read <a href="http://twitter.com/michaellperry" target="_blank">@michaellperry</a> messages. It was my first contact with Michael:</p>
<p><img src="http://www.todocontenidos.com/images/articles/twitterexample08.png" /> </p>
<p>Then, I found his presentation:</p>
<p><a href="http://www.notatpdc.com/Schedule/Detail/50" target="_blank">Session Detail: Data binding without INotifyPropertyChanged</a></p>
<p>asking <a href="http://twitter.com/jfroma" target="_blank">@jfroma</a>:</p>
<p><img src="http://www.todocontenidos.com/images/articles/twitterexample06.png" /> </p>
<p>Now, having more context, I discovered Michael interests in his blog (note: Michael is display Twitter status at left):</p>
<p><a title="http://adventuresinsoftware.com/blog" href="http://adventuresinsoftware.com/blog">http://adventuresinsoftware.com/blog</a></p>
<p><img src="http://www.todocontenidos.com/images/articles/twitterexample09.png" /> </p>
<p>I discovered the open source library, base of Michael presentation:</p>
<p><a title="http://updatecontrols.net" href="http://updatecontrols.net">http://updatecontrols.net</a></p>
<p><img src="http://www.todocontenidos.com/images/articles/twitterexample10.png" /></p>
<p>I started to tweet about this library, and others take notice, like <a href="http://twitter.com/jyinglee" target="_blank">@jyinglee</a>:</p>
<p><img src="http://www.todocontenidos.com/images/articles/twitterexample07.png" />&#160; </p>
<p>All started with a simple message. That’s the power of Twitter. There is a “serendipity with help” from interesting people you follow and that follows you.</p>
</p>
<p>Angel “Java” Lopez    <br /><a href="http://www.ajlopez.com">http://www.ajlopez.com</a>     <br /><a href="http://twitter.com/ajlopez">http://twitter.com/ajlopez</a></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajlopez.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajlopez.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajlopez.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajlopez.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajlopez.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajlopez.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajlopez.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajlopez.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajlopez.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajlopez.wordpress.com/289/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajlopez.wordpress.com&blog=378226&post=289&subd=ajlopez&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ajlopez.wordpress.com/2009/11/21/the-beauty-of-twitter-example-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/086e1ed94cfc99c62fa27525e69b1a3b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajlopez</media:title>
		</media:content>

		<media:content url="http://www.todocontenidos.com/images/articles/twitterexample05.png" medium="image" />

		<media:content url="http://www.todocontenidos.com/images/articles/twitterexample08.png" medium="image" />

		<media:content url="http://www.todocontenidos.com/images/articles/twitterexample06.png" medium="image" />

		<media:content url="http://www.todocontenidos.com/images/articles/twitterexample09.png" medium="image" />

		<media:content url="http://www.todocontenidos.com/images/articles/twitterexample10.png" medium="image" />

		<media:content url="http://www.todocontenidos.com/images/articles/twitterexample07.png" medium="image" />
	</item>
		<item>
		<title>NHibernate running in the Azure Cloud</title>
		<link>http://ajlopez.wordpress.com/2009/10/31/nhibernate-running-in-the-azure-cloud/</link>
		<comments>http://ajlopez.wordpress.com/2009/10/31/nhibernate-running-in-the-azure-cloud/#comments</comments>
		<pubDate>Sat, 31 Oct 2009 13:12:03 +0000</pubDate>
		<dc:creator>ajlopez</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Azure]]></category>
		<category><![CDATA[Cloud Computing]]></category>
		<category><![CDATA[NHibernate]]></category>

		<guid isPermaLink="false">http://ajlopez.wordpress.com/2009/10/31/nhibernate-running-in-the-azure-cloud/</guid>
		<description><![CDATA[Yesterday, I was talking with Fabio Maulo (@fabiomaulo) about many things, related to software development, teaching programming and, of course, NHibernate. We are living in Buenos Aires, Argentina, and it was a pleasure to talk with him, as usual. Í’m following Fabio in Twitter, and I’m a suscriber of his blog. Fabio is collaborating with [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajlopez.wordpress.com&blog=378226&post=283&subd=ajlopez&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Yesterday, I was talking with <a href="http://fabiomaulo.blogspot.com" target="_blank">Fabio Maulo</a> (<a href="http://twitter.com/fabiomaulo" target="_blank">@fabiomaulo</a>) about many things, related to software development, teaching programming and, of course, NHibernate. We are living in Buenos Aires, Argentina, and it was a pleasure to talk with him, as usual. Í’m following Fabio in Twitter, and I’m a suscriber of <a href="http://fabiomaulo.blogspot.com" target="_blank">his blog</a>. Fabio is collaborating with NHibernate project for years, and he is a recognized developer in the .NET software community.</p>
<p>He told me details about a site built using NHibernate, and running on SQL Azure. You can see it online (Spanish content, Mexican site):</p>
<p><a title="http://salondetokio.autocosmos.com.mx/" href="http://salondetokio.autocosmos.com.mx/">http://salondetokio.autocosmos.com.mx/</a></p>
<p><img src="http://www.ajlopez.com/images/articles/nhibernateazure01.png" /> </p>
<p>Fabio and his team worked hard to write this site, in less of a month (I’m waiting the team posts, with more detailed info, so, I’ll write only about the public parts here).</p>
<p>Curiously, the site is running using WebForms, but without ViewState, and without form tags embracing the full body inner HTML. All we are waiting Maulo and his team, explaining the implementation details. The code is based on using Model View Presenter, and it was build using tests, mocks and stubs, from presentation to persistence. Hey, Fabio! Please, write about the process and architecture decisions! <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>More info about NHibernate and Azure:</p>
<p><a href="http://ayende.com/Blog/archive/2009/09/05/nhibernate-on-the-cloud-sql-azure.aspx">NHibernate on the cloud: SQL Azure</a> Ayende NHibernate test results on Azure</p>
<p><a href="http://fabiomaulo.blogspot.com/2009/09/quick-news-nhibernate-with-sql-azure.html">Quick news NHibernate with SQL Azure</a> Fabio’s first steps “All work… even the SchemaExport.” !!</p>
<p><a href="http://fabiomaulo.blogspot.com/2009/10/nhibernate-dialect-for-sql-azure.html">NHibernate dialect for SQL Azure</a> Adjustments for SchemaExport</p>
<p>I’m collecting links about NHibernate and Azure at:</p>
<p><a title="http://delicious.com/ajlopez/nhibernate+azure" href="http://delicious.com/ajlopez/nhibernate+azure">http://delicious.com/ajlopez/nhibernate+azure</a></p>
<p>There is an excellent post serie from Brad Adams, explaining Azure, Azure SQL, NHibernate, Silverlight, RIA .NET Service, and more:</p>
<p><a href="http://blogs.msdn.com/brada/archive/2009/10/27/index-for-business-apps-example-for-silverlight-3-rtm-and-net-ria-services-july-update.aspx" target="_blank">Index for Business Apps example for Silverligth 3 RTM and .NET RIA Services July Update</a></p>
<p>Related to NHibernate and Azure, in that series:</p>
<p><a href="http://blogs.msdn.com/brada/archive/2009/08/06/business-apps-example-for-silverlight-3-rtm-and-net-ria-services-july-update-part-nhibernate.aspx" target="_blank">Part 20: NHibernate</a>     <br /><a href="http://blogs.msdn.com/brada/archive/2009/08/21/business-apps-example-for-silverlight-3-rtm-and-net-ria-services-july-update-part-23-azure.aspx" target="_blank">Part 23: Azure</a></p>
<p>Any other project using NHibernate on the cloud?</p>
<p>Angel “Java” Lopez    <br /><a href="http://www.ajlopez.com">http://www.ajlopez.com</a>     <br /><a href="http://twitter.com/ajlopez">http://twitter.com/ajlopez</a></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajlopez.wordpress.com/283/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajlopez.wordpress.com/283/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajlopez.wordpress.com/283/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajlopez.wordpress.com/283/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajlopez.wordpress.com/283/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajlopez.wordpress.com/283/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajlopez.wordpress.com/283/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajlopez.wordpress.com/283/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajlopez.wordpress.com/283/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajlopez.wordpress.com/283/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajlopez.wordpress.com&blog=378226&post=283&subd=ajlopez&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ajlopez.wordpress.com/2009/10/31/nhibernate-running-in-the-azure-cloud/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/086e1ed94cfc99c62fa27525e69b1a3b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajlopez</media:title>
		</media:content>

		<media:content url="http://www.ajlopez.com/images/articles/nhibernateazure01.png" medium="image" />
	</item>
		<item>
		<title>A 10 finger Multitouch User Interface</title>
		<link>http://ajlopez.wordpress.com/2009/10/15/a-10-finger-multitouch-user-interface/</link>
		<comments>http://ajlopez.wordpress.com/2009/10/15/a-10-finger-multitouch-user-interface/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 10:34:22 +0000</pubDate>
		<dc:creator>ajlopez</dc:creator>
				<category><![CDATA[Interface]]></category>
		<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://ajlopez.wordpress.com/2009/10/15/a-10-finger-multitouch-user-interface/</guid>
		<description><![CDATA[This a video demostration new ideas about a multitouch device from http://10gui.com/:
Over a quarter-century ago, Xerox introduced the modern graphical user interface paradigm we today take for granted.     That it has endured is a testament to the genius of its design. But the industry is now at a crossroads: New technologies [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajlopez.wordpress.com&blog=378226&post=265&subd=ajlopez&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>This a video demostration new ideas about a multitouch device from <a href="http://10gui.com/">http://10gui.com/</a>:</p>
<blockquote><p>Over a quarter-century ago, Xerox introduced the modern graphical user interface paradigm we today take for granted.     <br />That it has endured is a testament to the genius of its design. But the industry is now at a crossroads: New technologies promise higher-bandwidth interaction, but have yet to find a truly viable implementation.      <br />10/GUI aims to bridge this gap by rethinking the desktop to leverage technology in an intuitive and powerful way. </p>
</blockquote>
<p><span style="text-align:center; display: block;"><a href="http://ajlopez.wordpress.com/2009/10/15/a-10-finger-multitouch-user-interface/"><img src="http://img.youtube.com/vi/zWz1KbknIZk/2.jpg" alt="" /></a></span></p>
<p>More info at <a title="http://10gui.com/background/" href="http://10gui.com/background/">http://10gui.com/background/</a>. You can follow Clayton Miller in Twitter: <a href="http://twitter.com/claymill" target="_blank">@claymill</a>.</p>
<p>It’s interesting to see the drawing pad idea now leveraged with multitouch. This way, we could add multitouch capabilities to any monitor, hardware, instead of using a dedicated multitouch display. The problem: the fingers are out of our vision. The solution: the fingers are tracked and displayed on screen, in the same way we usually track the mouse using the onscreen arrow cursor.</p>
<p>The other interesting point is the “con10uum”, and the finger set interaction. I guess it’s like learning to play a musical instrument: you must practice, but with little effort, the finger gestures seem practical.</p>
<p>Angel “Java” Lopez   <br /><a href="http://www.ajlopez.com">http://www.ajlopez.com</a>    <br /><a href="http://twitter.com/ajlopez">http://twitter.com/ajlopez</a></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajlopez.wordpress.com/265/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajlopez.wordpress.com/265/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajlopez.wordpress.com/265/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajlopez.wordpress.com/265/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajlopez.wordpress.com/265/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajlopez.wordpress.com/265/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajlopez.wordpress.com/265/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajlopez.wordpress.com/265/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajlopez.wordpress.com/265/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajlopez.wordpress.com/265/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajlopez.wordpress.com&blog=378226&post=265&subd=ajlopez&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ajlopez.wordpress.com/2009/10/15/a-10-finger-multitouch-user-interface/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/086e1ed94cfc99c62fa27525e69b1a3b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajlopez</media:title>
		</media:content>

		<media:content url="http://img.youtube.com/vi/zWz1KbknIZk/2.jpg" medium="image" />
	</item>
		<item>
		<title>Time for simplicity?</title>
		<link>http://ajlopez.wordpress.com/2009/10/14/time-for-simplicity/</link>
		<comments>http://ajlopez.wordpress.com/2009/10/14/time-for-simplicity/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 12:00:50 +0000</pubDate>
		<dc:creator>ajlopez</dc:creator>
				<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ajlopez.wordpress.com/2009/10/14/time-for-simplicity/</guid>
		<description><![CDATA[ These days, Ted Neward wrote a very interesting post “Agile is treating the symptons, not the disease” quoting a phrase of Billy Hollis, from Patterns and Practice Submit this week in Redmond. I read:
“A lot of software written back in the 90&#8217;s was written by 1 or 2 guys working for just a few [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajlopez.wordpress.com&blog=378226&post=264&subd=ajlopez&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><img style="display:inline;margin:0 20px 20px 0;" src="http://www.todocontenidos.com/images/articles/compsimp.png" align="left" /> These days, Ted Neward wrote a very interesting post <a href="http://blogs.tedneward.com/2009/10/12/quotAgile+Is+Treating+The+Symptoms+Not+The+Diseasequot.aspx" target="_blank">“Agile is treating the symptons, not the disease”</a> quoting a phrase of Billy Hollis, from Patterns and Practice Submit this week in Redmond. I read:</p>
<p><em>“A lot of software written back in the 90&#8217;s was written by 1 or 2 guys working for just a few months to slam something out and see if it was useful”</em></p>
<p><em>“The problem is the complexity of the tools we have available to us today preclude that kind of software development.”</em></p>
<p>I see the problem is more associated with technologies, not with the tools. Web services, as example. For me, web services are not a tool, like libraries, compilers, or IDE. Web services are technology. Most of the tools (i.e. Eclipse, Visual Studio) are fighting the complexity of the underlying technologies. 1 or 2 guys, today, can still create a wonderful open source library, but try to write with the same team an enterprise application, involving database, communications, security, manageability, instrumentation, and so on. There are lots of details in the underlying technologies to implement, that the complexity of any non trivial application could be (and usually is) dauting.</p>
<p>Back to web services. Did you visit <a href="http://en.wikipedia.org/wiki/Web_service" target="_blank">Wikipedia page</a> about that topic, recently? You&#8217;ll find dozens of specifications. You could spend weeks or months, trying to grasp all the technicalities involved in WS-Trust, WS-Addressing, WS-Transaction, WS-PutYourWordHere. I guess REST style adoption is a reaction to such madness (REST style, not REST principles, or RESTFul). Sometimes, libraries are coming to rescue, and sometimes, their fail. My preferred example of a failed trying to hide web service complexity is Windows Communication Foundation (WCF). I wrote about this at <a href="http://ajlopez.wordpress.com/2009/03/04/windows-communication-foundation-configuration-madness/">Windows Communication Foundation configuration madness</a>.</p>
<p>Complexity in software, is not bad for itself. It could be good. Software is in every human activity. Internet popularity, fueled by the World Wide Web adoption, is now in practically every place of our days. As software developers, we are contributing to such progress. We are not pursuing our comfort zone, we are looking for software value.</p>
<p>Now, customer requirements are more challenging: massive multiuser access, scalability, distributed processing, online availability, are usually included in most of current enterprise applications. And there is no simple solution now to cover all the corners.</p>
<p>Said that, complexity is still with us, and it could be fighted. I spend most of my work hours teaching programming, and the rest of the time working on software development. I suffer the complexity of the current state of affairs in software development. The amount of details to take into account (ORMs setups, dependency injection configuration, testing setup, mock libraries, WCF or JBoss configuration… ) is so big, that our minds are lost in the middle of such jungle.</p>
<p>Do you remember Petzoldian age? Lots of lines to write a simple “Hello world” program that runs on Windows. Then, Visual Basic was born. Visual Basic was an effective way to hide the Windows API and behaviour complexity, saving generations of developers of struggling with handles, and LONG values where the mouse coordinates are coming in the Windows messages. That was hell, truly hell.</p>
<p>Do you remember reading VTOCs in IBM disks? Writing Job Control Language? Writing macro assemblers? For each of those tools, there were a solution that hides the underlying complexity, using the “old trick”: raising the level of abstraction. Instead of thinking in registers and sectors, we could manage variables, and SQL statements.</p>
<p>I guess it was end of eighties, beginning of nineties, were the software development in PC arena reach the top of power/complexity ratio (Turbo Pascal, Visual Basic, Access): lots of power, low complexity. Since then, we are in a free fall. The “old trick” of “rise the abstraction level” didn&#8217;t embrace again: we are still building software using third generation languages, the macro assemblers of the sixties.</p>
<p>One way to escape is going for the next level of abstraction. We forget about registers and Branch And Link Register instruction and adopted general programming languages. Now, we need to write software in a higher level. My bet: Domain Specific Models and Languages. But it’s only a bet. Using DSLs, DSMs, code generation (do you realize that compiling your C# program is “code generation” NOW?), we could leverage the existing technology, hiding the underlying complexity.</p>
<p>With so many languages, libraries, technologies to use, there is no simple solution to hide all this mess. Note that there are many kinds of complexity. One is the complexity of the customer requirements: business logic, functional requirements. That&#8217;s ok. And I think that agile methodologies are attacking such kind of complexity. But the complexity that hurts us now, is the technological one. We should stop the journey towards a Petzoldian age. (recently, I found the concept of Accidental Complexity, in a <a href="http://en.wikipedia.org/wiki/Rich_Hickey" target="_blank">Rich Hickey</a> talk (hmmm… I guess he named it as incidental complexity). From Wikipedia page <a href="http://en.wikipedia.org/wiki/Accidental_complexity" target="_blank">about accidental complexity</a>:</p>
<p><em><b>Accidental complexity</b> is complexity that arises in </em><a href="http://en.wikipedia.org/wiki/Computer_program"><em>computer programs</em></a><em> or their development process (</em><a href="http://en.wikipedia.org/wiki/Computer_programming"><em>computer programming</em></a><em>) which is non-essential to the problem to be solved. While </em><a href="http://en.wikipedia.org/wiki/Essential_complexity"><em>essential complexity</em></a><em> is inherent and unavoidable, accidental complexity is caused by the approach chosen to solve the problem</em></p>
<p>)</p>
<p>Another interesting posts, triggered by Neward original one:</p>
<p>Jeffrey Palermos&#8217;s <a href="http://jeffreypalermo.com/blog/response-quot-agile-is-treating-the-symptoms-not-the-disease-quot-by-ted-neward/" target="_blank">Response: “Agile is treating the symptoms, not the disease” by Ted Neward</a>ç    <br />Phil Haack&#8217;s <a href="http://haacked.com/archive/2009/10/13/software-externalities.aspx" target="_blank">Software Externalities</a>    <br />Ted Neward’s response to Haack <a href="http://blogs.tedneward.com/2009/10/13/Haacked+But+Not+Content+Agile+Still+Treats+The+Disease.aspx" target="_blank">Haacked, but not content; agile still treats the disease</a>&#160;</p>
<p>I have so much to comment about all these writings and thoughts. But they deserve other commenting posts, not to comment now.</p>
<p>I want to remember one more thing here: complexity is not the only challange in software development. Every succesful project could suffer of complexity AND change. Those are the problems agile methodologies are treating: fighting complexity with baby steps, eating an elephant piece by piece, and stop fearing change, embracing it, adopting disciplines to lower the cost of change in the middle of the development.</p>
<p>Another point: with Internet adoption, our current software development culture is flourishing, with so many ideas, reference implementations, open source libraries, patterns, practices, frameworks, and programming languages (there a new set of dynamic languages, mounted over Java and .NET). The Pandora&#8217;s box was open: I don&#8217;t see any way to close it.</p>
<p>In his cited post, Ted Neward wrote:</p>
<p><em>Let me rephrase Billy&#8217;s talk this way: </em><em>Where is this decade&#8217;s Access?</em></p>
<p>I have some ideas, to response to that question. But now, I should go to teach .NET: I hope no big complexity hurts today class.</p>
<p>(Note: English is not my mother tongue, so, feel free to suggest corrections to my writing. Most of my ideas about the complexity subject should be expressed in a short way, that could be clear enough, I hope still this post could be understood: this is a fascinanting topic: how to improve the creation of software?)</p>
<p>Angel “Java” Lopez   <br /><a href="http://www.ajlopez.com">http://www.ajlopez.com</a>    <br /><a href="http://twitter.com/ajlopez">http://twitter.com/ajlopez</a></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajlopez.wordpress.com/264/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajlopez.wordpress.com/264/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajlopez.wordpress.com/264/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajlopez.wordpress.com/264/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajlopez.wordpress.com/264/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajlopez.wordpress.com/264/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajlopez.wordpress.com/264/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajlopez.wordpress.com/264/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajlopez.wordpress.com/264/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajlopez.wordpress.com/264/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajlopez.wordpress.com&blog=378226&post=264&subd=ajlopez&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ajlopez.wordpress.com/2009/10/14/time-for-simplicity/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/086e1ed94cfc99c62fa27525e69b1a3b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajlopez</media:title>
		</media:content>

		<media:content url="http://www.todocontenidos.com/images/articles/compsimp.png" medium="image" />
	</item>
		<item>
		<title>Exploring objects</title>
		<link>http://ajlopez.wordpress.com/2009/09/23/exploring-objects/</link>
		<comments>http://ajlopez.wordpress.com/2009/09/23/exploring-objects/#comments</comments>
		<pubDate>Wed, 23 Sep 2009 09:38:10 +0000</pubDate>
		<dc:creator>ajlopez</dc:creator>
				<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[Smalltalk]]></category>

		<guid isPermaLink="false">http://ajlopez.wordpress.com/2009/09/23/exploring-objects/</guid>
		<description><![CDATA[I’m following @jarober (James A. Robertson) in Twitter, Cincom Smalltalk Product Evangelist. He post links about news and resources about Smalltalk, and Cincom Smalltalk in particular. He writes a blog:
http://www.cincomsmalltalk.com/blog/View.ssp
powered by Smalltalk. If you visit his blog, there are many entries about Smalltalk. Recently, Robertson posted:
Smalltalk Daily: Exploring Objects
There is the video:

Robertson wrote:
Many times, you [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajlopez.wordpress.com&blog=378226&post=261&subd=ajlopez&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I’m following <a href="http://twitter.com/jarober" target="_blank">@jarober</a> (James A. Robertson) in Twitter, Cincom Smalltalk Product Evangelist. He post links about news and resources about Smalltalk, and Cincom Smalltalk in particular. He writes a blog:</p>
<p><a title="http://www.cincomsmalltalk.com/blog/View.ssp" href="http://www.cincomsmalltalk.com/blog/View.ssp">http://www.cincomsmalltalk.com/blog/View.ssp</a></p>
<p>powered by Smalltalk. If you visit his blog, there are many entries about Smalltalk. Recently, Robertson posted:</p>
<p><a href="http://www.cincomsmalltalk.com/blog/blogView?entry=3430713089" target="_blank">Smalltalk Daily: Exploring Objects</a></p>
<p>There is the video:</p>
<p><span style="text-align:center; display: block;"><a href="http://ajlopez.wordpress.com/2009/09/23/exploring-objects/"><img src="http://img.youtube.com/vi/_4fUt3Bi_6E/2.jpg" alt="" /></a></span></p>
<p>Robertson wrote:</p>
<blockquote><p>Many times, you want to do something, know that it can be done &#8211; but just aren&#8217;t sure how to construct the code to do it. If you have an object, you can usually solve that problem by drilling into it with the inspector and looking at it. Today we learn how to programmatically change workspace page text by drilling into a workspace.</p>
</blockquote>
<p>It&#8217;s refreshing to see such interaction with objects, so “Smalltalk-way” of interaction.</p>
<p>I should work on my <a href="http://ajlopez.wordpress.com/category/ajtalk/" target="_blank">Smalltalk VM (interpreter) AjTalk</a>, to have support of visual interaction. My idea is to wire the current VM with .NET framework, WinForms. In this way, I could leverage the built-in GUI support in the framework. In these day, every language should take advantage of a class framework: .NET and Java are the obvious choice (see <a href="http://clojure.org" target="_blank">Clojure</a> as a “modern” example of this strategy)</p>
<p>Angel “Java” Lopez   <br /><a href="http://www.ajlopez.com">http://www.ajlopez.com</a>    <br /><a href="http://twitter.com/ajlopez">http://twitter.com/ajlopez</a></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajlopez.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajlopez.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajlopez.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajlopez.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajlopez.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajlopez.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajlopez.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajlopez.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajlopez.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajlopez.wordpress.com/261/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajlopez.wordpress.com&blog=378226&post=261&subd=ajlopez&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ajlopez.wordpress.com/2009/09/23/exploring-objects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/086e1ed94cfc99c62fa27525e69b1a3b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajlopez</media:title>
		</media:content>

		<media:content url="http://img.youtube.com/vi/_4fUt3Bi_6E/2.jpg" medium="image" />
	</item>
		<item>
		<title>AjSharp programming language: a C#-like dynamic language</title>
		<link>http://ajlopez.wordpress.com/2009/09/21/ajsharp-programming-language-a-c-like-dynamic-language/</link>
		<comments>http://ajlopez.wordpress.com/2009/09/21/ajsharp-programming-language-a-c-like-dynamic-language/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 08:58:40 +0000</pubDate>
		<dc:creator>ajlopez</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[AjSharp]]></category>
		<category><![CDATA[Programming Languages]]></category>

		<guid isPermaLink="false">http://ajlopez.wordpress.com/2009/09/21/ajsharp-programming-language-a-c-like-dynamic-language/</guid>
		<description><![CDATA[During the creation of AjGenesis, my code generation project, I defined an interpreted language, named AjBasic, used to write templates and tasks for code generation process. Last year, I began to separate AjBasic implementation of AjGenesis core, and as a proof of concept, I wrote AjSharp, another interpreted language but with more C#-like syntax, using [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajlopez.wordpress.com&blog=378226&post=256&subd=ajlopez&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>During the creation of <a href="http://ajgenesis.codeplex.com" target="_blank">AjGenesis</a>, my code generation project, I defined an interpreted language, named AjBasic, used to write templates and tasks for code generation process. Last year, I began to separate AjBasic implementation of AjGenesis core, and as a proof of concept, I wrote <a href="http://ajlopez.wordpress.com/category/ajsharp/" target="_blank">AjSharp</a>, another interpreted language but with more C#-like syntax, using the same core interpreter that I wrote for <a href="http://ajlopez.wordpress.com/category/ajbasic/" target="_blank">AjBasic</a>. The core machine was AjInterpreter. More info at:</p>
<p><a title="AjSharp- a C Sharp-like interpreter, work in progress" href="http://ajlopez.wordpress.com/2008/09/25/ajsharp-a-c-sharp-like-interpreter-work-in-progress/">AjSharp- a C Sharp-like interpreter, work in progress</a></p>
<p>Now, this year, I started a clean implementation, inside <a href="http://code.google.com/p/ajcodekatas" target="_blank">my AjCodeKatas Google Code</a>. The core interpreter is now AjLanguage, and AjSharp is the language with a parser that relies on the core “virtual machine” to build and execute an abstract tree:</p>
<p><img src="http://www.todocontenidos.com/images/articles/ajlanguage01.png" alt="" /></p>
<p>Current source code (under development) can be downloaded from:</p>
<p><a title="http://code.google.com/p/ajcodekatas/source/browse/#svn/trunk/AjLanguage" href="http://code.google.com/p/ajcodekatas/source/browse/#svn/trunk/AjLanguage">http://code.google.com/p/ajcodekatas/source/browse/#svn/trunk/AjLanguage</a></p>
<h2>Variables, expressions and commands</h2>
<p>Variables are untyped, and are automatically declared when they are used:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0;">
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">a = 1;</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;">b = 2;</pre>
</div>
</div>
<p>These variables contain integer values, but they can be assigned to values of other types:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;">
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">a = “one”;</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;">b = “two”;</pre>
</div>
<p>The common commands are supported:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;">
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"></pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">if</span> (k&gt;0)</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"> <span style="color:#0000ff;">return</span>;</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"></pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">for</span> (k=1; k&lt;=10;</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">k++)</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"> sum = k+sum;</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"></pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">while</span></pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">(j&lt;10)</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"> DoProcess(j);</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"></pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">foreach</span> (element <span style="color:#0000ff;">in</span></pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">elements)</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"> AddElement(element);</pre>
</div>
<p>Conditional expressions can be any expression, not only boolean ones. See above, False value explanation.</p>
<h2>Functions and Subroutines</h2>
<p>This is the sintax to write down a factorial function:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;">
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">function Factorial(n)</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">{</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"> <span style="color:#0000ff;">if</span></pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">(n&lt;=1)</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"> <span style="color:#0000ff;">return</span></pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">1;</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"> <span style="color:#0000ff;">return</span> n * Factorial(n-1);</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">}</pre>
</div>
<p>The word “sub” can be used to define subroutines.</p>
<p>Functions and subroutines are like any other values. They can be defined without name and assigned to variables:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;">
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"></pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">Add1 = function (n) { <span style="color:#0000ff;">return</span> n+1; }</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">two = Add1(1);</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">function Apply(func,values)</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">{</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"> list = <span style="color:#0000ff;">new</span></pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">List();</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"> <span style="color:#0000ff;">foreach</span> (<span style="color:#0000ff;">value</span> <span style="color:#0000ff;">in</span></pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">values)</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">list.Add(func(<span style="color:#0000ff;">value</span>));</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"> <span style="color:#0000ff;">return</span> list;</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">}</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">numbers = <span style="color:#0000ff;">new</span></pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">List();</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">numbers.Add(1);</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">numbers.Add(2);</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">numbers.Add(3);</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">function Square(n) { <span style="color:#0000ff;">return</span> n*n; }</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">squared = Apply(Square, numbers);</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">squared2 = Apply(function (n) { <span style="color:#0000ff;">return</span></pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">n*n; }, numbers);</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"></pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"></pre>
</div>
<h2>Native .NET objects</h2>
<p>One of the design goals of AjLanguage core is to have access to .NET objects. They can be created using the new keyword:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;">
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"></pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">ds = <span style="color:#0000ff;">new</span> System.Data.DataSet();</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">dinfo = <span style="color:#0000ff;">new</span> System.IO.DirectoryInfo(“.”);</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">foreach</span> (fi <span style="color:#0000ff;">in</span> dinfo.GetFiles()) {</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">PrintLine(fi.FullName);</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">}</pre>
</div>
<h2>Dynamic objects</h2>
<p>Dynamic objects can be created using the new keyword. A dynamic object accepts new members (variables and methods):</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;">
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"></pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">dynobj = <span style="color:#0000ff;">new</span> DynamicObject();</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">dynobj.FirstName = “Adam”;</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">dynobj.LastName = "Genesis”;</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">dynobj.Age =</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">800;</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">dynobj.FullName = function() { <span style="color:#0000ff;">return</span> FirstName + “ “ + LastName; }</pre>
</div>
<p>Another notation:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;">
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">dynobj = <span style="color:#0000ff;">new</span> { Name = “Adam”, Age = 800 };</pre>
</div>
<p>Another notation:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;">
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"></pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">dynobj = <span style="color:#0000ff;">new</span> { var FirstName = “Adam”; var LastName = “Genesis”; function</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">FullName() { <span style="color:#0000ff;">return</span> FirstName + “ “ + LastName; }</pre>
</div>
<p>Dynamic objects are defined automatically, setting theirs properties:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;">
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"></pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">Project.Database.Provider = “…”;</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">Project.Database.ConnectionString =</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">“…”;</pre>
</div>
<p>creates Project dynamic object, with a Database property pointing to another dynamic object. It’s equivalent to:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;">
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"></pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">Project = <span style="color:#0000ff;">new</span> DynamicObject();</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">Project.Database = <span style="color:#0000ff;">new</span></pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">DynamicObject();</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">Project.Database.Provider =</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">“…”;</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">Project.Database.ConnectionString = “…”;</pre>
</div>
<p>An experiment: lists are defined automatically using Add method:</p>
<div id="codeSnippetWrapper">
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">Project.Entities.Add(<span style="color:#0000ff;">new</span> { Name = “Customer”, Table = “dbo.Customers” });</pre>
<p>it’s equivalent to:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;">
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"></pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">Project = <span style="color:#0000ff;">new</span> DynamicObject();</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">Project.Entities = <span style="color:#0000ff;">new</span></pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">List();</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">Project.Entities.Add(<span style="color:#0000ff;">new</span> { Name = “Customer”, Table = “dbo.Customers”</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">});</pre>
</div>
<h2>Dynamic classes</h2>
<p>A class can be defined using this sintax:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;">
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"></pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">class</span> Person {</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"> var FirstName;</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"> var</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">LastName;</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"> var Age;</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"></pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"> function</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">FullName {</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"> <span style="color:#0000ff;">return</span> FirstName + “ “ +</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">LastName;</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"> }</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">}</pre>
</div>
<p>A new instance can be created as usual:</p>
<div id="codeSnippetWrapper">
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">adam = <span style="color:#0000ff;">new</span> Person() { FirstName = “Adam”, LastName = “Genesis”, Age = 800 };</pre>
<p>The instance is dynamic: new members can be attached to it, and methods could be redefined:</p>
<div id="codeSnippetWrapper">
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">adam.FullName = function() { <span style="color:#0000ff;">return</span> “The “ + FirstName; };</pre>
<p>You can create class as values:</p>
<div id="codeSnippetWrapper">
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">Person = <span style="color:#0000ff;">new</span> DynamicClass();</pre>
<p>but the interface to add members is still in flux.</p>
<h2>Defined Classes</h2>
<p>There are some predefined classes:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;">
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"></pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">dynobj = <span style="color:#0000ff;">new</span> DynamicObject();</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">list = <span style="color:#0000ff;">new</span> List(); <span style="color:#008000;">// implementing </span></pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">IList</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">dict= <span style="color:#0000ff;">new</span> Dictionary(); // implementing IDictionary</pre>
</div>
<h2>Primitive Functions</h2>
<p>A few functions and subroutines are predefined:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;">
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"></pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">Print(“Hello”);</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">PrintLine(“Hello World”);</pre>
</div>
<p>There three predefined functions to execute and evaluate dinamic code:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;">
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">Include(<span style="color:#006080;">"program.ajs"</span>);</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">Evaluate(<span style="color:#006080;">"k+1"</span>);</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">Execute(<span style="color:#006080;">"k=1;"</span>);</pre>
</div>
<div id="codeSnippetWrapper">Include execute the commands in a file. Evaluate parses and evaluate an expression. And Execute compile and execute commands.</div>
<h2>False value</h2>
<p>Anything that is false, null, zero or empty string, is evaluated as false in conditional expression:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;">
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"></pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">if</span> (k)</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"> PrintLine(“<span style="color:#0000ff;">true</span>”);</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">else</span></pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">PrintLine(“<span style="color:#0000ff;">false</span>”);</pre>
</div>
<p>The above command prints “false” on execution, if k is zero or undefined. If a variable is undefined, any access to its member returns null, instead of a null exception:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;">
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"></pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">if</span> (Project.Database.ConnectionString)</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">PrintLine(“<span style="color:#0000ff;">true</span>”);</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#0000ff;">else</span></pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"> PrintLine(“<span style="color:#0000ff;">false</span>”);</pre>
</div>
<p>This command prints “false” again, if variable Project is undefined.</p>
<h2>Arrays, List and Dictionaries</h2>
<p>Native arrays can be defined with length:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;">
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"></pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">firstprimes = <span style="color:#0000ff;">new</span> <span style="color:#0000ff;">int</span>[10];</pre>
</div>
<p>or with values:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;">
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"></pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">firstprimes = <span style="color:#0000ff;">new</span> <span style="color:#0000ff;">int</span>[] { 1, 2, 3, 5, 7, 9 };</pre>
</div>
<p>A list is created if you need a dynamic array:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;">
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"></pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">numbers[0] = “zero”;</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">numbers[1] = “one”;</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">numbers[2] =</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">“two”;</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">numbers[3] = “three”;</pre>
</div>
<p>A dictionary is automatically created if the subindices are not numeric:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;">
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;"></pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">numbers[“one”] = 1;</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">numbers[“two”] = 2;</pre>
<pre style="font-size:12pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:Courier New, courier, monospace;background-color:white;text-align:left;border-style:none;margin:0;padding:0;">numbers[“three”] = 3;</pre>
</div>
<p>If you need more feature, remember, you can use the native .NET framework.</p>
<h2>Console interface</h2>
<p>The project AjSharp.Console is a console application, where you can enter and execute AjSharp commands (not expressions):</p>
<p><img src="http://www.todocontenidos.com/images/articles/ajlanguage02.png" alt="" /></p>
<p>No command to exit, yet. Just control+c in Windows.</p>
<h2>Next steps</h2>
<p>There are so many features I want to add. Partial list:</p>
<p>- AjBasic as another language over AjLanguage</p>
<p>- Generics support</p>
<p>- Template support (as in AjGenesis)</p>
<p>- Integrate to <a href="http://ajgenesis.codeplex.com" target="_blank">AjGenesis</a> code generation</p>
<p>- Compile AST to Dynamic Language Runtime</p>
<p>Angel “Java” Lopez</p>
<p><a href="http://www.ajlopez.com">http://www.ajlopez.com</a></p>
<p><a href="http://twitter.com/ajlopez">http://twitter.com/ajlopez</a></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajlopez.wordpress.com/256/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajlopez.wordpress.com/256/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajlopez.wordpress.com/256/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajlopez.wordpress.com/256/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajlopez.wordpress.com/256/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajlopez.wordpress.com/256/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajlopez.wordpress.com/256/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajlopez.wordpress.com/256/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajlopez.wordpress.com/256/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajlopez.wordpress.com/256/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajlopez.wordpress.com&blog=378226&post=256&subd=ajlopez&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ajlopez.wordpress.com/2009/09/21/ajsharp-programming-language-a-c-like-dynamic-language/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/086e1ed94cfc99c62fa27525e69b1a3b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajlopez</media:title>
		</media:content>

		<media:content url="http://www.todocontenidos.com/images/articles/ajlanguage01.png" medium="image" />

		<media:content url="http://www.todocontenidos.com/images/articles/ajlanguage02.png" medium="image" />
	</item>
		<item>
		<title>Lord of the REPLs (Read Eval Print Loops) and CodePad</title>
		<link>http://ajlopez.wordpress.com/2009/09/15/lord-of-the-repls-read-eval-print-loops-and-codepad/</link>
		<comments>http://ajlopez.wordpress.com/2009/09/15/lord-of-the-repls-read-eval-print-loops-and-codepad/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 09:26:57 +0000</pubDate>
		<dc:creator>ajlopez</dc:creator>
				<category><![CDATA[AjLisp]]></category>
		<category><![CDATA[Lisp]]></category>
		<category><![CDATA[Programming Languages]]></category>

		<guid isPermaLink="false">http://ajlopez.wordpress.com/2009/09/15/lord-of-the-repls-read-eval-print-loops-and-codepad/</guid>
		<description><![CDATA[These days, I&#8217;m implementing interpreted language. My first interest is Clojure, my work is an implementation using C#, written from scratch, you can see the progress at:
http://code.google.com/p/ajlisp/source/browse#svn/trunk/AjSharpure
Last year I wrote a Lisp interpreter AjLisp- a Lisp interpreter in .NET, that I should improve, but past weeks, I started to write an Scheme-like language:
http://code.google.com/p/ajlisp/source/browse#svn/trunk/AjScheme
With so much [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajlopez.wordpress.com&blog=378226&post=255&subd=ajlopez&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>These days, I&#8217;m implementing interpreted language. My first interest is Clojure, my work is an implementation using C#, written from scratch, you can see the progress at:</p>
<p><a title="http://code.google.com/p/ajlisp/source/browse#svn/trunk/AjSharpure" href="http://code.google.com/p/ajlisp/source/browse#svn/trunk/AjSharpure">http://code.google.com/p/ajlisp/source/browse#svn/trunk/AjSharpure</a></p>
<p>Last year I wrote a Lisp interpreter <a title="AjLisp- a Lisp interpreter in .NET" href="http://ajlopez.wordpress.com/2008/07/30/ajlisp-a-lisp-interpreter-in-net/">AjLisp- a Lisp interpreter in .NET</a>, that I should improve, but past weeks, I started to write an Scheme-like language:</p>
<p><a title="http://code.google.com/p/ajlisp/source/browse#svn/trunk/AjScheme" href="http://code.google.com/p/ajlisp/source/browse#svn/trunk/AjScheme">http://code.google.com/p/ajlisp/source/browse#svn/trunk/AjScheme</a></p>
<p>With so much activity on Lispy languages, I did research about many implementations. My discoveries were collected, as usual, in my delicious:</p>
<p><a href="http://delicious.com/ajlopez/lisp">http://delicious.com/ajlopez/lisp</a>     <br /><a href="http://delicious.com/ajlopez/clojure">http://delicious.com/ajlopez/clojure</a>     <br /><a href="http://delicious.com/ajlopez/scheme">http://delicious.com/ajlopez/scheme</a></p>
<p>One of the gems I discovered, is this Google App Engine tool:</p>
<p><a title="http://code.google.com/p/lotrepls/" href="http://code.google.com/p/lotrepls/">http://code.google.com/p/lotrepls/</a></p>
<blockquote><p>LotREPLs is a multi-lingual read-eval-print-loop in your browser powered by Google App Engine and the Java runtime. It&#8217;s a technical demo, not something to do serious work with. The following languages are supported: </p>
<ul>
<li>BeanShell </li>
<li>Clojure </li>
<li>JavaScript </li>
<li>Python </li>
<li>Ruby </li>
<li>Scala </li>
<li>Scheme </li>
</ul>
</blockquote>
<p>You can try it a:</p>
<p><a title="http://lotrepls.appspot.com/" href="http://lotrepls.appspot.com/">http://lotrepls.appspot.com/</a></p>
<p><img src="http://www.todocontenidos.com/images/articles/repl03.png" /> </p>
<p>You can enter your command, and see the result of evaluation, without installing nothing in your machine.</p>
<p>Another discovery, supporting C, C++, D, Haskell, Lua, Ocaml, PHP, Perl, Python, Ruby, Scheme, Tcl, is:</p>
<p><a title="http://codepad.org/" href="http://codepad.org/">http://codepad.org/</a></p>
<blockquote><p>codepad.org is an online compiler/interpreter, and a simple collaboration tool.      <br />Paste your code below, and codepad will run it and give you a short URL you can use to share it in chat or email. </p>
</blockquote>
<p><img src="http://www.todocontenidos.com/images/articles/repl01.png" /> </p>
</p>
<p>The code you enter and run, can be referenced by an URL, to share with other developers:</p>
<p><img src="http://www.todocontenidos.com/images/articles/repl02.png" /> </p>
<p>Some day, all our tools will be in the browser… <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Angel “Java” Lopez    <br /><a href="http://www.ajlopez.com">http://www.ajlopez.com</a>     <br /><a href="http://twitter.com/ajlopez">http://twitter.com/ajlopez</a></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajlopez.wordpress.com/255/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajlopez.wordpress.com/255/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajlopez.wordpress.com/255/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajlopez.wordpress.com/255/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajlopez.wordpress.com/255/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajlopez.wordpress.com/255/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajlopez.wordpress.com/255/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajlopez.wordpress.com/255/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajlopez.wordpress.com/255/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajlopez.wordpress.com/255/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajlopez.wordpress.com&blog=378226&post=255&subd=ajlopez&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ajlopez.wordpress.com/2009/09/15/lord-of-the-repls-read-eval-print-loops-and-codepad/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/086e1ed94cfc99c62fa27525e69b1a3b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajlopez</media:title>
		</media:content>

		<media:content url="http://www.todocontenidos.com/images/articles/repl03.png" medium="image" />

		<media:content url="http://www.todocontenidos.com/images/articles/repl01.png" medium="image" />

		<media:content url="http://www.todocontenidos.com/images/articles/repl02.png" medium="image" />
	</item>
	</channel>
</rss>