Welcome to SpellCoder Sign in | Join | Help

 

Well, DLR hosting API has been all over the place and some of the obvious convenient methods in IronPython 1.1 such as CreateMethod disappears. The latest DLR hosting spec was released on Jan 3, 2008 and it was out of sync from the latest IronPython 2 Beta 1.

 

I spent a couple of hours yesterday to investigate the new DLR hosting implementation in IronPython 2 Beta 1 and have successfully figured out the "new ways" of DLR hosting API.

 

Copy these codes and run it in your environment. Replace the "X2" or "2" suffix in some of the namespace. I had to do this because I am working on a CMS that works on ASP.Net Futures 2007 release with IronPython 2 Alpha 1 as the implemenation for the asp.net support  and I have a code execution engine that I want to upgrade from IronPython 1.1 to the latest beta. Naturally those two IronPython runtime clashed and I have to recompile the IronPython Beta 2 with new namespace and assembly name.

 

The following codes demonstrate of the capabilities for the "hosting scenario level 2" (per DLR hosting spec). Enjoy.

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Scripting2.Hosting;
using IronPythonX2.Hosting;
using IronPythonX2.Modules;
using IronPythonX2.Runtime;
using IronPythonX2.Runtime.Exceptions;
using MbUnit.Framework;
using Microsoft.Scripting2;
using Microsoft.Scripting2.Runtime;

namespace HostingRunner
{

    public class Simple
    {

        ScriptEngine _engine;
        ScriptScope _scope;
        public Simple()
        {
            _engine = ScriptRuntime.Create().GetEngine("py");

            var sy = new SymbolDictionary()
            {
                { SymbolTable.StringToId("n"), 10}
            };
            _scope = _engine.CreateScope(sy);
        }

        public string ExecuteBLOCKED EXPRESSION
        {
            _scope.SetVariable("n", 10);

            var code = @"
x = 1 + 1
";
            var compiledCode = _engine.CreateScriptSourceFromString(code, Microsoft.Scripting2.SourceCodeKind.Statements);

            try
            {
                compiledCode.Execute(_scope);
                return _scope.GetVariable<int>("x").ToString();
            }
            catch (Microsoft.Scripting2.SyntaxErrorException e)
            {
                return e.Line + " : " + e.Column + " : " + e.Message;
            }
            catch (Exception e)
            {
                return e.Message;
            }
        }

        public string CreateMethod()
        {
            var code = @"
def function():
    return 1 + 1 + 200

";
            var sourceCode = _engine.CreateScriptSourceFromString(code, Microsoft.Scripting2.SourceCodeKind.Statements);

            sourceCode.Execute(_scope);

            return _engine.GetVariable<Func<int>>(_scope, "function")().ToString();

        }

        public string CallOneCodeMultipleScope()
        {
            _scope.SetVariable("n", 16);

            var code = @"
def function():
    return 1 + n

";
            var compiledCode = _engine.CreateScriptSourceFromString(code, Microsoft.Scripting2.SourceCodeKind.Statements).Compile();
            compiledCode.Execute(_scope);

            var firstResult = _engine.GetVariable<Func<int>>(_scope, "function")();

            var secondScope = _engine.CreateScope();
            secondScope.SetVariable("n", 10);

            var secondResult = _engine.GetVariable<Func<int>>(_scope, "function")();

            return (firstResult + secondResult).ToString();
        }

        public string CallMultipleExecutionOverASingleScope()
        {
            var code = @"
def function():
    return 1 + 1";

            _engine.CreateScriptSourceFromString(code, Microsoft.Scripting2.SourceCodeKind.Statements).Execute(_scope);

            var code2 = @"
def function2():
    return 10 + function()
";
            var compiledCode = _engine.CreateScriptSourceFromString(code2, SourceCodeKind.Statements).Compile();

            compiledCode.Execute(_scope);

            return _engine.GetVariable<Func<int>>(_scope, "function2")().ToString();
        }

