Content by Category
.NET 1.x
.NET 2.0
.NET 3.0
.NET 3.5
.NET 4.0
.NET Assemblies
.NET Framework
.NET Getting Started
Accessibility
ADO.NET
Advertorials
Agile Development
AJAX
Architecture
ASP.NET
ASP.NET MVC
ASP.NET WebForms
Azure
B2B (Business Integration)
Bing
BizTalk
Book Excerpts
Build and Deploy
C#
C++
ClickOnce
Cloud Computing
Code Contracts
CODE on the Road!
COM+
Community
Conferences
Continuous Integration
Crystal Reports
CSLA.NET
CSS
Data
Design Patterns
Development Process
Display Technologies
Distributed Computing
DotNetNuke
DSL
Dynamic Programming
Editorials
Enterprise Services ("COM+")
Entity Framework
Events
Expression Blend
F#
Fox to Fox
Frameworks
Functional Programming
Git
Graphics
Internet Explorer 8.0
Interviews
iPhone
Iron Ruby
Java
Java Script
jQuery
LINQ
Linux
Mac OS X
MDX
Microsoft Application Blocks
Microsoft Business Rules Framework
Microsoft Dynamics
Microsoft Expression
Microsoft Office
Mobile Development
Mobile PC
Mono
MsBuild
Network
NHibernate
Object Oriented Development
Open Source
Opinion
Opinions
Oracle
ORM
Other Languages
Parallel Programming
Patterns
Podcasts
Post Mortem
PowerPoint
Print/Output
Product News
Product Reviews
Project Management
Python
Q&A
Rails
Rake
Reporting Services
REST
RIA Services
Ruby
Ruby on Rails
Search
Security
Services
SharePoint
Silverlight
SOA
Social Networks
Software & Law
Software Business
Source Control
Speech-Enabled Applications
SQL Server
SQL Server 2000
SQL Server 2005
SQL Server 2008
SQL Server CE/AnyWhere/Mobile/Compact
Subversion
Sync Framework
Tablet PC
TDD
Team System
Techniques
Testing and Quality Control
Tips
UI Design
UML
User Groups
VB Script
VB.NET
Version Control
VFP and .NET
VFP and SQL Server
Virtual Earth
Vista
Visual Basic
Visual Basic 6 (and older)
Visual FoxPro
Visual Studio .NET
Visual Studio 2005
Visual Studio 2008
Visual Studio 2010
Visual Studio Tools for Office
VSX
WCF
Web Development (general)
Web Services
WF
Whitepapers
Windows 7
Windows Azure
Windows Live
Windows Server
Windows Vista
WinForms
Workflow
WPF
XAML
XML
XNA
XSLT



DevConnections


 


DevReach

Reader rating:
Click here to read 1 comment about this article.
Article source: CoDe (2008 Sep/Oct)


Article Pages:  1  2 - Next >


Polyglot Programming: Building Solutions by Composing Languages

Polyglot programming refers to leveraging existing platforms by solving problems via solutions that compose special purpose languages.This concept leverages the multi-language nature of the CLR to create simpler solutions to vexing problems. This article delves into the motivation, benefits, and challenges of writing applications in this style.

Back in 2006, I coined the term polyglot programming in a blog post. It is not a new concept (being at least as old as Unix and probably much older-I just attached a modern term to it). That blog post was a response to what some are calling a renaissance in computer languages. Polyglot programming refers to using special purpose languages combined in the same context to create better problem solutions. To fully appreciate this concept, I’m going to review some recent history about the abstraction mechanisms that developers use to solve problems today, and point to a new way to do so in the future.

A Historical Framework

For the last 20 years or so, developers have been building virtually all applications using object-based languages. One of the promises of object orientation is ease of code reuse. Certainly, the core characteristics of object-oriented languages provide the facilities for reuse: encapsulation, polymorphism, and effective abstraction. But developers found it hard to achieve large-scale reuse using these atomic building blocks. So, they’ve resorted to two approaches that use object-oriented features as building blocks: components and frameworks.

Components work extraordinarily well for visual reuse. First VBX, then ActiveX controls showed that you can create a vibrant ecosystem of reusable components. Building non-visual behavior is harder. Windows platform developers have made attempts with lots of corresponding acronyms: COM, COM+, MTS, BizTalk, etc. And that’s just the .NET space. The Java world took the good ideas of MTS and went down a long, dark path with Enterprise Java Beans. And yet none of these techniques for achieving business domain reuse has worked well (which is why we keep trying).

Components rely on a certain physical ecology to work: tools that understand how to display property inspectors, event mechanisms, and lifecycle control for the components. This ecosystem represents the other great example of code reuse: frameworks.

