Programming

My Erlang Religious Moment

It is not often that a piece of code cause me to have a religious moment, but this one managed to:

posted @ Saturday, March 20, 2010 12:00 PM | Feedback (3)

Challenge: What does this code do?

What language is it? What is it doing? Why?

posted @ Friday, March 19, 2010 12:00 PM | Feedback (17)

You can’t learn the basics from the pros

There was a question recently in the NHibernate mailing list from a guy wanting to learn how to write database agnostic code from the NHibernate source code. While I suppose that this is possible, I can’t really think of a worst way to learn how to write database agnostic code than reading an OR/M code. The reason for that is quiet simple, an OR/M isn’t just about one thing, it is about doing a lot of things together and bringing them together into a single whole. Yes, most OR/M are database agnostic, but trying to figure out the principles...

posted @ Friday, March 12, 2010 12:00 PM | Feedback (10)

Getting code ready for production

I am currently doing the production-ready pass through the Rhino DivanDB code base, and I thought that this change was interesting enough to post about: public void Execute() { while(context.DoWork) { bool foundWork = false; transactionalStorage.Batch(actions => { var task = actions.GetFirstTask(); if(task == null) ...

posted @ Saturday, March 06, 2010 12:00 PM | Feedback (24)

Nice process, but what about the engineering bits?

Software processes has always been a popular topic of discussion in our industry. Those can get quite heated, with advocates of the “stable / stale” Waterfall method pointing fingers toward “rapid / rabid” Agile methods, with the CMMI people throwing documents around and Lean people standing on the sidelines muttering about Waste. This isn’t a post about a specific software process, I’ll defer that to another day. Instead, I want to focus on a flaw in the basic building blocks in many* software building processes. They ignore the actual building the software. ...

posted @ Saturday, February 20, 2010 3:23 AM | Feedback (31)

WPF WebBrowser and JavaScript interaction

I found myself needing to interact with JavaScript API in a WebBrowser hosted in a WPF application. That turned out to be quite a challenge to figure out, but I prevailed :-) Given the following XAML: <Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"> <Grid> <WebBrowser x:Name="Browser" /> </Grid> </Window>

posted @ Friday, January 15, 2010 12:00 PM | Feedback (2)

My Java Experience

As I mentioned before, I am actively trying to find what I don’t know, and plug it. As part of that endeavor, I spent the last week learning Java EE. I decided that in the interest of saving time I am going to invest some money and I took a week long course in it. That allowed me to kill several birds in a single stone, I got to experience Java in an environment that had an instructor that I could call on for help, it allowed me to learn Java EE and it allowed to me experience how people...

posted @ Thursday, January 14, 2010 12:00 PM | Feedback (39)

As to the methods there may be a million, but principles are few

I run across the following quote a while ago, and I found it quite interesting. “As to the methods there may be a million and then some, but principles are few. The man who grasps principles can successfully select his own methods. The man who tries methods, ignoring principles, is sure to have trouble.” - Ralph Waldo Emerson (1803-1882) I have been programming, in one form or another, for about fifteen years, but I can put my finger on the precise moment in which I moved from a mere...

posted @ Monday, January 11, 2010 12:00 PM | Feedback (19)

The problem with compression & streaming

I spent some time today trying to optimize the amount of data the profiler is sending on the wire. My first thought was that I could simply wrap the output stream with a compressing stream and use that, indeed, in my initial testing, it proved to be quite simple to do and reduced the amount of data being sent by a factor of 5. I played around a bit more and discovered that different compression implementation can bring me up to a factor of 50! Unfortunately, I did all my initial testing on files, and while the profiler is...

posted @ Sunday, January 10, 2010 12:00 PM | Feedback (12)

Production profiling security considerations

I am currently in the process of building support for the production profiling. The technical part (how to reduce the footprint of the profiler when not profiling) is pretty easy, and I spiked it out in a matter of a few hours. The non technical part has been driving me mad for days. One of the major issues that I have to deal with with regards to production profiling is the issue of security. There are actually multiple levels to this issue. The most obvious one is that we want to secure who can start profiling. Initially I thought...

posted @ Monday, January 04, 2010 9:06 PM | Feedback (36)

Using ReaderWriterLockSlim’s EnterUpgradeableReadLock

I got a comment in this post suggesting that the code can make use of the EnterUpgradeableReadLock method to simplify this code: public static string Intern(string str) { string val; locker.EnterReadLock(); try { if(strings.TryGetValue(str, out val)) return val; } finally { locker.ExitReadLock(); } ...

posted @ Monday, January 04, 2010 12:00 PM | Feedback (17)

A persistence problem, irony, your name is…

The major goal that I had in mind for the profiler was online development usage. That is, do something, check the profiler, clear it, do something else, etc. One of the things that I am finding out is that people use it a lot more as a dumping ground. They push a lot of information into it, and then want to sift through that and look at how the application behave, not just a single scenario. Surprisingly, it works quite well, especially with the recently implemented performance profiling sessions that we just run through. One scenario, however, remains stubbornly...

posted @ Monday, December 28, 2009 12:00 PM | Feedback (15)

String Interning: The Garbage Collectible way

Since I know people will want the actual implementation, here is a simple way of handling string interning in a way that will allow you to GC the results at some point. The issue is simple, I want to intern strings (so a string value is only held once through my entire app), but I don’t want to be stuck with them if the profiler state has been clear, for example. public class GarbageCollectibleStringInterning { private static IDictionary<string,string> strings = new Dictionary<string,string>(); private static ReaderWriterLockSlim locker = new ReaderWriterLockSlim(); ...

posted @ Sunday, December 27, 2009 12:00 PM | Feedback (15)

Non invasive Windows event tracing listening?

One of the things that I would like to do with L2S Prof is to figure out how to detect row counts and query duration. The problem is that there is absolutely no way of doing that at the Linq to SQL level. So one of the things that I have been researching is trying to get to the tracing that are present at the System.Data.SqlClient level. For more information about those, you can read this article, which explains them in depth. Basically, Windows comes with a really good support for optional tracing, and System.Data.SqlClient makes use of...

posted @ Saturday, November 14, 2009 12:00 PM | Feedback (4)

Rant: Compilers != Parsers

This is just something that really annoys me. There is a common misconception that compilers are mostly about parsing the code. This couldn’t be further from the truth. About the easiest step in building a compiler is parsing the text into some form of machine readable format. There are great tools to help you there, and a lot of information. It is the next stage that is complex, taking the machine readable format (AST) and turning that into executable. There is a lot less information about that, and that tends to be a pretty gnarly sort of a...

posted @ Monday, October 19, 2009 10:31 PM | Feedback (18)

Texo – My Power Shell Continuous Integration Server

Yes, I wrote my own CI server. I even did it in Power Shell, because that looks cool. You can find the source here. It is currently running in production and is responsible for pushing NH Prof builds out. Now, what was I thinking when I built my own CI server? Put simply, I had the following goals: Test WPF apps – CC.Net doesn’t allow it, since it is running as a service and that affects the way WPF tests behave. Texo shell out a different process, so it doesn’t have this limitation. Most other...

posted @ Tuesday, October 06, 2009 4:35 AM | Feedback (15)

Licensing a commercial product

This is another forum question, this time from Brendan Rice: A lot of developers are unsure of how best to go about making money from a product, how do you go about implementing licensing, what pay system do you use, how do you accept payment, are there any legal issues... Well, talk about an open ended question. There are several aspects for the answer, legal, licensing and payment processing. There are somewhat related, though. From the legal side, you need to understand basic concepts in the legal side of software engineering. You need...

posted @ Tuesday, October 06, 2009 1:30 AM | Feedback (7)

Your queries are going to fail in production

Reading Davy Brion’s post There Is No Excuse For Failing Queries In Production had me twitching slightly. The premise is that since you have tests for your queries, they are not going to fail unless some idiot goes to the database and mess things up,and when that is going to happen, you are going to trip a circuit breaker and fail fast. Davy’s post is a response to a comment thread on another post: Bertrand Le Roy: Would it make sense for the query to implement IDisposable so that you can put it in a using...

posted @ Monday, August 31, 2009 11:26 AM | Feedback (19)

How to lose respect and annoy people

This post is going to be short, because I don’t think that at my current state of mind, I should be posting anything that contain any opinions. This is a reply to a blog post from X-tensive titled: Why I don't believe Oren Eini, which is a reply to my posts about the ORMBattle.NET nonsense benchmarks. I will just say that if I was willing to let X-tensive enjoy the benefit of the doubt the reason they run the benchmarks the way they did, the post has made it all too clear that doubt shouldn’t be entertained. Here...

posted @ Friday, August 21, 2009 6:21 PM | Feedback (56)

What is maintainable?

Frans Bouma left the following in this post, which I found quite interesting: The person who spend a lot of time inside the code base obviously finds it logical and knows his way through the codebase and where to make changes what to avoid etc. For that person, the codebase is maintainable. It is different for a person who's new to the codebase. If that person has to spend a lot of time figuring out where what is and most importantly: why, it's already a sign things aren't as maintainable as it should. I...

posted @ Wednesday, July 29, 2009 9:13 AM | Feedback (44)

Pitfalls

Mike Scott has pointed out a bug in this code, relating to the use of DateTime.Now vs. DateTime.UtcNow, which can cause inaccurate wait durations during daylight change time. That made me think for a bit, there are things that just naturally make me highly suspicious, because they are a common source for bugs. Using a WCF service in a using block, creating a session factory, a foreach loop with database calls, a select without a limit clause. What are the things that cause a flashing neon sign to go through your head when you see...

posted @ Monday, July 27, 2009 12:07 PM | Feedback (32)

Lying as a valid coding pattern

Davy Brion has an interesting post about Protecting Your Application From Remote Problems, which contains a really interesting implementation of CircuitBreaker. One thing, though, bothered me about it. Let us look at the code: private class OpenState : CircuitBreakerState { private readonly Timer timer; public OpenState(CircuitBreaker circuitBreaker) : base(circuitBreaker) { timer = new Timer(circuitBreaker.timeout.TotalMilliseconds); timer.Elapsed += TimeoutHasBeenReached; timer.AutoReset = false; timer.Start(); } private void TimeoutHasBeenReached(object sender, ElapsedEventArgs e) { circuitBreaker.MoveToHalfOpenState(); } public override void ProtectedCodeIsAboutToBeCalled() { throw new OpenCircuitException(); } } The code works correctly, but I… don’t like the implementation. Please note that this is based on more gut feeling than anything else. The part that I don’t like is that it is doing...

posted @ Wednesday, July 15, 2009 10:30 AM | Feedback (12)

Connection Pooling: Implemention

Given the following contact: /// <summary> /// Thread Safety - This is NOT a thread safe connection /// Exception Safety - After an exception is thrown, it should be disposed and not used afterward /// Connection Pooling - It is expected that this will be part of a connection pool /// </summary> public class DistributedHashTableStorageClient I decided that I needed to really didn’t want to pass the responsibility for that to the client, and that I wanted to handle that inside my library. Here is what I came up with: ...

posted @ Saturday, June 06, 2009 7:12 PM | Feedback (8)

A good refactoring session is…

One in which I get to remove a lot of code. Here is a particularly interesting tidbits, SqlStatement is one of the core classes in NH Prof, look what I did to it: For those of you not used to reading diffs, the orange marking on the side bars are removed lines. It dropped from a 484 lines to 153.

posted @ Wednesday, May 27, 2009 11:45 PM | Feedback (13)

Waiting, it isn’t as simple as twiddling your thumbs

Just thought that it would be interesting post to talk about the evolution of a single method. This is used solely for the integration tests, by the way. public void WaitForAllMessages() { while (mailBox.IsEmpty == false) { Thread.Sleep(100); } } It started its life very simply, as just a method that waited until the mailbox was empty. But then we run into a problem, sometimes the method returned while a message was being processed, and that caused the tests to fail. Then we had this: ...

posted @ Friday, May 22, 2009 7:14 PM | Feedback (10)

The things that you have to do to protect your application

The following is NHProf’s Main method: Each of the currently existing conditions (and I am pretty sure that they will grow) is there because of bug reports from the field. It gets… interesting, sometimes, the things that user do to my poor app.

posted @ Sunday, May 17, 2009 2:35 PM | Feedback (12)

The BIG Merge

Merging is one of my least favorite activities, this is especially true when we are talking about a big merge. You might have noticed that I have been talking lately about some big changes that we are making to NH Prof. And now the time has come to merge it all back together. Well, big changes is quite an understatement, to be fair. what we did is rip apart the entire model the application used to work with. We moved from a push model to a pull model, and that had quite a lot of implications throughout the code...

posted @ Friday, May 08, 2009 8:59 AM | Feedback (14)

Why I love ReSharper, Part X of N

I mean, of course I intended to say StatementSnapshot instead.

posted @ Tuesday, April 28, 2009 9:12 AM | Feedback (16)

I don’t speak Russian, but I do speak code

Here is a snippet from a blog post describing a lecture I gave yesterday in the Ural University: Imagine him [Ayende] giving a public lecture at the Ural State University and demonstrating one of the numerous code snippets he prepared. Suddenly a guy (I think his name is Alex) interrupts him and tries to point out an error in the code. Unfortunately, Alex fails to express himself in English, and instead just mumbles incomprehensibly. After two more attempts, he gives up and explains the bug to the audience — in Russian. But before anyone has a...

posted @ Friday, March 13, 2009 3:39 AM | Feedback (10)

Unmanaged API “fun”, finding out MSMQ subqueues names in C#

I needed to get a list of subqueues of a queue, and there is no way of actually doing that in managed code. I decided that I can still use P/Invoke and just make the appropriate unmanaged calls. In hindsight, it would have been significantly simpler to just build an unmanaged DLL in C++/CLR, but I was already too deep, and I can never remember how to properly compile a C++ app anymore. I finally had to slap myself a couple of times and remind me that I was a C++ developer for a long time, and I damn...

posted @ Saturday, February 21, 2009 5:17 AM | Feedback (1)

The other side of build vs. buy decisions

This is one of the most common arguments in the software world. I am usually firmly in the “just buy this stuff” party. Yes, I know that it looks like I am the guy that the “build it ourselves” party threw out because he was too radical, but do not let the misconception fool you. I firmly believe that if you can get what you want by just buying something off the shelve, I think you should do it. The only qualification to that whatever you buy should be able to meet your needs. What we have here...

posted @ Saturday, January 17, 2009 4:09 PM | Feedback (5)

Stop! Or I am writing another framework!

There is a small dwarf in my head that whispers about persistent binary trees and RESTful services, views using DSL and JSON data interchange. In other words, I really want to write NCouchDB. I had the exact same thing happening with queuing, and it didn't stop until I wrote Rhino Queues (five or six times!) I keep trying to justify to myself that this is needed. But I already busy over my head. Please, help me stop this, before I lose all control.

posted @ Thursday, November 13, 2008 5:40 AM | Feedback (9)

Get that queue out of my head

For some reason, I am having a lot of trouble lately getting Rhino Queues out of my head. I don't actually have a project to use it on, but it keep popping up in my mind. Before committing to the fifth or sixth rewrite of the project, I decided to take a stub at testing its performance. The scenario is sending a hundred thousand (100,000) messages, with sizes ranging from 4Kb to 16Kb, which are the most common sizes for most messages. On my local machine, I can push that amount of data in 02:02.02. So just above two...

posted @ Sunday, September 21, 2008 11:18 AM | Feedback (0)

What I am working on...

I am just going to post that, and watch what happens. I will note that this is code that I just wrote, from scratch. public class TaxCalculator { private string conStr; private DataSet rates; public TaxCalculator(string conStr) { this.conStr = conStr; using (SqlConnection con = new SqlConnection(conStr)) { con.Open(); ...

posted @ Wednesday, August 27, 2008 10:39 PM | Feedback (59)

Legacy Driven Development

Here is an interesting problem that I run into. I needed to produce an XML document for an external system to consume. This is a fairly complex document format, and there are a lot of scenarios to support. I began to test drive the creation of the XML document, but it turn out that I kept having to make changes as I run into more scenarios that invalidated previous assumptions that I made. Now, we are talking about a very short iteration cycle, I might write a test to validate an assumption (attempting to put two items in the...

posted @ Wednesday, August 27, 2008 10:37 PM | Feedback (4)

re: MVC Storefront Part 19: Processing Orders With Windows Workflow

Rob Conery has another MVC Storefront post, this time focusing on using Windows Workflow. Those are my random impressions: You probably do want to test your work flow. In the same way you want to have an integration test for the system. The sequence work flow seems to be a very heavy weight approach to just orchestrating actions in the application. I wonder what the perf implications of creating a workflow here would be. My gut feeling is that this is not good, but I don't really have data...

posted @ Sunday, August 17, 2008 5:59 AM | Feedback (12)

3 Levels Of Failures

You have the no-failure, everything completed successfully and everyone is happy. You have complete-failure, someone just pull the power cord off the machine. And in the middle, you have partial-failure, something bad happened, (network is down, someone pulled the USB key out) but the system can (and should) keep running. Most people give up on the complete failure scenario, leaving that up to transactional storage to handle this. That is usually the smartest solution. The problem occur with partial failure, where you need to recover in...

posted @ Friday, August 01, 2008 4:24 PM | Feedback (0)

Useless Java

This article (The 'Anti-Java' Professor and the Jobless Programmers) has really annoyed me. Not because of its content, but because the professor being interview is so narrowly focused that he is completely out of it. Let us take this quote: “Furthermore, Java is mainly used in Web applications that are mostly fairly trivial,” Dewar says, with his characteristic candor. “If all we do is train students to be able to do simple Web programming in Java, they won't get jobs, since those are the jobs that can be easily outsourced. What we need are software...

posted @ Wednesday, July 30, 2008 4:36 PM | Feedback (33)

Not all objects are created equals

I found something extremely surprising while profiling a project. Take a look at this piece of code: Stopwatch stop = Stopwatch.StartNew(); for (int i = 0; i < 1000000; i++) { new WeakReference(null); } stop.Stop(); Console.WriteLine("WeakRef: " + stop.ElapsedMilliseconds); stop = Stopwatch.StartNew(); for (int i = 0; i < 1000000; i++) { new string('a', 5); } stop.Stop(); Console.WriteLine("'aaaaa': " + stop.ElapsedMilliseconds); On my machine, this has the following output: WeakRef: 980 'aaaaa': 35 Creating a WeakReference is much more costly than creating a normal object. Not surprising, when you think of it, WeakReference has deep ties to the CLR, but I couldn't really believe it when I...

posted @ Tuesday, July 29, 2008 1:53 AM | Feedback (7)

Testing interleaved async file writing

Here is another interesting aspect that I run into when thinking about writing to files. What will happen if I start two async write operations? Will they get interleaved? Will they get interleaved? Will I get errors when using this? Here is using a single stream: var path = "test.txt"; if (File.Exists(path)) File.Delete(path); var handles = new List<WaitHandle>(); using ( var stream = new FileStream(path, FileMode.CreateNew, FileAccess.Write, FileShare.None, 0x1000, FileOptions.Asynchronous)) { for (int i = 0; i < 64; i++) { var handle = new ManualResetEvent(false); var bytes = Encoding.UTF8.GetBytes( i + Environment.NewLine); stream.BeginWrite(bytes, 0, bytes.Length, delegate(IAsyncResult ar) { stream.EndWrite(ar); handle.Set(); }, stream); handles.Add(handle); } WaitHandle.WaitAll(handles.ToArray()); stream.Flush(); } This worked perfectly, the writes are written in...

posted @ Saturday, July 26, 2008 10:47 PM | Feedback (0)

In search of an embedded DB

I need to use an embedded DB in a project. Naturally, I turned to my old friend, SQLite. It has served me well in the past, and I am well versed in all its tricks. Except... SQLite really fall apart when you are talking about even moderately multi threaded applications. By that I mean, it works just as advertised, for sure. It just lock the entire DB when used, which tend to kill other threads who want to access the poor DB. I then turned to FireBird, but a short spike told me that it is... inadequate. I managed...

posted @ Thursday, July 03, 2008 11:04 AM | Feedback (24)

Production TDD

I'll leave you the conclusions. The test pass now :-)

posted @ Tuesday, July 01, 2008 2:30 AM | Feedback (1)

Premature optimizations

I just finished doing a second de-optimization for NMemcached. This is the second such change I do, turning the code from using the async read pattern to using a simple serial read from a stream. Both those changes together takes the time to complete my simple (and trivial) benchmark from 5768.5 ms to 2768.6 ms. That is less than 50% of the original time! In both cases, I started with high use of BeginXyz, in order to get as much parallelism as much as possible, but it actually turned out to be a bad decision, since it meant that...

posted @ Monday, June 09, 2008 11:38 PM | Feedback (3)

Scratching an itch: NMemcached

Last night I found myself up at 1 AM, feeling restless. I decided that I need a new project, something that is very simple and will allow me to channel some energy. I decided to pursue something that I have long been curious about, build a Memcached server in .Net. The Memcached server is a distributed cache server that is very popular in the Ruby, PHP & Perl worlds, with some following on both Java & .Net side. It is written in C, and it is has some fairly interesting characteristics. Chief among them, it is a straightforward technical...

posted @ Friday, June 06, 2008 6:28 PM | Feedback (34)

Verifying assumptions with tests

Here are a few interesting tests that I just wrote: [TestFixture] public class SystemWebCacheTests : CacheMixin { [SetUp] public void Setup() { ClearCache(); } [Test] public void IterationWithModifications() { Cache["foo"] = new object(); Cache["bar"] = new object(); foreach (DictionaryEntry de in Cache) { Cache.Remove(de.Key.ToString()); } Assert.AreEqual(0, Cache.Count); } [Test] public void IterationWithAdditions_ShouldGet_ConsistentSnapshot() { Cache["foo"] = new object(); Cache["bar"] = new object(); bool first = true; int count = 0; foreach (DictionaryEntry de in Cache) { count += 1; if(first==false) Cache["baz"] = new object(); first = false; } Assert.AreEqual(2, count); Assert.AreEqual(3, Cache.Count); } [Test] public void IterationWithRemoval_ShouldGet_ConsistentSnapshot() { Cache["foo"] = new object(); Cache["bar"] = new object(); bool first = true; int count = 0; foreach (DictionaryEntry de in Cache) { count += 1; if (first) Cache.Remove("bar"); Assert.IsNotNull(de.Value); Assert.IsNotNull(de.Key); first = false; } Assert.AreEqual(2, count); Assert.AreEqual(1, Cache.Count); } } I have no idea if this is just a coincidental evidence, but I like the...

posted @ Friday, June 06, 2008 12:11 PM | Feedback (2)

Challenge: Striving for better syntax

Or, as I like to call them, yes another stupid language limitation. I did some work today on Rhino Mocks, and after being immersed for so long in DSL land, I had a rude awakening when I remembered just how much inflexible the C# language is. Case in point, I have the following interface: public interface IDuckPond { Duck GetDuckById(int id); Duck GetDuckByNameAndQuack(string name, Quack q); } I want to get to a situation where the following will compile successfully: IDuckPond pond = null; pond.Stub( x => x.GetDuckById ); pond.Stub( x => x.GetDuckByNameAndQuack ); Any ideas? Note that unlike my other challenges, I...

posted @ Tuesday, May 27, 2008 7:13 PM | Feedback (28)

Resharper 4.0 in now in beta

Just got the email about it. ReSharper 4.0 moved to a beta status. You can find the details here. Personally, I have been using a fairly old build, with relatively few problems.

posted @ Friday, May 23, 2008 2:27 AM | Feedback (19)

Matching SVK revision numbers to the SVN revision number

I am using SVK as a way to learn Distributed SCM, and it has been fine so far, except for one big issue. I am trying to apply SVN patches against SVK repositories. Actually, I setup SVK so I work against a local mirror, so the workflow is exactly the same, but the revision numbers are different. Trying to apply a patch just doesn't work because of that. You can go into the patch and edit the root revision, so it is not hard to make this work, except... SVK doesn't give me any mapping between the local...

posted @ Sunday, May 04, 2008 8:21 PM | Feedback (0)

Critical Mass

When a software project is started, there is a lot of new functionality to be written. Most of the time you are dealing with new code. After a while, if it is done right, you have a solid foundation that you can use to keep building the application. Whenever I recognize this moment, it feels me with deep sense of satisfaction, this is how it should be. Rhino Mocks has reached that point some years ago, and I noticed that SvnBridge has crossed that point as well recently. As telltales for this, I use the amount of effort it takes to build...

posted @ Thursday, April 24, 2008 6:36 AM | Feedback (2)

A Messaging Saga

One of the core concepts in NServiceBus is the idea of a Saga. A saga is a stateful class, responsible for handling a set of related messages. It is important to understand that the saga is not kept in memory between messages, but persisted to storage. This means that we can have large amount of concurrent sagas, without worrying about about memory consumption. Let us take a real example, from my previous post, and see how a saga can take care of it. [Serializable, Transactional] public class CandidateVerificationSaga : ISaga<VerifyCandidateMessage>, ISaga<ReferenceVerificationMessage>, ...

posted @ Tuesday, April 08, 2008 10:39 AM | Feedback (11)

Hibernating Torrent: A simple torrent server for Windows

I think that I already mentioned that I started to run into scaling limits with my screen casts. More specifically, the latest screen cast, was already downloaded 7,300 times! It is a 160Mb file, it also means that I have to pay for obscene amount of traffic. Since I didn't want to pay for all that bandwidth, and since in principal I don't believe in having to pay to give something (which cost a lot to make) for free, I was in somewhat of a problem. The idea of torrents was very attractive, except... There are...

posted @ Tuesday, April 08, 2008 5:06 AM | Feedback (18)

How to get good people: Two phase code tests

It is fairly common in job interviews to request some sort of a code sample. Generally a solution for a problem that the prospective employer gives the candidate. An interesting twist on that is to go over the code, give a single additional requirement, then see what the result it.

posted @ Thursday, April 03, 2008 4:48 AM | Feedback (15)

After writing my own "XML Parser", SOAP Stack was the obvious next target

Okay, this left really bad taste in my mouth. I had to do SOAP based called today using: WebRequest.Create() Handle the correct SOAP Action. Construct the request using string concatenation. Manually parse the result using XmlDocument and xpath. I thought that the whole point of using web services was to avoid this bloody nonsense stuff. Urgh!

posted @ Wednesday, March 05, 2008 9:33 AM | Feedback (7)

The mysterious life of mutexes

Last night I was talking with Ron Grabowski (of log4net fame) and the subject of mutexes came up. Specifically, the subject of abandoned mutexes across threads, AppDomains, and Processes. I was pretty sure what the behavior should be, but we wrote a set of test cases for that, with... surprising results. My expectation that after I get a hold on a mutex, I have to explicitly let it go. If I am killed or interrupted somehow, then I would expect the next person to acquire the mutex to get an AbandonedMutexException. The first code sample does exactly that:...

posted @ Thursday, February 28, 2008 5:20 PM | Feedback (8)

Continuous Environment Validation

For some reason, it seems like I am talking about Release It a lot lately, to a lot of people. As I said when I reviewed it, that book literally changed the way that I approach problems. It also made me much more aware of the failure scenarios that I need to deal with. A while ago I sat down in one of Jeremy Miller's talks and he mentioned that he had added the ability to do Environment Validation to StructureMap, so when the application is starting up, it can verify that all its dependencies are in a valid...

posted @ Wednesday, February 27, 2008 6:07 PM | Feedback (5)

MsBuild vs. NAnt

A long while ago I moved the Rhino Tools repository to using MSBuild. I am not quite sure what the reason for that was. I think it was related to the ability to build it without any external dependencies. That is not a real consideration anymore, but I kept that up because it didn't cause any pain. Now, it does. More specifically, I can't build the rhino tools project on a machine that only have 3.5 on it. The reason is that I have a hard coded path with 2.0, which worked well enough, until I tried to...

posted @ Sunday, February 24, 2008 9:08 AM | Feedback (22)

Performance, threading and double checked locks

A very common pattern for lazy initialization of expensive things is this: GetDescriptionsHelper.Delegate getDescription; if (GetDescriptionsHelper.Cache.TryGetValue(entityType, out getDescription) == false) { MethodInfo getDescriptionInternalGeneric = getDescriptionInternalMethodInfo.MakeGenericMethod(entityType); getDescription = (GetDescriptionsHelper.Delegate)Delegate.CreateDelegate( typeof(GetDescriptionsHelper.Delegate), getDescriptionInternalGeneric); GetDescriptionsHelper.Cache.Add(entityType, getDescription); } This tends to break down when we are talking about code that can run in multiply threads. So we start writing this: lock(GetDescriptionsHelper.Cache) { GetDescriptionsHelper.Delegate getDescription; if (GetDescriptionsHelper.Cache.TryGetValue(entityType, out getDescription) == false) { MethodInfo getDescriptionInternalGeneric = getDescriptionInternalMethodInfo.MakeGenericMethod(entityType); getDescription = (GetDescriptionsHelper.Delegate)Delegate.CreateDelegate( typeof(GetDescriptionsHelper.Delegate), getDescriptionInternalGeneric); GetDescriptionsHelper.Cache.Add(entityType, getDescription); } } Except, this is really bad for performance, because we always lock when we try to get the value out. So we start playing with it and get this: GetDescriptionsHelper.Delegate getDescription; if (GetDescriptionsHelper.Cache.TryGetValue(entityType, out getDescription) == false) { lock(GetDescriptionsHelper.Cache) { MethodInfo getDescriptionInternalGeneric = getDescriptionInternalMethodInfo.MakeGenericMethod(entityType); getDescription = (GetDescriptionsHelper.Delegate)Delegate.CreateDelegate( typeof(GetDescriptionsHelper.Delegate), getDescriptionInternalGeneric); GetDescriptionsHelper.Cache.Add(entityType, getDescription); } } This code has a...

posted @ Monday, January 21, 2008 1:15 PM | Feedback (15)

Task Scheduling Improvements

I took some time to see how I can improve the sample implementation of the task scheduling that I posted yesterday. You can checkout the code here. What I wanted to check is the ability to scale the solution to many tasks and to IO bound tasks. In a stress test that I made, the library held its own while scheduling 9,864,100 tasks, at one point we had ~3,500,000 concurrently queued tasks. Memory usage hovered at the ~500Mb range. The next stage was to see what happens when we have tasks that takes a long amount of time to execute,...

posted @ Tuesday, January 08, 2008 2:31 AM | Feedback (14)

Erlang processes on the CLR

I mentioned that getting to Erlang like processes is something that I really want to get to. I started thinking about how I can make it work with the IEnumerable<T> implementation. As it turned out, that was fairly simple, once I got the idea. Take a look at this class diagram: We have tasks, and we register them in the scheduler. We can also wait for them without blocking the thread. Check out this trivial example. We have the following long running task: public class MultiplicationTask : AbstractTask { private readonly int value; ...

posted @ Monday, January 07, 2008 2:24 AM | Feedback (3)

It's the future now

For various reasons, I had to implement the Future pattern in two completely different settings in three different ways today. A future is a place-holder for the undetermined result of a (concurrent) computation. Once the computation delivers a result, the associated future is eliminated by globally replacing it with the result value. That value may be a future on its own. The last implementation was the explicit one, it was simply: public class Future<T> { private T value; private bool hasValue; private string error; public void SetValue(T value) { this.value = value; hasValue = true; } public void SetError(string error) { this.error = error; } public bool HasError { get { return error != null;...

posted @ Wednesday, January 02, 2008 11:24 PM | Feedback (25)

Import/Export Business, Est. Rube Goldberg and Co.

I want to get local access to my blog data. The problem is that it is somewhere on a server, and while I can probably open a connection to it, it is not really something that I would want to deal with on a regular basis. So, I decided to export the data locally, and work on it from there. After some failed restarts, I had come to the realization that trying to copy that much data over a WAN is probably not a good idea. So I started to look at local export solutions, which I could then...

posted @ Saturday, December 08, 2007 1:18 AM | Feedback (0)

Silverlight RTL

And on the heels of the Blame Microsoft post, here is a perfect example. Silverlight doesn't support Right to Left languages. This means that if I want to display Hebrew or Arabic content, it is flat out. This is usually the place where you sharpen a steak knife and go to meeting with a lot of red faced people and you need to wear ear muffs. Until an angel appears... Justin Angel went ahead and built RTL support to Silverlight. Check the links for details, but there a CodePlex project, a webcast and an online demo. Rendering Comparison ...

posted @ Saturday, October 27, 2007 12:08 PM | Feedback (1)

More generics gotchas, argh!

I have been working on .NET 2.0 for a long time now, generics still manage to trip me. Consider this piece of code: public interface IFoo<TFromInterface> { } public class Foo<TFromClass> : IFoo<T> { } [Test] public void More_Generics_Gotcha() { Assert.AreEqual(typeof(IFoo<>), typeof(Foo<>).GetInterfaces()[0]); } This test fails. the returned System.Type instance is a IFoo<TFromClass>, which is  an unbounded generic parameter, but not the same as IFoo<> itself. Now I need to apologize for Windsor, it wasn't its fault all along.

posted @ Tuesday, October 23, 2007 6:31 PM | Feedback (5)

D.O.A Software

From Don Demsak on the ALT.Net list: D.O.A. - Designer Oriented Architecture. Which is a good start for this post, which talks about Business Process Management tools, and manage to express some of the pain that I feel very clearly: And here is where it breaks down. All these unusable drag and drop tools, and “easy” XML programming languages aren’t targeted at programmers. They are targeted to suits who can buy into the idea that some non-techy is going to orchestrate these services and modify business rules. These products are unworkable because they are based on the idea that...

posted @ Monday, October 15, 2007 10:23 PM | Feedback (4)

On Rails, Ruby and the CLR

Rob Conery has an excellent post about Imploding Rails, which manage to hit a lot of my own thoughts about Rails. I believe that I have stated it before, I am thrilled by what is going on there, but I don't see a good reason to move, since all the nice stuff are either already here or can be brought here. And yes, that include the Ruby's magic. James Avery has a broader look at this, which I agree to, but doesn't negate's Rob's points. Rob's comment on James' post had me LOLing: Ruby is slow, I need to...

posted @ Thursday, October 11, 2007 8:41 PM | Feedback (0)

From demo to production: Handling the edge cases that aren't there

There is a difference between getting a scenario to working and actually finishing it. The first part is just making sure that the tech stuff work, that is generally easy, the hard part is getting all the stuff that you need to take care of taken care of. The biggest problem is that often you don't really see those issues. Let us start with an example from today. Let us have this user story: As part of the nightly maintenance routines, two days before the event, the system will remind all the participants about the event using SMS....

posted @ Tuesday, October 09, 2007 10:48 PM | Feedback (21)

The CRM Horror

It is rare that I get to the foint where I am just flat out speechless from seeing something. Today I went beyond that, I was flat out speechless and aghast. The image that you see here is a small part of the FilteredAccount view in Micorosft CRM. Yes, you got that right, a small part. I got to this from experimenting with the DB model, trying to figure out how things work. I was strongly adviced not to make any use of any sort of view that started with Filtered. "It would make you cry", they said,...

posted @ Sunday, October 07, 2007 7:33 PM | Feedback (14)

Trying to mimic Erlang style tasks in C#

After I lamented about missing key features for Erlang style tasks, Avish has told me about ThreadPool.RegisterWaitForSingleObject, which I was unaware of. I bang out this implementation of parallel sort as an example. Hacking code, proof of concept, written at 3AM in the morning, etc. public static WaitHandle ParQuickSort<T>(T[] domain, int lo, int hi) where T : IComparable<T> { if (hi - lo <= 1) { return new ManualResetEvent(true); //already signalled, no wait } ManualResetEvent manualResetEvent = new ManualResetEvent(false); Semaphore semaphore = new Semaphore(0, 2); int pivot = Partition(domain, lo, hi); WaitOrTimerCallback releaseSemapore = delegate { int release = semaphore.Release(); if (release == 1) { manualResetEvent.Set(); } }; ThreadPool.QueueUserWorkItem( delegate { WaitHandle leftWaitHandle = ParQuickSort(domain, lo, pivot - 1); ThreadPool.RegisterWaitForSingleObject(leftWaitHandle, ...

posted @ Friday, October 05, 2007 3:52 AM | Feedback (4)

Refactoring threading code

Let us start by saying that threading is complex, hard and complicated. A while ago I was asked to do a code review of a JoinAll() method, it looked somewhat like this: public void JoinAll(IEnumerable<Thread> threads) { foreach (Thread thread in threads) { if(thread.Join(500)==false) thread.Abort(); } } I was properly horrified by the use of thread.Abort(), but as you know, all rules have exceptions, so instead of commenting on the implementation details of the method, I asked to understand the entire scenario. This piece of code will probably easier than me trying to explain: List<Thread> threads = new List<Thread>(); List<string> results = new List<string>(); foreach (string urlParam in GetUrlsToQuery()) { string url =...

posted @ Friday, October 05, 2007 2:39 AM | Feedback (14)

Yet one more reason to like ReSharper

Sometimes it feels like it reads my mind, but in a good way.

posted @ Tuesday, October 02, 2007 10:23 AM | Feedback (3)

Generated Code Quality

Jeremy Miller made the mistake of opening the DataSet.Designer.cs file and got: You know the orange bars that ReSharper puts into the vertical scroll bar to denote warnings in the code?  In the DataSet code it looked like a solid bar of orange sherbert.  The discussion in the comments is about the quality of generated code, and it is fairly interesting. As someone who does quite a bit with code generation, I wanted to note two things: The quality of the generated code is the result of the generator, with the qualification that the generated code may be used to...

posted @ Friday, September 21, 2007 11:54 AM | Feedback (1)

A most applicable approach to the Fertilizer pattern

I recently had a chance to go through several legacy applications, bug spotting in one and evaluating the possibilities of code reuse in another. Stuff like "a most applicable approach to the Fertilizer pattern" began to run on my head as I read it, and at one point I had to go away to be able to curse in private (there were ladies present). Some of the things that I run into (across all the applications): Goto inside a grid implementation, after a little fact finding, it was discovered that they lost the original source, and just copy /...

posted @ Friday, September 21, 2007 11:39 AM | Feedback (0)

Development Platforms, again

Jeffery Pallermo commented about the applicability of SharePoint as a development platform, the conversation in the comments is fantastic. Sahil Malik replied to that in a post that says that SharePoint is a terrific development platform. I want to go through Sahil's points for a moment: I haven't ever walked into a shop with a home grown ASP.NET app that was any easier to install than sharepoint is. Here are the steps to install (on a bare bone server) my current project: Prerequisites: IIS .Net 2.0 + 3.0 SQL Server DB   Steps: Open cmd.exe \\storage\tools\subversion\svn co svn://subversion/MyProject/trunk MyProject msbuild default.build...

posted @ Thursday, September 20, 2007 10:06 PM | Feedback (4)

Fluent Refactoring

I have just made the following refactoring, starting from here: Owner owner = GetAccountOwner(); Lookup to = new Lookup(EntityName.queue, Settings.Default.ControlQueueID); Lookup from = new Lookup(EntityName.systemuser, owner.Value); Guid regarding = PostState.new_parentpolicy.Value; Picklist priority = PickLists.EmailPriority.Type.High; SendMail(from, to, title, body, owner, regarding, priority); I moved here: Owner owner = GetAccountOwner(); Email .Owner(GetAccountOwner()) .From(EntityName.systemuser, owner.Value) .To(EntityName.queue, Settings.Default.ControlQueueID) .Regarding(PostState.new_parentpolicy.Value) .Priority(PickLists.EmailPriority.Type.High) .Title(title) .Body(body) .Send(); Not much in terms of lines of code, but my sense of aesthetics is pleased, at least. And at least it ensures that we won't have this:  SendMail( new Lookup(EntityName.systemuser, GetAccountOwner().Value), new Lookup(EntityName.queue, Settings.Default.ControlQueueID), title, body, GetAccountOwner(), PostState.new_parentpolicy.Value, PickLists.EmailPriority.Type.High);

posted @ Tuesday, September 18, 2007 2:10 PM | Feedback (22)

Putting things in perspective

Josh Robb is talking about the sense of accomplishment of doing anything non trivial in WebForms, and concludes with: When this happens I experience this strange sense of achievement and even pride. The feeling that I have really done some “hardcore” programming today. Then I remember that I just managed to inject a string into the middle of another string and write the result to a stream. :-)

posted @ Tuesday, September 18, 2007 11:43 AM | Feedback (2)

Mixed Mode Authentication

I just finished spending half a day implementing support for mixed mode authentication in my application. I am putting it here mostly to remind me how it is done, since it was a pretty involved process. As usual, the requirement was that most of the users would use Windows Authentication in a single sign on fashion, and some users would get a login screen. I am using Forms Authentication, and I want to keep is as simple as possible. After some searching, it seems that most of the advice on the web seems to include building two sites, and...

posted @ Thursday, August 30, 2007 4:41 PM | Feedback (3)

In the authentication maze

Well, it looks like I have once again managed to put myself in a tricky spot. I have the following scenario: Domains: A1 & A2 - no trust or any association between the two. A user access a Website on A1, using windows authentication, which makes a web service call to a machine on domain A2 (anonymous security, at the moment). As a result of the web service call, the machine on A2 needs to make another web service call to A1, and it needs to do it with windows authentication, with the credentials of the original...

posted @ Sunday, August 26, 2007 8:38 PM | Feedback (8)

Ergonomic Hardware

Like many people who work with computers a lot, I suffer from wrist pain. I recently switched to using a Microsoft Natural Keyboard 4000, and it reduced those issues very quickly. The main benefit of the keyboard, aside from the ergonomic, split, design, is that it is  raised, which mean that my wrists doesn't have to bend in order to use the keyboard. I have found that this to be a great product, with the single complaint that the wrist rest hand doesn't stretch enough to the left, so I have no easy way to access the left most keys...

posted @ Saturday, August 25, 2007 12:17 AM | Feedback (19)

Useful lies about JavaScript Prototype Model

Note: This is not how it works, but it is close enough that it is a valid mental model for most scenarios. When I think about JavaScript and its type system, I usually envision objects as hash tables that can carry values or functions. The prototype idea is just an associated hash table, and so on. The moment that I settled on this mental model, it was much easier to grok javascript. Now, that is a vague explanation if I ever heard one, so let us speak in code: public class Object { private readonly Dictionary<string, Procedure> functions = new Dictionary<string,...

posted @ Wednesday, August 22, 2007 11:12 PM | Feedback (1)

How to test for SQL Injections

Not only does this snippet effective in finding simple SQL Injection attacks:  The side effects are highly reduced ratio of second offences, and a sudden improvement in backup practices. Now if I could fix the weeping issue...

posted @ Wednesday, August 22, 2007 12:48 AM | Feedback (4)

I want to see it, live!

Smalltalk had it right from the start, when I want to explore a system, I want to explore a live system, once I can interact with and get immediate results. REPL systems are very good (those are live interpreters, such as boo, perl, python, ruby, etc has) for exploring, but today the requirement for Liveness was brought home very clearly when I needed to work with some web service I knew nothing about. Now, I could have looked at the WSDL, and tried to figure out what it means (either by looking at the WSDL itself or looking at the...

posted @ Wednesday, August 15, 2007 12:49 AM | Feedback (0)

Abstract Syntax Trees

Consider this a very high level explanation, I just wrote this in an email, and I felt that it is a shame to waste the info. AST is the most common way for computers to work with structured text. They turn it into a graph, and then they can do operation on the graph, instead of manual text parsing. Again, this is a rough description of how it works, but it is an essential part of any text parsing routine of any complexity. Most often, compiler, interpreter and the like are based around AST and operations on AST. Let us...

posted @ Friday, August 10, 2007 10:26 PM | Feedback (2)

You can't estimate a month

Udi is talking about not trusting a developer's estimate: Developers don’t know how to estimate. Or more specifically, the variance in the actual completion time of a feature from the estimate given by a developer increases probably exponentially with time. For example, if the estimate is a day, you can expect it to be finished in around a day. If the estimate is a week (5 works days), it will probably vary between 4-10 work days. If the estimate is a month, in all actuality the developer probably doesn’t know enough to say but will answer when pressed. I...

posted @ Thursday, August 09, 2007 12:18 AM | Feedback (6)

Those untrustworthy developers...

From Jeremy Miller's blog: But Jeremy, that might be fine for you, but I can't trust my developers to just do the right thing.  I need governance.  First, what are you doing to change their behavior?  Secondly, why did you hire them in the first place if they can't be trusted, or can you tighten up the hiring process.  Three, is that really the case?  I've heard this line about not being able to trust the developers far too many times.  Why, or how, is the manager responsible, but the developers aren't?  Allow me to spin the question...

posted @ Monday, August 06, 2007 8:26 AM | Feedback (3)

First Class Functions: Having fun with delegates & design patterns

When writing Rhino ETL, I am getting more and more attached to the idea of first class functions, and their usage. The ability to just send a method (with context!) to be executed elsewhere is amazing. The really nice thing is the ability to express design patterns with focus on the intent vs. focus on the how. As an aside, this post should make your head hurt. Let us take a factory, for example: public delegate WaitHandle WaitHandleFactory(); public WaitHandleFactory CreateWaitHandleForCommand(ICommand command) { return delegate { ManualResetEvent resetEvent = new ManualResetEvent(false); command.Completed += delegate { resetEvent.Set(); }; return resetEvent; }; } And a decorator: public delegate void Command(); public Command DecorateWithPerformanceLogging(Command...

posted @ Saturday, August 04, 2007 3:52 PM | Feedback (2)

Evaluating a Business Platform

A business platform, as far as I care, is an application that I develop on top of. SAP, Oracle Applications, CRM, ERP, etc. Those big applications are usually sold with a hefty price tag, and a promise that if can be modified to the specific organization needs as required. That is often true, actually, but the question is how. This often requires development, and that is where this post comes in. I am a developer, and I evaluate such things with an eye to best practices I use for "normal" development. In a word, I care for Maintainability. Breaking it...

posted @ Friday, July 27, 2007 12:59 AM | Feedback (1)

Application Types

At first, there was the Utility, it was written quickly, for doing just this one small thing, and no one cared much about it. Then came the Project, which took a few weeks, and saved some work for people to do. And on the third day the Application, which had users and did useful work. It was both more complex and more valuable. From the trenches, the Batch Process appeared, to make order in the chaos. Over the horizon the Framework came into place, and all was orderly and there was order in the DAL and the BAL....

posted @ Friday, July 27, 2007 12:40 AM | Feedback (2)

Map, Reduce, Filter

Dustin Campbell has a couple of posts about Map/Reduce/Filter: Basic Concepts Using it in C# 3.0 He makes it easy to understand, but he forgot one thing that is important, usage of the Map/Reduce/Filter pattern make it very easy to parallelize your code, since you have already separated everything into an action on a set, which can be performed in parallel safely (in most cases).

posted @ Friday, July 13, 2007 8:10 PM | Feedback (3)

The value of a feature

How do you value a feature? My own estimation is based on the amount of effort that it took, but the client has a totally different metric. The value of a feature for a client is directional proportional to the amount of pain it removes, with complete and utter disregard to the effort it took to implement. I have been reminded of this when the customer completely failed to appreciate my JavaScript multi threading capabilities (that enabled a drop down list), and was supremely impressed with the user impersonation feature, which took about an hour to write. Amusingly enough, a...

posted @ Friday, July 06, 2007 12:43 AM | Feedback (5)

Adding to list from multiple threads?

I just read an email from someone that assume that it is safe to access a collection from multiple threads, if this is done for adding items to the collection only. My gut feeling said that this is a bad idea, but I set out to verify it anyway. Here is the test case:  static void Main(string[] args) { List<int> ints = new List<int>(); ManualResetEvent resetEvent = new ManualResetEvent(false); int additions = 0; int totalCount = 1000000; for (int i = 0; i < totalCount; i++) ...

posted @ Friday, July 06, 2007 12:36 AM | Feedback (10)

7 Approaches for AOP in .Net

Here are all the ways that I can think of to add AOP to your application. This mostly focus on the interception side of things, because once you have that, everything else it just details. Approach Advantages Disadvantages ...

posted @ Monday, July 02, 2007 5:43 AM | Feedback (8)

Using partials in Web Forms

Partial is a MonoRail term to a piece of UI that you extract outside, so you can call it again, often with Ajax. This is something that is harder to do in WebForms. Yesterday I found an elegant solution to the problem. ASPX code:<div id="UserDetailsDiv"> <ayende:UserDetails runt="server" ID="TheUserDetails"/> </div> User Control:<div> Name: <asp:label ID="Name" runat="server"/> <br/> Email: <asp:label ID="Email" runat="server"/> </div> Client Side Code:function changeUser(newUserId, div) { var srv = new MyApp.Services.UserDetails(); srv.GetUserDetailsView(newUserId, onSucccessGetUserDetailsView, null, div); } function onSucccessGetUserDetailsView(response, userContext) { var div = $(userContext); div.innerHTML = response; new Effect.Highlight(div); } Web Service Code:[WebMethod(EnableSession = true)] public string GetUserDetailsView(int userId) { User user = Controller.GetUser(userId); //there may be a better way to do this, I haven't bothered looking UserDetails...

posted @ Friday, June 15, 2007 5:16 PM | Feedback (11)

ReSharper 3.0 Beta

I am using R# 3.0 Beta, and I am loving it, check out the suggestions:   And this one: Or this one:   The really great thing about it is that it is three key strokes from suggestions to having better code!

posted @ Saturday, June 02, 2007 5:00 PM | Feedback (3)

MVC in WebForms: The impossible fight to get rid of the views centric world

Let me start out by saying that I know of a lot of people that are doing MVC with WebForms, I am doing it myself right now, which put me in the position to talk about the pain that it brings.  Let us consider the traditional MVC pattern: Now, in such a pattern, who is supposed to be in control? To drive the application? If you have guessed that the "Controller" is the one that is supposed to be in control, you got the jackpot, but missed...

posted @ Friday, June 01, 2007 8:32 AM | Feedback (18)

Contrary to popular belief...

Patrick Cauldwell has a post about a set of guiding principal, which I mostly agree on, except: Buy, not build Take full advantage of the platform, even if it only solves the 80% case ...

posted @ Thursday, May 24, 2007 11:10 PM | Feedback (0)

What I don't like the Patterns & Practices efforts

The P&P groups has a lot of stuff that they release to the world, often with a lot of fanfare and people talking about that. I have reached the point that I no longer care about what the P&P guys are doing. Just having them release something, practically guaratees that this is not something that I would like to use. This has nothing to do with OSS vs. MS or something stupid like that. This has to do with the following reasons: The...

posted @ Friday, May 18, 2007 2:57 PM | Feedback (21)

Reflectoring && Learning

I had a few discussions recently with Roy Osherove, about learning WPF. Roy is a fun of Petzold book about it, mainly because it goes through all the API and explain their usage in depth. I haven't read that book, but I am currently going through Adam Nathan's book about WPF, and I am enjoying it very much. From Roy's perspective, Adam's book is too high level, not giving all the details that Roy feels he should know in order to be a great WPF developer. I don't agree with that approach, personally....

posted @ Wednesday, May 16, 2007 3:22 PM | Feedback (4)

Beware of the technical solution

Imagine this fictitious scenario, you are working on some functionality, and you are pretty pleased with what you have so far. Then, a new requirement come in, and it require something that is plain out not possible with the approach that you have taken so far. Then you start to investigate it a little further, and you find that if you do this, and push that, and maybe not look too closely at the end result, you can get what you want, without major changes to your code. I have done this. I...

posted @ Friday, May 04, 2007 5:27 PM | Feedback (1)

A developer so retarded

I just run into this post, that talks about a presentation about mocking, and included this statement (about using Rhino Mocks):I once heard a story about a developer so retarded that he and his team spent a good amount of time trying to debug a mock only to find out that he forgot about ReplayAll()*.  Who hires guys like that anyway? That developer, it would be me, and it can happens quite often. And I wrote the tool, so I should know what I am doing when I am using it. ...

posted @ Saturday, April 28, 2007 9:45 PM | Feedback (7)

Maintainability as a first level concern

I have no idea how I missed this post from Anders Norås. It is talking about some of the problems in using traditional software factories (code-gen) vs. using smarter frameworks. It is a long read, but it is excellent. Maintainability is the enabler of all the other "itities" of an architecture. Experience shows that typical EJB applications often was hard to maintain even if code generation made them easy to develop. The IDE driven code generation for EJB paved way for vendor lock-in. ...

posted @ Tuesday, April 24, 2007 1:46 PM | Feedback (2)

"Read The Code" is not a valid answer

Scott Bellware has a post titled Just Read the Code (or, Let them Eat Cake)That open source software can be opened and read is a great quality of open source.  But reading code and understanding code are two different things. Here is a simple example, from my own code With.Cache, it is a small class, but in order to understand what it is doing you have to grok Disposable Actions, Semi Statics and the Local Data concept. And then you need to find out where the properties on this class are used, to understand what...

posted @ Monday, April 16, 2007 3:22 AM | Feedback (3)

A good definition of scripting languages

From Avi Bryant:You extend Java by writing Java, you extend C++ by writing C++, you extend C# by writing C#, but you extend TCL and Perl and Ruby, as often as not, by writing C.

posted @ Sunday, April 15, 2007 8:20 AM | Feedback (6)

Business Objects vs. Entities: What is the diff?

Recently I have noticed several discussions about the differences between entities and business objects.  I have my own opinions in this matter, naturally, but before I get to them, let us try to define what each term mean, and I can't quite put this in words. An entity is something that has a valid domain meaning, and is usually persisted to durable storage. I am not so clear on the definition of a business objects, and I am not sure that my entity definition is very clear, either. Options?...

posted @ Saturday, April 14, 2007 7:14 AM | Feedback (8)

Give me the code!

Here is an amusing thought. I am explicitly a code guy (vs. designers guy). My persistance format is code My configuration is code My database is generated from code

posted @ Friday, April 13, 2007 1:04 AM | Feedback (4)

Development stats

A single page. 34 integration tests. 432 lines of test code (excluding data setup and stuff move to test infrastructure). 66 lines of code behind 210 lines of Javascript 641 lines of in the ASPX file (include the javascript above) ...

posted @ Wednesday, April 04, 2007 8:25 AM | Feedback (4)

More on change tracking...

Frans Bouma has an excellent post about Why change-tracking has to be part of an entity object. I like the level that he has gotten into, but I don't agree with his conclusion. The main issue is about a disconnected scenario, where you object went somewhere, and then came back, and you don't know what hapepned to it in the middle. Frans gives an excellent description about how it works in the infrastructure level using the ASP.Net data source, which I will continue to use. The main problem here is not...

posted @ Tuesday, April 03, 2007 2:27 PM | Feedback (4)

Limitations of Declerative Coding

David Hayden is talking about AOP, and he mentioned Caching declaratively, which sturk a chord, and I had to write a post about it. I want to talk about a completely different aspect of declerative coding, how far you should go with it. Just to be clear, this is fake code, and it has little to do with David's post other than using the scenario to make a point. Let us take the code example that David has:public class NewsController { private INewsService _service; public NewsController(INewsService service) { _service = service; } [CachingCallHandler] public...

posted @ Monday, April 02, 2007 5:36 AM | Feedback (3)

.Net Communit Process

Here are some interesting thoughts in the subject. And some very interesting comments and replies from ScottGu replying the open letter that David posted.

posted @ Tuesday, March 27, 2007 1:47 PM | Feedback (0)

How not to go about "Building user interfaces for object-oriented systems"

Update: This article is fron 1999, which I somehow missed, not news by far. Still wrong, even for its time, though. This really annoys me, the author of the article tries to preach an OO methodology for writing UI. In general, I don't have an issue with that, but his arguments contains this:An object-oriented solution tries to encapsulate those things [adding a field to a screen] that are likely to change in such a way that a change to one part of the program won't impact the rest of the program at all. For example,...

posted @ Friday, March 23, 2007 1:05 PM | Feedback (9)

Working with Code, not Executable XML

A couple of commenters on my last post said that XML is easier to work with tool-wise. This is true in a very strict sense. Code is incredibly expressive, and you can easily turn it into an object graph by simply executing it. I did something very similar a year ago, Saving object graphs to file: CodeGen and Executable Graphs.  

posted @ Friday, March 23, 2007 12:27 PM | Feedback (2)

How would I build MsBuild...

In the Open Letter to Scott Guthrie David talks about copying the features from OSS projects, and bring MsBuild as an example. MsBuild is a project that reached feature parity with Nant, there is basically no technical reason that I know to prefer on over the other. NAnt has more tasks, but MsBuild has quite a few as well. The problem is that feature parity is just that, not enough. Both Nant and MsBuild are xml based programming languages. Read the last sentence again, and you can probably tell what I don't like in...

posted @ Friday, March 23, 2007 3:52 AM | Feedback (8)

WebForms and lies

I made the comment several times that I feel that WebForms lies to me,  Joe Young asks what do I mean by that. Here is a small reproduction that I just created, that demonstrate the problem. Put this in an ASP.Net page, and run, select another value, and see what you get. <script runat="server">        protected void...

posted @ Tuesday, March 20, 2007 2:34 AM | Feedback (14)

Reporting business logic

Here is an interesting problem. I didn't give it any though whatsoever yet, I am just presenting the problem. A bit about the model:  This is a temporal model, meaning that objects change over time. Validity is a date range object, which define in what range the object is valid. AppointmentSpec is very similar to an outlook recurring meeting. The actual infromation about the meeting is in the AppointmentSpecSnapshot. The scheduling of the appointment is in the ScheduleSpecSnapshot. As you can imagine, both of those can change independently. Appointment is...

posted @ Friday, March 16, 2007 6:36 PM | Feedback (5)

A Frustrating Day

I did some major modifications to the project two days ago, moving properties around, adding / removing them. It was based on additional input about the model that we just got. It also meant that I had broke just about everything in the application, from the injection support to the CRUD functionality. We have tests (not nearly enough, in my opinion, but we are working on it), but they are mostly building the UI right now, so there is a lot of focus there at the moment. We started testing with Selenium, and...

posted @ Friday, March 09, 2007 1:32 PM | Feedback (1)

The Microsoft Religion

It is not often that I get an Ah-ha! moment when reading a post, but Nikola just did it. Check out his post. The most important part about it is:m. Even going out and searching for something better is a pain, and you may well not recognize if it is better unless you actually invest time in it. On the other hand, the label “Microsoft” on some random technology almost guarantees it is somewhat decent. And that makes a lot of sense.

posted @ Thursday, March 08, 2007 12:30 AM | Feedback (4)

Building the Policy Injection in 40 Minutes with Windsor

David Hayden posted about the policy injection block, and he mentioned that he believe that it should be integrated into the various EntLib offerring. Since he is using Windsor already, I asked why he is not using Windsor's capabilities to do this. Apperantly, they are not well publicized, since he wasn't aware of it. Therefor, I decided to take a look at what it would take to implement the Policy Injection capabilities with Windsor. It took me about 40 minutes and 400 lines of code. I didn't look at the Policy Injection...

posted @ Wednesday, March 07, 2007 12:07 AM | Feedback (6)

No, you are not allowed to write generic code

I had a discussion with a dev on my team today:Me: Why are you doing it this way? You are never going to need this code in this scenario. Him: I don't want to write the code to fit just this particular scenario, I want it to be generic. Me: This is in the controller for this particular use case, there isn't any other scenario that it will ever handle.  

posted @ Tuesday, March 06, 2007 6:07 AM | Feedback (7)

CLR Types

Argh! Can someone explain to me why there is such a sharp distinction between types and nested types? I get it that nested types can be private, and normal types can't, but why is just about everything in System.Type qualified for nested and non nested types? This rant brought to you by this code: bool isNestedAndInternal = target.IsNested && (target.IsNestedAssembly || target.IsNestedFamORAssem); ...

posted @ Tuesday, March 06, 2007 5:39 AM | Feedback (0)

How are you keeping up with this deluge of technology?

Sahil Malik has an interesting post about the keeping with the pace of technology. He posted an impressive list of technologies that he manage to get a handle on in a short time. Frankly, I use a simpler approach for keeping up with technology. I don't. A while ago my company had a guy who dedicate a significant amount of his time to finding out everything there was to know about new and upcoming Microsoft technologies. The end result was that we would get several emails a day, each containing references to multiply...

posted @ Tuesday, March 06, 2007 5:04 AM | Feedback (4)

Removing the leaky abstractions from WebForms

My preferred approach to develop on the web is using MonoRail, but since I am doing a lot of work for clients, they sometimes get to choose the technology. My current project is using Web Forms and Atlas.  I already mentioned that I am using Igloo to provide a truer MVC support for WebForms, it is not as good as what MonoRail can provide, but it is nice. (The only problem is that I keep feeling that my controllers are getting too big and complex, I have finally finished doing a stint on the UI that...

posted @ Monday, March 05, 2007 12:26 AM | Feedback (20)

Atlas weight issues: what am I missing?

I have the strong feeling that I am missing something. We have just run into a major slow down in one of our pages, as a result of adding the CalendarExtender. This led me to do some searching, and I am not sure that I can believe the results. Let us take this simple page: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="ExplodingMonkeys.Web.test" %> ...

posted @ Wednesday, February 28, 2007 9:47 PM | Feedback (15)

Method Dispatch Internals

Sasha Goldshtein just posted some very interesting stuff about the way the JIT optimize method dispatch. Despite the interesting topic, what caught my eye more than everything else was:Currently, the JIT is documented (perhaps "blogged about" would be more precise here) I found it hilarious. Recommended reading.

posted @ Tuesday, February 27, 2007 10:25 PM | Feedback (0)

Generics Challange: Solved

Take a look here to see what it takes to solve my previous challange. It was extremely hard to get it to work in all scenarios, and I am pretty sure that there are additional edge cases that I have not thought of, but for now, all the tests are green. I also have a 100% repreducable (on several machines) VS crashing bug, which is about the fifth that I know of. I actually started to put MsgBox.Show() in the code, and had a serious JavaScript deja-vu as a result...

posted @ Sunday, February 25, 2007 1:21 AM | Feedback (2)

Brail Update: Fixing AmbigiousMatchException for lazy loaded classes

There is probably a bug in Dynamic Proxy that causes it to output overrides to methods in such a way that when you reflect over the generated types, you get two methods for each overriden methods, instead of a single overriden method. I looked into it in detail a while ago, and I couldn't figure out how to make it work like I expect it to. The code that it generate is verifable, so this is something that the CLR supports, but I am not quite sure that I understand what the semantics for this is....

posted @ Sunday, February 25, 2007 1:20 AM | Feedback (3)

Reusable tests

It is generally accepted that reusability is not something that you should strive for in your tests. However, I have found that reusing tests is an interesting way to save time when you are testing a full process. Take for instance this piece of code: [Test] public void SuccessfullySavingTemplateWillShowConfirmation() ...

posted @ Thursday, February 22, 2007 7:57 PM | Feedback (2)

Igloo: Model View Controller In ASP.Net

I wrote about Igloo before, but now I am writing after several weeks of using it for a big project of ours. A bit about the architecture, we are using MVC (by utilizing Windosr + Igloo) in a way that I find very elegant. The UI layer is composed of WebForms and Atlas, and the backend is Active Record using Repository<T>. Transactions are handled by the Automatic Transaction Management facility from Windsor. Let us think about creating a new policy, there are a lot of fields to fill, so the...

posted @ Wednesday, February 21, 2007 8:28 PM | Feedback (10)

If coding is too hard...

Jeremy has a great quote here: I think you can almost break coding philosophies into two general camps. Camp #1:  Coding is too hard, so let's not write code anymore.  Model Driven Architecture, Executable UML, Business Rules engines, Rapid Application Development ...

posted @ Wednesday, February 21, 2007 7:49 PM | Feedback (0)

Serialization Hurts Me

I am now adding serialization support to Dynamic Proxy 2, and it is painful. It is painful because: I never did much with serialization, and there seem to be a lot of black magic there with regard to whatever you implement ISerializable, has [Serializable] or use any of the special hooks. I am working with serializaztion by directly manipulating the IL generation. This makes for fun debugging. ...

posted @ Friday, February 16, 2007 3:04 PM | Feedback (3)

Evaluating Atlas

Sorry, I meant that I am evaluating Microsoft(R) ASP.Net(TM) Ajax(Patent Pending) Extentions :-). I mentioned before that I am not really feeling overly excited about that whole Ajax thing. Because of a client constraints, I am unable to use MonoRail (but I use just about everything else from the Castle stack :-) ), so I thought that I would give Atlas a try. This is still very early in the project, but I like to understand how things works so I know why they broke. And for some reason, just about anything breaks...

posted @ Monday, February 12, 2007 10:09 PM | Feedback (7)

On the Framework Design Principles from Raymond Lewallen

Raymond Lewallen posted his presentation from Framework Design Principles. I mostly agree with what he has to says, except that on slide #5 he has this:Don’t supply virtual members if you don’t have to.  - Can cause problems by users of your framework who don’t understand it.  - Virtual members cannot be inlined. What?! The first issue is very simple, if a programmer do not understand what a virtual method is, he has no business touching. This is such a basic gap that you just...

posted @ Saturday, February 10, 2007 10:26 PM | Feedback (5)

Stories from the Code Reviews: Threading

I am doing code reviews, and I am running into some unique ideas about how code should work. Take into account this new locking pattern: public void ShouldOnlyAllowSingleInstance() {   object syncLock = new object();   lock(syncLock)   {     // code that modify a thread-shared resource    } ...

posted @ Thursday, February 08, 2007 11:35 PM | Feedback (10)

Concat in MsBuild

After building my own concat task for MsBuild, Jordan E. Terrell informed me that it is build in. In my defense, I couldn't find it on google :-) At any rate, Jordan was kind enough to send me a test script that showed how it worked and directed me at the documnetation. Here is the script: <?xml version="1.0" encoding="utf-8"?> ...

posted @ Wednesday, February 07, 2007 9:26 AM | Feedback (0)

Defending Hack Bombing

Adi posted a rebuttal to my suggestion about Hack Bombing:Whenever there is the slightest possible chance of your code leaving your personal computer, never insert UI meant for your personal use into it - in the worst possible scenario the customer may get a product containing this code. My point of view is that most developers (certainly I am included in this) will ignore "minor" issues when they focus on a bigger goal. The problem is that those "minor" issues tend to get not so minor very fast. I find that the easiest...

posted @ Tuesday, February 06, 2007 12:55 AM | Feedback (5)

Active Directory Authentication, Part 2

After getting some advise about the previous piece of code, I decided to dig deeper, and here is what I have now: public bool IsValidLogin(string username, string password) { ...

posted @ Monday, February 05, 2007 7:32 AM | Feedback (3)

Public Code Review

Okay, so I need to check if a username/password are valid on a given Active Directory domain (which is not the one that I am runing on). Here is the options that I came up with: public bool IsValidLogin(string username, string password) { ...

posted @ Sunday, February 04, 2007 11:05 PM | Feedback (2)

Hack bombing

You have done it in the past, and you had little time and needed to get something working, so you put together something that made you cringe a bit. It worked, but it wasn't good. You maybe put a little TODO there, but deep in your hearth, you know that you are going to forget it. Let me introduce you to a new paradigm: Hack bombing - the practice of where you leave a hack, you time bomb it so you would have to come back and fix it later. ...

posted @ Sunday, February 04, 2007 9:23 PM | Feedback (11)

Pictures from the Microsoft Academy

Here is me (on the left, looks like a bully), talking with Eli Lopian ( on the right ) , at the Type Mock booth. We chatted a bit about the way they are doing their mocking, and I was impressed with the capabilities of the platform they have. There are several things that they can do with them that should really blow you away when you see them. I hope that they will expand into those areas as well. And here is me...

posted @ Friday, February 02, 2007 2:12 PM | Feedback (3)

Did you know? SharpDevelop in under LGPL!

And appernatly has been this way for quite a while. I was still under the impression that it was under GPL, which meant that I couldn't make use of its components in my application, but it being LGPL, it is making stuff much easier. For those of you whom the last sentence means nothing, here is a Great OSS Licensing Debate in a two sentences: GPL is viral, LGPL is not. GPL means no traditional commercial use, LGPL allows it*. SharpDevelop was under GPL for its 1.0 version, and I continued to think...

posted @ Friday, February 02, 2007 11:41 AM | Feedback (1)

Rhino Generators

Like I said, I got envious from the Eleutian guys, and I decided to try to implement a very simple task with code preprocessing. After a small false start (choose the wrong code parser), I was able to come up with a preprocessor that could take this: [PerformanceCounterCategory("TestFoo")] ...

posted @ Friday, February 02, 2007 12:01 AM | Feedback (1)

Can you learn to program better?

Phil Haack has a post that you should read. There is an interesting quote there:I am not convinced by the idea that developers are either born with it or they are not. Where’s the empirical evidence to suport these types of claims? Can a programmer move from say the 50th to 90th percentile? I have a different view of programmers, as you can see below: The first steps for beginners are relatively easy to start, then there is the first hump, which is usually where the non-programmers quits. Then there is the ...

posted @ Thursday, February 01, 2007 6:23 AM | Feedback (8)

The Zen Of Python

I opened the python shell and entered "import this", here is what came out: The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat...

posted @ Saturday, January 27, 2007 12:22 PM | Feedback (0)

How much a hypothesis weight?

Well, roughly 6Gb. That is the download that I had to go through to get Orcas. And I am not even that interested in Orcas itself at the moment. I just want to test a crazy idea that I had. At any rate, I got the answer that I was looking for. The code below is not legal: public class Foo {     [IsValid( x => x==null )] ...

posted @ Friday, January 26, 2007 2:59 PM | Feedback (5)

Why Drag & Drop doesn't work

Moran commented on my Thinking about Developers post, and it got me riled up enough to post an immediate response*. Here is his comment (emphasis mine):The bottom line, Drag-and-Drop kind of programming works. You can’t blame companies for hiring cheap developers with poor skills that can produce a working outcome. If the end results of such developers were poor exactly like they are, perhaps something would change in the world, but Microsoft made it pretty easy for these guys to keep their jobs… thus lowering costs of developing using their drag...

posted @ Sunday, January 21, 2007 10:42 PM | Feedback (1)

The Anti Team

Jeremy Miller has an excellent post the Anti Team. I thought I would add a few team members to the mix: The New Guy - not the newest guy in the team, but the one who is always two steps ahead of everyone else, keep insisting that we should re-write the entire system in XYZ technology of the day. Will go to an event and come back talking excitedly about all the new stuff that is Right Around The Corner. ...

posted @ Sunday, January 21, 2007 9:39 PM | Feedback (3)

Open Sourcing SQL Server

[Via Stefano] I reached this post about a thought experiment regarding open sourcing SQL Server under the GPL. The author is a former Microsoft employee, and he spends quite a bit of time trying to explain how GPLing SQL Server will not hurt Microsoft business model. The terms that he suggests are similar to the way MySQL works, a GPLed products for free and a commercial version + support avialable for $$$. I just don't see the point here. SQL Server is one of those products that I feel that I can rely...

posted @ Friday, January 19, 2007 7:13 PM | Feedback (8)

Thinking about developers

Part of my job is interviewing developers, and I get all sorts, some that sticks to mind: ASP.Net programmer - 2 years experiance - couldn't explain how clicking on a button on the client cause the event to fire on the server. "It is ASP.Net that does it." - he kept saying. An experiance programmer, that had a difficulity reversing a string. ...

posted @ Tuesday, January 16, 2007 7:13 PM | Feedback (6)

Why me?

I just chased a bug that basically resolved into:static NHibernateNullablesSupport() {    tINullableType = Type.GetType("Nullables.INullableType, " + NullableAsm, false); } For those that are unfamiliar with GetType, the last parameter is bool throwOnError, passing false ensure that it wouldn't throw if it can't find the type. But it did. Eventually I tracked it down to:MbUnit.AddIn.MbUnitTestRunner.AssemblyResolveHandler Which will try to resolve an assembly, but will throw if it is not found. Breaking the behavior of the above code. I don't mind the bug, it is reasonable action...

posted @ Saturday, January 13, 2007 9:27 PM | Feedback (2)

Blog temporarily down: dasBlog Limitations

Well, it looks like I have run into some limits with dasBlog. I have over 2,000 posts, and close to 1,200 files in my content directory. It gets to the points that just opening the directory has a noticable delay. Trying to run dasBlog currently takes roughly 100% of the CPU, and takes forever. This is on my machine, by the way, so it is single user only. Trying that on the server apperantly killed it.  Profiling it shows that the fault is probably...

posted @ Saturday, January 13, 2007 3:07 PM | Feedback (1)

Fun with the ThreadPool #2: Find the bug

This bug caused a production system to grind to a screeching halt, under just the right amount of load. Took a while to figure out what was happening.  I created a small test that shows what the problem is. Here is a little description: The timer wakes a set of services that need to process input. To avoid re-entrancy issues, I used synchornized methods. ...

posted @ Friday, January 12, 2007 9:32 AM | Feedback (4)

Race Conditions, Synchornized methods and overloading, oh my...

The question was brought up, and I had to find out what the behavior is under this conditions. Here is the test scenario: class Program {       Hashtable t = new Hashtable();...

posted @ Thursday, January 11, 2007 8:46 PM | Feedback (1)

How Virtual Methods Work

The truth is so precious that she should always be attended by a bodyguard of lies I got into a discussion of this at work, so I thought that I might as well put a full explanation in the blog. I should preface this post by saying that everything that I says here is a lie. It doesn't really work like this. The compiler, the JIT, the OS and the CPU are doing a lot of extra stuff that you generally do not need to concern yourself with. It is (more or less) a high level overview of...

posted @ Friday, January 05, 2007 7:26 AM | Feedback (0)

How do you know when you did too much WPF?

I just got a compiler error that had me laughing out load.Apperantly this is not a valid C# code:user.SetToAdmin()/>

posted @ Monday, January 01, 2007 2:19 PM | Feedback (0)

EntLib's Object Builder Issues: What am I doing wrong?

First, let me describe the scenario, I am using Object Builder in a web application to manage the services of the application. Under load, we started to get exceptions from deep within Object Builder. I should also preface this by saying that I have very little knowledge of Object Builder and it is entirely possible that I am commiting some grave error in using it. Anyway, here is a simple wrapper for Object Builder: public class

posted @ Wednesday, December 27, 2006 11:54 PM | Feedback (2)

MonoRail, Active Record & Repository<T> Sample Application

Since I was asked, here is a demo application for using Active Record and Repository<T>.  Please note that this is an internal application that I use to merely test some ideas, so it is a bit rough, and there isn't any real functionality. The more interesting stuff for ActiveRecord & Repository<T> can be found in the FaqController. The entities are in Exesto.Model assembly, with all the usual attributes. ...

posted @ Wednesday, December 27, 2006 11:31 PM | Feedback (3)

A Challange: Simple HR Model + Rules

It seems like no one is ready to take my Linq Challange, so I decided to expand it a bit and meet my own standards. I decided to implement the challange in Active Record, since it is much faster to work with than NHibernate. Note that this is just the object model and the mapping, nothing more. Overall, this is 800 lines of code and 20 lines of configuration, and I think that it took about three to four hours to build this demo. Here is the object diagram:...

posted @ Sunday, December 24, 2006 9:51 PM | Feedback (0)

Code complexity

If we are talking about code comments, here is a piece of code that I don't think should deserve a comment: public IEnumerable<RuleResult> Validate(Rule rule, DateTime date) {        if (false == this.IsInRange(date)) (Update: Moved to an explicit method...

posted @ Sunday, December 24, 2006 8:55 PM | Feedback (16)

On Code Comments

dJeff Atwood had a post about code comments, which I am completely agree with. One of the comments to the post caught my eye, talking about the assumption made when commenting: It is not always feasible to have a programming guru on hand to fix every issue. Not everyone has the same skill set. Sometimes companies are stuck having to maintain code in languages their current staff aren't well-versed in. Gurus aren't available either at all in some areas, or for the money some companies have alotted for their IT staff. I...

posted @ Sunday, December 24, 2006 8:39 PM | Feedback (5)

MsBuild overridable tasks?

I have the following structure in a common.build file: Clean Compile Test Zip Publish What I would like to do is to be able to stick additional points in the middle for projects to execute their own stuff....

posted @ Thursday, December 14, 2006 10:24 AM | Feedback (0)

Fix for "Cannot find custom tool 'NHibernateQueryGenerator' on this system."

If you have downloaded NQHG 1.7 and are trying to use it from Visual studio, you probably got the following error: Cannot find custom tool 'NHibernateQueryGenerator' on this system. The issue is that I didn't update the setup script correctly, and the version that it registers as a COM addin is set to 1.6, while the assembly version is 1.7. This cause the COM load to fail. This script will reset the NHQG version to the correct one, until I manages to find some time for fixing this properly....

posted @ Tuesday, December 12, 2006 6:20 PM | Feedback (0)

Interview Questions From Hell: Take IV

It somehow came up in chat today, and it occurs to me that this is yet another great question that I probably will never ask in an interview: Tell me how System.Object.GetHashCode() works, here is a computer with net connection, google away. Personally, it took me 11 minutes to find how the implementation worked, and another seven to find it. Possible reactions: Candidate faints...

posted @ Sunday, December 10, 2006 10:44 PM | Feedback (2)

On Reuse and Thrashing

There is an interesting debate in the Castle deveoper list at the moment. It is interesting because I think that all sides agree on just about all the points under discussion. :-) Anyway, it got to the point where the subject of 3rd party controls and Mono Rail came up. Mono Rail has support for Web Forms view engine, which means that you can use all the usual ASP.Net controls (the in-the-box ones, Infragistics, Component Art, Telerik, etc). As readers of the blog already know, I am... not fond of the Web Forms...

posted @ Thursday, December 07, 2006 9:55 PM | Feedback (4)

OR/M and Performance

I spent most of the day going over an NHibernate application that was slow. The cause was most probably large number of queries for the database. I took my own advice and enabled performance logging for the application and let it run for a few days. When I read the logs today it looks like there were a number of pages where the number of queries was outside of any reasonable proportion. When I started reading the code for this pages, I realized that the problem wasn't with mis-use of NHibernate, or rather, it...

posted @ Thursday, December 07, 2006 5:57 PM | Feedback (0)

Not My Business... most of the time

I am so happy that I don't have to worry about Buffer Overruns anymore. If I did, though, this would be a good place to start looking for examples. I had to do a code review on a C++ code, and it was basically something like: // memory management // memory management // memory management // memory management // memory management ...

posted @ Tuesday, December 05, 2006 8:30 PM | Feedback (0)

Mem Cached Information Util

I have been doing a lot of work with Mem Cached lately, and I have been frustrated with the lack of information that I have from it as I tried to use it. The main problem is not that the information isn't avialable, it is that I feel that telneting to a service and querying its status using text commands (and them trying to turn bytes to MB in my head) is a bit primitive. This utility will simply query the MemCached server every 5 seconds, and display a more friendly status. You...

posted @ Thursday, November 23, 2006 10:57 PM | Feedback (0)

Introducing RollingSqlAppender

I have explained before what the constraints I have when working with logging. I got several good comments about it, and several has hit the nail directly on the head. Just to recap, here is the list of my requirements: The output from the logs should be deliverable by email by a layman. This basically means a file. The ouptut should allow me to slice / dice the data. The best way...

posted @ Saturday, November 18, 2006 4:26 AM | Feedback (0)

Active Metrics or Slapping the Sloppy Developers

Any performance advice you hear starts with "Measure". And indeed, I know of nothing worse than making "performance improvements" without numbers that you can check. But I am not going to talk about perf tuning in this post, I am going to talk about something a bit different, how to avoid the more major pitfalls of performance, and in general, how to put (strict) guidelines for developers. It is safe to assume that the #1 cause of performance issues in most applications is talking to the database. It is really easy (especially if you are...

posted @ Thursday, November 16, 2006 9:18 PM | Feedback (0)

I am going to get sued for temporal harassment

Go read the title again, first. It is not what you think. I mentioned before that I am working on temporal system. Actually, it didn't start as temporal system. It started as you everyday business system. Fairly complex domain, very interesting problems. At the time, I had Evan's DDD heavy on my mind, and I had a really nice domain model that I could work with. Just to make a point, the code I am going to show is a very simple piece of code, meant to sort a list of employee's contracts by...

posted @ Tuesday, November 14, 2006 6:59 PM | Feedback (5)

Wiki for NHibernate course

Head over here and check how I split up the stuff so far. This is on the wiki in purpose. I got a lot good feedback so far, and I would like to keep getting it. Feel free to edit the page and add / move topics in a more appropriate way.

posted @ Saturday, November 11, 2006 11:49 AM | Feedback (5)

My MSDN Article

My MSDN article has been published and can be found here. It covers using IoC (specifically Windsor) to create very flexible systems. Users of Rhino Commons will be able to recognize a lot of the thinking that went into building Rhino Commons. Specifically, the foundations of IRepositorty<T>. The article has been brewing for four or five months. It started as a blog post after a particulary annoying day, but it took a long time to create it properly, and it got too big for even what I would consider a blog post :-). I am really...

posted @ Friday, November 10, 2006 6:24 PM | Feedback (12)

Reviewing 70-528...

Following Howard's advice, I decided to take exam 528. I feel better when I tell myself that I am reviewing the test rather than take them. It is a marked improvement on the previous two exams that I took. For a start, it was mostly focused on the web, and didn't digress into other topics. It also had only a single question that had me going WTF ("you have no SCM, and you need to publish an updated site to the server" - No SCM??!!) and another that had no correct answer that...

posted @ Friday, November 10, 2006 5:51 PM | Feedback (1)

Ajax: What the hell is the buzz all about?

So today I had used ajax functionality for the first time. By that I mean that I used Ajax as it should be use, to show a progress bar for a lengthy process (about 1 minute). What I wanted is to load a page with a progress indicator, and at the same time, start the action in the server, when the results are ready (a grid), they would be sent to the client, which would replace the progress indicator with the gird. The current result set is about 5,000 items (expected to be...

posted @ Sunday, November 05, 2006 11:25 PM | Feedback (4)

Web Message Box

This is probably a really bad idea, but here it is: public class WebMsgBox {       public static void Show(string msg) ...

posted @ Thursday, November 02, 2006 1:40 PM | Feedback (5)

The ASP.Net Anti Pattern: MoTrolliew

This is really great overview of ASP.Net WebForms vs. Ruby on Rails. What is interesting is that for the first time I learned what the name of the anti pattern was: MoTrolliew - mixing all concerns together, and claiming seperation of concerns because you are using the code behind.  

posted @ Wednesday, November 01, 2006 4:33 AM | Feedback (1)

Code Stats

I run Source Monitor* on my system, trying to get an impartial idea some idea of how big is the damage, it turns out to be pretty good, actually. General stats: ...

posted @ Wednesday, November 01, 2006 3:19 AM | Feedback (2)

Code and Presentation from my lecture yesterday...

Can be found here. The code include all the dependencies that you need to build the project and start playing. Have fun...

posted @ Tuesday, October 31, 2006 6:03 PM | Feedback (1)

Correction: MonoRail vs. WebForms

Ken Egozi reminded me that my issue is not with ASP.Net itself, but rather with the WebForms implementation. As someone who had done quite a bit of work with the internals of ASP.Net, I have nothing but respect to the way it is architected and impelmented, This is truly a really great platform. (Except the entire System.Web.Cache API, which is completely internal, and therefor very bad in my eyes). Update: I forgot to mention another point about Ken's post/comment. He suggested a view engine in C# / VB.Net. Unfortantely, this is not easily possible. To...

posted @ Thursday, October 26, 2006 9:30 PM | Feedback (5)

To Public Or Not To Public, That Is The Question...

Paul Stovel talks about defaulting to making your code public (accessible to developer). There is nothing more infuriating than looking at the exact code you need in Reflector, yet not being able to call it yourself. I said it before, many times, and I fully agree with him on that. Scott Hansleman reponded: When you're designing for Users, you do a usability study. When you're designing for Developers, you need do a a developability study. Yes, and when you give me six months and real...

posted @ Monday, October 23, 2006 8:59 PM | Feedback (6)

Things that scares me, Mission Critical Caches

NCache has a new version out, and while the freature list seems really impressive, they added support to clustered, fail over caching. I have strong issues with any application where caching is mission critical to the point where you need to cluster it for reliability. To me, this points to one of two things: You are Google (and they have other solutions to this). You rely on the cache to an extent...

posted @ Monday, October 23, 2006 8:16 PM | Feedback (2)

The difference between VB6 and Ruby

I'm listening to DNR #198 at the moment, and Carl compares Ruby to VB6 and says that the main difference is that now we have tests. I don't agree with this statement. In my opinion, the main problem with VB6 compare to Ruby, JavaScript, Python, or any other dynamically typed langauge, is that the only concession that VB6 had for dynamicasim (is that a word?) was in its typing system. In other words, variant, automatic type conversion and duck typing (to some degree) were the only dynamic features of VB6. ...

posted @ Wednesday, October 18, 2006 7:59 PM | Feedback (3)

NHibernate Mapping File Item Template

I find myself creating it quite a bit, and I got tried of copy/paste to add the item, so I create an item template for VS 2005. You can download it here. I am thinking about creating a project template as well (I keep creating small projects to test stuff, or abusing my existing NHibernate.Generics project), but I hate the GAC and I don't want hard coded paths in the template. Any ideas how I can add the DLLs themselves to the template?

posted @ Sunday, October 01, 2006 9:58 AM | Feedback (1)

OR/M and SQL Injections

ScottGu is talking about SQL Injections and he mentions that neither stored procedures nor OR/M are a complete protection from it. In a way, he is correct. If the stored procedure that you are using is called sp_executesql, then you are not protected from SQL injection. A more problematic approach is when your SP uses sp_executesql to do some of its work (usually because it need to work on a table dynamically, or your precedecor was a sadistic freak that enjoy doing things the really hard way). Users of ORM are...

posted @ Saturday, September 30, 2006 11:58 PM | Feedback (2)

Background Worker

I just found myself writing this in an email:It [background worker] allows you to use multi threading with drag & drop, which was the first time many developers used multi threading. Many developers still don't. Let me repeat this "multi threading with drag & drop"... I'm going to have a liedown.

posted @ Saturday, September 30, 2006 3:12 PM | Feedback (2)

Upward compatability: Preparing for next version

Okay, here is an interesting issue. I am currently building a big project using NHibernate 1.0.2, and I need some features on NHibernate 1.2, mostly with regard to the new critieras. At the moment, we can't move to 1.2, there are concerns about it being beta and other changes that will keep us busy with technical stuff rather than building business stuff. Those are valid concerns, but I still feel that it will take more time in the end to move to the new version. I can solve the problem with 1.0.2,...

posted @ Friday, September 29, 2006 3:18 PM | Feedback (0)

Side benefits of testablity

A while ago I needed to test the output of a class that wrote data to a file. I didn't want to start reading/ writing files in my tests, so I created the following interface: public interface IOutputFactory {   TextWriter Create(string name); } This was easy to mock, and I could get the output back very easily. I didn't gave it...

posted @ Tuesday, September 19, 2006 6:32 AM | Feedback (0)

Introducting Binsor: The Boo DSL For Windsor

On the on-going battle between yours truly and XML, there has been a score on the good side! I just finished implementing most of the usable functionality in Binsor, which is a Boo DSL* that is directed at configuring Windsor. Before I get into the details, take a look at the most minimal xml configuration possible for Windsor: <?xml version="1.0" encoding="utf-8" ?> ...

posted @ Saturday, September 16, 2006 5:09 AM | Feedback (2)

Ruby and the critical performance path

Joel wrote about Ruby's performance, and DHH replied with a post showing how he outsourcedhe performance-intensive functions. To note, my only experiance in Ruby is writing very few Watir tests. So I can't really say anything about Ruby's perfomance first hand. I agree with DHH that this is a good thing, but I wonder about how to handle this in situations where the performance critical part is something that is core to the business logic. I'm not talking about general stuff like image resizing, encryption or bayesian filtering (which I think you are crazy if you...

posted @ Friday, September 15, 2006 3:07 AM | Feedback (5)

There Be Dragons: Rhino.Commons.SqlCommandSet

After last night's post about the performance benefits of SqlCommandSet, I decided to give the ADO.Net team some headache, and release the results in a reusable form. The relevant code can be found here, as part of Rhino Commons. Beside exposing the batching functionality, it is very elegant (if I say so myself) way of exposing functionality that the original author decided to mark private / internal. I really liked the declaration of this as well: [ ...

posted @ Thursday, September 14, 2006 5:25 AM | Feedback (2)

Solving the HttpModule mess

Okay, I think that I managed to dechiper most of the strange behavior in ASP.Net's Http Modules.An AppDomain may hold zero or more instances of HttpApplicationA new instance of HttpApplication may be created (for reasons that I have not been able to figure out) - a set of all the http modules will be created as well.An instnace of HttpApplication may be disposed (with its associted http modules) at any time.A request will always be served by a fully initialized HttpApplication.The result of this is that you cannot set/unset static variables from an HttpModule or HttpApplication.Or, more correctly, you can't...

posted @ Sunday, September 10, 2006 7:29 PM | Feedback (0)

I Have Refactored !!!

This is what an interface looks like after about two week of work and seventeen refactoring. At one point, it looked like this: interface IHaveMultipleOccurrences<T> : IHaveNameAndId, IHaveValidityRange<T> where T : IHaveValidityRange<T> But the fear of the compiler puking on me kept the design a little simpler.

posted @ Sunday, September 10, 2006 7:12 PM | Feedback (0)

More HttpModules Strangeness

My web.config file defines the following Http Module: <httpModules>     <add name="UnitOfWorkModule"            type="Rhino.Commons.HttpModules.UnitOfWorkModule, Rhino.Commons"/></httpModules> Yet, for some reason, I get two instances of the UnitOfWorkModule, and I can't quite figure out why. It looks like it is proccessed okay, when I look into the Http Application Initialization, I get the following registered modules:But, if I put a break point on the Init() method in the Http Module, it is called twice! I run it many times, and the "secret" seems to be multiply requests in the application's start. It looks likes several HttpApplication instances are created, and this is what is causing the issue.This...

posted @ Sunday, September 10, 2006 11:52 AM | Feedback (10)

HttpModules Bug?! Dispose() called more than Init()

I run into some very strange issues latelt with regard to Http Modules. I am using Http Modules to setup the environment for my application. In particular, I am using Unit Of Work Module to mange my Unit Of Work and the life time of application wide resources (like the Inversion Of Control container instnace). The problem that I run into was that I began to get errors from the application, saying that the container was missing. That, of course, was not possible, since I registered the HttpModule correctly, and it certainly did it job, for a time. The issue was mainly that...

posted @ Sunday, September 10, 2006 11:02 AM | Feedback (0)

Why you can't code in Hebrew...

In response for my DDD in Hebrew, I was asked why it is not recommended to code in Hebrew. I decided to question my initial response, and give it a shot. I quickly gave it a try and created the following domain model. I don't expect you to be able to read it (although if you can, you'll find it hilarious). Here is my DDD in Hebrew, the classes are Employee (right, top), Report (Left, Top), HoursReport (Middle, Bottom), WontBeHereReport (Left, Bottom) and Repository<T> (Right, Bottom): ...

posted @ Friday, September 08, 2006 12:10 PM | Feedback (12)

Performance Logging

I just added a small http module to Rhino Commons. It is a very simple module that times how long it takes to process a page.It only times the server-side processing, of course, but it is a great way to tell you where you need to pay attention.It is using log4net to log the data, so you can redirect the output to a database, and from there, you can get all the data you want.Configurating the module is very simple. Create the following table: CREATE TABLE [dbo].[PagePerformance](     [Id] [int] PRIMARY KEY IDENTITY(1,1) NOT NULL,     [Date] [datetime] NOT NULL,     [Message] [nvarchar](max) NOT NULL,     [PageURL] [nvarchar](max) NOT NULL,    ...

posted @ Thursday, September 07, 2006 5:43 PM | Feedback (0)

How to write GetHashCode() correctly

Today I spent quite a while chasing caching bugs. The reason turned out to something like this: public override void GetHashCode() {   return date.GetHashCode() & name.GetHashCode() & another.GetHashCode(); } The issue turned out to be that in most cases, the GetHashCode() returned the same value, which completely broke caching support. (For example, assume that date is MinValue, in this case, the result of this method...

posted @ Wednesday, September 06, 2006 9:50 PM | Feedback (5)

MVP on ASP.Net

Bill Piece continues his talk about MVP in ASP.Net using Castle's Windsor. It looks very interesting...

posted @ Monday, September 04, 2006 10:19 PM | Feedback (0)

Rules, Time, Hierarchies, Oh My!

I have been talking vaguely about time dependant stuff for quite a while, and I figure that it is about time to talk about some of the problems in a more concrete way. One of the things that I work on are time and hierarchy depednant rules. For instnace, take the following rules structure: All employees are allowed 3 paid lunch breaks, but managers are allowed 4. For the week of 10/09 - 16/09, Bob (a manager) got a benefit of as many paid lunches as...

posted @ Monday, September 04, 2006 10:14 PM | Feedback (1)

Joel & Leaky Abstractions

The recent posts by Joel caused quite a bit of noise lately, but are several things in Joel's Wasabi post caught my eye that I haven't seen blogged elsewhere:Another neat thing is that when you want to do something on the client (the web browser) you can write the code once, in Wasabi, and compile it to JavaScript for the browser and get identically functioning VBScript or PHP code for the server Can anyone say leaky abstractions? VBScript & JScript are very similar, I will grant him that, but client side vs. server side...

posted @ Sunday, September 03, 2006 11:43 AM | Feedback (4)

Active Record To Repository

David Hayden has a post about moving away from the Active Record pattern. In it, he suggests to create two classes per domain model object. For instnace, a Customer class and a CustomerDAO (data access object) class. I tend to call this object a Repository, instead of DAO, but this is mainly a matter of taste, I think. What is more interesting is the different reasons for choosing one approach or the other. I tend to use Active Record (both library and pattern :-) ) when I don't need to take complex...

posted @ Sunday, September 03, 2006 11:07 AM | Feedback (1)

Handling nullable datetime in NHibernate : The Interceptor

System.DateTime is a value type, and as such, cannot be null. The default value for DateTime in .Net is DateTime.MinValue, which equals to 01/01/001 00:00. The problem is that SQL Server's dates start at 1753, or there about. This is usualy solved in .Net 2.0 using Nullable<DateTime> (or DateTime? in C#), but my "entities" are messages to web services, and are generated from WSDL, so they lacked this nice feature. I also didn't realize that some of the DateTime values were nullable until pretty late into the game. After a...

posted @ Thursday, August 31, 2006 4:40 PM | Feedback (6)

Distributed Applications Failure Points

The worst part of building a distributed application is that you get different state in different parts of the system. Let us take a look at a simple message passing application, and the issues there. At the end of the day, each and every message should arrive once, and exactly once. I am assuming that it is not possible for the message to be corrupted in transmissions (The TCP/IP stack in general makes sure that you won't see those messages). The simplest model is where everything works out great: ...

posted @ Wednesday, August 30, 2006 11:18 PM | Feedback (1)

Server side vs. Client Side

I just had a discussion about server side programming complexity vs client side programming complexity. I hold the view that doing client side programming in an order of magnitude harder than doing stuff server side. I was shocked to see this proof of my correctness: And yes, I realize this is a falacy.

posted @ Wednesday, August 30, 2006 6:36 PM | Feedback (2)

IRepository(Of Customer) vs. CustomerRepository

Using IRepository(Of Customer): Customer[] customersWithUnpaidOrders = repository.FindAll(@"select c from Customer c, Order o  where o.Customer = c and o.Status = OrderStatus.Unpaid");  Using CustomerRepository:Customer[] customersWithUnpaidOrders = repository.GetCustomersWithUnpaidOrders(); The difference is the level of abstraction that is used. In the first case, the code define the question explicitly, using the generic repository to pose the question. In the second, it is the CustomerRepository responsability to get the data. The first is much more flexible, but it is harder to test. The second is much easier to...

posted @ Wednesday, August 30, 2006 10:49 AM | Feedback (8)

Don't get greedy with online ads

I just spent four minutes configuring AdBlock to remove annoying ads from this page, I don't have an issue with normal advertising, but naything that blinks, jumps, etc is annoying. I am not going to pay positive attention to stuff that annoys me. The end result that I don't know what the ad was about (it was big and black and green, that is all), but just about any ad server from this page is forever blocked on my browser.

posted @ Tuesday, August 29, 2006 4:47 PM | Feedback (0)

C# Riddle #5

Following Alex's post about traps in interviews, I thought about posting bits of code that I won't use in interviews. Mostly because I don't think that it is fair to the interviewee. I can think about crazy usages to langauge features, and not in a good way. Consider the following peice of code (which is valid C# 2.0):public IEnumerable<Predicate<Customer>> ValidationPipeline() {  yield return delegate(Customer c)  {   return c.Name != "";  };    yield return delegate(Customer c)  { ...

posted @ Tuesday, August 29, 2006 9:28 AM | Feedback (7)

The Curse Of The Infrastructure

If at all possible, minimize any dependencies on infrastructure that you have in your applications. The more dependencies on infrastructure you have, the less freedom you can get. I define infrastructure as anything that I can put on my laptop and use without being connected to any network whatsoever. Some examples of infrastrcuture bound applications are: Domain dependencies - the application must contact a domain controller for autentication, authorization, or just for the hell of it. (The reverse is...

posted @ Tuesday, August 29, 2006 9:14 AM | Feedback (2)

Love the debugger team

I have quite a bit of rants against several teams at Microsoft, but I wanted to dedicate this post to the VS debugger team, which has done a superb job in VS 2005. Maybe it has to do to the fact that I am a debugger user and not a developer, but so far the only issues that I had with the debugger are stuff like "You didn't configure E&C in the option panel, etc". This post was prompt by a fact that I accidently discovered recently. You can step into the web...

posted @ Tuesday, August 29, 2006 6:38 AM | Feedback (0)

On Interviews and Traps

Alex is making a good point about interviews questions and traps. Interviews questions are not real code, at least not at the first stages. Most of the stuff that I intend for interviews is not going to get somebody called on the carpet if I get to it on production code. In an interview, I need to be able to judge someone's technical skills very quickly, and hopefully accurately. I can spend a day pairing with a guy and then give a highly accurate view of his/her abilities, mindset and match for our team....

posted @ Monday, August 28, 2006 11:16 PM | Feedback (2)

Taking the measure of a developer

Continuing on the interview stuff, here is something that can tell you quite a bit about a developer. Given the following error, what do they do? Here are a couple of options: They tell you: "I can't get it to work, it keeps failing and I don't know why." Look into the inner exception. Googles the...

posted @ Monday, August 28, 2006 10:20 PM | Feedback (6)

Great Interview Question

Here is something to add to the indicators list: What does the following do?selected = selected++; If they can't figure this out, you got a problem. More interesting question may be: Contrast the results of the following two operations: selected = selected++; selected = ++selected; [Via The Daily WTF - Sidebar]

posted @ Monday, August 28, 2006 9:58 PM | Feedback (8)

Timing is everything...

To my sorrow. Before:current.StartTime After:current.At(DateTime.Today).Time.Start

posted @ Sunday, August 27, 2006 7:13 PM | Feedback (0)

Things that will make me come after you with a BIG stick: Part 1

For some reason, I get to see a lot of WTF?! in the field, and I think that this is about time that I do something about it. I'm going to start a series of posts about the stragest stuff that I see. Today, we have the New Data Model to observe. As you hopefully know, there are three (and only three) ways to create associations in the database, one to many, many to one and (using an association table) many to many. Trying to invent new ones will cause pain. ...

posted @ Saturday, August 26, 2006 2:40 PM | Feedback (3)

Programmer's Bill Of Rights

Jeff Atwood published the Programmer Bill Of Rights, which I like. Of the list, I currently don't have is #3 (mouse & keyboard that I want) and that is because I have a laptop, and I refuse to increase the time it takes to set it up for work.

posted @ Saturday, August 26, 2006 1:27 AM | Feedback (1)

Reading the SSCLI Comments

I'm browsing through the Shared Source CLI at the moment, for no good reasons... I found the following comment in the System.String implementation...**Action: Many years ago, VB didn't have the concept of a byte array, so enterprising **        users created one by allocating a BSTR with an odd length and using it to **        store bytes.  A generation later, we're still stuck supporting this behavior. Good to show a sense of humer in the code, I always says. Did you know that the CLR has a week reference hashtable? (Marked internal, of course, so you will not be able to use that ("Why, you horrible little man, why would you want to use a weak hashtable? Infidel") You...

posted @ Friday, August 25, 2006 8:06 PM | Feedback (0)

Ah, the smell of the compiler breaking in the morning...

Nothing like making a refactoring that goes through 140 compiler errors that I need to handle manually. Right now my least favoriate class in the framework is System.DateTime. Nothing like adding a forth dimention to your application to make you realize how much you hate time. On the other hand, I did get to create an OutOfTimeException which are going to provide me with hours of fun...

posted @ Thursday, August 24, 2006 10:03 AM | Feedback (0)

Watching the logs run with log4net

Logging is fairly critical to many applications, and it is especially critical when you are trying to understand in a complex application. I'm using log4net for logging, because it is so simple to start with and it can scale up to very complex needs. The problem that I had was watching the logs. Specifically, watching the logs run in real time. The application is heavily mutli threaded, and run as a windows service. It is pretty hard to get what is going on there unless you watch the progress of the logs. At...

posted @ Tuesday, August 22, 2006 10:32 PM | Feedback (2)

Primitive are not datatypes - or how to make me scratch my head

This post hit a really sensitive point with me, Eber is showing some of the more complex forms of generics. Here is how he hold all the files in all the directories in all the computersDictionary<string, Dictionary<string, List<string>>> list =  new Dictionary<string, Dictionary<string, List<string>>>(); I can't read code like this. I have a dictionary of a dictoary of a list. That is all fine and dandy, so far. The using code looks like this:list[@\\Rhino][@"C:\Files"][5]  The problem is that without knowing what this mean, I have no idea how to work with this. What...

posted @ Tuesday, August 22, 2006 9:18 PM | Feedback (3)

NHibernate Generics 1.0.10

NHibernate Generics 1.0.10 is a small bugfix release that is intended to allow inheriting from EntityList<T>, EntitySet<T>, etc. Check here for the scenario that was fixed. As usual, binaries and code are here

posted @ Monday, August 21, 2006 6:40 PM | Feedback (0)

Spiking Rhino Proxy - Dynamic Proxy on CodeDOM

What is Rhino Proxy? Rhino Proxy is a little spike of mine, duplicating the work that has gone into Dynamic Proxy, but using CodeDOM, instead of Reflection.Emit. The good news is that it took me about 3 days to duplicate nearly all the the functionality in Dynamic Proxy (I didn't do events, but it should be easy enough to do). The really good news are that I managed to support generics methods interceptions, so interfaces like this are now valid: ...

posted @ Saturday, August 19, 2006 8:33 PM | Feedback (0)

I want one of those: Active Writer - VS Designer for Active Record

Check out the pretty pictures! Even better information at the source. Gokhan Altinoren has done some tremendous work there. Can't wait to get the bits.

posted @ Saturday, August 19, 2006 1:54 PM | Feedback (0)

Threading E-Book

A nice threading ebook, I had a short look, and it looks very good. [Via Roy Osherove]

posted @ Saturday, August 19, 2006 3:44 AM | Feedback (0)

MemCached Applicance

I just checked the VMWare Virtual Appliances Contest, and discovered this gem: Hermes Memcached Virtual Appliance a 3MB VM that you can just download, throw on a machine and have distributed caching in your environment. Way cool. Certainly a very easy was to start using Memcached. Just to remind you, I talked about memcached here, and it has a C# API.

posted @ Friday, August 18, 2006 1:48 PM | Feedback (1)

Subversion and Visual Studio

Following the release of AnkhSVN 1.0 RC2, here is another way to integrate TortoiseSVN with VS.Net

posted @ Friday, August 18, 2006 12:25 PM | Feedback (0)

Code Darwinism

Jeff Atwood posted about the power of View Source in javascript and the resulting code darwinism. Interesting post. Personally, I find that just having reflector is a big help, and I use it quite often in order to hunt through libraries of code that I already have (my own, NHibernate, Castle, Boo, etc). Beside reflecting over other's assembly, Reflector is the very best code browser that I have used.

posted @ Friday, August 18, 2006 12:19 PM | Feedback (1)

On Source Control

Jeff Atwood has a couple of things to say about Anything, but Source Safe. I couldn't agree more. Check out the comments, there are some highly insightful things there.

posted @ Friday, August 18, 2006 11:00 AM | Feedback (0)

What is the difference?

Here is another challange, related to the previous one, what is the difference between the following lines of code: throw Activator.CreateInstance<ThreadAbortException>(); Thread.CurrentThread.Abort();  

posted @ Friday, August 18, 2006 10:06 AM | Feedback (0)

Special Exceptions Riddle

Here is a good riddle for interviews. It is short, concise, and it shows that they have quite a bit of experiance. What special exceptions do you know of in .Net? By special I mean exceptions that behave differently from normal exceptions (such as ApplicationException). Note: Of the top of my head, I can think of at least three or four that I would consider special, but there are probably more.

posted @ Friday, August 18, 2006 9:55 AM | Feedback (5)

Patches in the commercial world

I mentioned before that I am now in the final testing and deployment stage. The process for getting stuff to the staging server is long, twisted and painful. It involve a USB key, hours of prayers and maybe the soul of a flightless bird. The problem is that some of the things that the application is doing is infrastructure stuff (routing requests), which means that such thing as routers, firewalls, etc are of great meaning to the application. It is a given that I can't install Visual Studio or a real debugger there, so...

posted @ Friday, August 18, 2006 9:50 AM | Feedback (0)

Castle And The Open/Close principal

Recently I have been trying to use Castle Windsor to make me a cup of coffee. So far I managed to gray screen the coffee machine, but I am okay with this limitation, since it is just about the only thing that I can't do with it. The scenario, I have a set of similar services that I want to load from configuration. They all implement the same class, but have different configuration, here is a sample:public WebService(string url, DateTime start, DateTime end) My first attempt to solve this issue was with this configuration: ...

posted @ Sunday, August 13, 2006 8:41 PM | Feedback (0)

Define: USB Debugging

USB Debugging takes its name from the way you usually deploy to staging servers. The act of finding bugs on staging servers where you cannot install any tools and have no network that you have access to, but you are allowed to copy files via USB key (which is first screened by security {each time you copy}). In those situations, the cycle of deploying usually goes like this: Copy files to USB key Hand to security ...

posted @ Sunday, August 13, 2006 8:06 PM | Feedback (0)

Reflection.Emit vs. CodeDOM

Both technologies allow you to generate executable code at runtime (even though CodeDOM may not have been originally intended for this). This opens up some interesting possibilities (Rhino Mocks and NHibernate, for instnace, uses Dynamic Proxy, which uses Reflection.Emit to generate proxies for object at runtime). Reflection.Emit gives you complete control of the generated IL, while CodeDOM leaves you creating source code dynamically. Reflection.Emit has the following advantages: You can generate new classes directly into an existing assembly, this helps...

posted @ Sunday, August 13, 2006 6:56 AM | Feedback (3)

And there was much rejoicing, for the Exception was raised

A lot of programmers seems to be afraid of exceptions. The moment they get one they throw their hands up in dispair and exclaim "This piece of shit doesn't work." And then they come to me to help. They usually start with "It threw an error", "It doesn't work", etc. At first I try to hone my clairvoyant skills, and give them an answer anyway, but after being accused for using KGB interrogation technique* I decided to stop that. Nowadays, I refuse to help them unless they tell me what the exception is. And...

posted @ Sunday, August 13, 2006 6:27 AM | Feedback (3)

Where did my file go?

What happen if you are doing something like this in ASP.Net:File.WriteAllText("fun.txt", "Foo Fum"); On my machine, it goes to: c:\windows\system32\inetsrv\fun.txt Remember that the current directory in ASP.Net is wherever the server process has decided it should be, if you want the directory that your application is on, use AppDomain.Current.BaseDirectory for it.

posted @ Thursday, August 10, 2006 7:45 PM | Feedback (3)

Someone here doesn't get Test Driven Development

Trying to get a report of a test run, a shady guy around here has wrote the following code, included in full: private DataSet ExtractResult(TestSuiteResult result) {     DataSet res = new DataSet("AllResult");     res.Tables.Add ( "Diagnostics" );     res.Tables["Diagnostics"].Columns.Add(new DataColumn("Description", typeof(string)));     res.Tables["Diagnostics"].Columns.Add(new DataColumn("Passed", typeof(bool)));     res.Tables["Diagnostics"].Columns.Add(new DataColumn("Message", typeof(string)));     foreach (TestSuiteResult o in result.Results) ...

posted @ Thursday, August 10, 2006 7:14 PM | Feedback (1)

How to use Rhino Commons in ASP.Net

In the web space, the Unit of Work pattern is usually mapped to a unit of work per web request. This translate very easily to an http module, which you can find here. It configures the container automatically from a file named (by defauly) "windsor.config", and starts / dispose unit of works as part of the http pipeline. Basically, this means that you never need to worry about this. The configuration is simply: < ...

posted @ Wednesday, August 09, 2006 9:35 PM | Feedback (6)

Visual Studio Riddle

I have the following project structure: ...

posted @ Wednesday, August 09, 2006 8:10 PM | Feedback (8)

Sanity Checks: The Active Record Version

Following my NHibernate Sanity Check, here is the Active Record version: public class AR_Sanity_Checks : ActiveRecordModel {     public static void DoSanityCheck() ...

posted @ Wednesday, August 09, 2006 7:46 PM | Feedback (1)

NHibernate Mapping: Creating Sanity Checks

Here is a very easy way to find out if your database schema is still the same one that NHibernate expects: [Test] public void AllNHibernateMappingAreOkay() { ...

posted @ Wednesday, August 09, 2006 8:38 AM | Feedback (3)

How to write Session Code

I stand behind every word in this post, this is certainly how you should interact with any dictionary object, not just the session. As a side note, using the session state is going to hurt your scalability, prefer to use the Share Nothing approach.

posted @ Tuesday, August 08, 2006 9:09 PM | Feedback (2)

Testing ASP.Net UI: WATIR Impressions

I've started looking at writing integration tests for an ASP.Net application. I have a farily complex application with quite a bit happening in the UI layer. Some pages are fairly simple data entry forms, and some contains UI that is scary to just think about (the amount of work it would take). It has long been my belief that it is not worth testing the UI layer. A lot of effort goes into this, and it is usually fragile in the face of changes. The problem is that without tests is it...

posted @ Tuesday, August 08, 2006 8:50 PM | Feedback (4)

Arabic is not safe for ASP.Net

This actually has nothing whatsoever with the current state of affaris in Israel. I was trying to input some Arabic text into ASP.Net controls, and I got the Potentially Dangerous Request Detected exception, interesting.

posted @ Tuesday, August 08, 2006 8:17 PM | Feedback (1)

How to debug a windows service

Usually you are told that it is not easy to debug services, but they aren't much different than normal applications, except for the security context and no desktop environment. Here is how I build most of my services: static void Main(string[] args) { ...

posted @ Monday, August 07, 2006 9:43 PM | Feedback (1)

MsBuild Annoyances: Take 2

I have put this in my project file: < ConfigFile Include="$(MSBuildProjectDirectory)\Bin\$(Configuration)\**\*.config"/> After loading the project into VS.Net, it turned it into this: < ConfigFile Include="D:\Work\Tester\..\Configuration\FileStructure.config" /> <ConfigFile Include="D:\Work\Tester\..\Configuration\Tasks.config" /> Even ignoring the fact that this is not recursive (and I have need of recursiveness there), this is annoying in...

posted @ Monday, August 07, 2006 9:37 PM | Feedback (7)

The most useful key in the keyboard is...

The little DEL one. I keep telling people, "you have source control, just delete this stuff." There is also nothing as satisfying as working with someone when you just select a couple hundreds lines and delete them. The expressions are priceless. Delete as much code as you can, it means less stuff that you'll need to puzzle out in 6 months time.

posted @ Sunday, August 06, 2006 11:50 PM | Feedback (2)

Working with high levels tools: A Performance Perspective

The performance question was raised in the Castle's Forums, hammett has posted a blog entry about it, but I have my own two cents to add. The question was about a performance test made with NHibernate vs. ADO.Net, resulting in NHibernate being quite a bit slower. Just to note, at the moment I'm talking about performance in terms of milli seconds, I'll talk about performance in terms of days in a bit. A test between ADO.Net and NHibernate is going to be meaningless for the most part. Sure, you can issue a SELECT to get...

posted @ Sunday, August 06, 2006 3:27 AM | Feedback (0)

Custom Tool For VS.Net: How to generate the filename?

The NHibernate Query Generator generate files using the Custom Tool interfaces to VS.Net, but I can't figure out how to control the generate filename. Ideally, I would like to have the files named something like: Customer.hbm.g.cs This way I can skip all the checks on them, any ideas?

posted @ Sunday, August 06, 2006 3:11 AM | Feedback (2)

Continious Integration: What about 3rd Party stuff?

I'm now building the CI server, and I'm installing all the neccecary things like cruise control, SDK, NUnit, etc. The question is where do I draw the line? The ideal is to have as little as possible on the CI system itself. For instance, how should I handle Infragistics' controls?

posted @ Saturday, August 05, 2006 1:11 PM | Feedback (1)

What make me effective developer

Tool / Add Ons: ReSharper Subversion Tortoise SVN Cool Commands Test Driven .Net ...

posted @ Friday, August 04, 2006 11:12 PM | Feedback (7)

Testing generated code

A couple of days ago I asked about how to test that code that generates code. Basically, there are two or three options: String comparisions - Fragile, but easiest to do. Use a C# Parser and check the resulting DOM Compile the code and test that I went with the third option, mostly because it was the easiest to write....

posted @ Friday, August 04, 2006 8:50 PM | Feedback (1)

Ideas for a sample application?

I'm seeking ideas for a sample application to demonstrate the capabilities of Rhino Commons. Anyone has suggestions? It should be geared toward showing the benefits of using this approach, and yet simple enough so it wouldn't take too long to create. And I am kinda sick of bug tracking systems.

posted @ Monday, July 31, 2006 11:11 PM | Feedback (5)

Introducing the NHibernate Query Generator

Okay, it looks like I can track down fairly easily what books I read, when I read Working Effectively with Legacy Code, I wrote Rhino Mocks. Now I am reading Applying Domain-Driven Design and Patterns, and I wrote the NHibernate Query Generator. So, what is this all about? NHibernate has two major API for querying objects. The first one is called the query API, and uses HQL, a language similar to SQL but with OOP aspirations. The second is called the criteria API, and it is far simpler API, but...

posted @ Monday, July 31, 2006 8:34 PM | Feedback (10)

More on repositories

I forgot to add that I am using a static forwarder class to get a better syntax, so I have this (after the change from RegisterSave()/RegisterDelete() to Save()/Delete() ). Another thing that I wanted to talk about was the FindAll()/FindOne() methods. While they have their overloads for working with ICriterion (and wait for a surprise there too), they also have overloads for queries. Now, I believe that one of the responsabilities of good API is to encourage good code, so I don't have any overload which...

posted @ Sunday, July 30, 2006 9:50 AM | Feedback (2)

Thinking About The Repository API

I'm currently building the API for the my Repository interface (I talked about it here). Here is what I have so far: Couple of things to note, I don't have Delete or Save methods, instead, I use RegisterSave() and RegisterDelete(), both of those make it clearer that a Unit Of Work is in action here. To make it more explicit (and to allow several repositories to use in a single Unit Of Work, I made the Unit Of Work an explicit concept: ...

posted @ Sunday, July 30, 2006 9:34 AM | Feedback (0)

No, I will probably not explain...

This post is dedicated to HBool, which is always false on Sunday.

posted @ Thursday, July 27, 2006 7:33 PM | Feedback (2)

Lectures Arsenal

I am currently building a "lecture arsenal", which means that I should have a set of lectures that I can give at a moment notice. The idea came from Justin, who usually walks around with a portable projector, so he literally can be in the middle of a talk and start saying: "You know, I have a lecture of that. Give me three minutes and we can start" :-) What I have at the moment is the following: Inversion of Control &...

posted @ Wednesday, July 26, 2006 10:15 AM | Feedback (9)

Polymorphic Databinding Solutions

Let us assume that you have the following class hierarchy: Now, what do you think the result of this code will be? BindingList<Animal> animals = new BindingList<Animal>(); animals.Add(new Dog()); ...

posted @ Tuesday, July 25, 2006 1:56 PM | Feedback (6)

Fixing log4net 1.2.9 AdoNetAppender NULL bug

In log4net 1.2.9 there is a bug in the AdoNetAppender. It will not log null values appropriately. This bug is fixed in log4net 1.2.10, but it is not always possible to move to the next version. (In my case, both NHibernate and Castle uses log4net 1.2.9) I tried recompiling everything to use 1.2.10, but it took too long, and eventually I simply wrote this little trigger: CREATE TRIGGER [ReplaceNullLookAlikeWithNulls] ...

posted @ Monday, July 24, 2006 11:13 PM | Feedback (0)

Empty Headed

I am reading this WTF and cringing, but what prompt this post is this comment:I worked for a place that liked to test new candidates to better gauge if they were the ‘right stuff’.  One of the tests was to put the person in front of a computer and have them write a couple of apps.  One of the apps was to write a sort algorithm, and it could be any sort algorithm.  Clearly anyone who could implement a bubble sort was the ‘right stuff’ (sarcasm) Hm, I don't think that I can come...

posted @ Monday, July 24, 2006 11:07 PM | Feedback (2)

Useful blogging

I wrote this comment last week over a piece of code: /// <summary> /// Yes, this is ugly. /// Yes, we need fix it. /// If you read it, take the time to do it yourself. ...

posted @ Monday, July 24, 2006 11:00 PM | Feedback (0)

MonoRail Generator

Take a look at this, very awesome. It is still alpha/beta, but it looks just amazing.

posted @ Monday, July 24, 2006 9:54 PM | Feedback (0)

Deep Diving Into NHibernate: The Tests Structure

Just a quick note before continuing. In NHibernate, most tests inherits from the abstract NHibernate.Test.TestCase class. This class is responsible for the infrastructure of the test. By that I mean that it instansiate a Session Factory, create the appropriate tables, etc. A test fixture specify how to find its mapping using these two properties: /// <summary> ...

posted @ Monday, July 24, 2006 8:20 PM | Feedback (0)

Deep Diving Into NHibernate: The Second Level Cache

I mentioned before that I am now part of the NHibernate project, but so far I haven't done much with it. In what turns out to be a nice timing, I found a fairly obscure bug that I hope that I can fix, and I am going to bore you with all the nitty gritty details of how I am going to do it. Before I can begin, let me describe what area I am going to work at. NHibernate has two level of caches. The first level is the...

posted @ Monday, July 24, 2006 12:04 PM | Feedback (7)

Wish: Assembly Redirection For The Compiler

We have assembly redirection for compiled assemblies, but is there such a thing for the compiler? Spesifically, my problem is replacing a production version of a dll with a modified debug version, and then runing that. The issue is that I can't use the production dll and then replace it for debugging + assembly redirect, since on of th dll has a dependency on that modification. I solved that issue by recompiling everything against the debug modified version, but that is a PITA. Is there a better way? ...

posted @ Friday, July 21, 2006 12:13 AM | Feedback (5)

Harvesting For Frameworks

It is getting to that point in again where I find that I am writing the same code in several projects, and I get tired of that by the third repetition. It is time to harvest those projects for reusable pieces. At the moment I am planning on making this a part of Rhino Commons (what can I say, I like my Rhinos :-) ). Currently I am planning the following additions: Extentions to Windsor that includes: ...

posted @ Friday, July 21, 2006 12:07 AM | Feedback (5)

Doing Things the Simple/Default Way Sucks!

I really wanted this project to be simple, I abandoned all my usual supporting frameworks, and just implemented it using the bulit in compnents. It didn't take long to remember why I don't like to program with my tools. Just trying to write stuff down took too long. I felt as if I was writing ten times more code than I needed to acomplish the simplest tasks. (Writing a row to the database should not take more than two lines of code). Trying to manage the complexity myself was getting to be impossible. Taking...

posted @ Thursday, July 20, 2006 10:23 PM | Feedback (2)

Global Methods in C# 3.0

As you probably know, you can't define a stand alone method in C#, It must always reside within a class. C# 3.0 adds extention methods to the lagnague, which allows you to add methods to existing classes. We can take advantage of that to implement a "global" method, like this: public static class GlobalMethods {    public static bool IsNull(this object ignored, object obj)    { ...

posted @ Wednesday, July 19, 2006 7:08 AM | Feedback (2)

What is a control?

I had an argument yesterday about the interface that a control should expose to the prorammer, and I think that it makes for an interesting discussion. First, we are not talking about a System.Web.UI.Control, which is used to display a list of possible organization units. This control is written spesifically for this purpose. My take on the interface is something like this: public class OuPager : Control {   public OrganizationUnit CurrentOrganizationUnit { get; set; }...

posted @ Tuesday, July 18, 2006 8:50 PM | Feedback (10)

Complex Object Graphes

Recently I have been working on an application that require high level of configurability. I choose to use Castle's Windsor and Inversion of Control as the main principals when designing the application. I think I took a slightly different route than the normal one. I use Windsor to generate the entire object graph once, and then I start working with it. Actually, it is a little more complicated than that. The object graph just need a push (a call to Start() ) and it start working on its own, with no additional input/output from...

posted @ Tuesday, July 18, 2006 12:16 AM | Feedback (3)

Interfaces: Consolidate, Partition or Combine?

(Just to note, I am working on more than one project at any given time, so if you wonder why I am jumping between topics, it is because I am drawing from several very different projects, with different goals and technologies.) I have a project where most (all?) of my entities implements several common interfaces: IHaveNameAndId IHaveHistory - I think that I will have to hate that one. Think about chained...

posted @ Sunday, July 16, 2006 11:11 PM | Feedback (7)

Safe Multi Threading

I am using the code below to run work in multiply threads. A client registers a callback and an input, and it is executed on the thread pool. I have some notes about this code below: public class WorkManager<T> : IWorkManager<T> { ...

posted @ Thursday, July 06, 2006 8:20 AM | Feedback (2)

The Null Method Operator "?!"

After reading this, I was reminded how much I want the null method operator. Here is the scenario: string name = user != null ? user.Name : "no-name"; The Null Method Operator work like this:string name = user.Name ?! "no-name"; The rules: The first object reference is checked, and if it is null, it skips the method call and goes to the other line. Only the first object reference is checked. Chained method calls are not supported, this should throw an NullReferenceError,...

posted @ Thursday, July 06, 2006 7:52 AM | Feedback (5)

Riddle: Active Record as a Rule Engine

I mentioned in a previous post that I used Active Record as a Rule Engine, and a couple of people asked just how. Before I will post the answer, I want to see if you can come up with the same idea. The scenario: A rule engine that can process big amount of data. The engine will run as a Windows service, and not as a part of another application.Throughput is important, as well as flexibility in the rules and what they can do. The processing of each rule can be quite complex,...

posted @ Sunday, July 02, 2006 5:47 AM | Feedback (2)

Suggestion: Consider Inheriting Acting Interfaces From IDisposable

It felt like I was posting a lots of posts lately, but checking the numbers, I didn't come close to scratching my daily record in the entire weekend, and I still have items in my blog scratch pad that I need to post (down to five items, though). Anyway, this post is about interfaces, not about my blogging habits. I mentioned that it takes quite a bit of interfaces to write a file to database (8 interfaces and 15 classes, on last count). I found it useful to make all the interfaces inherit from...

posted @ Sunday, July 02, 2006 5:27 AM | Feedback (0)

Do NOT Mock System.Data.*

While it is possible, it is a pain in the ass. I'm working on a project now that doesn't use NHibernate (yes, I am surprised too). There is very simple data acess there, and nearly nothing to do with touching the data, so I thought that I could simply use ADO.Net. It works, sort of, but my code is full of strings, and it is nearly untestable. The main issue is that all the *DataAdapter expect their own *Command, *Connection, etc. Which mean that I can't mock much of it. ...

posted @ Sunday, July 02, 2006 1:00 AM | Feedback (0)

Pessimistic Locking

I need to be able to ask the database for some rows to work on, and I need to be sure that I am the only one that works on those rows. After thinking about it, I came up with this SQL: SET TRANSACTION ISOLATION LEVEL SERIALIZABLE BEGIN TRANSACTION ...

posted @ Saturday, July 01, 2006 3:56 PM | Feedback (5)

How much code you need to read a file to database?

Well, in my case, it looks like I need: 12 classes 5 intrefaces 1 (modified) Inversion Of Control Container 700 Lines of code 80 lines of XML configuration 350 lines of...

posted @ Saturday, July 01, 2006 2:40 PM | Feedback (1)

Isolating Tests From External Influences

I just posted about semi statics, and now it is finally the post where I explain how I broke the external dependencies in my tests. That was the reason that pushed me to start talking about static in the first place. I am using NHibernate to handle the data access (naturally), and when I started the project, there was no seperation in the tests from those that needs to touch the database (test that the mapping are working) and those that shouldn't (testing business logic). I started to feel the pain...

posted @ Saturday, July 01, 2006 2:28 PM | Feedback (0)

How I start a project

I'm starting a new project now, and I thought it might be worth while to blog how I'm starting out. I started with the initial requirements, and then just let them sit in my head for a day or two. Just thinking about the abstract concepts and trying things out without actually having to put something on paper or keyboard. Then I created a new project in VS, and started with the class diagram. I just put down a single class and several interfaces, and a few methods. I am...

posted @ Friday, June 30, 2006 9:15 PM | Feedback (3)

On Naming...

After reading Oren's post about naming interfaces, I started to notice how I name my interfaces. My own contribution to the "interface names that give me a chuckle" is IHaveNameAndId and IDecideWhenToStartTask, which I just created. I am probably going to rename that one, though. And, as long as we are dealing with naming. I got an outstanding bug that read like this: "Rename Fetch class to something that actually have a meaning." This class has a single method (well, one mehtod, several overloads) that looks like this:comboBox.DataBind = Fetch.IdAndDescription( ... ) ; ...

posted @ Friday, June 30, 2006 12:42 PM | Feedback (2)

What should a new programmer learn?

Leon is talking about what a new programmer should learn first, and I can't agree more. Learn what fails, and how, and why. Don't call someone more experiance unless you already spent some time on this already.

posted @ Friday, June 30, 2006 12:10 PM | Feedback (0)

Rhino Commons

I made some updates to my commons library. It is just a set of utility classes that I find useful. At the moment it contains: Static Reflection Bulk Deleter Collection Actions - Find, Select All, Select All Not, etc Date Range with operations - For Each...

posted @ Friday, June 30, 2006 9:48 AM | Feedback (3)

How to look at encapsulation

Eber Irigoyen has a post about what should I hide?, based on advice from Code Complete 2. Eber is making the statement that the question should be reversed. What should I expose? On the face of it, it looks like a reasonable suggestion, after all, I assume that we all accept that encapsulation is a good thing. The problem is that this completely ignore the notion of extensibility. It only give you the extensibility that you think of ahead of time. For examples of where this approach fail, just look at caching &...

posted @ Wednesday, June 28, 2006 10:53 PM | Feedback (2)

XML Is Code!

Mike has an excellent rant on "No Code, just a bit of XML here and there" approach. Check it out. I wholeheartedly agree. What we need is a lightwieght script for configuration.

posted @ Tuesday, June 27, 2006 10:02 PM | Feedback (2)

Unmanaged is being lonely

For the past week I have been doing quite a bit of work in unmanaged C++. It is mainly a set of small utilities that we need, and they can't have a dependency on anything. I used to be a big bigot for C++. I understood RAII and shared_ptr, I could read templated code without a hitch and I occationaly even managed to write a program where pointer chasing was optional :-) Now that I am working in C++ again, I am amazed to find out just how much I...

posted @ Saturday, June 24, 2006 9:37 PM | Feedback (2)

Api Consideration

What would you prefer from ease of use point of view?void Connect(); void Disconnect(); Or:public bool Connected { get; set; }  

posted @ Friday, June 23, 2006 10:10 PM | Feedback (15)

Solving a Tricky SQL Problem

I'm starting to get quite a bit of mail from this blog. Some of those questions are about subjects I can answer immediately, some require a fair amount of work (which can be had, if you really want), and the more interesting ones are those that require some thinking, but does not require too much time. This question from Dave is the best one so far, and I got his permission to blog about it, so I'm doubly happy. The issue is working against a legacy database to get the data for...

posted @ Thursday, June 22, 2006 11:13 PM | Feedback (7)

Interface + Base Class

Oren Ellenbogen has posted about generic constraints in the case where you have both an interface and a common base class. I tend to use the same Interface + Default base class often enough in my code.  The issue I have with this is whatever the interfaace is even needed? I often find myself extending only from the base class and never directly from the interface. Take for instance the MethodRecorderBase and IMethodRecorder from Rhino Mocks. Everythings works against IMethodRecorder, but all the concrete classes are decendants of MethodRecorderBase. In this case,...

posted @ Thursday, June 22, 2006 9:54 PM | Feedback (1)

Static Thread Safety

My last post about static variables caused a few comments, so I think that it needs more clarifications. The first thing is to understand what I am talking about when I'm thinking about thread safety. Thread safety issue when you initialize something (which I actually run into today :-) ) where two threads try to access a lazy resource and end up initializing it twice. This is relatively easy to solve using static constructor or static initializators. They are guaranteed to run before somebody...

posted @ Wednesday, June 21, 2006 9:46 PM | Feedback (10)

The New Methodology: ADD

It seems oddly appropriate that in one of those overlong meeting, the Methodology (with a captial M) that this application is develop under was named. Ajax Driven Development ADD - The New Methodology For Your Applications You will not be surprised that it already has it own wikipedia entry. Now everything is clearer...

posted @ Tuesday, June 20, 2006 5:58 AM | Feedback (3)

Don't Discuss, Implement

This is just to vent a personal frustration. There is nothing really new or innovative here. Recently I've been spending a lot of time talking about a specific feature about how it should be implement and what the concerns should be and how it should be handled, etc. The sad part is that I could have implemented the feature and get working code in about one third of the time that it took to discuss the issues.m

posted @ Monday, June 19, 2006 8:42 PM | Feedback (2)

Field Access Performance Tests

Dave Peck has a post about the performance of Linq over collections, where he makes the comment: static field access on generic classes is up to 100x more expensive than on regular classes. I never even heard on this issue, so I decided to make a check, here is my test harness: static void Main(string[] args) ...

posted @ Saturday, June 17, 2006 11:27 PM | Feedback (0)

Microsoft Productfeedback & Service Packs for .Net

I have to agree with Frans in this matter, Microsoft Product Feedback sucks. I reported several crashing bugs there (compiler, IDE), among other things. I never even got "we are checking" message. In th same vein, and from the same source, Frans also talks about the due date for .Net 2.0 SP1. Apperantly it has been set to Orcas' release. I'm not overly concerned about this, since I have far more problems with VS than the framework itself. The due date for this SP is Q3 of this year, which has already started, and...

posted @ Thursday, June 15, 2006 6:59 PM | Feedback (1)

On the "Look Ma, No Code!" Approach

Just a few words about this issue. As you can probably guess, I'm not an advocate of this approach. The problem I see with this is that the code exists, it is just not code as you normally think about it. But it is there, and it will have bugs, and you will need to fix it. I'm suspicious of the whole deal because it is a leaky abstraction at best, and highly rigid most of the time. It also tend to break down when things gets complex. The WinForms designer and ASP.Net...

posted @ Thursday, June 15, 2006 6:14 PM | Feedback (2)

What not to put in your resume

I've reviewed a lot of resumes lately, and there have been some that actually made me cringe. When applying to a developer, this guy listed email as a core competency. And no, he did not mean that he can chat about the relative merits of POP/SMTP vs. IMAP over coffee. I understand the need to put everything in the resume to inflate it, but some things should be implict. Another gem was a guy listing several years of experiance in Java,...

posted @ Thursday, June 15, 2006 6:10 PM | Feedback (3)

OR/M Madness in Microsoft

It looks like someone in Microsoft is loving OR/M even more than I do. They are going to release two competing OR/M frameworks. DLinq (now Linq for SQL) and Linq for Entities. I guess that no one in microsoft has read In Search of Stupidity: Over 20 Years of High-Tech Marketing Disasters. It is going to Windows 9x vs Windows NT all over again. How are you going to explain to a customer what is the difference between the two? ...

posted @ Tuesday, June 13, 2006 5:27 AM | Feedback (4)

Going after VS, This time with numbers

I had enough of waiting for VS. I keep saying that it is slow and that it is hunging my system. So I decided to run a test. Tomorrow I am going to use this little program to know how much time I am wasting because of VS. class Program { ...

posted @ Tuesday, June 13, 2006 12:15 AM | Feedback (3)

Mock Objects And Mock Turtles

I just dicovered this web cast talking about TDD, Mocking, Dependency Injections, Design Patterns, etc. I am currently watching this, and it looks very good.

posted @ Monday, June 12, 2006 10:00 PM | Feedback (0)

Riddle me this...

What is the result of the following code: public class Foo {       public static void Recursive() ...

posted @ Sunday, June 11, 2006 5:58 PM | Feedback (2)

.Net Versions, 2 Years From Now

After reading this post, a scenario came to mind:We are going to build this application on the CLR 3.2 in .Net 4.1 SP3 using C# 3.0 and WCF 3.8 with WPF 3.1 as smart client deployed using ClickTwicePointThree. Yes, it is absurd, but I can sense the confustion this is going to cause.

posted @ Saturday, June 10, 2006 11:54 PM | Feedback (1)

List is broken

It is broken because it is a basic framework class that doesn't have a single virtual method. I want to have a list where a delegate is called when an item is added or removed, but I can't do that, since this means that I need to override the Add()/Remove() methods. I need to create a completely new class, implement the entire IList<T> functionality, to get such a basic behavior. Yes, I know about Collection<T>, but this isn't acceptable. Why have two seperate classes? If I want a custom collection with ForEach() method on it,...

posted @ Saturday, June 10, 2006 11:27 PM | Feedback (3)

On Memcached

For some reason, I have not heard much about Memcached in the .Net circles, which is a shame. Memcached is a distributed memory caching system, which makes it very interesting for ASP.Net applications in web farms scenarios (but not just), since the ASP.Net cache is local cache, and can go out of sync with the other caches on the The basic idea is that a Memcached server is listening on a port, and you set and get data from it. So far, it is not very exciting, but the nice part is...

posted @ Saturday, June 10, 2006 12:59 PM | Feedback (1)

Big Company Open Source Behavior Patterns

Here is an interesting post about OSS and big companies. It seems to be focused on unix/java side of the fence, though. It makes no mention of Microsoft, although my experiance with them is something like "This open source product is interesting, but you should use our product XYZ, the next version will have all the features that you want."

posted @ Friday, June 09, 2006 11:48 PM | Feedback (0)

Unable to obtain public key for StrongNameKeyPair

This problem came up a few time in the Rhino Mocks mailing list. The issue is that you can no longer sign assemblies (which is something that Rhino Mocks does on the fly). There are several things that you can do to fix this issue: Use "sn.exe -m n" to set the key containers to user based. use "sn.exe -c" to reset the CSP. Most often the issue...

posted @ Friday, June 09, 2006 7:23 PM | Feedback (1)

Great Defination for Consultants

Take a look at this quote:As a consultant, I can tell you this: if I write unmaintainable code, I don't get invited back next quarter. If I don't contribute right away, I don't get invited back next week. So true.

posted @ Thursday, June 08, 2006 9:01 PM | Feedback (0)

The Wheel, slightly eliptic

A similar piece of code ( in PL/SQL and cursors ) kept me busy for most of the day. I have translated it to C# because I really don't think that I could stand seeing another cursor today. Figure out what it does (it is tricky). And see if you can suggest an improvement. Both SQL and C#/ VB/ C++ (whatever) are accepted. public void You_Commited_Grave_Sin_In_A_Past_Life_And_Are_Now_Being_Punished() ...

posted @ Wednesday, May 24, 2006 8:12 PM | Feedback (9)

NUnit 2.4 Alpha

Halleluja! Check out the release notes for NUnit 2.4. Here are the things that I'm excited about. Can install by non administrators CollectionAssert - At long last, we have it. I can't tell you how often I wanted those asserts. And check out the methods that this has. AllItemsAreNotNull ...

posted @ Tuesday, May 23, 2006 12:52 AM | Feedback (0)

Client Side C# - Script#

Nikhil has implemented a C# to javascript/ajax compiler. It looks very interesting. I got a request just like this one just a few days ago. Being able to write Ajax in a strongly typed langauge is going to have a huge affect on the cost of using it, in my opinion. Especially if it produce valid javascript for all browser. (And from what I have seen, it does). The killer application for this would be to be able to debug the C# code, of course. But I wouldn't like it, since...

posted @ Tuesday, May 23, 2006 12:42 AM | Feedback (1)

Yet Another Way To Crash VS.Net

This one is in the common path, incredibly easy to trigger, and will cause you to lose your work. In Vs.Net, create a C# console application project Right click the project and click View Class Diagram Ctrl+A, Delete to get rid of everything Now change the ClassDiagram1.cd name to Foo.cs (the extention...

posted @ Monday, May 22, 2006 11:47 PM | Feedback (0)

Working With Team System Source Control

I got a chance to work a while with Team System (I'm heavily into Subversion) and I had a hard time working with it. It is not that it is not good, it has some very nice features (the diff tool is awesome, for instance), but I do not like the way it was setup (which is the default, as far as I know). Exclusive checkouts are a pain in the ass to work with, even beyond locking files, just the idea that every time I try to edit a page (or something tries to edit a...

posted @ Monday, May 22, 2006 10:15 PM | Feedback (6)

NHibernate Best Practice - Assert Cascade Behaviors

I've said it before, one of the trickiest parts on NHibernate is the cascade behaviors. Why is it tricky? Because a slight configuration can cause the application to get exception at best, or silently lose data at worst. How does this work? Let us assume that I have the Blog -> Posts model, and I want to create a new post. I can do this like this: using(ISession session = factory.OpenSession()) ...

posted @ Monday, May 22, 2006 10:11 PM | Feedback (2)

Solving the Assembly Load Context Problem

One of the more annoying things about the way .Net is handling assemblies is the load context. If you load an assembly using Assembly.LoadFile(), it will not be available if you then do Assembly.Load(). There are any number of scenarios where this is a major hurdle. Any kind of plug in architecture, for instance. After getting bit by this when I wrote NHibernate Query Analyzer, I know way too much about resolving assemblies and the problems that this entails. It can get much worse when you try to load assemblies...

posted @ Monday, May 22, 2006 10:07 PM | Feedback (12)

OR/M Is Not About Data

The main benefit of an OR/M is not that it can fetch data from the database. There are multitude of other ways to do this task. The main benefit is that it makes us think about our model as a set of objects, and not as rows in tables. Objects has behaviors, inheritance structure, encapsulation, etc. The ability to use OO tools and practices in all the layers of your application is fantastic. It means that I can replace case statements with strategies, that I get a general algorithms instead...

posted @ Monday, May 22, 2006 8:52 AM | Feedback (0)

Web Continuations Considered Harmful

IanG has an excellent post about why continuations are not suitable for the web. The underlying point that he is making is that if you try to force a foreign model into a process, you'll break stuff, hard. A good web framework should not high the nature of the beast, it should make it explicit. To do other wise is to court trouble.

posted @ Sunday, May 21, 2006 1:42 AM | Feedback (0)

Learning Code

How I approach a code base that I am not familiar with? I know what it is supposed to do. I got no idea how it does it, though. Hopefull it is not something as vague as "handle client transactions". The next step is to read through the code. Not in any particular order, just pick an Access Point and start you search from there. Most of the OO techniques are about seperating concerns, and this means that you may have a hard time figuring out what exactly is going...

posted @ Sunday, May 21, 2006 1:31 AM | Feedback (3)

ASP.NET 2.0 WebParts WebCast

Justin has a 2 hours web cast about web parts in ASP.NET 2.0. Hebrew only. The web cast contains just about every bit of information that you need to start working with web parts, including very advanced topics. Personally, I think that he is crazy, that is not the way to job security, Justin :-)

posted @ Sunday, May 21, 2006 12:53 AM | Feedback (0)

Model View Controller In ASP.Net

As it turned out, it takes 20 lines of code to add MVC to ASP.Net*: public class ModelViewControllerHandlerFactory : IHttpHandlerFactory {     public IHttpHandler GetHandler(HttpContext context, ...

posted @ Saturday, May 20, 2006 10:50 AM | Feedback (2)

CallContext on ASP.Net

I'm very fuzzled at the moment, I just run into the CallContext class, and I'm pretty confused. I'm a pretty heavy use of Context bound items, and I usually need to bind to the current request in asp.net or to the current thread. I even create a class to make it easier. It looks like CallContext does the same thing, but it is built into the framework. From googling around, it looks like in 1.1, it was the way HttpContext was implemented, and from Reflecting over 2.0, it seems that there...

posted @ Friday, May 19, 2006 10:57 PM | Feedback (1)

Date Merging Challange Solved

I will give some wierder problem next time, Scott solved the problem (the simple one and the harder) in a really nice way. What more, he posted about how he solved the problem, and this is great. I often don't bother to explicitly think about the step to a solution, so it was a pleasant surprise to see how he got to the answer, not to mention that anyone reading it gains some valuable insight about how to solve those kind of problems. Great job Scott!

posted @ Friday, May 19, 2006 9:42 AM | Feedback (2)

SQL Challange, Date Merging

...

posted @ Thursday, May 18, 2006 8:38 PM | Feedback (6)

More Dynamic Than Thou

Well, that didn't take very long. In a couple of hours, I have four ways to solve my challange. I guess this means that C# is getting near C++ in expressiveness, I guess. Omer van Kloeten got very near to what I had in mind, but I am afraid that it is not dynamic enough for me. So, without further ado, I present to you my Foo: class

posted @ Thursday, May 18, 2006 8:25 PM | Feedback (0)

It is not as simple as you might think

I really like this post, asking for clarification to file copy operation.Check out this link, both for the fun factor, and for realizing that a "simple" operation such as copying a file is anything but, and that there are a multidue of concerns that need to be addressed in order to get a sufficent result.

posted @ Thursday, May 18, 2006 6:04 PM | Feedback (0)

A Challange: Implement This...

How would you write the following code so it would print "Bar" to the screen: Foo foo = new Foo(); foo.DoWork("Foo"); foo.DoWork("Bar"); Can you...

posted @ Thursday, May 18, 2006 5:56 PM | Feedback (14)

Cheating The compiler: Generic Properties

One of the more annoying design decision in C# is the lack of generic properties. This mean that I can't do things like: Context .Repository<Customer>.Get(15); This is incredibly annoying, since the syntax for the above is just ugly with methods. Using the same example as the last several ones, here is how I implemented it: public static class

posted @ Monday, May 15, 2006 11:53 PM | Feedback (1)

A Few Words About The Decorator Pattern

I was asked about my recent post about Generic Repositores, the question was what is the place of the Security Decorator? The Decorator Pattern is one of my favorites with regard to building flexible APIs. For the purpose of the discusion, I am going to concentrate on just the Get(id) method: public class SecurityReposiotyDecorator<T> : IRepository<T> ...

posted @ Monday, May 15, 2006 11:34 PM | Feedback (5)

The nature of Generic Type Names

I got a chance today to work with reflection & generics, and I learned some interesting things about generic type names. First, let us look at a generic name:System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[System.String, mscorlib]], mscorlib In this case it is a Dictionary<string,string>. You should note several things here. Orange - Before the tick "`", it is a normal type name plus namespace. Pink - The number after the tick is the number of...

posted @ Monday, May 15, 2006 10:30 PM | Feedback (0)

Pissed Off By Vanatec OpenAccess

I was mentoring NHibernate today, and I run into this advertisement when doing a search on Google about NHibernate: Stop Hibernating. Start real O/R Mapping. - using Visual Studio. Read why! I clicked on the link, intrigued that I wasted so much time using a fantasy OR/M. I'm a sucker for Real Programmer Tools & Practices, so I couldn't help myself. I will not get into whatever it is moral to buy adwords on someone's else products, there is...

posted @ Sunday, May 14, 2006 11:02 PM | Feedback (6)

Writing Maintainable Code

Brian Kernighan said:Debugging is twice as hard as writing code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. Quite often I find myself rewriting parts of code that I written to make them reasable to a future me (that is without even starting to talk about other developers who may have to maintain my code). Consider the following code, what does it do? foreach (Order order...

posted @ Saturday, May 13, 2006 3:13 PM | Feedback (0)

Power Shell

Monad is out, it has a new name, it sounds like a poster from the fifties, but whatever. Cool things so far: UNC Paths are supported! I never understood why cmd.exe didn't support them, but they are finally welcomed to the cli world. You can download a 230 pages user guide I got to play with it a bit, trying...

posted @ Saturday, May 13, 2006 2:08 AM | Feedback (0)

IDE Wish list - The Spell Checker

No, I don't want something that will look in my comments and fix them. I am talking about something like the auto text feature in Word. Considerring that I am mostly working on writing text to an exteremely rigid pattern, I don't see why the IDE shouldn't be able to help me there as well. A common example my be "SELECT * FORM Blah", I can't tell you how many time I made this mistake. And when we are talking about a langauge like C#, there is a lot of information that can...

posted @ Friday, May 12, 2006 11:16 PM | Feedback (5)

DLinq Answers

I posted this two days ago, and I got some answers to share. I'm not an expert on DLinq, so this isn't writ in stone. DLinq supports lazy loading, but call it delay / deferred loading. Not sure why they pick a different term than the standard one in other O/RM. It also supports rich eager fetching support, which is...

posted @ Friday, May 12, 2006 4:44 PM | Feedback (0)

DLinq Questions

I'm going to be in the DLinq Session tomorrow morning, and I'm posting a list of questions that I've right now. If you would like me to post a question, put it in the comments or email me. Does DLinq support lazy loading? What kind of associations DLinq supports (many to many is not support, I already know)? What happen if I try to load an object that is already loaded? How do you build a good DAL with DLinq? Obviously the samples I've seen so far are not going to work. I'm not going to the database directly from the UI. What sort of...

posted @ Wednesday, May 10, 2006 11:41 AM | Feedback (1)

From Tech Ed Eilat

I'm writing this post on IE 7 from a Vista laptop that is about twice the size of my normal laptop. It is so big that it has a full keyboard, including the numeric keypad. I have no idea what the model is, but the screen it huge. I was at the LINQ Session right now, and I was impressed with the capabilities even though I already knew about most of them. One very troubling things came up on this talk. DLinq is not going to support many to many assoications on the first version. This is fairly common, and I'm...

posted @ Wednesday, May 10, 2006 11:33 AM | Feedback (0)

Number Of Joins

When people want to say that a database was normalized too much, they generally say "It takes seventeen joins to get the username an email." Am I the only one who noticed it? Can you guess why this is the number that repeats itself?

posted @ Monday, May 08, 2006 6:11 PM | Feedback (2)

Patterns Posters

This is very nice

posted @ Friday, May 05, 2006 6:58 PM | Feedback (0)

The Prison Domain Model Challange: Answers

Chris Bilson give a nearly complete answer of how to find the valid / invalid commands for an inmate in the comments of the post. It is a very elegant solution, in my opinion. I took upon myself to improve his solution a bit. The result is this query: SELECT     ...

posted @ Wednesday, May 03, 2006 4:06 PM | Feedback (4)

That Boring UI...

Rocky got a nice post about why software is hard. In general, I agree with what he says in general, but I don't accept his numbers. Applications are not 98% / 2% (data entry vs complex stuff), they are more likely 80% / 20% for the simple cases, and 70% / 30% for the complex ones. And the problem is not in data entry type of applications. Those are solved by access, you can get them done in minutes. If all you want is to take data from the user and store it as is...

posted @ Tuesday, May 02, 2006 10:37 PM | Feedback (0)

Great Advice On Screws

Jeff has a great post about screws, and why we need so many.Go read it, it worth your time, and will provide you with some insight you can use later.

posted @ Tuesday, May 02, 2006 5:27 AM | Feedback (0)

Reliable Software is Hard

There is a really good post about writing reliable software and why it is so hard.Damien's writing is really good, and he touches on many interesting subjects.Recommended.

posted @ Saturday, April 29, 2006 2:01 AM | Feedback (0)

AccessViolationException in Windows Services

I wrote a Windows Service and I couldn't get the service to start properly. After trying too long to debug it in a service mode, I gave up and tried running it as a console application, I immediately got the following error:Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. I so thought that I left those kind of bugs when I left C++. Just to be clear, there isn't a hint of unsafe / unmanaged code in the application. It turned out...

posted @ Thursday, April 27, 2006 11:07 PM | Feedback (0)

Rant

Note: This post started as a comment on the post just below, but it developed into a full blown rant along the way. I'm detailing many of my frustrations with the tools. Scott Bellware has posted Mort or Elvis? A Question for a Bygone Era, which is a great post (as usual), but it also hit many of the pain points that I feel in working with VS 2005 recently. In fact, Scott does a great job of expressing those pain points than I could. ...

posted @ Wednesday, April 26, 2006 7:05 AM | Feedback (3)

Concurrency Questions

I was asked a question today, and I'm not sure what the answer is. The issue is with optimistic concurrency on the web. I got an edit page that allows a user to edit a page. I want to throw a concurrency exception if a second user has changed the object while the first user was editing it. The issue is that when I get the values of the form back when the user is finished editing, I no longer know what version of the object the user has edited. It looks like...

posted @ Monday, April 24, 2006 10:38 PM | Feedback (3)

Book Review: Data Binding with Windows Forms 2.0: Programming Smart Client Data Applications with .NETand

Data Binding with Windows Forms 2.0 : Programming Smart Client Data Applications with .NET (Microsoft Net Development Series) 12:57: I got this book from a friend, and I'm going through it in a speedy pace. I'm only finsihed chapter 2 right now, but I think that I can tell that this is going to be a good book. The datasets chapter was very good, without being condensingly simple, like most of the datasets tutorial that I encountered. As someone who can honestly claim to have never...

posted @ Saturday, April 22, 2006 1:13 PM | Feedback (4)

WinForms 2.0 Data Binding Resources?

I'm not a UI guy, not even close. Nevertheless, I need to work with it often enough. Right now I got to write a WinForms UI that involves displaying and organizing data from several sources, Database (via Active Record), Reflection, etc. I want to use data binding for the whole thing, since the data is basically text and some combo boxes, nothing special. The problem is that while I can find a wealth of information on data binding in ASP.Net via declarative markup, and some information about binding and manipulating datasets in WinForms,...

posted @ Friday, April 21, 2006 10:50 PM | Feedback (2)

I Inerit from ValueType, But I am a Reference Type, who am I?

Apperantly, the winner for this question is Enum. Check out the 1.1 documentation for it. I can't make heads or tails of this statement:Class Enum is derived from class ValueType; that is, Enum is itself a reference type, not a value type. Anyone knows what this is?

posted @ Thursday, April 20, 2006 8:46 PM | Feedback (4)

VS.Net resolving references of referenced assemblies

I have a problem with VS.Net 2005, it seems like it stopped copying the assemblies that are referenced by the assemblies that my project is referencing. For instance, I am using Castle.ActiveRecord, which is using Castle.Model. I have a reference to Castle.ActiveRecord, and when I run the project, I get an error because it can't find the Castle.Model assembly. This is the first time that I got this issue, and googling doesn't seem to find anything about it.

posted @ Thursday, April 20, 2006 2:31 AM | Feedback (5)

Stating the Obvious

I'm pretty sure that you already what I'm going to say, but whatever. If you are trying to achieve throughput, make sure that you turn logging off. Especially if you are using NHibernate, which is quite chatty in its logs (wonderful for tracking problems, really bad otherwise). I managed to get to 40,000 logged messages before I realized what was going on. P.S: It may be a good idea to create SqlBulkCopyAppender for log4net. ...

posted @ Wednesday, April 19, 2006 12:07 AM | Feedback (0)

Bulk Data Operations Using NHibernate

If there is one thing that NHibernate (and most other O/RMs) are not very good at, it is bulk data operations. What does it mean? Well, let's take a simple case of wanting to delete all the records in a table. (I'm going to use Active Record Blog Sample for the sample, it is much simpler). Let take this, for instance:Post.DeleteAll(); This will delete all the rows from the Posts table. Really easy to write or do, but what is the meaning here? What goes under the cover is something like: ...

posted @ Tuesday, April 18, 2006 10:01 AM | Feedback (4)

You really shouldn't write your own O/RM

You do not have the resources to do as effectively as the existing tools in most scenarios. There is a reason that Nhibernate got over 100,000 Lines of Code. The simplest O/RM is just mapping from columns to properties. This is repetetive work that can be done by a code generation tool easily. Then you realize that you need: Transactions Concurrency Control ...

posted @ Wednesday, April 05, 2006 11:25 PM | Feedback (0)

Random Thoughts

Nothing new, just random stuff going through my head: Do you like the pretty pictures in the recent posts? Evil thing of the day: Put the BSOD Screen Saver on the computer of someone just before an important presentation. Evil thing of the day #2: Put the BSOD screen saver on your computer before...

posted @ Wednesday, April 05, 2006 11:19 PM | Feedback (2)

If it is dynamic, it is going to be hard to debug

Just to clear something before we begin, I'm not talking about static vs. dynamic languages. I'm talking about static vs. dynamic object models. Consider a simple model of a windows application. It has a couple of menu items and an action associated with each menu item. This is really simple. Now bulid the menu dynamically, then try to figure out why the wrong action is called when a button is pressed. It is much more complicated Now. If we will make it even more dynamic, the action can change the state of...

posted @ Wednesday, April 05, 2006 10:45 PM | Feedback (2)

You can't escape the complexity

For every complex problem, there is a simple, elegant solution. It is also wrong. Sahil is talking about the pitfalls of DLinq, how a seemingly minor change in the code created a drastically different query which drastically different performance implications. Just to note, this is not unique to DLinq, it's something that exists in NHibernate, or any other O/RM in the market. O/RM is a leaky abstraction at best, I have said it before, and I will probably say it many times in the future. This mean that you need to...

posted @ Wednesday, April 05, 2006 10:07 PM | Feedback (1)

Advantages of Stored Procedures?

Eber Irigoyen had this to comment on my post about SPs:...the point is how much scalability, flexibility, security, etctirity the SP give you, remember the rule of thumb, always use the right tool for the job, use what will give you the most benefits in the long run I completely disagree with this, if you didn't catch on so far. Here is my refutal: Scalability: ...

posted @ Wednesday, April 05, 2006 8:08 PM | Feedback (18)

Closures in VB.Net

Bill is talking about closures in VB.Net, conicidently, he also covers the same issues that I had in my last two posts. I dont' usually do VB.Net, but it's an interesting read nonetheless.

posted @ Wednesday, April 05, 2006 5:54 PM | Feedback (0)

Using the IsTrue Operator

Matthijs was kind enough to answer the question I asked about the IsTrue operator. It is usable from C#, here is my new base object: class Program {     static void

posted @ Monday, April 03, 2006 7:33 PM | Feedback (1)

Generics & Specialization

Here is a proof that I didn't do C++ in too long, I completely forgot about template specialization.  Pierre-Andre van Leeuwen has a post that reminded me that such things exists. The following code works as expected: static void Main (string[] args) ...

posted @ Saturday, April 01, 2006 1:19 PM | Feedback (0)

Castle And Bicycle Riding

A while ago I was trying to explain the benefits of Castle to developers, and I just couldn't get through. It is pretty easy to explain the benefits of using Active Record, but I had a hard time explaining MonoRail and Inversion Of Control. Here is my elevator speach for MonoRail:MonoRail is RAD MVC framework built on ASP.Net that supports the Front Controller pattern and force strict seperation between UI and Business Logic. I got into a lot of problems with this, since it doesn't convey the benefits to the people I am...

posted @ Friday, March 31, 2006 10:21 PM | Feedback (1)

Wish: Reflector.Debugging

One thing I really wish that I could do is to make the debugger use Reflector if it can't find the source files for an assembly. This would be a nice way to track problems into the framework (or other libraries). This is what I have to do today, but I do it in my head, which doesn't really work.

posted @ Friday, March 31, 2006 9:21 PM | Feedback (3)

Rocky Lhotka on TDD, Take #2

Rocky took the time to clarify his comments on TDD in dotNetRocks #169. There seems to be a couple of main points there: As a testing methodology TDD (as I understand it) is totally inadequate... ...the idea that you’d have developers write your QA unit tests is unrealistic TDD is not a QA methodology. TDD is about designing the system so it is easy to test. This makes you think about what the code does, rather how it does it. The end result is usually interfaces that are easier for the...

posted @ Friday, March 31, 2006 8:54 PM | Feedback (0)

Printing

Do you ever print any of your code? I can't recall the last time I did it, and I know that it was never something that I did often. I'm not a real example, since I print about 2 pages a month on average (and even that I'm doing while muttering bitterly about dinosaurs).   I can see one good use for printouts, and that is for paper code review. I can see the value there, especially since red pen is one of the easiest ways to communicate. Although, I guess I would get stuff like this one all too often: The only things that I print right now are object...

posted @ Friday, March 31, 2006 8:29 PM | Feedback (1)

Obfuscation Question

The question is actually very short: Why? I just saw an obfuscation package for .Net that goes for over 600$, and I'm not sure if that is per developer or not. I know that there is this belief that obfuscation will protect your IP, etc, but I fail to see the point in this endavor. I can see several scenarios for wanting to obfuscate the code: You are a component vendor and you don't want people ripping you work...

posted @ Friday, March 31, 2006 7:00 PM | Feedback (5)

Testing UI - A Challange

Here is the story:When the a node in the graph is hovered via the mouse, a connection point (a node can have several) is made visible, and the user can drag the connection point to another node (when it enter the second node, the second's connection points will be visible) and create a connection between the two connection points. A visible line should exist when dragging the connection, and after it was attached it should be permenantly visible. I got this to work without tests, since I just can't think of how to...

posted @ Friday, March 31, 2006 3:37 PM | Feedback (0)

The return of PVOID

I think that the Daily WTF should be required reading for developers. I don't believe that I would have ever thought about using the language like that. Check out the Vector Oriented Programming, or the really dynamic typing, sure to bring tears to the eyes of old timers around the world. It combine hard coded indexes, random data types and the familiar sense that you need to remember the manual by heart (and memorize a passage each day, lest you start to forget) before you can do hello world in the system. In...

posted @ Wednesday, March 29, 2006 10:13 PM | Feedback (0)

Null Method Invocation

About 6 months ago I left a comment here, and I returned now to check it, and found a real gem. Check this out, it is about invoking methods on null, like this: Foo foo = null; foo.DoWork();  Wesner Moise explains what the possibilities are: ... An instance method can treat an null in special, default way to maintain continuity...

posted @ Wednesday, March 29, 2006 9:45 PM | Feedback (0)

Underused NHibernate Feature: Creating Objects In The Select Clause

I got a comment today from Jim Bolla asking about this query: select new Address(c.Address, c.City, C.Zip) from Customer c His comment was: I've been using NHibernate for at least 6 months now and haven't heard of this feature. Does this really work? What are the requirements/limitations? Is this in the documentation? Or even in the example code/tests? As he didn't leave an email or another...

posted @ Wednesday, March 29, 2006 9:11 PM | Feedback (0)

Testing the unknown

I set out today to write something that I never did before, but which I thought was too small to deserve a true spike. I'm talking about my persistance to code implementation, of course.I started by writing the following test:[Test]public void SaveEmptyGrap(){    Graph g = new Graph();    StringWriter sw = new StringWriter();        g.Save(sw);        string actual = sw.ToString();    Assert.AreEqual("??",actual);}I had no idea what I was going to get, but I went ahead and played with the code until it compiled, and then I looked at the result, verified that it was correct* and used that as the expected value.I...

posted @ Wednesday, March 29, 2006 6:59 PM | Feedback (0)

Testing as a motivation

There has been a lot said about testing and their affect on the code. I just had the tests affect me as I write the code. You are probably aware that I started a new project recently, and I've (as always) taken my time with a lot of spiking on the design.Even when I am spiking, I feel very nervous without the tests, and because I'm making such profound changes to the application, there are long stretches of times when I can't even get the application to compile.This mean that thinking about something and seeing it fail (and it always...

posted @ Wednesday, March 29, 2006 6:50 PM | Feedback (0)

Saving graphs as Code Dom, part 2

I posted a few days ago about Saving object graphs to file: CodeGen and Executable GraphsI just wrote the final test that made it all happen! I got objects that knows how to persist their state to code, and then load themselves right back from this code.This is the first time I worked in Code Dom, and it was very easy to get it to work very quickly.This is a huge security hole, of course, but I'll probably just play with the AppDomain permissions so the only thing it will be able to do is to give me the complete...

posted @ Wednesday, March 29, 2006 6:39 PM | Feedback (0)

You know you've been doing too much CodeDom when...

You start throwing InvalidOperationExpression all over the place :-)

posted @ Wednesday, March 29, 2006 3:59 PM | Feedback (0)

After talking about the EntitySet so long...

I just run into a bug that happened because I used EntitySets.I was relying that the order I'll get the items from the set will be identical to the order I inserted them.It even pass a couple of tests when I wrote this, but it started to break today until I figured out what was wrong. A quick change to EntityList (which does have this guarantee) solved the problem. 

posted @ Wednesday, March 29, 2006 1:35 PM | Feedback (0)

DotNetRocks #169 and TDD

I was listening yesterday to DotNetRocks episode 169 with Rocky Lhotka, and I was muttering "WTF??!!" throughout the first part of the show. The issue that I had was Rocky talking about TDD and saying stuff that simply didn't match the reality, not by a long shot. Jeffery Palermo post about it as well, by the way. Rocky's main objections seem to be:When you are working Test First, you don't get intelli sense for classes and methods that don't exists, and that seem to hurt his development style. ...

posted @ Wednesday, March 29, 2006 7:41 AM | Feedback (2)

Appropriate Comments

Both Analtoly and Oren Ellenbogen  had commented on my commenting post (pun intended). The example we are using right now is this piece of code: outputs = new EntitySet<IConnection>(       delegate(IConnection connection) { Raise(OutputAdded, connection); },       delegate(IConnection connection) { Raise(OutputRemoved, connection); }       ); I argue that this piece of code should stand on its own, without any comments to explain what is going here. I think at least part of the...

posted @ Tuesday, March 28, 2006 2:21 PM | Feedback (11)

More on comments and code

Anatoly Lubarsky has commented on my previous post about commenting:Sorry for this but you are totally wrong. I don't want to search or read documentation or debug to understand your code. It is totally useless work until you write for yourself only. I also don't like this code and don't think it is descriptive. I started to reply, but it turned to be pretty long and pretty...

posted @ Tuesday, March 28, 2006 10:38 AM | Feedback (7)

Ideal XP environment

Continuing on the TDD list, this message from Robert Hanson has the best description of the goals of XP that I've ever read. In an excellent programming environment there is no fear. The customer has told us exactly what he values most. I have no fear that I might be working on something he does not want. ...

posted @ Monday, March 27, 2006 11:13 PM | Feedback (0)

On Comments And Code

There is an interesting discussion about commenting code in the TDD mailing list. I think that we can agree that this comment is uselss: //Disable the button btnAdd.Enabled = false; I don't like commenting in general, and I've been told that it makes my code harder to read and understand. In general I really hate to explain what is happening, even if the code itself is fairly complicated. To take an example, Rhino Mocks has...

posted @ Monday, March 27, 2006 10:58 PM | Feedback (2)

XForms

Kurt explains XForms. Check out the examples he gives. This is the first time that I had a look at this, but this is just flat out facinating. Talk about a way to do clean MVC on the web. I really wish that I could use this to write web applications today (not feasable unless you would like to build site like this cool one).

posted @ Monday, March 27, 2006 10:20 PM | Feedback (1)

On Starting a Project and Design Bugs

The part that I hate the most about a project of a type that I never done before is the start. The issue is that I produce a design that mostly works, but when new stuff need to be implemented, I often need to explore several approaches before I know what will work for this project, my last post in an example of the approaches I thought about for persisting object graphs. The thing that really bothers me is that changing those approaches can lead to major changes in the code. This means...

posted @ Monday, March 27, 2006 10:01 PM | Feedback (0)

Speaking Of ReSharper

Looks like build #229 is fresh out the oven. I'll give it a spin tomorrow, and see if the stuff I run into has been fixed already.

posted @ Sunday, March 26, 2006 10:04 PM | Feedback (0)

Working with VS.Net 2003

I had to do a two minutes task in Visual Studio 2003 today, and it took me exactly three seconds to run into something that doesn't exist in 2003 that I've grown to like in 2005. I thought that I didn't like VS.Net 2005, but it's a great deal (better | slower) than VS.Net 2003. I also got ReSharper to work semi reliably on VS 2005, so that makes all the difference in the world in the amount of satisfaction that I get from work. I had ReSharper generate a full blown class...

posted @ Sunday, March 26, 2006 10:02 PM | Feedback (0)

Thread Safe Stop Watch

Joe Duffy posted about using the stop watch class from the 2.0 framework. I liked his implementation of weak hash table, that I going to come handy later.

posted @ Sunday, March 26, 2006 6:30 AM | Feedback (0)

1.5 BILLION Page Views A Day

ScottGu got some interesting statistics about ASP.Net 2.0: MySpace.com is now processing 1.5 Billion page views per day MySpace.com handles 2.3 million concurrent users during the day ...

posted @ Sunday, March 26, 2006 12:53 AM | Feedback (2)

It is all text, and it's meaningless

I'm pretty interested in compilers and text analysis, so I spent several hours today trying to grok ANTLR. I can work my way through some of the samples, and even figure out what the stuff is doing, but I can't seem to make stuff work when I try to go forward on my own. I want to be able to get an AST from ANTLR for the following text:from Foo select Foo.Bar And I want the AST to look like this: ...

posted @ Saturday, March 25, 2006 8:51 PM | Feedback (1)

Solving Library Mess With Type Forwarding

Why is it that every time that I run into a problem, I find a solution a few hours after I solved it in a less elegant fashion? Junfeng just posted about Type Forwarding in .Net 2.0. This looks really cool and can defiantely solve many versioning problems.

posted @ Saturday, March 25, 2006 11:29 AM | Feedback (0)

NHibernate Query Analyzer 1.1.3 Release

Don't ask about the version number, it just is. I haven't done an all-nighter in quite a while, and while it was fun to do, I'm not thinking very clearly right now. Here is the details about this release: I finally got around to take a good hard look into NHibernate Query Analyzer (AKA: NQA). I haven't update it in a while, and that is a shame. There was an issue with query translations when using parameters that kept me from going forward for a long time. Today I bit the bullet and...

posted @ Saturday, March 25, 2006 6:00 AM | Feedback (3)

Reflection / Fusion / Open Source Mess

I'm trying to load this type using Type.GetType(string):Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate, Version=1.0.2.0, Culture=neutral, PublicKeyToken=154fdcb44c4484fc The Nullables.NHiberante is loaded in the assembly, but I keep getting Strong Name Is Required exceptions. After spending way too much time on this, I figured out that I had added a reference to the NHibernate project, and that the Nullables.NHibernate library was looking for the NHibernate library (this is important, since the NHibernate project is not signed and the library is). I solve this, and I get a strange error about a Nullables.NullableInt32 could not be...

posted @ Saturday, March 25, 2006 5:39 AM | Feedback (0)

ReSharper and CodeRush

I just got a hung from ReSharper, and I managed to get a stack trace, and it looks like it is some interaction thingie between the DXCore (CodeRush engine) and ReSharper. This would explain why this is happening only on my machines (since I installed CodeRush on both desktop and laptop). I'm currently uninstalling the DXCore (CodeRush already expired) and I'm going to see if this is going to make a difference. If it is, then I'm going to back to business, with ReSharper handling all the menial tasks (like generating constructors or...

posted @ Saturday, March 25, 2006 1:15 AM | Feedback (0)

ReSharper #227

I'm testing Build 227 of Resharper now, and it's just good. I got a couple of hunging bugs that for some reason I can't repreduce, but I really like the experiance so far. The nicest new feature that I found is the Test Runner. It is just like TestDriven.Net, but with a really cool UI. I got my pair back :-)

posted @ Friday, March 24, 2006 8:02 PM | Feedback (0)

get-state "Open Source Projects"

Scott Hanselman posted about open source projects. He poses the question: "If you work on a Open Source Project, why do you do it? When will you stop?" I literally has to stop and think about the number of open source projects I'm involved with. Right now it is: Rhino Mocks - Under active development with a community that send patches when they run into problems. Really cool project. Started because I had too many problems with NMock and refactoring. ...

posted @ Friday, March 24, 2006 7:28 PM | Feedback (0)

Code I'm Proud Of

The recent work I did with graphs reminded me the time I wrote the orderring functionality in Rhino Mocks. (I asked my warders about it, and they still rib me about order in inorder recursively). It was one of the trickest parts in Rhino Mocks, to find an interface that will allow nested orderring behaviors that will be invisible for the users. In the end, I went with a variant of both chain of responsibility and composite. I worked very hard (and had a lot of tests) for this part of Rhino Mocks,...

posted @ Friday, March 24, 2006 9:32 AM | Feedback (0)

Excited about Monad

After listening to HanselMinutes about Monad, I'm pretty excited. I do a lot of stuff in the command line already, and I'm always on the lookout to find something new and fun. The amount of stuff that I can do there is really nice. (gci -recurse | where {$_.Name -like "*.cs"} | match-string ".").count Here is the ugly way to find all the lines of code in a project. This means that a 30 minutes search turned into a 20 seconds typing and getting the answer I need. That is truly powerful.

posted @ Thursday, March 23, 2006 10:39 PM | Feedback (0)

What happened to VS.NET 2005 Service Pack?

We were promised soon after the VS.Net launch that there will be a service pack for it in the first half of 2006, which is not so far away. Considerring that the promise for VS.Net 2003 SP in April is not likely to happen with the first beta just arriving, I'm concerned about this. I get annoyed daily that my 1.3 Pention M + 1Gb RAM isn't fast enough to run VS.Net (code editing only, I hardly ever use a wizard) in a mode that will not leave me waiting at least every couple of minutes....

posted @ Thursday, March 23, 2006 9:36 PM | Feedback (0)

Shuffling a list in SQL

Let's assume that you've a table with a position column that you use for indexing or orderring, and you want to shuffle the ordering of items there. You can do it with a single query like this one: UPDATE Attributes   SET Position = CASE position                          WHEN @From THEN @To                          ELSE Position+1 END WHERE ReferalID = @Referal and Position BETWEEN @To AND @From ...

posted @ Thursday, March 23, 2006 5:37 AM | Feedback (4)

On Vista's Delay

There is a good discussion in Mini Microsoft's comments about the Vista delay. Specifically, I like this, this and this in particular. My two cents are, ship it when it's ready. The entire world is going to have to live with this system for ~5 years minimum, so I really don't want Microsoft to release something that is not ready. And yes, little stuff matter, VS.Net 2005 is ~15% slower than VS 2003, in the long term, this hurt! Check the amount of negative comments that Microsoft got on the VS.Net 2005 launch. Microsoft reputation is...

posted @ Wednesday, March 22, 2006 9:39 PM | Feedback (0)

NHibernate Generics Update

I updated NHibernate Generics and added an EntityDictionary<Tkey,TValue> that you can use, along with all the known benefits of the library. Have fun, you can find the download here.

posted @ Wednesday, March 22, 2006 12:07 PM | Feedback (0)

No Knowledge Is Lost

Over a year ago I was working on NQA, and I wanted to show a pretty object graph. I cutomized the Lithium control to do so, and in the process learned quite a bit on the Netron Library and how to write custom controls in WinForms. Now I need to take that knowledge and apply it to a project, and it's all coming back to me. I spent quite a bit of time doing that, and it's nice to know that time wasn't just for fun. I found that even the most obscure...

posted @ Wednesday, March 22, 2006 11:58 AM | Feedback (0)

Can't code

I got VS.Net open since yesterday afternoon, a couple of bugs to fix, several new features to code on several projects. Interesting stuff, too. I just can't find the drive to do so. When I used to write fiction I got the same feeling. Authors call in Writer's Block and there are many methods to break it. For me, it usually pass in a day or two, but this is ridiculious. I know what I need to do, and how to do it, but the engine won't start. I've already tried...

posted @ Saturday, March 18, 2006 2:58 PM | Feedback (0)

On Abstractions

Haack is talking about abstractions. Actually, he is talking about Mort, but I paid more attention to the definations of different abstractions. Go read it.

posted @ Friday, March 17, 2006 11:52 PM | Feedback (0)

No another brick in the wall...

Great article from Rocky Lhotka about offshoring, cogs, deviations and what makes most programmers ticks. I recently met a couple of developers who worked for years in the same place. And they are able to navigate in a maze of code I can't grasp, look at something that makes my eyes blur, and tell me exactly what it does, why it does it and often enough (the scariest of all) who was the user that requested this feature, and how it is used. Those are the guys that this place got to keep,...

posted @ Monday, March 13, 2006 10:43 PM | Feedback (0)

The Value Of Reuse

Hammet has posted a comment from his article about Castle. The comment basically talks about reuse in NVelocity, one of the MonoRail's View Engines. NVelocity is not a full fledge programming language, and that means that you can't do some things that you can do with a full langauge (at least not easily). The end result is that you really don't want to write TheUberGrid in NVelocity, so you may end up writing a one-off, per scenario template, instead of a general control that can accept anything you throws at it and...

posted @ Monday, March 13, 2006 10:40 PM | Feedback (0)

Advantages Cooperative Threading

James has a post about SQL Server & Cincom Smalltalk both using application level threading for scalability, but I think that the comparision he makes is flawed. While I admit that I don't know how you manage the threads in smalltalk, I'm well aware of the differences between threads and fibers (app-threads, in windows). Cooperative threads relies on programmers' disipline to yield often enough to make sure that other threads are not starved. I can see several cases for doing this in SQL Server, since this can ensure that you'll not be pre-empted before...

posted @ Saturday, March 11, 2006 9:00 PM | Feedback (1)

Value of a framework

One important criteria about frameworks is how it handle complexity. For instance, consider VB6. You really don't need to do anything with it to get usable COM objects with all the fancy interfaces that you can want, and writing office automation there was actually easy. But try to write mutli threaded app in VB6, and you're up against a wall. I like MonoRail and I don't Like WebForms. It's probably easier to design pages using WebForms for most common scenarios. It's easy to write views in MonoRail in nearly any scenario. Both frameworks...

posted @ Friday, March 10, 2006 11:42 PM | Feedback (1)

Josling On Other Languagues

Josling (the father of Java) was quoted talking about C#, Ruby and PHP. It's amazing how such a short piece can annoy me so much. First, I did very short work with PHP (and really couldn't stand the dot operator for concantation), and virtually no work with Ruby. I work quite a bit in C#, as you probably know. I don't know of any usages of PHP outside the web, but I can certainly think of usages for Ruby outside the web. Ruby != Rails !! Ruby is used in WATIR (wrapper for IE's...

posted @ Friday, March 10, 2006 9:17 PM | Feedback (4)

Some considerations when choosing a framework

This article is a must for anyone who is evaluating any sort of a frameowork. All things in Computer Science can be solved by adding another layer of abstraction, except having too many layers of abstractions. Can I have a hammer please?

posted @ Wednesday, March 08, 2006 9:55 PM | Feedback (0)

Least Privileges on SQL Server

I'm a long time subscriber to the notion that users shouldn't run as administrators. It may take some work for a developer to run as non-admin, but I believe that this is worth it. The issue is more than security, it's about forcing coding practices (my code never write to Program Files, buecase it simply not allowed on my machine). I had to make some modifications to the environment (enable debugging for my user, for instance), but it wasn't very hard. One thing that I did run into is SQL Server. I don't...

posted @ Saturday, March 04, 2006 8:26 PM | Feedback (0)

MonoRail, MVC and ASP.Net

I run into this post, comparing MonoRail and ASP.Net 2.0, which I thought was interesting. I'll start by saying that I mostly disagree with the conclutions. Rodel is making a mistake by comparing the feature sets. The difference between ASP.Net & MonoRail is not something that you can break down by features. They are mostly comparable anyway. The issue are with the level of control, the amount of abstraction you have and the programming model you are working with. The problem with ASP.Net is when you start to deal with complexity. For simple...

posted @ Friday, March 03, 2006 9:57 AM | Feedback (1)

Castle Demo App: ViewComponents, Security, Filters and Friends

In this post, I'm going to explain how to secure the administration section of the site. Since the pages in our application do not map to a directory structure on the server, the ASP.Net default security isn't going to help us (I'm not entirely sure about this, though). Because of the way that the MonoRail is built, we often can make security decisions about the all the actions in a controller. Such is the case with the AdminController, only administrators should be able to access this page. Currently, we don't have the...

posted @ Friday, March 03, 2006 2:16 AM | Feedback (1)

Merging .Net 1.1 and 2.0 code, or abusing the type system...

If you've a code that you want to use for .Net 1.1, but still use features from .Net 2.0 (because they are such fun), you usually end with a bunch of #ifdef all over the place, or you create a second class and delegate functionality. It occured to me that C# allows a funky way to combine this functionality without too much bother. The idea is only applicable where you've a class that you want to be generic in .Net 2.0, and use System.Object on 1.1, this is the case in quite a...

posted @ Thursday, March 02, 2006 8:29 PM | Feedback (3)

Embarrassing Moments

Sometimes I make mistakes that has no reason whatsoever. It's like I developed a sudden blank spot in a particular area for a while. I had a piece of code similar to this one (PL/SQL, nonesense code): for rec0 in sql_data          if rec0.Status == 3 then      ...

posted @ Thursday, March 02, 2006 8:09 PM | Feedback (0)

Castle Demo App: Code Update

I've updated the code that is avialable. Now I also bundle the parts of Castle that you need in order to run it, so you will have easier time build and testing this code. All the binaries you need can be found in the Deps directory, you'll need to change the references to point to that directory. You will also need SQL Server or SQL Express for the database, as well as .Net 2.0. You can get the new release here (1.2Mb).

posted @ Wednesday, March 01, 2006 2:27 AM | Feedback (0)

Castle Demo App: Queries and Foreign Keys

Okay, one thing that I'm sure that you have noticed is that we have a bug in the DeleteUser method. The problem is that we don't check for foreign keys violations, and that will cause problems down the road (someone tries to delete a user that is assigned to a project, and he suddenly stares at an error page asking "But what did I do?" Let's try to prevent it before we get a bug report about it. First, we need to make a couple of policy decsisions. There are two ways that...

posted @ Wednesday, March 01, 2006 2:12 AM | Feedback (1)

Castle Demo App: Complex Interactions

Castle Demo App: Complex Interactions We have CRUD operations for users and projects. The next step is to add a way to assign / remove users from a project. We can do it both for users and projects, but this is just overly complex. We're going to allow a project edit page to add or remove users, and that is all. I'll be the first to admit that I'm not very good with JavaScript, and I've practically no knowledge in the Ajax capabilities of MonoRail (which are based on Prototype library). I'm just going to...

posted @ Tuesday, February 28, 2006 11:39 PM | Feedback (1)

Quick note on static vs. dynamic typing

I'm reading James Robertson's blog, mainly for the rants. I mostly agree with what he says, if not with the tone, but today I read something of his in the comments that really annoyed me.Detection of a missing method is utterly irrelevant. Why? Because such a flaw would turn up in initial testing. I just did a bunch of javascript, which is a dynamic language with just this kind of behavior. Sorry, this isn't even close to satisfying. I had about.. oh... maybe 50 lines of code, and I kept running into problems with method...

posted @ Tuesday, February 28, 2006 11:14 PM | Feedback (0)

What is wrong with JavaScript?

Stefan asks What Is Wrong With Javascript, I think that I've at least a partial answer to that. Here are my reasons: Until very recently, Javascript was just too slow by far to consider writing applications with it. Lack of a rich class library. Until recently, lack of good debugging tools. ...

posted @ Monday, February 27, 2006 11:24 PM | Feedback (2)

Rhino Mocks 2.6.2: Memory Requirements Improvements

Okay, this release should be a major improvement memory wise, I changed the implementation so instead of generating dynamic assemblies per MockRepository, all the Mock Repositories will generate to the same assembly. This should prove to be a dramatic reduction in the amount of space that Rhino Mocks consumes.  Sources and binaries are avialable here.

posted @ Monday, February 27, 2006 8:50 PM | Feedback (0)

FREAKING UN-Believable!

I just watched DNR TV #5, and I must say that it was one of the most amazing videos that I have ever seen. This is especially true when you consider that the feature being implemented on the show was one I wished that I had nearly a year ago.This video features Mark Miller doing on-the-fly implementation of source code organizing (sort by visibility, then by member type, then alphebatically, etc).Beside being a cool demonstration, and one of the few videos that managed to make me stop everything and watch them, the features of Code Rush that were shown were...

posted @ Sunday, February 26, 2006 8:43 PM | Feedback (2)

SqlClr outperforms T-SQL (7 times faster!)

Okay, a couple of months ago I posted about Finding Use for SqlClr for date processing, since it was much easier to do it in .Net than in SQL. Since then I retracted my statement about it. If you read my blog for a while, you probably noticed that I'm doing quite a bit of performance tuning lately. After making the switch from SqlClr to T-Sql, I noticed a sudden drop in performance. Some investigation lead me to the change from SqlClr function to T-Sql functon. Here is the source code for the .Net function (yes, I occasionally do VB.Net): <SqlFunction()>...

posted @ Sunday, February 26, 2006 11:43 AM | Feedback (2)

Castle Demo App: Let There Be A New User

Before we start with our regular content, a couple of bug fixes, the ValidateLength on the Name and Email properties of the User class should looks like this:  [ ValidateLength(0,50)] Specifying just one number means the exact length of the string. Okay, so far we have seen how to edit users and then save them to the database, but we haven't seen yet how to actually create the users. For myself, I think...

posted @ Wednesday, February 22, 2006 10:59 PM | Feedback (1)

Why So Many Snippets

So Microsoft has posted a lot more snippets, a Jeff has made them more accessible. I downloaded them and took a look. I'm pretty sure that you could hear my cries of horror all the way to Remond. Why? That is the question I have. Snippets are useful for things like generating a foreach (although the Microsoft implementation sucks, try the way ReSharper does it.) or maybe generating a method skeleton. I see them doing things there like Hashing A Password, Encrypting Files, etc. Why? This is just a recipe...

posted @ Wednesday, February 22, 2006 6:56 AM | Feedback (0)

Castle Demo App: Updating our Users

Okay, here we go again. One thing that I forgot to mention in the last post is how you access the pages you created. You simply need to use the following URLs: http://localhost:8080/admin/users.rails http://localhost:8080/admin/projects.rails Before we continue, a couple of words. When I started this series, I had the intention to make it possible to use this with the latest...

posted @ Wednesday, February 22, 2006 12:13 AM | Feedback (1)

Sharp Develop Rocks

I was pretty harsh about Sharp Develop in the past, but I'm using it lightly lately, and it is a great tool. Especially if you are doing any kind of work with Boo.

posted @ Tuesday, February 21, 2006 6:27 AM | Feedback (2)

Rad kills

I can only agree with Jeffrey on his post RAD kills. . . software post. And I'll top that one with an observation of my own, there is significant investment to learning how to work with RAD tools, with all their twists and quirks. I would say that there is just no faster way to display a table on a page than by dragging the table to the form and hitting F5. The problem is that the moment you want to do something with it that isn't obvious, you are suddenly out of...

posted @ Tuesday, February 21, 2006 6:26 AM | Feedback (0)

Castle Demo App: MonoRail At A Glance

Okay, so far we saw that MonoRail can be used to serve static files just as well as a 1993 Gopher Server. Considerring that Gopher is dead, we might want to add some stuff to our application. But allow me to give you a very short overview of the way MonoRail works. MonoRail has Controllers and Views. A controller is a normal class that inherit from the Castle.MonoRail.Framework.Controller class. When a request comes in, MonoRail analyze the URL and dispatch the request to the proper controller method. This is important, unlike in...

posted @ Monday, February 20, 2006 7:57 PM | Feedback (2)

Castle Demo App: The First MonoRail Page

So we finally made it to actually talk about MonoRail. :-) Just to set the expectations straight, we are going to create a web site for to the Mythical Bug Tracker application, using MonoRail and Brail. It's going be functional, but it is not going to look pretty. I'm not a designer, and I'm not going to waste my time talking about CSS and color coordination when you can go to someone who actually knows something about them and learn something useful. In two sentences, what is MonoRail? MonoRail...

posted @ Monday, February 20, 2006 7:56 PM | Feedback (5)

FileSystemWatcher & Visual Studio 2005

Okay, I've this very strange bug. I got an application that watch over a folder for changes in the files. When I edit the files in Visual Studio 2005, the application doesn't do anything. But when I edit the file in notepad, the change event is fired and everything is fine. Anyone knows what is going on there? Here is sample code the shows the problem: import System import System.IO   class Bug:         watch as FileSystemWatcher                 def StartWatching():                 watcher = FileSystemWatcher("""C:\Test""", Filter: "*.*")            ...

posted @ Monday, February 20, 2006 12:11 PM | Feedback (4)

Castle Demo App: Lazy Loading and Scopes

First, a bug correction, in an earlier post I said that the user's OpenBugs property should be initalized exactly the same as AssignedBugs, this is a mistake, it should be initialized like this: _openBugs = new EntitySet<Bug>(); The reason for this is that addition/removal to the OpenBugs shouldn't affect the AssignedBugs collection, which is what I accidently did. Okay, so now we have Users and Bugs (they...

posted @ Sunday, February 19, 2006 8:21 AM | Feedback (1)

Castle Demo App: Active Record Relations

For this part, I'm going to use NHibernate.Generics, which is an extention to NHibernate that allows to use generic collections for relationship between classes. You need to download it from here and add a reference to: NHibernate.Generics.dll Iesi.Collections.dll Okay, so we have a User, now we need a Bug class, so we can store the information about our bugs. I'm going to skip the parts that I've already covered and move to...

posted @ Friday, February 17, 2006 11:17 PM | Feedback (4)

Castle Demo App: Getting Started With Active Record

A few words about Active Record: Active Record is a wrapper around NHibernate, which is an Object Relational Mapping for .Net. I'm not going to explain how things works in this post, just how to use them. If you're going to be a serious Active Record user, I'm strongly recommend that you'll learn how to use NHibernate. You'll appriciate how much Active Record does for you much more afterward. Setting The Environment: Assuming that you already have the Castle's binaries on your machine, let's start by creating a class...

posted @ Friday, February 17, 2006 9:40 PM | Feedback (6)

Building a full blown application with Castle

Recently I'd a couple of IM conversations with people who wants to build applications with MonoRail & Brail, but there isn't any useful sample application for that. There is Castle's Samples, but they don't cover Brail, and there doesn't seem to be a step-by-step tutorial for creating a full application using Castle. The Pet Store example covers most of Castle, and it certainly helps, but some people like to read tutorials better than look at the code. I'm going to try to...

posted @ Friday, February 17, 2006 9:05 PM | Feedback (1)

Castle Samples

I just realized that there is a wealth of sample applications for all the parts of Castle. You can view those sample applications online here (or by just downloading the source and looking in the Samples directory). I tend to just read the Castle source until I find the right answer, I never thought about looking at the samples :-) There is quite a lot of information there.

posted @ Friday, February 17, 2006 8:04 PM | Feedback (0)

When it's time to be sloppy?

I posted before on the dangers of being overly dynamic in code. The end result of such things is that it's very hard to find what exactly is going on in the code. But there is a high value of using sloppy code to manage tasks you need to do one time only. For instance, recently I began to use a combination of SQL statements and Regular Expressions to generate batch files / sql scripts that does any number of one-off tasks. It's much faster than do those things by hand, and they are not worth writing...

posted @ Friday, February 17, 2006 9:29 AM | Feedback (0)

Batches

Oren Ellenbogen has a post about IDataReader.NextResult(); I saw that method in intellisense, but I never really understood what is it. It is used to send a batch of statements to the server (seperated by ';', apperantly) and then gets sets of results. One thing that interests me is how this is done on Oracle, since it throws exceptions on ';'.  

posted @ Friday, February 17, 2006 12:46 AM | Feedback (1)

25 Things that I don't like in Oracle Tools

I'm not going to talk about the database itself just yet, the tools has quite enough things about them to rant about. First, SQL*Plus seem to be one of the main tools to work with Oracle, and it's a piece of crap in so many levels. It's a console application that someone put a Windows wrapper around. The end result is a product that combines the worst of all worlds. Let's start with the fact that SQL*Plus has no text box, it's UI is a console, meaning that: ...

posted @ Friday, February 17, 2006 12:35 AM | Feedback (5)

On Lies & Linked Server

I'm not sure who is at fault here, but Oracle as a linked server really sucks. I'm not talking about general Oracle stuff here (I'll try to post something about it later). I'm talking about the database lying about data types that it doesn't like. For instance, take the following Oracle table defination: CREATE TABLE Foo ( ...

posted @ Thursday, February 16, 2006 10:58 PM | Feedback (0)

SQL Debugging

I just found out that you can debug a stored procedure the same way you can debug .Net code. To use: Open VS.Net Open Server Explorer (Ctrl+Alt+S) Go to the database where the stored procedure is locate Right click and choose Step Into Stored Procedure You can see what...

posted @ Thursday, February 16, 2006 10:53 PM | Feedback (0)

Circular Dependencies

So, I need to copy a set of tables from one database to another, the issue is that the source database keeps changing, so, in a true developer fashion, I added another layer of indirection and instead of writing scripts to copy the database I wrote a program that would write scripts that would copy the database. I'm pretty proud of it, it uses the SQL Runner tool that I mentioned earlier, and it work in stages, so the first thing that copied is tables with no foreign keys, then the tables that...

posted @ Thursday, February 16, 2006 10:29 PM | Feedback (2)

JustDate: Striping the time part from datetime variables

In oracle, there is a handy little function call trunc. That function is a real work hourse, it can truncate numbers, dates, programmers life time, etc. In the most basic form trunc(sysdate) will return the current day without the time part, it has quite a few options that are fairly nice as well. Anyone, for some reason this bulitin functionality is missing in T-SQL, so of course I had to implement it three times. The first was a scratch function that used string manipulation to do its work. The second was a SQL CLR function that...

posted @ Thursday, February 16, 2006 10:15 PM | Feedback (1)

Using Data Ranges

Okay, let's see some use for having a date range, let's assume that I've the following employees table:

...

posted @ Thursday, February 16, 2006 10:05 PM | Feedback (1)

The value of parallelism

I said that I used the little script that I posted about for short tasks.The reason for that is that it will run the files serially. This isn't very good if you want to get the maximum from your server. I actually wrote a multi threaded sql running that connects to a database and runs multiply queries in parallel. I'm using that for long queries (where long is thousands of files and the whole process takes hours). Running it in parallel (and from a different computer than the one the server is running on) improved the performance by a factor of...

posted @ Thursday, February 16, 2006 5:13 PM | Feedback (1)

The lost art of batch files

Here is a quick & dirty way to execute a command on all the files in a directory.for %f in (*.sql) do sqlcmd -E -S . -d DataBase_Name  < %f > %f.log In this case, I execute all the sql files in a directory and write the results to a log. This is useful if you've a common set of scripts that you need to run. I'm using it to get results of short operations. Why short? Well, this is for the next post.

posted @ Thursday, February 16, 2006 4:46 PM | Feedback (0)

The difference between a class and an instance of a class

There is a discussion in the TDD Yahoo Email group about class vs. instance of a class with regard to its design. Spesifically, the issue is the difference between: Employee emp = Employee.Find("John"); Vs.Employee emp = employeeFinder.Find("John"); The discussion revolves around managing the responsabilities of a class. For myself, I stand firmly on the first sentence, the responsability for locating an object of the class should be in the hand of the class. After all, it's an object as well (not a very dynamic one in C based language, but it does exists), why should we let it avoid any responsabilities? I...

posted @ Thursday, February 16, 2006 4:36 PM | Feedback (2)

Moving away from OOP

Here is an interesting article about the direction that C++ seems to take now. Basically, it's about moving from inheritance and strict OO to generic programming and external algorithms. When I was working with C++ I just loved the abilities of the standard library and the way I could plug things together. I mostly agree with the article, it's much better to have a way to hook things into a class from the outside than do it from the inside. It's one reason that I'm so excited about extention methods, they will allow you to do some very nice things without having...

posted @ Wednesday, February 15, 2006 4:55 PM |