        public string CallLoadExternalAssembly()
        {
            _engine.Runtime.LoadAssembly(System.Reflection.Assembly.LoadWithPartialName("SK.Framework"));

            var code = @"
import clr
clr.AddReference(""SK.Framework"")
from SK.Framework import Unique
";

            _engine.CreateScriptSourceFromString(code, Microsoft.Scripting2.SourceCodeKind.Statements).Execute(_scope);

            var code2 = @"
def function2():
    return Unique.Empty.Value
";
            var compiledCode = _engine.CreateScriptSourceFromString(code2, SourceCodeKind.Statements).Compile();

            compiledCode.Execute(_scope);

            return _engine.GetVariable<Func<int>>(_scope, "function2")().ToString();
        }
    }
}

namespace HostingRunner
{
    [TestFixture]
    public class SimpleTest
    {
        Simple _simple;
        [SetUp]
        public void Setup()
        {
            _simple = new Simple();
        }

        [Test]
        public void TestScope()
        {
            var value = _simple.ExecuteBLOCKED EXPRESSION;

            Assert.IsTrue(value == "2", "value must be equal 1 + 1 instead of " + value);
        }

        [Test]
        public void TestDelegate()
        {
            var value = _simple.CreateMethod();

            Assert.IsTrue(value == "2", "value must be equal 1 + 1 instead of " + value);
        }

        [Test]
        public void TestCompiledCode()
        {
            var value = _simple.CallOneCodeMultipleScope();

            Assert.IsTrue(value == "34", "value must be equal 1 + 1 instead of " + value);
        }

        [Test]
        public void TestMultipleExecution()
        {
            var value = _simple.CallMultipleExecutionOverASingleScope();

            Assert.IsTrue(value == "12", "value must be equal 55 instead of " + value);
        }

        [Test]
        public void TestReference()
        {
            var value = _simple.CallLoadExternalAssembly();

            Assert.IsTrue(value == "-12", "value must be equal 12 instead of " + value);
        }
    }

}

"@Lawrence: IronRuby is 4 people depending on how you measure it. IronPython is less than that depending on how you measure it (which we intend to fix).

@Darren: The Paul Revere anecdote is wonderful. Thanks for the ptr!" (John Lam - IronRuby PM)

"

One of the most powerful features of the ASP.NET MVC framework is its URL routing engine (I covered some of these features here).

This upcoming ASP.NET MVC preview release contains even more URL routing features and enhancements.  You can now use named routes (enabling explicit referencing of route rules), use flexible routing wildcard rules (enabling custom CMS based urls), and derive and declare custom route rules (enabling scenarios like REST resources mappings, etc).

We have also factored out the URL routing infrastructure from the rest of the MVC framework with this preview, which enables us to use it for other non-MVC features in ASP.NET (including ASP.NET Dynamic Data and ASP.NET Web Forms).

"

(MVC Framework Road Map)

 

I'm looking forward to a refactored routing infrastructure so that I can use it on the VPP level instead of using it on the ASP.Net processing level.

 

There have been some talks suggesting Microsoft to stop developing C# and simply move on to a new shiny language based on a reason that C# is becoming more complex and its development is approach a diminishing return.

 

Bleh.

 

I can agree with the sentiment but I think it's a bad idea to stop development for C# at this point because there's a couple of more features that can be added to C# 4.0 that will make it "oh, the greatest programming language of all". People always complain for complexity and only need 20% of the language most of the time; except that everybody uses different 20% of all available facilities in a language. I use IronPython extensively but I use only function, array, hash and tuples most of the time - I haven't defined a Python class for a long long time.

 

1. Add Design by Contract.

I don't know why this hasn't  been implemented yet. Implementing Design by Contract eliminates the need to write a kazillion of stupid kind of Unit Tests and have Unit Tests frameworks to access the meta information made available by DBC to verify the code automatically. Go check Spec# to see what I'm talking about.

2. Add Facility for  Macro support.

