It never crashes!
I keep hearing people complaining that MapReduce is not as easy as SQL. But there are others saying SQL is not easy to grok. I’ll keep myself away from this possible flame war and just point you out to this ☞ SQL to MongoDB translation PDF put together by Rick Osborne and also his ☞ post…
It never crashes!
[DISCLAIMER]
I am running snow leopard, and TotalTerminal (because the slide down is awesome)
[/DISCLAIMER]
It’s been some time now that I am playing and learning ruby, rails, and the tools around it to develop.
On a project I work on, we start having a bunch of services to start to be ready to work. If you want to really see what is going on, you want each of them in a separate tab.
And so the dance starts:
Cmd + T
cd <project>
[insert command to start service]
And the services to start are:
-mongod
-redis-server
-foreman
-passenger
-fork
-autotest
I looked for a way to script this repetitve work, and found how to open a new tab in your terminal using shellscript.
I edited it appropriately to pass it a command and Voilà :
And it is now in my .bash_profile with a better alias.
If you have better way, or equivalent ones, please tell me, I am always happy to learn!
This post expose the problem from the current project and technology I work with. However, the general lesson behind it can be applied to any other project or technology.
By curiosity, I checked the build time stats fromour Continuous Integration server (TeamCity) for our main Silverlight project. It’s big, and the compile time is a clearly pain on this platform.

