Archive for July, 2007

The Common Language Infrastructure (CLI) Architecture

This is a continuation of a previous post about .NET framework and these series are aim at presenting information about .NET framework that will hopefully make sense from a non-technical perspective. .NET is an interesting platform but its design and implementation has remain a mystery largely though there is sufficient information to describe it as well as its various implementation. Microsoft released the fundamental blue prints of the framework to the ECMA (European Computer Manufacturers Association) for the standardization hence it is accurate to conclude that Microsoft.NET (the framework) is an implementation of this standard though it is also prudent to keep in mind how much Microsoft’s implementation conforms to the publicly available standard.

The Common Language Infrastructure is the standard that has been endorsed by ECMA as ECMA 335. There are other standards related to the .NET Framework such as those that underpin the C# programming language. To paraphrase the standard documents, the CLI provides an environment in which applications written in multiple high level programming languages may execute in different environments without modification to adopt the application to the unique features of the target environment. Sounds like a complicated way of saying that it is just a virtual machine that abstract the application away from the details of the environment that host the virtual machine. While that’s the simple way of explaining what the CLI is, it is by no means the most comprehensive way of gaining a better understanding of it.

Whenever there is a discussion of the .NET framework there would almost certainly be reference to Java and perhaps it would be foolish to assume that Java has not had an influence on how, at least some, aspects of .NET were designed and implemented. However, the .NET framework is unique in its design to support multiple programming languages (which the JVM is capable of as well) but that’s a rather simplistic view of the support of multiple programming languages on .NET. The .NET framework goes an extra mile in making language integration and harmony amongst the various programming languages that target the CLR. Understanding the difference between support for multiple programming languages and language integration cannot be overemphasized: the GCC (GNU Compiler Collection) support multiple programming languages but the support languages are not integrated which means that code written in one language cannot be easily used in the other languages without modification. The support for language integration on the .NET framework means that exceptions thrown from VB.NET code can be caught and processed by C# or any other supported language and vice versa.

As mentioned above, the GCC set supports multiple programming languages and though that in itself is an interest subject to examine, it will have to be done in another day. Ask yourself this: what would it take to support language integration in a manner which the binaries written in one language would understand the stuff that come out of binaries written in other support language? If you are getting to the conclusion that the answer is like to be complex then you perhaps headed in the right direction in getting an epiphany of what the CLI is made up of.

The CLI is essentially an umbrella terminology used to refer to components that act together in tandem to realize multiple programming languages support as well as harmony between these languages. Its architecture comprises of the following key components:

  • Common Type System: Based on the example of exceptions being thrown and caught across language boundaries, each language that targets the CLR needs to have an understanding of an exception and the Common Type System (CTS) helps in establishing a common understanding of types across programming languages. However the CTS is not only limited to exception types – from the specification – the CTS is a unified type system that is shared by compilers, tools, and the CLI itself. It is the model that defines the rules the CLI follows when declaring, using, and managing types. The CTS establishes a framework that enables cross-language integration, type safety, and high performance code execution.
  • Virtual Execution System: if you have already concluded that this is what is called the CLR in the .NET framework then you wouldn’t be any where but on the truth of the matter. Various analogies come to mind to help describe the VES but for all intends and purposes it is the equivalent of the brains of the CLI as it is charged with implementing and enforcing the CTS. The VES is responsible for loading and running programs that are written for the CLI.
  • Common Language Specification: this aspect of the CLI architecture is described as an agreement between language designers and class library designers. The CLS specifies a sub set of the CTS and a set of rules that govern usage patterns. When language designers implement the CLS, they ensure that their users have access to frameworks that support the CLS. Similarly framework designers implement the CLS on the publicly accessible aspects of their class libraries and thus allow their frameworks to be accessed from CLS compliant languages.
  • Metadata: the operations of the CLI are metadata driven which means that every aspect of the system is described in metadata hence allowing communication across the various components that make up the CLI. Metadata is what describes the meaning of various entities of an implementation of the CLI.

This post dwelled on the architecture of the CLI which is defined by Partition I of the ECMA 335 standard which is currently at 4th edition (release in June 2006) as of this writing. The standard document defines six partitions.

Leave a comment

Basic Table Tennis Game Code Samples