Frameworks have become the preferred reuse mechanism. Frameworks consist of a large number of related classes with shared context. The most pervasive is, of course, the .NET Framework, and it includes several smaller frameworks (ADO.NET, ASP.NET, etc). Ancillary frameworks exist outside the Microsoft-supplied ones: log4net, nHibernate, iBatis.net, nVelocity, etc. None of this is news, of course: as a .NET developer, you’ve been steeping in this abstraction style so long you no longer even notice it.

But underlying this abstraction mechanism is the idea that you can have one true language to solve every problem. The one true language in .NET is either C# or Visual Basic. These general purpose languages allow you to interact with your component and framework reuse mechanisms. This works well for many of the kinds of applications you need to write, but it has its shortcomings as well. The idea that you can create a single computer language that solves all (or even most) problems ignores the vast variety of problems that developers must solve. Extending the one true language with frameworks helps with difficult abstractions, but mask the fact that sometimes the language you use is poorly suited to the problem you are trying to solve.

Object-orientation is an effective abstraction mechanism for much of the world because it organizes things in hierarchical fashion. Most of the world (as viewed by developers anyway) is hierarchical or can be mashed in to a hierarchy. But developers keep running into cross-cutting concerns: transactions, logging, security, etc. These don’t fit well within our existing hierarchies. This idea is illustrated in Figure 1. Thus, aspect-oriented development was born.

Click for a larger version of this image.

Figure 1: We need cross-cutting concerns to handle some of the problems that routinely arise.

For those not familiar with it, aspects weave code into existing hierarchies. Aspects have a specific syntax (different from either C# or VB) that describes pointcuts, or places where you can inject code (using a special compiler) directly into the compiled artifacts. Aspects allow you to define logging code in one place, and the aspect compiler injects byte code into your compiled code to add the necessary code to make all your logging calls. Consider this simple class:

public class MyClass {

  public int ProcessString(String s, 
      out string outStr) {

    // ...  

  }
}

If you want to add a logging call determining when this method executes and when it stops executing, you’d have to hand-write it like this:

public class MyClass {

  public int ProcessString(String s, 
      out string outStr) {
    log.debug("entering ProcessString 
       method");
    // ...  
    log.debug("exiting ProcessString
       method");
  }
}

Instead, you can add an aspect that allows you to intercept particular method calls for a class.

using DotNetGuru.AspectDNG.MetaAspects;
using DotNetGuru.AspectDNG.Joinpoints;

public class AspectsSample{
    
  [AroundCall("*
   MyClass::ProcessString(*)")]
  public static object 
   Interceptor(JoinPoint jp) {
     log.debug("entering ProcessString");
     object result = jp.Proceed();
     log.debug("exiting ProcessString");
     return result;
  }
}

Both the class name and method name can use wildcards like the namespace in the example above to allow this to work on a wide variety of classes. This example uses the AspectDNG AOP compiler for .NET, one of several open-source options.

This is more convenient than writing all that logging code by hand in every place it’s needed. But it also shows that the abstractions offered by the underlying language (C# or VB) are not suited to solving every problem.

And that’s fine. We’ll probably never create a language that’s suitable for every situation. In fact, we should stop trying. Microsoft designed the CLR to host multiple languages with a common target intermediate representation (IL). Why not leverage that more aggressively than we have in the past to create solutions by composing languages within the same solution?

&

By: Neal Ford

Neal Ford is Software Architect and Meme Wrangler at ThoughtWorks, a global IT consultancy with an exclusive focus on end-to-end software development and delivery. He is also the designer and developer of applications, instructional materials, magazine articles, courseware, video/DVD presentations, and author and/or editor of five books spanning a variety of technologies. He focuses on designing and building of large-scale enterprise applications. He is also an internationally acclaimed speaker, speaking at over 100 developer conferences worldwide, delivering more than 600 talks. Check out his web site at http://www.nealford.com. He welcomes feedback and can be reached at nford@thoughtworks.com.

nford@thoughtworks.com

Fast Facts

Developers do polyglot programming all the time without even realizing it. Do you write applications that talk to a database? Do you write Web applications? Chances are good that you do, which means that you are already polyglot programming.


Aspect-Oriented Programming Origins

This concept was introduced in 1997 in a paper by Gregor Kiczales and others in the Proceedings of the European Conference on Object-Oriented Programming, vol.1241



Article Pages:  1  2 - Next Page: 'Polyglot Programming Today' >>

Page 1: Polyglot Programming: Building Solutions by Composing Languages
Page 2: Polyglot Programming Today
Page 3:

How would you rate the quality of this article?
1 2 3 4 5
Poor      Outstanding

Tell us why you rated the content this way. (optional)

Average rating:
4 out of 5

1 people have rated this article.

      CODE TRAINING

 

CODE TRAINING