Sunday, September 30, 2007
LINQ Closures May Be Hazardous to Your Health!
ClustrMaps and Google Analytics regional data
- According to Google Analytics, I haven't visitors from Atlantic or Pacific Islands. ClustrMaps reports those.
- According to ClustrMaps, I have no hits from Angola. Google Analytics reports them.
If a programmer's favorite language is Blub...
In college my favorite language was LISP. Even so, I've lost contact with the FL paradigm working professionally on imperative languages for over 15 years. Now I feel like a Blub programmer.If a programmer's favorite language is Blub, which is positioned somewhere in the middle of the "power spectrum", he can most often only identify languages that are lower down in the spectrum. He can look at COBOL and say "How can anyone get anything done in that language, it doesn't have feature x", x being a feature in Blub.
However, this Blub programmer has a harder time looking the other way in the spectrum. If he examines languages that are higher up in the power spectrum, they will just seem "weird" because the Blub programmer is "thinking in Blub" and can not possibly see the uses for various features of more powerful languages. It goes without saying that this inductively leads to the conclusion that to be able to compare all languages you'll need to position yourself at the top of the power spectrum. It is my belief that functional languages, almost by definition, are closer to the top of the power spectrum than imperative ones. So languages can actually limit a programmers frame of thought. If all you've ever programmed is Blub, you may not see the limitations of Blub - you may only do that by switching to another level which is more powerful.
One of the reasons the mainstream doesn't use Haskell is because people feel that "their" language does "everything they need". And of course it does, because they are thinking in Blub! Languages aren't just technology, it's a way of thinking. And if you're not thinking in Haskell, it is very hard to see the use of Haskell - even if Haskell would allow you to write better applications in a shorter amount of time!
I can certainly understand the brevity, ease of understand, reusability, reliability (no side effects), functional validation and some of the powerful abstractions this languages offer us. But I need some (a lot?) of mileage on these languages to start getting into a really productive FL mindset. Ok, I admit it, and also to collect some baggage to throw to imperative skeptics.
So I'm setting a personal goal: to choose a (pure?) FL language, get acquainted with it and post my achievements.
Hope to see you soon about my first step: the language choice. I'm presently considering Haskell, or maybe ML (on the F# implementation). I admit the development environment is important for me. Here's my startup list.
Haskell vs C
3.1 Quicksort in Haskell
qsort [] = []
qsort (x:xs) =
qsort (filter (< x) xs) ++ [x] ++
qsort (filter (>= x) xs)
NOTE: I've broken into 4 lines because of my blog template limitations.
void qsort(int a[], int lo, int hi) {
{
int h, l, p, t;
if (lo < hi) {
l = lo;
h = hi;
p = a[hi];
do {
while ((l < h) && (a[l] <= p))
l = l+1;
while ((h > l) && (a[h] >= p))
h = h-1;
if (l < h) {
t = a[l];
a[l] = a[h];
a[h] = t;
}
} while (l < h);
t = a[l];
a[l] = a[hi];
a[hi] = t;
qsort( a, lo, l-1 );
qsort( a, l+1, hi );
}
}
Oops, is language evolution betting on the wrong branch?
Why Functional Programming Matters
As software becomes more and more complex, it is more and more important to structure it well. Well-structured software is easy to write, easy to debug, and provides a collection of modules that can be re-used to reduce future programming costs. Conventional languages place conceptual limits on the way problems can be modularised. Functional languages push those limits back. In this paper we show that two features of functional languages in particular, higher-order functions and lazy evaluation, can contribute greatly to modularity. As examples, we manipulate lists and trees, program several numerical algorithms, and implement the alpha-beta heuristic (an algorithm from Artificial Intelligence used in game-playing programs). Since modularity is the key to successful programming, functional languages are vitally important to the real world. The paper is available as postscript and pdf, and here is a bibtex entry.
A slightly less formal essay inspired by the paper above can be found in
Why Haskell Matters originally by Sebastian Sylvan
Taken from haskell.org.
CopySourceAsHtml
Unfortunately it doesn't work with Visual Studio 2008. Hope to see it ported soon.
Fibonacci revisitated
a, b = b, a + b
a and b are assigned in two independent branches, without side effects. In languages like C#, we often have to use temporary variables to garantee isolation.
A friend of mine just, Tiago Epifânio, posted a comment referring a pretty cool way to do it without the temporary variable:
b = a + (a = b);
b = a + (a = b) - a;
<update>
This usage is not as fun as the swap snippet Tiago gave us on his first comment - given the right order and a subtle variable substitution, the branches don't side effect; apart from readability, note that we could always express it like:
a = b;
</update>
Now that we're talking about isolation, it seems to me that BOO is actually doing something like:
Oops, clumsy... The question is: is there a clean and simple way to express "a, b = b, a + b" in C#?Stack<int> stack = new Stack<int>(2);
stack.Push(b);
stack.Push(a + b);
b = stack.Pop();
a = stack.Pop();
Saturday, September 29, 2007
Take a look at my language, she's the only one I've got
Take a look at my language
She's the only one I got
Not much of a language
Never seem to get a lot
This song somehow reflects the love/hate relationship this industry is discovering with the curly brackets programming languages family. You'll notice I've labeled this post under Social, so I'll keep technology out of here. The problem is mainly about resisting to change.
The thing is: we feel secure within our zone of comfort, as change frights the hell out of us.
I can understand the organization's need to maintain a stable branch of languages over decades, even at the cost of lowering agility. I can to a certain point understand the resistance to change from a 40 year old developer that as the C/C++/C#/java patterns carved in his way to solve computer problems. What comes as a surprise to me is when young people out of high school just with a couple of years of experience in C#/java observe the same resistance pattern.
Naturally this resistance disappears as people use the language (at least young people with open mind) and get acquainted with the advantages. But the first reaction I've been collecting is generally of rejection.
In the case of BOO's fibonacci implementation, I've collected responses like:
- "it's unreadable!"
- "how can you debug this? (generators)"
- "I'll do it just as well in plain C"
My everyday work language is C#. C# is a great language, above all because it's constantly evolving, constantly borrowing concepts from other languages. C# is also great because of it's recently acquired lambda expression and extension capabilities. But this doesn't mean C# is the only language for all of my problems.
Well, enough of techtalk, let's end this post with some kind of conclusion: a programming language is just a tool to solve a problem, and we, developers, tend to elevate it to a religion - I know I've been doing it for ages. A tool is just a tool, we should have the tools we need, no more and no less.
The future developer will probably use more languages than we use today. So get used to it :)
Friday, September 28, 2007
Internet Uses 9.4% of Electricity In the US
Hope these heavy investment will be well used building knowledge to help our planet...
VS 2008 Performance Improvements
For example, with the new LINQ facility we set a goal that LINQ performance be significantly better than using a SqlDataAdaptor for the same query and competitive with using a SqlDataReader, the lightest weight interface available for retrieving data from SQL Server. In our testing, LINQ does in fact out-perform SqlDataAdaptor on almost every test case we tried, and in many of the exceptions, it is no more than 10% slower than using a SqlDataReader to accomplish the same task. Given the power of LINQ, we feel this is a very reasonable trade-off.
Scrolling large C# files in the Editor is 100% faster, while typing in new text is 50% faster
The response time of IntelliSense with large types in C# is up to 10 times faster
TFS Version Control command processing was re-written to support unlimited sized operations on key commands without being memory bound on the server. In our measurements, key Commands also run 10% - 60% faster, with the larger improvements associated with bigger projects
We also focused on performance improvements that exploit multi-core hardware. As I blogged about earlier, we added multi-threaded support to MSBuild
Wednesday, September 26, 2007
Fibonacci in C#
namespace Fibonacci
{
class Program
{
public static IEnumerable fib(int number)
{
int counter = 0;
int a = 0, b = 1;
while (counter++ < number)
{
yield return b;
int previousA = a;
a = b;
b = previousA + b;
}
}
static void Main(string[] args)
{
// Display fib
foreach (int i in fib(10))
{
Console.WriteLine("{0} ", i);
}
}
}
}
Fibonacci number program
I'll try to implement Fibonacci in C# somehow closer to this boo's implementation - hopefully it will help me on the boo learning process. It will have to wait for the weekend, I'm presently burried in work...
See you back on Monday - I hope.
Ten Tips for a (Slightly) Less Awful Resume
Tuesday, September 25, 2007
Language Trends
Some months ago, André Cardoso, Telmo Felix and me started an internal group down at Link Consulting to tackle our "Language Trends" vision.
We had our first internal presentation today (mostly around C# and LINQ), with the following agenda:
- Declarative/functional over imperative advantages
- Current state of C#
- Trends
- The LINQ case-study
Yeap, this first approach was very Microsoft centric. The next one will definitely cover other areas.
Here are the slides, in Portuguese.
Fluent Interface
IInterfaces interface = context.Session
.CreateInterface(typeof(Fluent))
.MatterIfIsDSL (Please.Dont)
.AddComment("Ok, not a proper internal DSL, but who cares")
.AddComment("Cool way to manifest declaration intentions on an imperative environment");
Ok, maybe Fowler is better than me describing patterns...
The future will be about programming languages
During this Jazoon keynote Ted Neward talks about why the next five years in IT will be about languages. The programming language virtualization, tools, linguistic focus and expressiveness are different forces that are coming of age. Not to mention the impact of the over-used and over-hyped Domain-Specific languages. How will these languages tackle the evolving application security demands or rich user interfaces, Ted Neward approaches these questions in his own unique style
I got it from LambdaTheUltimate, where an interesting poll is referenced: Top 10 programming languages of the future.
Sunday, September 23, 2007
XUnit - the next NUnit?
James Newkirk, one of the original creators of NUnit, which is currently the most popular Unit Testing framework for .NET (he now works for Microsoft at the patterns and practices team if I'm not mistaken) has announced on his blog that together with Brad Wilson (also a Microsoftie) a new Unit Testing framework which is open source (it is hosted on the Microsoft CodePlex site under the Microsoft Permissive License. the new Unit Testing framework's name is XUnit.NET.
Roy also drop us a link to a syntax comparison matrix between NUnit, XUnit and MbUnit.
7 reasons to switch back after 2 years on Rails
The point is: RoR brought us a great concept over a great framework and language, but porting everything to RoR like there's no tomorrow is not always the best of choices. Usually the best choice is the one we feel comfortable with. That's also my choice: I'm (evolutionarily) adopting some of RoR concepts on platforms I'm conformable with. And hopefully those platforms will get closer to some of Ruby and RoR capabilities.
PS: he ends up with a list of reasons for coming back to PHP. I loved the 7th: "PROGRAMMING LANGUAGES ARE LIKE GIRLFRIENDS: THE NEW ONE IS BETTER BECAUSE *YOU* ARE BETTER"
Architecting tiers over LINQ
Though the reason seems obvious - isolating the usage from the data access layer itself -, it just crops the composibility capabilities of the solution. This tier has to know everything it can be asked. Even a simple paging would have to be pushed here.
The question I must ask is: if LINQ is a language integrated query extension, shouldn't LINQ queries be allowed to pass tiers to guarantee composibility - eventually accepting the dependency for the "LINQ to *" implementation used?
Should we reuse code in unit tests?
I agree with Scott when he says:
I think that Jim is on the right track, but I'm the kind of guy that feels that a test class's greatest responsibility is to document behavior in the clearest possible way, even if that means sacrificing design qualities best reserved for functional code - like reuse.
Above all, unit tests should be as close to non unit tests usage as it could be. And reuse justs breaks it.
But the world is not just black and white, and often we have to trade some principles for the sake of practicability. And to risk to end up testing the reusability module itself, or worse, to miss a test hidden by the reusable module. But that's what's life is made of: compromises.
Saturday, September 22, 2007
Can I (economically) justify swapping my CRT to an LCD?
Friday, September 21, 2007
Jack of All Trades
Some years ago I started to feel the need to some specialization, and opted for the Microsoft branch. Now even on Microsoft, the technology is getting too wide to be known by one guy, so I'm considering dropping some of my new areas of interest. It's sad...
.NET Tip of the Day
The C# ?? null coalescing operator
We simply use it like:
return somenullablevariable ?? "oops, data was null";
Pick it from ScottGu, where it extend it's usage to LINQ
Thursday, September 20, 2007
Comparison of Photo Catalog Software
Hopefully this article will help me choosing my next catalog software - I'm presently using Adobe Photoshop Album, and it didn't just scale well over my 140k photos...
Thank for the link, Pedro.
Parallelizing is here to stay
André also makes reference to another article from last MSDN: TPL (Task Parallel Library). It's purpose is to write managed code that can automatically use multiple processors. Using the library, you can conveniently express potential parallelism in existing sequential code, where the exposed parallel tasks will be run concurrently on all available processors. Usually this results in significant speedups. Here's a sample:
The performance benchmarking are just great, can't wait to use it (hopefully I'l have a change on my next project, where I'll have a change to do some Linear Programming groovy application).void ParMatrixMult(int size, double[,] m1, double[,] m2, double[,] result)
{
Parallel.For( 0, size, delegate(int i) {
for (int j = 0; j <>
result[i, j] = 0;
for (int k = 0; k <>
result[i, j] += m1[i, k] * m2[k, j];
}
}
});
}
I'll have to end with a question: wouldn't it make sense if parallel support was added to the languages them self, not to the class library?
Quaere: LINQ Arrives for Java
It seems like LINQ is a Anders monopoly. Anders Noras introduced the Quaere library, billed as LINQ for Java, last week at JavaZone.
An example of retrieving a list of product name’s from a list of products is:
Listproducts = Arrays.asList(Product.getAllProducts());
IterableproductNames =
from("p").in(products).
select("p.getProductName()");
Oops, it seems like typed checking is out. Not really LINQ in an language extension way, is it?
Why WCSF is not ramping up
- "It is too complicated"
- "It is over-engineered"
- "It is too complex"
- "I am overwhelmed"
- "Where do I start?"
Oops...
Wednesday, September 19, 2007
Storex MPIX 355 400Go
I'm very disapointed with the device. Here's my experience until now:
- .XP recognized the device, but didn't mount the disk;
- I downloaded the fat32 formater - the only useful info I got from the poor documentation (although the provided link had a redirection error); as expected, no drive was available for formating;
- I had to create a partition on 'Disk Management'; then I've formated it on NTFS just to get the fat32 formater to work - the utility worked as expected: I now had a 370GB fat32 drive
- I've copied some JPG files to the disk and plug it into the TV: no directories or files found! No wonder, the device reports 900GB free, 1100GB used!
- www.storex.eu alternated between terribly slow and unavailable for maintenance; even now I still could't get to the faqs page, and there isn't one single download for MPIX 355; most of the references on the net are in french, a language I'm not confortable with;
- Solid (conservative)
- Silence
Microsoft is cooking a MVC?
Scott Guthrie (aka ScottGu) showed me a rough prototype of a cool MVC framework they are working on for a future version of ASP.NET
Hope this MVC, MVP, or MV* gets to see the light of our screen monitors...
Tuesday, September 18, 2007
VMWare Utilities
Monday, September 17, 2007
Case study: Redesigning the BMW USA website with Genome
Database administrators in particular have been notoriously difficult to convince when it comes to O/RM, if they can be convinced at all. After all, they are hardly going to want to put themselves out of a job. Besides, how could a tool ever issue as clean code as a skilled DBA with a fine, manually tuned data access layer?ORMs are darn difficult to sell to DBAs, ORMs step all over their comfort zone.
In my modest opinion, DBA's opposition is a mistake. DBAs should embrace ORMs to do their trivial work, recovering valuable (and expensive) time where DBA excel: modeling, tunning databases, rewiring ORM SQL to handcrafted stored procedures when needed and making those custom stored procedures ORM just can't do.
Ages ago some lunatics proposed that compilers should generate assembler code for developers. Developers had the same reaction: no compiler could ever generate assembler code that could match their handcrafted code. And here we are using compilers and interpreters for most of our work.
Open your mind. Embrace ORMs.
howsoftwareisbuilt.com
www.howsoftwareisbuilt.com is a blog forum created by Microsoft to encourage community dialogue about open source and proprietary software development models.
Industry IT professionals, Scott Swigart, Richard (Dick) Bowler, and Sean Campbell are driving this project . The aim is to create a forum that will facilitate a lively community discussion and help gather insights from a large audience interested in this topic. Ongoing discussions have been held with various industry subject matter experts to help gather different perspectives on both open source and proprietary software development models. The transcripts are posted on this blog forum.
European Community: 497 - Microsoft: 0
Oops...
Friday, September 14, 2007
Surrogate Key vs Natural Key
Though I'm a surrogate key myself, I can't overlook some some natural key advantages. To me, the problem of natural keys is that it is hard to ensure them to be natural - at least over time. Also for normalization and implementation reasons, I adopt surrogate keys to most of my design. Even on N-M tables...
Wednesday, September 12, 2007
Domain Model or Service Model? Is this the question?
But still I can recognize the advantages of the Service Model, like the entity decoupling and wireability. And above all the capability to inject dependencies and mock objects.
This is an option I come across every now and then. The rational answer is probably the Service Model, but it isn't always the choice I make. Isn't it funny when we choose worse solutions just to stay on our comfort zone?
Mental note: choose more often the Service Manager pattern.
Sunday, September 09, 2007
I love when things appear on the right place
The great feature is speed dial. It's just in the place where you needed, and where I've never imagined it to be so useful.
Good for you, Opera. And congrats on the Opera Mini.
PS: I'm posting this on Firefox - the spell checker isn't working. Oh well...
More wattmeter readings
By the amount of heat I had this coming... As a good geek, I had one of this plugged on my bedroom, and another on the living room. This is an ecological crime. And a economical one. 2 transformers x 9W x 24h x 30days x 0,12€ / KW/h / 1000 = 1,6€/month.
They are now only connected when needed. A huge revolution is taking place here. Start yours!
PS: by the way, my mini vacuum cleaner waists 4W charging.
Watch out for some kind of reusability...
- Not harvesting from proven practices.
- Solutions that are more complex than the problem.
- Custom solutions to generic problems.
- Diverging too far from the base platform.
- Lock-in to a single company or architectural approach.
- Not considering ongoing maintenance and support costs.
- Not focusing on usability, documentation and training .
I can relate to some of these - they make me remember some of my own old mistakes :) From the new ones, I recognize to have a slight tendency for number 5 (Lock-in to a single company or architectural approach).
LINQPad
LINQPad: Joseph Albahari has an incredibly awesome LINQ query expression tool that you can use to quickly try out LINQ expressions. Think of it as SQL Query Analyzer - but with LINQ expressions as the queries. Definitely a useful free tool to add to your toolbox.It works fine, for now just felt the need for auto-completion... Still awesome :)
Friday, September 07, 2007
Why don't we use WCSF?
When reading it, it was clear why WCSF adoption is so weak: usage is too complex compared with the simpler event driven model. Too many steps and too many code doesn't seem to compensate the isolation, testing and reusability advantages. Programmers have to be educated, and changes propagated to more files . But probably the bigger adoption obstacle, as I've mentioned earlier, is lack of out-of-the-box support in Visual Studio. When this happens we will have productive factoring and refactoring tools, and above all, programmers will be educated on this paradigm.
No wonder so many choose to implement the MVP pattern on their own...
Monday, September 03, 2007
First things first
Sunday, September 02, 2007
Calories...
Less then1 calorie? Is this possible? I've follow the (*) link, and found out this:
"1 Cal = 1000 cal".
Uau... has Coca-Cola has just invented a measurement unit on a marketing war? As I just found out, no. Wikipedia states:
In non-scientific contexts the kilocalorie is often referred to as a Calorie (capital "C"), or just a calorie, and it has to be inferred from the context that the small calorie is not intended.
Isn't it silly the world we live in?...
Continuous integration on the rise in .NET
With the upcoming Visual Studio Team System 2008, the practice of continuous integration (CI) will be a “first class experience,” according to Microsoft. Although CI could be configured in Team Foundation Server 2005, it is now supported right ‘out of the box’ - from within the product.
...
According to Microsoft, new CI features in Visual Studio 2008:
• Make it easier to define very specific mappings of what files to include in a particular build definition, where they come from, and where the build products go
• Allow you to define the triggers for when a build starts; continuously on every checkin, or sequentially, queuing checkins until the current build finishes
• Define a fine-grained retention policy for the build products. You can create rules to delete failed builds, but keep partially successful builds, and
• Modify the build definition on the fly, enabling a debug flag for the next build for example.
• Target build agents (machines) to use for the actual build
• Show you more informative and manageable build queues