Tuesday, March 13, 2007

More Power per Source Code line



Now this example is just hypothetical and grossly overestimation of the reality. But the point is, we are writing less line of code to achieve same results. In my opinion, this is because

1. Powerful programming constructs and smart compilers [for example, C# closure]

2. Advances in Algorithm and Hardware

3. Greater level of code level abstraction

For Example, Consider following example in C# and same code compiled by MS CLR

[Example from : http://www.thinkingms.com/pensieve/CommentView,guid,fd10bfa8-1aeb-4353-84c8-cd80e418424f.aspx]


// Display powers of 2 up to the exponent 8:
foreach(int i in Power(2, 8))
Console.Write("{0} ", i);

Now this code will be compiled as

public static IEnumerable Power(int number, int exponent)
{
int counter =0;
int result = 1;
while(counter++ < result =" result">
{
result = result * number;
yield result;
}
}

So the point is, foreach is an elegant syntax. It also hides a lot of complexity at the programming construct level. Now, the level of abstraction and its impact on performance is altogether a different topic.

Still, if we are using high level language like C# or Java for developing business applications then this abstraction and syntax simplicity is good. [This argument is based on a long discussion with my friend Jon Saltzman]

Again, I heard an argument that this abstraction will result in increased programmer productivity. I am not sure about that. Anyway, point is modern programming languages provide more power per source code line

No comments: