Wednesday, July 07, 2010
In my setup I said I was going to learn Python, and at the same time dive into the world of CQRS. After getting my feet wet a little bit, I decided to go with something completely different. I present to you: BYOB, the Python edition! I have to be honest and I’ll mention straight away that this is NOT my own idea. I borrowed it from the honorable Rob Conery, who at a certain time last year mentioned that it’s a good idea for EVERY serious developer to build his own blog. He gives a nice summary of the reasons why:
- It’s the perfect app for a geek who wants a blog to build – they’re the perfect domain experts
- It’s easy (for the most part) but gets harder and harder the farther in your dive
- It’s ubiquitous. What a perfect interview topic: “I’d love to see how you handled asynchronous pings to Technorati and – oh – do you have a POP feature? Also – did you use MetaWeblog or Wordpress?”
- It’s your calling card. If your blog rocks – likely you do too. If it sucks and it’s slow – well…
- It’s a great way to learn a language. Want to try out ASP.NET MVC? Compare the LOC and features to your Webforms blog – then try Rails…
- Luke did it – and that’s good enough for me
If you’re wondering about rule number 6: His reasoning is that if Luke (Skywalker) had to build his own lightsaber, developers should build their own blog.
So I am. I will keep source code on Github. I will try to copy the look and feel of my current blog (this one), with similar features. Basically:
- Index page with the last <x> articles, first paragraph. Browsable.
- Detail page, showing the full article and comments (possibly powered by disqus).
- Archive by month. Works in a similar fashion as the index page.
- Archive by tag. Works in a similar fashion as the index page.
- Profile page. Basically a static page with a nice picture of me and some info.
- Ability to use Windows Live Writer (love you!) to publish my blog.
What I won’t do (yet):
- Theming support.
- Multi language support.
- Multi blog support.
- Pingback detection and what not.
- Sharing links. Who shares my articles anyway :-(
- Web based administration panel. I don’t NEED to do that, I only publish via Live Writer.
For now, I am off to github to create a repository for my new blog: Sir Blogalot!
Sunday, July 04, 2010
One of the first things I do when getting started with a new programming language is to find myself a good development enviroment. I love Visual Studio, and I love the things Jetbrains does (ReSharper, IntelliJ IDEA). Visual Studio can work with python, in the appearance of IronPython. However, I want to go straight to the bone first and start out with the ‘original’!
JetBrains recently launched a new line of editors: a web editor, one for PHP, and… One for Python! PyCharm comes with everything you’re used to have in IntelliJ IDEA, combined with all the goodness of Python. I’d say that’s reason enough for me to try it out, now is it? Either way, first of all getting started with Python: the bare way. Trust me, it couldn’t be simpler!
Setting up Python
- Navigate your browser to www.python.org.
- Find the download button.
- Download your preferred package (at the time of writing, I picked the windows installer for 2.6.5).
- Install/unpack!
- Done.
See? That wasn’t all too hard. To test it out, you can either use the interactive command line, or simply write a small program to test it. Here’s a small sample program:
def test_function(input):
print input
if __name__ == "__main__":
test_function("hello world")
To run this, all you have to do is drop it on your python.exe or run python.exe <insert-filename-here>. You should see ‘hello world’ printed out on your screen!
Setting up PyCharm
Once again, this couldn’t be any simpler (well, except for not installing this IDE). First, execute the steps for setting up Python. You’ll need that environment before you do anything else. After you’ve done that, you’re supposed to point the IDE to the installed Python framework. To do this, you go to File –> Settings, select Python Interpreter from the list and add an entry pointing towards your installation folder.
Once again, to see if everything is working, you should create a new project, add a file (test.py) and then set up some stuff to get a valid configuration to run the script:
First, you go to Run –> Edit Configurations. Add a configuration, and select your script. Once you save this, it will be available to run via the play button on the toolbar.
Alright, that’s all you need to know for now. Next time I’ll share my first experiences with Python, it’s dynamically strong typedness and perhaps something completely different!
Wednesday, June 30, 2010
As a hardcore .NET developer it’s hard to say this, but I’m going to do it anyway. I’m going to stray from the environment I enjoy the most at the moment, to try out something new. It’s not because I don’t like .NET or C#, or because I don’t like the way the community is. The reason I’m going to invest some time in learning this completely new environment is to broaden my horizon, and possibly increase my chances on the market.
That being said, I will be combining this with a bit of research into CQRS (Command-Query Responsibility Segregation) which will hopefully give me something to blog about. Udi Dahan has a very concise explanation on what CQRS actually means for us mere human developers:
CQRS is about coming up with an appropriate architecture for multi-user collaborative applications. It explicitly takes into account factors like data staleness and volatility and exploits those characteristics for creating simpler and more scalable constructs.
A simple example is this. Given we have a contact management system, which incorporates the usuals: Address data, payment terms, payment record. A sales representative just finished a phonecall with the contact, which revealed that the address data of the contact is out of date. The representative changes the address data, and hits the save button. So far so good. However, at the same time, the accountant finds out that this customer has some unpaid bills, and changes the payment record of this contact. Both operations are executed using the same information, so which one is going to be executed first? In most cases, updating the contact record means updating the full record, based on (stale) information used to display the values in the edit screen. How CQRS solves this problem is for a later post, but it’s an interesting problem to wrap your thoughts around.
Either way, for now it’s back to ‘Hello World!’, and after that, perhaps moving into ‘Estimating the Airspeed Velocity of an Unladen Swallow’.
Thursday, March 11, 2010
I’ve recently had a lot less (pun not intended) time to spend on .less, but I do keep track. Scott Hanselman mentioned the new ASP.NET site went live, and it looks good!
What REALLY caught my eye is the section on open source projects it has, under the ‘community’ tab. It has a lot of nice, established projects mentioned, like Nhibernate, Subtext, Spark and a lot of others. What really amazed me is that .less is mentioned! If you scroll down to the Misc section, there it is! Seems like I really have to schedule my work better so I can invest more time in .less again. That’s a good thing, right?
Saturday, January 09, 2010
I’m always up for a challenge. I still have to watch the Mastering LINQ videos up on TekPub (which is amazing by the way, I encourage you to check it out!), but someone (hi Tuna!) tweeted about a small challenge related to the series.
Basically, the challenge is to use a chained LINQ statement to create a prime number filter, without using any custom functions. Without further delay, here’s my solution:
var primes = Enumerable.Range(1, 30)
.Where(x => x > 1)
.Where(x => x%2 != 0 && x != 2)
.Where(x =>
!Enumerable.Range(2, (int) Math.Sqrt(x)).Any(y => x%y == 0)
);
This isn’t an optimal solution, but good enough for a first version. Basically, this is what’s happening:
- All primes are greater than one. So filter on that first.
- All primes are odd, except the number 2. Filter on that using modulus, and a hardcoded check for 2.
- Now comes the real work: A prime can be found by trying to divide the subject by all numbers up to the square root of the subject. If any of the divisions has no remainder, the subject is not a prime.
I’m curious to see who’ll come up with a neat solution first, as this is obviously more or less brute force. While waiting, I’ll try to come up with another solution.
Thursday, November 26, 2009
I just ran into a situation which could lead to very annoying latent bugs in your web application. Observe the following code.
The view:
<form method="post" action="Photo/Save">
<input type="text" name="Photo" />
<input type="text" name="Title" />
</form>
The Controller action:
public ActionResult Save(PhotoDTO photo)
{
// do something with the object
return RedirectToAction("Index");
}
The class:
public class PhotoDTO
{
public string Photo { get; set; }
public string Title { get; set; }
}
At first sight, there’s nothing wrong with this code. You’d say when the form is posted, the PhotoDTO object gets automatically created by the default modelbinder in the framework, and you’ll be able to do what you want with the PhotoDTO (like, errr, save it?). However, what REALLY happens is that the parameter photo will be null. Now I’ll give you a moment to realize what’s happening.
…
…
Alright, that’s enough. What’s happening is that the field with the name ‘Photo’ is getting precedence over binding the whole thing to the PhotoDTO class. So let’s say I put the value “SomePhoto” in the textbox, it’ll try to bind that value to an object of the type PhotoDTO. That fails, so it returns null.
I’m not sure it’s intended, I’m assuming it’s just a side-effect of what needs to be done to be able to bind to complex models as well as simple parameters. Either way, if you’re not aware of this quirk you’re in for a surprise if you accidentally run into this!
The conclusion
I asked Phil Haack on twitter if this was intended. He said:
@erikvanbrakel yes, by design. BTW, your PHotoDTO needs to make properties public too.
So there you have it, keep this in mind when writing your code, it’s not going anywhere, it’s as intended!
Note: I corrected the PhotoDTO, it was missing the ‘public’ access specifiers.
Monday, November 23, 2009
I just checked our analytics after I noticed a bit of retweeting going on after Jon Galloway picked up .Less. Can you spot at which points in our graph twitter was flooded with .Less tweets?
I thought so ;-)
I’d like to use this oppportunity to thank everyone for bringing us extra publicity! Thanks!
Sunday, November 22, 2009
I had a short twitter conversation with Aaron Jensen on the decisions we made developing .Less. As I’ve blogged about before, for me personally it was more of a learning project than something with a set goal, at first. That aside, I had one thing in mind: being able to use less during development, without having to worry about it, add a handler and go!
Less.Net, v0.1
My first solution was to simply install ruby and wrap the whole system call in a HttpHandler. Very clunky, but it worked! I blogged about this a while ago: Using LessCSS in an ASP.NET site.
I got it working, tried to implement it in my web project, and ran into another problem: It’s SLOW. Could be solved with caching, but in development I generally dislike that. It presents another point of failure which can take quite some time to figure out.
Another point was the fact that ruby should be installed. If you’re familiar with the .NET ecosystem you’ll know that a lot of people just want to deploy a single DLL and be done with it. Installing ruby, getting it to install a gem and then using that in your build process is quite a bit of work you want to avoid, if at all possible. That’s two problems I wanted to solve.
Being influenced a bit by the things I saw coming by on twitter (Linq to NHibernate to be exact) I looked into ANTLR for the parsing, which was simply an interesting technique to learn. I got a working prototype for a simple less file, published it, and got in touch with Daniel and Chris, with which we formed the current .Less project. Before joining up, Daniel gave IronRuby a shot for implementing the ruby gem in .NET, but it turned out to be too painful to deploy and too slow.
Perhaps with the next version of the CLR IronRuby will be a good option for Less, but honestly, I don’t expect that to be mainstream for at least another year.
Less.Net and nLess become .Less
After a few talks via skype, we decided to work on Chris’ codebase, called nLess at that moment. The reason why is that the grammar style he used is very similar to the ruby treetop grammar, which makes porting new language features quite painless. Also, I ran into a few problems with my grammar which would require quite a bit of rewriting of the grammar.
We’re not aiming for creating our own dialect, we want to adhere their standard as much as possible. The general idea is to introduce the less syntax in the .NET world, in such a way that it’s recognizable for the average .NET developer. That’s why having a grammar which is easily ported from one to the other is of great value to the project.
The future
While we do want to adhere to the ‘official’ syntax, we’re not bound to the functionality the ruby gem offers. We’ve got a few cool ideas we can do, but not before we’ve got a more edge cases of the current implementation covered. We’re also looking into creating a Visual Studio plugin, to, again, reduce the friction of using less in your ASP.NET solutions.
Another thing that’s on our agendas is to create more viable specs to test. We’re currently using the somewhat outdated ruby specs, which are generally very big umbrella specs. They also don’t exactly do what you’d expect. Hopefully we can create a common set of specs both the ruby gem as our .NET DLL, as the PHP version that’s around there can use. That way it won’t matter which environment you use, your less files will always work.
Well, that’s the story about .Less and how it came to be. If you’re interested in the project, I invite you to go to http://www.dotlesscss.com/ and try it out. We’re usually quite fast on the response to our google group, so if you want to ask anything, feel free to do so.
Saturday, November 21, 2009
Lately I’ve run into several bugs which were caused by developers incorrectly assuming that the default locale settings were good enough for parsing a value. I’ll show you what I mean.
Case 1
Consider the following snippet:
.something {
width: 21.4em;
}
This is a simple CSS rule, making all elements with class ‘something’ have a width of 21.4em. In .Less, we parsed this without an explicit locale. The output would only show 21em, truncating the value from the implied decimal separator onwards. Once we set the locale to Invariant (who needs specific locales in CSS?), the problem was fixed. All in all a fix of only an extra parameter on the parse method.
Similarly, I am setting up a private TeamCity server, just for trying out how it works. I used a git plugin to enable downloading the source from github, which threw an exception when parsing the date. Consider the following two snippets:
private static final String GIT_DATE_FORMAT = "EEE MMM dd HH:mm:ss yyyy Z";
private static final String VERSION_DATE_FORMAT = "MM/dd/yyyy HH:mm:ss";
public static final SimpleDateFormat GIT_DATE = new SimpleDateFormat(Constants.GIT_DATE_FORMAT);
public static final SimpleDateFormat VERSION_DATE = new SimpleDateFormat(Constants.VERSION_DATE_FORMAT);
private static final String GIT_DATE_FORMAT = "EEE MMM dd HH:mm:ss yyyy Z";
private static final String VERSION_DATE_FORMAT = "MM/dd/yyyy HH:mm:ss";
public static final SimpleDateFormat GIT_DATE = new SimpleDateFormat(Constants.GIT_DATE_FORMAT, , new java.util.Locale("en"));
public static final SimpleDateFormat VERSION_DATE = new SimpleDateFormat(Constants.VERSION_DATE_FORMAT, new java.util.Locale("en"));
The first one is the bugged one, the second one is the fixed one. All I did was make sure the date is being parsed expecting english localization. This simple fix enables the plugin (it’s from the git-teamcity plugin on github) to work on any system, opposed to the ones who happen to have their locale set to any english variant.
This leads me to one conclusion: developing on a non-english locale is a good thing, you’ll find a lot more bugs that way! Joking aside, these examples led me to be a lot more careful with assumptions, especially on region specific settings.
Thursday, November 19, 2009
For .Less we use TeamCity by JetBrains for continuous integration. Whenever one of us commits to the master branch, the server notices, runs the tests and produces the binaries we need. When one or more tests fail, the committer gets an e-mail to make sure build errors are noticed as soon as possible. Working like this reduces the friction a lot when working with a team: members of the team are getting direct feedback if something goes wrong, AND there’s always a source for the latest binaries for anyone who likes to run on the bleeding edge.
Daniel set up our TeamCity environment, and I must say, he did a very good job at it. However, this meant that I have no experience setting up the thing, while I do think it’s useful to know how it works. So, I decided to give it a shot. I’m simply going to install it on my windows box, as I don’t really need to deploy it anywhere. I just want to figure out how it works, and have easy access to it.
Installing the server
Simply go to the TeamCity website and download the windows package. This is a around 220 megabytes served from a decent server, so it shouldn’t take you more than a few minutes (you’re a dev, you’ve got a good internet connection, right? RIGHT?). When it’s done, start the installer. It’s a default windows installer, so it should pose no problem.
I suggest installing the bunch (build client, server, both as windows service), so the defaults are fine. I changed my paths to point to a different home directory though. I like to have things together, so I created a TeamCity folder on my X: drive. My folder layout looks like this:
- \
- \TeamCity
- \TeamCity\bin
- \TeamCity\config
I’ve pointed the binaries to the bin folder, and set the default config folder to config. This way my TeamCity files will all be in their own cozy folder. I won’t say you have to do this, but if you like to keep things together like I do, go for it!
TeamCity has a web interface, which defaults to port 80. I don’t like to have anything that’s not a production website on port 80, so I changed it to another random port number > 1024.
Alright, now we’ve got the server installed, let’s move on to the next bit:
Configuring!
First steps
Make sure your services are running and accessible. Your next work will involve a web-browser and the TeamCity web UI. Open your favorite browser, and navigate to http://localhost:<your port>/. TeamCity will present you with the next installation steps. When asked to create an administrator account, keep in mind that it might be handy to use the same username as you use on your VCS for notification purposes.
Once you’re done with these simple steps, login to TeamCity using your shiny new administrator account. You’ll see the following screen:
If you see that, you’ll know that everything is alright, and you can start configuring a project!
What’s next?
.Less uses Git, so we’ll need to install a plugin to allow TeamCity to download sources from a Git repository. There’s basically two options: git-teamcity on github, by Chris Ortman, or the official JetBrains plugin. Although I usually tend to go for the official releases, we’re going to use the one by Chris. The official plugin has a few restrictions, and we don’t want to have to work around this.
The next post will deal with building and installing the git plugin. If you want to be prepared, make sure you’ve got a recent Java SDK install and Apache Maven on your machine.