Geeks With Blogs
RebelGeekz' Blog Overclocked brain at work!

COmega Refactored

This is how COmega would look like after refactoring academia for real life usage.

Tenets:

  • Extend the framework, not the language.
  • SQL is dynamic
  • XML is dynamic too
  • In conclussion: Data is dynamic!
  • Data can be local or remote.
  • SQL can be applied to both!
  • A table is a two dimensional array, with field types as metadata.
  • XML as a type, not a literal.
  • Access XML as an object with oPath and oQuery.
  • Forget about all the X* dialects, X* in my domain turns into O*

Enough marketing babble, let's go right to the fun:

// Sql as a language construct ??
foreach( row in select ContactName from DB.Customers ){
       Console.WriteLine("{0}", row.ContactName);
}
// Change: Sql as dynamic strings managed by a datafactory class
DataTable table = dataServer.sql("select ContactName from DB.Customers");
foreach( row in table ){
       Console.WriteLine("{0}", row.ContactName);
}
// Data servers can be remote:
DataServer dataServer = new DataServer(sqlconnection);
DataTable table = dataServer.sql("select ContactName from DB.Customers");
// or local: (no need to instantiate any server)
DataTable table = DataLocal.Sql("select ContactName from Customers");
// Where DataLocal is a static class with powerful methods like Sql, SqlValue, SqlXml, SqlExecute
// for use with all locally define tables, structs, arrays and so

// Sample2: Structs and Redundancy static struct{ string Title; string Artist; CDStyle Style; int Year;}* CDs = new{new{ Title="Lucky Frog", Artist="Holly Holt", Style=CDStyle.Alt, Year=2001}, new{ Title="Kamikaze", Artist="Twista", Style=CDStyle.HipHop, Year=2004}, new{ Title="Stop Light Green", Artist="Robert O'Hara", Style=CDStyle.Alt, Year=1981}, new{ Title="Noctures", Artist="Chopin", Style=CDStyle.Classic, Year=1892}, new{ Title="Mimosa!", Artist="Brian Groth", Style=CDStyle.Alt, Year=1980}, new {Title="Beg For Mercy", Artist="G-Unit", Style=CDStyle.HipHop, Year=2003} }; results = select Title, Artist from CDs where Style == CDStyle.HipHop; results.{ Console.WriteLine("Title = {0}, Artist = {1}", it.Title, it // Better: Bidimensional arrays as tables Struct fields = { string Title; string Artist; CDStyle Style; int Year }; DataRow[] rows = (DataRow){ {"Lucky Frog" , "Holly Holt" , CDStyle.Alt , 2001}, {"Kamikaze" , "Twista" , CDStyle.HipHop , 2004}, {"Stop Light Green", "Robert O'Hara", CDStyle.Alt , 1981}, {"Noctures" , "Chopin" , CDStyle.Classic, 1892}, {"Mimosa!" , "Brian Groth" , CDStyle.Alt , 1980}, {"Beg For Mercy" , "G-Unit" , CDStyle.HipHop , 2003} }; // Merge the struct with the array DataTable CDs = New DataTable(fields, rows); results = DataLocal.Sql("select Title, Artist from CDs where Style == CDStyle.HipHop"); foreach( row in results){ Console.WriteLine("Title={0}, Artist={1}", results.Title, results.Artist); }
// Note: SQL clauses like Where, Group by, Order by are part of Standard SQL // Nothing new here, stop pretending like COmega has just discovered them!
// Now, please stop this abomination!!! Insert record Into Table ??? // Put down the crack pipe and stick to SQL standards!!! // Or later on it will bite you in the ass. // Embedding parameters and let the data class do the mix Ok = server.Sql("Insert Into Table(field1,field2) Values(?val1,?val2)");
// XML Literals ??? // Constants are bad, specially in a dynamic world. // Who wants to use the same piece of data again and again? // They are good for examples but rarely used in real life. // Data is dynamic, it is read, massaged, processed and written. NewsItem news = <NewsItem title="Hello World" author="John Doe"> <date>{DateTime.Now}</date> <body>I am the first post of the New Year.</body> </NewsItem>; // Use an XML constructor, it will let you bend xml to your needs NewsItem news = new Xml("<NewsItem title='Hello World' author='John Doe'> <date>{DateTime.Now}</date> <body>I am the first post of the New Year.</body> </NewsItem>"); // Once we have the object we can do whatever we want with it with oPath and oQuery. // The XML type is important, not the XML literals, it adds garbage to the language. // XML is transitory. Don't pollute the language. Console.WriteLine(news.title + " by " + news.author + " on " + news.date); Console.WriteLine(news['title']); Console.WriteLine(news['@author']); // Extend the framework, not the language! foreach (b in bs.book){ yield return <result> {b.title} {b.author} </result>; } // Better: foreach (b in bs.book){ yield return Xml("<result> {b.title} {b.author} </result>"); }

This is it my dear friends.

Data to the max, data to the masses.

Posted on Friday, January 21, 2005 9:27 AM | Back to top


Comments on this post: COmega Refactored

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © RebelGeekz | Powered by: GeeksWithBlogs.net