A clear drop happened. What did we do for the build time to drop by nearly 30 seconds?
Looking at the history, what happened is that we cleaned up the styles from our solution. We use the Telerik suite of controls, and they come with a massive style library. Over time, we accumulated lots of them in our projects. some where not even used anymore. or styles from controls that we don’t use where hanging around.
Yep. Parsing, compiling and packaging this file was adding 20 (TWENTY) seconds to the build time!
Before: 1min 57sec (not that a few days before it was even above 2 min) After: 1min 37sec
I bet we would get under 1 min build time if we would clean up further the styles. (note that 1min build is still really long on any other technology than Silverlight…)
How many time/day do we build the client? Let’s say 20 times/day/developer. If we manage to trim 1min in total. (from the initial 2min to about 1 min), we would save 20min per day per developer. That’s 1h40/week/dev Consider 3 developers working on that project, that’s 5 man hours per week lost waiting for compilation! 20 man hours per months on compilation! imagine if you have 20 developers working on that project!
And we don’t consider the extra time lost because the developers change focus, go get a coffee or check their mail while waiting for the compiler. I’m also pretty sure that Visual Studio would be very happy to have less files/code/xaml to handle and would hang much less.
So how much is compile time worth working on? Why don’t you spend 5h getting that compile time down?
This is how I want all my tools. I had lots of ideas for better tools popping up in my head while watching this video. The kind of paradigms that he talks about are applicable to most of the creative processes. It’s really amazing to watch, whether you understand code or not.
via http://boingboing.net/2012/02/15/technology-interaction-and-eth.html
It was about one year ago that we switched to Git. Previously, we used Subversion, through the Mac app Versions, which (rightly) holds an Apple Design Award.
I made the executive decision to leave our comfy world of Versions because it seemed clear that Git was winning the Internet. There was much grumbling from my teammates, who were busy enough doing actual work thank you very much.
But I pressed forward. We signed up for accounts on Github. We learned how to type
'git push'and'git pull'. We became more confident. Git is just like any other source control system! But it wasn’t long before one of our devs called me over to look at a…situation.
It has been a year now that I work on a silverlight project. As any respectful developer I write unit tests. But in silverlight, things are not all that easy when it comes to testing.
First of all, the unit testing framework doesn’t come out of the box. Instead, you will find it in the Silverlight Toolkit. On the bright side, this allow a separate release cycle than the one from silverlight.
Then, you might be aware that you need to run your silverlight tests in the browser, because the silverlight runtime can only run in the browser, or hosted by a wpf application since silverlight 4.
A very important part of unit testing is to have a fast feedback loop. I want to run my tests often, and therefore, I want them to run fast. Having to run them in the browser unfortunately doesn’t help it.
Those are common complains from developers who write unit tests on a silverlight project.
But the issue I will expand is different.
In MsTest framework, if you mark a method with a [TestInitialize] attribute, it will run before each tests. As the attribute name suggest, this is useful to initialize the state of the system before running each tests of the fixture.
Here is the problem. if the initialization fails, I really want to see my test fail. But with the silverlight testing framework, if an exception is thrown in the testinitialize method, the test will not fail. This can result in false positive, and that’s an issue because I can’t trust my tests anymore.
To work around it we have a simple base class that looks something like the following :
public class TestBase
{
private Exception _exception;
[TestInitialize]
public void TestInitialize()
{
try
{
Initialize();
}
catch (Exception exception)
{
_exception = exception;
}
}
[TestMethod]
public void InitializeTest()
{
if (_exception != null)
{
throw new InvalidOperationException("Failure running test setup", _exception);
}
}
public virtual void Initialize() { }
}
So when I write a test fixture now, I don’t add a TestInitialize attribute above a method. Instead, I inherit from this base class and override the Initialize method. But this is obviously a dirty workaround. My tests still don’t fail. What I get is another test that tests the initialize method… At least I have a failing test when an exception is thrown.
If you don’t like this easy workaround, you might want to have a look at the xunit.contrib project, or at nunit for silverlight. These have other advantages that I will expand in another post.
Une animation intéressante sur les multiples façons de mesurer les retours sur investissement du design de l’expérience utilisateur (façon animation RSA).
Toujours pas convaincus?
Sometimes, you want to be able to change the implementation of a component depending on a variable that you don’t control at design time, a user action for example. This will be a lot easier to explain if we use a concrete example. I will present the problem that I faced to illustrate the usage of the method.
Consider a simple search form, but you want to be able, with the same form, to search in different data stores.
You already know that more data stores will be added to the requirements, so you also need a way to extend this it easily. The following solution supposes that you know the basic concepts of dependency injection and how to setup your mvc application to take advantage of it.
I use StructureMap here, but it could of course be swapped by any other IoC container.
Consider that you will have different implementations of this Search action, which will build the query in different ways, and each will make calls to different APIs. You create an interface ISearchManager as follow :
public interface ISearchManager
{
IEnumerable<ResultItem> Search(string keyword);
}
And the possible implementations :
public class TwitterSearchManager : ISearchManager
{
public IEnumerable<ResultItem> Search(string keyword){ //Search using Twitter Api and returns a collection of Tweets }
}
public class FacebookSearchManager : ISearchManager
{
public IEnumerable<ResultItem> Search(string keyword){ //Search in the Facebook Api and returns a collection of Status }
}
public class ForumSearchManager : ISearchManager
{
public IEnumerable<ResultItem> Search(string keyword){ //Search in another Api and returns a collection of Forum posts}
}
You controller could then receive an ISearchManager in his constructor
public SearchController:IController
{
private readonly ISearchManager _searchManager;
public SearchController(ISearchManager searchManager)
{
_searchManager = searchManager;
}
}
And you can happily search in different store without changing anything in the controller… Well, not exactly, because your IoC controller doesn’t have a clue of what radio button is ticked when it creates your SearchController, therefore it cannot resolve the dependency on ISearchManager. What you need is a factory to create the correct instance of ISearchManager depending on a parameter.
public SearchController:IController
{
private readonly ISearchManagerFactory _searchManagerFactory;
public SearchController(ISearchManagerFactory searchManagerFactory)
{
_searchManagerFactory= searchManagerFactory;
}
public ActionResult Index(string provider, string keywords)
{
var searchManager = _searchManagerFactory.Create(provider);
var results = searchManager.Search(keywords);
…
}
}
And the implementation of the factory often ends up like this :
public class SearchManagerFactory : ISearchManagerFactory
{
public ISearchManager Create(string provider)
{
switch (provider)
{
case “twitter” : return new TwitterSearchManager();
case “facebook”: return new FacebookSearchManager();
…
}
}
}
Well, that’s ok if you have a very small dependency graph, but you still, you start to spread the configuration of your dependencies in multiple places. You have an IoC container which decides which type each controller should receive, and you have this switch statement hidden inside a factory to decide which SearchManager. If my SearchManager have further dependency on, let’s say, a QueryBuilder (because the queries need to be built differently to satisfy the different APIs), it really becomes messy.
It would really be nicer if my factory could ask my container which implementation to return, with all its dependencies resolved. This turns out to be rather easy with most of the IoC containers.
They allow you to assign a key to the different implementations of an interface. With StructureMap we have IContainer.GetInstance<T>(string key); Let’s see how we can use that in our factory.
public class SearchManagerFactory : ISearchManagerFactory
{
readonly IContainerWrapper _container;
public SearchManagerFactory(IContainerWrapper container)
{
_container = container;
}
public ISearchManager Create(string provider)
{
return _container.Resolve<ISearchManager>(provider);
}
}
That was easy. Our factory is now asking our IoC container for a ISearchManager, but I don’t really want my factory to know which IoC Container I am using. Instead, I have this simple IContainerWrapper. Its implementation for StructureMap is straight forward :
public interface IContainerWrapper
{
T Resolve<t>(string key);
}
public class StructureMapWrapper : IContainerWrapper
{
private readonly StructureMap.IContainer _container;
public StructureMapWrapper(StructureMap.IContainer container)
{
_container = container;
}
public T Resolve<T>(string key)
{
return _container.GetInstance<T>(key.ToLower());
}
}
Now we’re all set. All we need to do is wire up all those components in the IoC configuration:
ObjectFactory.Initialize(x =>
{
x.For<ISearchManager>().Use<twittersearchmanager>().Named(“twitter”);
x.For<ISearchManager>().Add<facebooksearchmanager>().Named(“facebook”);
});
ObjectFactory.Configure(x =>
{
x.For<ISearchManagerFactory>()
.Use(new SearchManagerFactory(new StructureMapWrapper(ObjectFactory.Container)))
);
This is the trick. I first set up the ISearchManager implementation, and give them a name in the Initialize method of StructureMap. Since I need to pass a reference of the container to my factory, the container needs to be already initialized when that happens. That’s why I set up the ISearchManagerFactory dependency after the initialization is done, in the Configure method.
That’s it, the dependency to the SearchManagers is now resolved by the IoC Container, depending on a runtime parameter. Why I think this is better? because that way, you keep all the configuration in one single place. You could even potentially change that configuration without recompiling if you configure your IoC using an XML config file.
(Source: alsagile.com)