This blog entry outlines some basic information to get up to speed with the development of a basic table tennis game. At this point, it is not meant to be a complete implementation neither is it going to impose any particular (other than what’s obvious) design and/or architectural understanding of the project’s terms of reference.

  • Basic introduction to OpenGL: you need to get a basic OpenGL program up and running; this will give you an understand of the OpenGL environment generally and how much code it takes to have a Window display on your computer. I found this tutorial to be a useful introduction to OpenGL; it is useful for an absolute beginner as it walks you through OpenGL step by step. There are also Visual C++ 6.0 project code downloads from the tutorial.
  • The Game’s Screen: the game is essentially comprised of quadrilaterals (rectangles of varying widths and height – assuming a square (the ball) can be called a rectangle as well. From the tutorial in the point above, identify the code section that is responsible for rendering images on the screen. To draw a rectangle in OpenGL you need the coordinates of its four corners (vertices); strictly speaking, you just need the coordinates of one of the corners of the rectangle. The image below illustrates that; the coordinates of the single vertex is required to establish the position of the rectangle.

image 

Update: added game layout diagram

image

The following artifacts in the game can be represented as rectangles:

  • The Game boundary: the largest rectangle in the drawing depicting the game;
  • The Ball: it can be represented as a filled square (strictly speaking not a rectangle but it requires the drawing of four sides);
  • Computer Player Pad and Human Player Pad: rectangles of varying heights;
  • Net: a filled rectangle;

The following code sample renders a rectangle in OpenGL:

glColor3f(0.4f, 1.f, 0.2f);
glBegin(GL_LINE_LOOP);
glVertex3f(-1.5, -1.0f, 0.0);
glVertex3f(1.5, -1.0f, 0.0);
glVertex3f(1.5, 1.0f, 0.0);
glVertex3f(-1.5, 1.0f, 0.0);
glEnd();

And the next one renders a filled rectangle:

glColor3f(0.4f, 1.f, 0.2f);
glBegin(GL_POLYGON);
glVertex3f(-1.5, -1.0f, 0.0);
glVertex3f(1.5, -1.0f, 0.0);
glVertex3f(1.5, 1.0f, 0.0);
glVertex3f(-1.5, 1.0f, 0.0);
glEnd();

With information above it is possible to create a method that renders a rectangle, given one corner or vertex, as well as the rectangle’s width and height. This would be optimal because most of the shapes in the Game’s screens are rectangle which would mean writing complicated code that would be seemingly hard to debug.

void draw_rectangle(Point start_point, width, height){

glColor3f(0.1f, 1.f, 0.2f);
glBegin(GL_LINE_LOOP);
glVertex3f(start_point.x, start_point.y, 0.0);
glVertex3f(start_point.x+width, start_point.y, 0.0);
glVertex3f(start_point.x+width, start_point.y+height, 0.0);
glVertex3f(start_point.x, start_point.y+height, 0.0);
glEnd();

}

/**

 * In order to user the above form, you will need to create a Point  * class.

 **/

Or it can be implemented like this:

void draw_rectangle(float x, float y, float width, float height){

glColor3f(0.1f, 1.f, 0.2f);
glBegin(GL_LINE_LOOP);
glVertex3f(x, y, 0.0);
glVertex3f(x+width, y, 0.0);
glVertex3f(x+width, y+height, 0.0);
glVertex3f(x, y+height, 0.0);
glEnd();

}

I hope the above information is helpful. If there is any improvements you think need to be included in the aforementioned, please add a comment – it might help someone.

Happy hacking!

6 Comments

Weekend Light Reading: .NET Framework Essentials

Over the weekend, I found myself engrossed in a book about Microsoft’s .NET Framework and though the book was old (relative to the current state of affairs as pertains to Microsoft .NET). The book was based on Microsoft.NET framework version 1.1 which was released back in 2003 which in any normal measure of time was not long ago but in Internet measure of time, that likes ages ago. Anyhow, we are currently in version 3.0, with version 3.5 currently in beta as of this writing. The introduction of .NET was perhaps a confusing moment which was not helped by the fact that every other Microsoft division or product group was contemplating products with a .NET suffix at the end of it which inevitably meant that the true meaning of Microsoft.NET was not immediately apparent to the rest of the world which wanted to come to grips with this new creation of Microsoft.

The book titled .NET Framework Essentials give an overview of the design goals of Microsoft.NET and indeed the understanding of the what the framework was at the time version 1.1 was released. Much of it remained true, I suppose since the the framework is increasing integrated into a lot more Microsoft products but it has largely been de-emphasized in products whose audience wouldn’t care any more about language independence and integration.

Anybody who has an idea of what the .NET framework is knows about the CLR and the central role it plays in making the promise of .NET a reality; reading the book also gave me a better understanding of how the CLR works and indeed how language integration is achieved on the framework. The .NET framework makes pervasive use of meta data which describes the types, resources, security, threading details of the code that will be executed by the CLR. The metadata is stored in a manner that is language agnostic which means that any language and tool that targets the CLR can make use of descriptive and referencing information that is the metadata. This data about data is also used by tools to enable compatibility with already deployed technologies like COM: you have type library exporters that make COM components appear like a .NET assembly (the basic unit of deployment in the .NET universe) which means that existing COM components can interoperate with new code that typically targets the CLR. The exporter is just one of many tools that makes the framework interoperate with existing technologies.

The .NET framework is immensely huge and in the spirit of most of the computer related technologies that have come, there are a slew of acronyms that describes aspects of it. In the .NET work these include include acronyms like CLR (Common Language Runtime) which largely makes sense and can be adequately described as a virtual machine environment that compiles IL (Intermediate Language) code and manages the execution of the resultant native code. One of the key differences between the CLR and JVM (Java Virtual Machine), besides the fact that former works with IL and the latter works on bytecode, is that the CLR never interprets IL; the IL code is JIT compiled into native code and executed as such. The JIT compilation is made more efficient by the extensive support of metadata in the .NET framework which basically means that the JIT compiler can compile a small section of a .NET assembly (deployment unit) and thus not require a slow down in program execution – compilation is done incrementally without much negative effect to program execution. With the extensive support for Metadata, the management of execution (which includes type checking, exception handling, debugging, security and of course the all important garbage collection) can proceed without requiring the entire compiled .NET assembly to be loaded.

Key to the functioning of the CLR are other technologies/specifications that goes by acronyms such as CTS, CLS, CLI which stand for Common Type System, Common Language Specification and Common Language Infrastructure. A little digging into this most impressive alphabet soup revealed that all these acronyms are under the general umbrella of the CLI according to the ECMA documentation that defines a CLR like standard; in fact the CLR is Microsoft’s implementation of the CLI.

Leave a comment

Solution Context

An innovation by its very nature is targeted at a particular problem and as such it can be viewed as a solution to a problem. From a broader perspective, there has been a tremendous amount of innovation from the past and these innovations continue to yield advances in various fields even sometimes creating new disciplines all together. A problem is circumstance specific in a sense what one person or perhaps society defines as problem is not a problem to another person or society. This has the implications that not all solutions can be universally applied to all the problems there are. Perhaps of greater concern is the fact that solving a problem is not necessarily the end of the story but instead there is a great possibility that today’s solutions will form the basis of a problem that will need a solution in the future.

The engineering disciplines have a set of rules that all professionals in the field follow in order to develop and implement solutions to problems. While these principles are an abstraction of best practices based on experience in the past, they also take into account the context within which they are applied. The effect of this understanding is that engineers need to understand their context when they think of solutions to problems; this makes sense because there are advantages in the environment that will make the solution long lasting and even less disruptive to its surrounding. Though it is sometimes necessary to disrupt an environment in order to introduce advances but generally people are not inclined to take up any radical and sudden change in how they approach life. A successful problem solver thinks outside the box and is also aware of the box that he/she is in and in combining these two views come up with the most appropriate solution to the problem at hand.

1 Comment

Crossing Music Genres

The universality of music is amazing, with all the variations in genres and eventual mixing and cross of the ill defined image boundaries of music genres. I recently got an earful (sweet earful that is) of a compilation CD entitled CHANT DOWN BABYLON that centrally features Bob Marley tracks but the tracks have been remixed with artists like Guru, Erykah Badu, Mr. Cheeks (Lost Boyz), Krayzie Bone (Bone Thugs N Harmony) amongst others. Writing about this compilation doesn’t do it any justice but engage your imagination, if you will: remember any nice Bob track that you have heard (well, I hope you are a fan of Bob’s music) and then picture that being mixed with the lyrics and tempo of a rapper like Guru. I think the track that features Bob and Guru is currently my favorite though Gultiness (Bob and Mr. Cheeks) is up there on my personal ratings as well.

Here is a quote from CDUniverse.com about this compilation CD:

Krayzie Bone offers a rendition of “Rebel Music” that is one of the album’s high points, while Erykah Badu oozes fiery soul over “No More Trouble” as through she were standing right next to Bob in the studio. Other standouts include Aeorsmith’s appearance on “Roots Rock Reggae” and Rakim’s addition to “Concrete Jungle.” The excellent CHANT DOWN BABYLON functions like a rare glimpse of what Marley’s music may have been like if he were recording today.Erykah Badu,Krayzie Bone,Guru, Steven Tyler&Joe Perry,Busta

Crossing Reggae and Rap is amazing but I think groups like Bone Thugs N Harmony tend to produce some great collaborations with other artists from other genres. The first time I heard of Chant Down Babylon and that it featured a member of Bone Thugs N Harmony, I knew it was going to be a great collaboration judging from the collaboration between Bone Thugs N Harmony and Phil Collins: rap and alternative rock (or whatever you want to call Phil Collins style of music). Another amazing remix and music genre cross was done by Erick Sermon (EPMD) featuring Marvin Gaye; the song is called music.

I am not a musician but I enjoy good music and it would seem my taste is quite varied and I am looking to expand it as much as I can.

… Let me go wear down my favorite tracks on Chant Down Babylon … 😀

Leave a comment

Programming Round up

Programming is an interesting undertaking but over and beyond producing lines after lines of code is the effort spent in thinking about the structure of the problem and forming an idea about the eventual shape of the solution. In that regard, the code is a fulfillment of an idea, design and architecture. I have come to enjoy the process of developing a solution through careful considerations of various options in terms of tools and technologies as well as the processes involved in implementing the solution. With time, I have learnt enough and there is still more to learn which I keep looking forward to each day.

At the moment, there are an inordinate number of projects that needs to be implemented. The main two need implementation in C/C++ and C#. For the former, I am taking advantage of it to perfect the idea of developing portable code: I want my code to be able to execute on Linux (Ubuntu) and also on Windows. The C/C++ project is a Computer Graphics unit assignment which is sufficiently challenging but interesting never the less. I initially wanted to use Python for my implementation but the project needs to be done in a group and C/C++ is lowest common denominator in the context. While on the subject of language choices, I wanted to work on Python on Linux but at the same time my unit is almost exclusively biased to Windows so this would have meant that I also ensure that the Python code is portable across OS platforms.

The C# project on the other hand is an application which I hope to find a market for. I am implementing it in ASP.NET 2.0 and it is coming along quite nicely (I am thinking of posting some screen shots of the work I have done thus far). A while back, I stated my intention to post a LINQ tutorial, that’s still in the works. Anyhow, back to ASP.NET: since the app is essentially an implementation from scratch, I took the opportunity to incorporate something things that were originally envisioned for post version 1.0 such as AJAX. I am currently using ASP.NET 2.0 AJAX Extensions 1.0 (yes, the version numbers are a bit confusing but hey those are Microsoft naming). The application scenarios that AJAX enables are impressive to say the least.

I have done more work on my Ubuntu installation and it is going to play an important role in my intention to produce portable code. I don’t think it is a big challenge to have pretty generic C/C++ code, more so when the code in question primarily (or at least should) target OpenGL. For the Computer Graphics project, there may be need to use physics engines as well as libraries that makes event handling much easier that it seems in OpenGL. I have Eclipse running on Ubuntu and the CDT is nicely configured and working. I still need to work on writing my own makefile and then use it to compile a project. I am aware that I can have a managed C/C++ project in Eclipse but I am more interested in getting a closer feel of C/C++. Besides Eclipse, I am also running the preview release of NetBeans 6.0. I am in the process of downloading Sun Studio 12 which runs on Linux and I want to install it and see how much easier it makes my development efforts.

The other subject that is programming related that has been occupying my mind is dynamic languages and more specifically Python; I have a nice Python tutorial on Ubuntu as well as an installation of IronPython on the Windows Vista machine. The code semantics of these two implementations of Python is the same (as far as the knowledge I have gained so far is concerned) but there is of course significant difference between the standard Python and IronPython though I can’t quite articulate these difference at this time; it basically boils down to how tightly integrated each implementation is to the Microsoft’s .NET. IronPython, being a language that runs on the CLR has access to the extensive .NET framework base class library. Standard Python do have a massive number of extensions to it as well from GUI extensions such as wxPython to OpenGL extensions such as Pyogengl.

Leave a comment

PHP 4 End of Life

The PHP development team announced that support for PHP 4 will come to an end by the end of this year at which time there will not be any new releases of PHP 4.4. Here is the announcement from php.net:

[13-Jul-2007] Today it is exactly three years ago since PHP 5 has been released. In those three years it has seen many improvements over PHP 4. PHP 5 is fast, stable & production-ready and as PHP 6 is on the way, PHP 4 will be discontinued.

The PHP development team hereby announces that support for PHP 4 will continue until the end of this year only. After 2007-12-31 there will be no more releases of PHP 4.4. We will continue to make critical security fixes available on a case-by-case basis until 2008-08-08. Please use the rest of this year to make your application suitable to run on PHP 5.

It is interesting how most of the major platforms have required migration in the recent past. Locally, I think people haven’t gotten wind of the .NET framework and all the languages it has including C# and Visual Basic.NET. This means that there is a large number of Visual Basic 6 code base that may need to be migrated or at least strategies developed to keep them running. Now PHP code needs to be migrated as well – I hope the learning institutions are taking note of this and updating the focus of their courses accordingly.

2 Comments