C# 3.0 already has Expression Trees and right now people only use it to support creating LINQ provider. I think Anders is preparing some new nemerle Macro facilities to make it easier to do meta programming. I bet you  a gallon of beer on this. There's little sense to present Expression Trees if they just stop here. Why would you have an ability to treat Code as Data and not use it to enable Macro?

3. Introduce Fine Grain Immutability construct - side effect free medicine.

We are already moving to Functional style programming with all the LINQ facilities and stuff, it's time to make one of the core idea of functional programming to be included in the language, immutable data structures. Check out Eric's trial balloon on the idea of new fine grain immutability support or Joe's immutability posts.

4. Instant Data Type

Yeah, I know we are all craving for multiple function return values using anonymous class.  Why not introduce some facility to make the local anonymous type to namespace level, pretty much C# capable of declaring JSON style class definition.

public static var ReturnSomething()
{
   return new { FirstName = "Hello", LastName = "World"};
}

named public InstantType returnVal = ReturnSomething()
.csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }

This way it solves the problem of C# inability to handle heterogeneous data type (other than using casting all over or long generic statement)  - I would kill for a Tuple support but that's less likely.

5. Mixin would be great, maybe Traits too.

6. Add Duck Typing please.

7. Pattern matching.

 

The goal of above features are:

  • Increase software safety by making programmers intent verifiable by compiler.
  • DSL
  • Less typing.
  • Add new ways to do software composition.

 

That's all :)

"

Query expressions provide a language integrated syntax for queries that is similar to relational and hierarchical query languages such as SQL and XQuery.

query-expression:
from-clause query-body

from-clause:
from typeopt identifier in expression

query-body:
query-body-clausesopt select-or-group-clause query-continuationopt

query-body-clauses:
query-body-clause
query-body-clauses query-body-clause

query-body-clause:
from-clause
let-clause
where-clause
join-clause
join-into-clause
orderby-clause

let-clause:
let identifier = expression

where-clause:
where boolean-expression

join-clause:
join typeopt identifier in expression on expression equals expression

join-into-clause:
join typeopt identifier in expression on expression equals expression into identifier

orderby-clause:
orderby orderings

orderings:
ordering
orderings , ordering

ordering:
expression ordering-directionopt

ordering-direction:
ascending
descending

select-or-group-clause:
select-clause
group-clause

select-clause:
select expression

group-clause:
group expression by expression

query-continuation:
into identifier query-body

A query expression begins with a from clause and ends with either a select or group clause. The initial from clause can be followed by zero or more from, let, where, join or orderby clauses. Each from clause is a generator introducing a range variable which ranges over the elements of a sequence. Each let clause introduces a range variable representing a value computed by means of previous range variables. Each where clause is a filter that excludes items from the result. Each join clause compares specified keys of the source sequence with keys of another sequence, yielding matching pairs. Each orderby clause reorders items according to specified criteria.The final select or group clause specifies the shape of the result in terms of the range variables. Finally, an into clause can be used to “splice” queries by treating the results of one query as a generator in a subsequent query." (From C# Unified Specification document)

 

It is important to master the basic concept on how LINQ operates. I think there are too much emphasis on LINQ for "specific provider". There are still unexplored depth in how we can much better construct programs using this declarative/set oriented using LINQ concepts.

So memorize these query expressions keywords to mind : "from, in, select, group, by,  let, where, join, on, equals, orderby, ascending, descending, into,  " and understand what these individual keyword does and you'll be able to freely hack LINQ style in no time. Don't forget to exercise on 101 LINQ Samples and read up C# Standard Query Operators.

"Microsoft only is a very limited painful yet guaranteed option, ALT option is the total amazement and innovation but can simply disappear in a moment." (Gurustop)

 

Alt.Net is yet another moniker for some sort of alternative lifestyle to .Net development. I can understand the desire to differentiate but I found these type of slogan driven movement quite empty other than probably selling new conference themes or generating new thought leaders.

 

