Alexander Beletsky's development blog

My profession is engineering

Few Things I Learned From IdeaStrike Project

First of all, I have to say Code52 team is doing just amazing job. It’s very original initiative, cool ideas and highly productive team. Each time they announce next thing to build I have “product envy” inside me. Check out their blog or github account to be updated.

My attention this time was attracted by IdeaStrike project. It suppose to be analog of uservoice for OS community. As always, first release was very fast and I was very curious what’s inside. So, I cloned the repo and did small hacker session. I’ve spend some hours with it and would like to share some initial thoughts.

Build script is small and clean

Project contains build.cmd as I run it downloaded all dependencies by NuGet, build web site and run all unit test. Basically, all you need for any small project. Then I looked inside, it turns out like:

@echo Off
set config=%1
if "%config%" == "" (
   set config=Debug
)

%WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild build.proj /p:Configuration="%config%" /t:AppHarbor /m /v:M /fl /flp:LogFile=msbuild.log;Verbosity=Normal /nr:false

At the time I first looked in it also contained small script for running tests, but later they moved that to .csproj as separate target.

Use NuGet without committing to SCM

I was amazed, how fast git repository was cloned and as I checked out packages folder with all dependencies were just empty. How can it be? As I said in #1 as I run build script they just automatically downloaded for me. As it turns out, this is feature of NuGet that allows to work with dependencies, without real necessity of committing those to SCM. This is very cool, especially if you have big project, so cloning and branching appears to be prolonged operations. The implementation details is on nuget site.

Deploy application DB at first launch

IdeaStrike is based on EF 4.3 Beta 1 currently, using Code First approach. EF Code First also includes very cool feature called Migrations. This is something I really lack first time I tried EF Code First approach. You define the Context, DbConfiguration class and migration scripts (that’s also, just a C# code), so at application bootstrap you call the code like:

private static void DoMigrations()
{
    var settings = new IdeastrikeDbConfiguration();
    var migrator = new DbMigrator(settings);
    migrator.Update();
}

The database and schema will be automatically deployed on first application run.

Social login with Janrain

As I clicked to Sign In button, I’ve been showed nice dialog to select my existing social account to login.


social login

JanRain is very cool solution. I remember I tried to investigate something like that for ASP.NET MVC and was really disappointed, because I actually found nothing. For all of existing solutions you have to read OAuth spec and write own code. JanRain does all dirty job for you. As user authorized you receive POST on given URL, with a special token. By given token you request the details about the user, like name and email and so on (see LoginModule.cs). It has fair plans for hobby projects and bloggers.

Bootstrap your CSS and HTML

Bootstrap neither new nor very unique, at least I know several good CSS/HTML frameworks. But IdeaStrike proved one more time - it has no sense to invent the wheel. Take advantage of results produced by people who are smarter than you, that’s the rule of pragmatic programmer.

Dear future me, please never ever again start your application with HTML/CSS from scratch, you can build nothing more as shit. Bootstrap is great for different kind of projects and prototypes. Taking into account number of watches and forks on github I expect even more improvements and features in future.

Nancy as web framework

I’ve heard about Nancy many times, but it’s only now I got a change to touch it. For me it’s just alternative reality comparing to ASP.NET MVC. It is not hard to understand what the code does. It is not hard to apply changes there. You are very explicit of what you are doing, by specifying HTTP verb, route and action as lambda. First class citizen in Nancy is Module, all module’s logic is placed inside the constructor:

public FeatureModule(IIdeaRepository ideas, IFeatureRepository features, IUserRepository users)
    : base("/idea")
{
    _ideas = ideas;
    _features = features;

    this.RequiresAuthentication();

    Post["/{idea}/feature"] = _ =>
    {
        int id = _.Idea;
        var feature = new Feature
                        {
                            Time = DateTime.UtcNow,
                            Text = Request.Form.feature,
                            User = Context.GetCurrentUser(users)
                        };
        _features.Add(id, feature);

        return Response.AsRedirect(string.Format("/idea/{0}#{1}", id, feature.Id));
    };
}

Nancy application could be hosted as ASP.NET / WCF / Self hosted runtimes, it supports different View Engines (including Razor). In short, it is great ALT.NET tool and will find a lot of applications in different projects. More details on Nancy github account.

Conclusions

IdeaStrike is great example of open source project you can learn something from. I would not say I got only positive impressions, moreover there are some obstacles that block me from my normal development flow. I’ll try to share my observations on next blog posts.

NancyFX, probably be my next web framework to learn, since I need to move out of ASP.NET MVC which is comfortable zone for me now. I’ll be keep looking for IdeaStrike and hope to do some pull requests as well.