I don't think simply dividing technologies based on its source or 'coolness' as a helpful exercise. A crappy software does not become "cool" or "innovative" simply because it is slapped into some sort of "open source" or "alt.net" label. Nor any "Microsoft approved" technology can be guaranteed or viewed as thoroughly stable. I think these labels are mostly used to smack other people on online debates. Nobody give a damn about what kind of technology powers their software. Users either love it or hate it. That's the bottom line.

 

There are software that have been maintained using un-cool technology that powers the world. Your in-flight software is not written in the latest C# 3.0 or tested using xUnit latest iteration. Most of ecommerce or CMS or online portals are written in un-cool technologies such as PHP that have been behind the buzzword curve or technology movement. Lord knows Dave Winer single handedly pioneered weblogs, RSS or OPML using an outdated custom language in a cool object database without source code revision tool.

 

Process and technology are important, but  resulting product is paramount. We should put more focus on the end product of our technology development and make judgement of that. Why not start a "cool software" movement or "great products that change the world" slogan.

This is one amazing quote from the best agent in the literary business, Andrew Wylie. I think this hold true with software as well.

 

"I think that quality—which is more valuable over time—has been undervalued, and quantity—which is less valuable over time—has been overvalued."

I always cite this rule to developers about the need to dedicate their time to master their craft.

"The one thing that all expertise theorists agree on is that it takes enormous effort to build these structures in the mind. Simon coined a psychological law of his own, the 10-year rule, which states that it takes approximately a decade of heavy labor to master any field. Even child prodigies, such as Gauss in mathematics, Mozart in music and Bobby Fischer in chess, must have made an equivalent effort, perhaps by starting earlier and working harder than others." (Scientific American)

 

This 10 year rule has a sound scientific basis on how the human brain works. If you want to be really good at anything, you need to dedicate 10 years to achieve it. If you do not dedicate yourself to a craft, you are setting up yourself to a major failure in the future.

There is no lazy way to achieve mastery in anything.

Check this blog entry about about what's hot or not in the .Net development space.

"

The paper then goes on to describe the results of four studies which led researchers to conclude the following:

  1. Incompetent people will tend to grossly overestimate their skills and abilities. A part of the study, the subjects were given various tests and then asked to predict their scores and relative rankings. People in the bottom quartile overestimated their performance by an average of 45-50% while people in the top quartile actually underestimated their skills.
  2. Incompetent individuals fail to gain insight into their own incompetence by observing the behavior of other people. After being allowed to review the test results of their peers, the estimates of the bottom quartile actually worsened while the estimates of the top quartile improved. This led researches to conclude that the mis-calibration of the incompetent stems from an error about the self, whereas the mis-calibration of the highly competent stems from an error about others.
  3. The way to make incompetent individuals realize their own incompetence is to make them competent. In the last study, researches found that the estimation skills of the bottom quartile dramatically improved if they were given training in the domain knowledge of the test. Not only did their scores improve, but they finally became aware of their short-comings relative to their peers and revised their prior estimates downward."

(Caffeinated Coder)

 

Click on the link and read the whole paper. It's been out for about a year but it's still an interesting research that gives insight to human nature.

Now I can start writing a .Net library for it. Check the announcement here.

CouchDb sounds like a really great infrastructure to access and store unstructured data and all the data is queried over a REST interface. The next iteration of Havana will adopt CouchDb as an alternative storage so people can define schema and build query on a web interface.

"In fact, software development methodologies are one of the biggest delusions of all. They help keep us sane by protecting us from the truth that building software is hard. They delude us into thinking that by following a preset script we will end up successful, that even the biggest software challenges can be overcome by engaging in a widely varying set of patterns and practices, that somehow if we all just planned better with a more precise schedule or gave ourselves the freedom to think big and react quickly the actual problems of finding the right solutions and building the software will take care of themselves. Yet, its just not true. On some level we know its just not true. Every project always ends the same, with some piece of something produced and everyone bemoaning how horrible the process was or how intolerable or inflexible.  Instead of realizing that it is just hard and we are not really good at doing it, we distract ourselves by diving deep into naval contemplation, trying to devise improvements for the process for the next go around. However, we might as well have gone out and gotten new haircuts for all the good it does us.

The truth is that most of us can't really build software well, no matter the system. A few among us, however, can with apparent ease accomplish just about any development task, to any degree or complexity, in spite of whichever methodology is in use. We deny this too because it upsets the belief that its the methodology, not ourselves, that is really at the heart of the matter. We think of these folks as renegades or cowboys. We build up even bigger defenses to minimize the damage and marginalize their impact. We tell them they can't work on the entire project, they must pick some smaller piece befitting a mere mortal. We wall them off into little rooms and let them build, and then we fear what they produce, because it always ends up grander, more complete and more compelling than all the work done by everyone else combined. Often their work surpasses even the most ambitious dream. Yet we react to it by squelching it using backroom politics, voting it off the island.

The truth is, that if we could only harness the power of these exceptionally brilliant few in a meaningful way we would be ahead of the game. Instead of devising systems to distract ourselves into believing we all can do it, why not acknowledge the fact that really only these few know what the hell is going on and build a system to basically keep them functioning at prime efficiency? Instead of textbooks lauding the latest practices to keep our armies of developers in sync and on track, we should be pull the men out of the silos and teach them how to be a support team for the guy or gal in the center.

" (Matt Warren)

 

You have to have talented people so that when the process breaks down, the project is still successful. Nothing replaces the people quality in a creative endeavor  like software programming. This why you see innovation such as RubyOnRails was created by one guy compared to the team of programmers, PM and processes in Microsoft ASP.Net team.

 

"Sure, you can take a bunch of typical developers and have them slog out the implementation of an LOB application, and you'll get what you get, some confusing, arcane, input-forms nightmare, babble of buttons.  Or you can focus them all on aiding the prime ape on his journey to producing a masterpiece of technical wizardry that not only solves the LOB application problem, but allows the company an opportunity to rethink its corporate strategy, refocussing instead on the sale of that very same LOB app to the other fortune 500's, boosting profits for the year by 1000%, cornering the market and becoming the next big software powerhouse to compete against Microsoft.

It's your choice." (Matt Warren)

Testable UI Interface through MVC for ASP.Net by ScottG

"

Microsoft's Internet business (MSFT) got some good press this summer, when MSN's share of search queries briefly jumped (before dropping again), and the division's ad revenue continued to accelerate.  The latter trend is truly good news.  But don't confuse this and other headlines with online success.  Microsoft is still running a distant No. 4 in the online wars--the same position it has held for the last 12 years--and there is no real sign that this will ever change.

Why shouldn't we view MSN's recent ad acceleration as a sign that Microsoft is finally beginning to do what it did to Lotus, Apple (round one), WordPerfect, et al--(steamroll them)?  Because, over the past year, MSN's expense growth has vastly exceeded its revenue growth, even when you look only at advertising revenue.

Did you know that MSN is currently losing about $1 billion a year (run-rate)?  That's right, $1 billion.  On about $2.2 billion of advertising revenue.  (See this page for details).  Unless Microsoft's disappearing access business is losing a lot of money--which we doubt--all of the division's losses are attributable to the advertising and media business.  That means that MSN is losing nearly $0.50 for every $1.00 of advertising it sells." (Silicon Alley)

http://static.rubiverse.com/podcasts/2-scott-bellware-on-microsoft-and-ruby.mp3

 "After the doing Ruby On Rails for 2 weeks, I can never take a look at a .Net code again". (Scott Bellware - Microsoft MVP)

This is a must listen podcast - it tells the story of a ex very dedicated .Net developer that gave up hope on the kind of technology Microsoft is coming up for the Web and finding happiness developing outside the .Net realms.

More Posts Next page »