And when you call it, you can call it Util

No. Actually you can’t call it Util*. You might think I’m a pain in the backside, nitpicking on issues like naming. I’m not.

Util, short for Utility is something useful. And it would probably be really useful if I could find it. But that’s the problem. You don’t always find it. When you’re working on a foreign codebase, things aren’t always as obvious as they seem. The only real thing that you can go by is the hope that other developers named things in sensible ways. Because otherwise you’re lost.

In fact, you’re not only lost, but you might even end up duplicating efforts, you know, you might end up writing that wretched helper method and put it in a class called FormatHelper as opposed to FormatUtil. And when Jack comes along, well he’ll just write his own and place it in FormatServices. Why? Cause the first time, we didn’t care too much about the name.

The only thing that I should rely on, the only thing I should be dependent on to understand the code, is the code. I shouldn’t have to bug a teammate to find out how something works or what a parameter means, or whether some routine exists or I should create it myself. We should leverage the language we all communicate in and understand and name things coherently.

Next time you’re figuring out what you should name a class, name it as what it does. And if you think that it does too much to describe it eloquently, then you’ll solve two problems in one go.

That’s why I’m so picky about naming. Because, despite what you think, it is not obvious until its obvious. And for you, the author, its always obvious. For me, it’s not.

* Util, Service, Helper, Manager, ….all of these are pretty much worthless…

The Kotlin Journey Part I : Getting things set up

For the past year or so, a team of developers at JetBrains, lead by Andrey Breslav have been working on a new language codenamed Kotlin, a statically-typed language targeting the JVM and JavaScript. Kotlin is a multi-purpose language and can be used for pretty much any type of development.

As someone interested in languages, I’ve taken it upon myself to learn more about Kotlin and offering you to join me in the journey. If like me, most of your time in the past few years has been spent as a C# developer, not a Java one, then we’re pretty much in the same space. So you’ll feel right at home.

A little about Kotlin

image

Kotlin has been developed in an attempt to improve the way we work. It has removed some of the bad things Java has and added some nice features that Scala provides. It is an Object Orientated language, not a functional one, although it does have higher-order functions and function literals. If you are interested in the reasons as to why Kotlin has been developed, check out some of the entries in the FAQ. There is also this post that is worth checking out about why JetBrains needs Kotlin.

Another important fact about Kotlin is that it is OSS, both the compiler and the IntelliJ IDEA plugin. Taking into account that we also provide an IntelliJ Community Open Source edition, the tooling costs for using Kotlin is zero.

Setting up IntelliJ to work with Kotlin

Several days ago we announced the general availability of the EAP for Kotlin.The entire source code for Kotlin is available on our GitHub account. There is also a build of the compiler available as a zip. That’s pretty much all you need to work with Kotlin. However, to make the experience much nicer, we’re going to work inside of IntelliJ and use the Kotlin plugin already available for it.

So the first step is to download IntelliJ. I’m working with the Ultimate Edition, but you can use the Community Edition if you like. Note however that the plugin DOES NOT WORK with IntelliJ 11 or prior versions. It is only supported in IntelliJ 11.1 EAP which you can download from here. I’m using build 114.98. The codename for this EAP is Nika and the executable is named Nika too so make sure you run the correct instance of IntelliJ if you have 11.0 or a prior version installed. Even though the plugin might load in previous editions, it won’t work correctly.

Once IntelliJ is installed, next step is to install the plugin. Download it from here and then click on Preferences inside IntelliJ and type ‘Plugin’ in the search box to get quick access to the list of Plugins.

image

On the right panel, click on Install plugin from disk and select the zip file downloaded.

image

Once complete, you should now see the Kotlin plugin installed

image

You will have to restart the IDE.

Creating the first Hello World project

Now that the plugin is installed, we can create a new project. Kotlin does not currently have its own project type. Kotlin is merely a language. You can use it in any type of Java Application. In fact, Kotlin can interoperate with Java so pretty much all the JVM is at our disposable. What we’re going to do, is create a new Java  Project. I’m going to assume zero knowledge of how to create a project in IntelliJ so we’ll go through the steps.

1. Click on File | New Project. Select Create project from scratch and hit Next

image

2. Type in name for the project (KotlinHelloWorld). Leave all the options intact and click Next

image

3. On the source folder, leave the default src and click Next.What this does is define the source folder where our source code files will be kept.

image

4. In the dialog box to select technologies to use, for now leave blank and hit Finish.

image

Note: If this is the first time you’re running IntelliJ you might be prompted to select the JDK folder to use. IntelliJ normally located this folder and you merely have to confirm it.

If everything went OK, your Project structure should look like this:

image

Sidetrack: ReSharper keymapping

Before continuing, and in an attemp to feal more comfortable in IDEA, I recommend installing my ReSharper key mappings. If you’re a ReSharper user, you will feel right at home since pretty much all of the key bindings are the same. In IntelliJ, to import key mappings, select File | Import Settings and point to a jar file which can contain key mappings as well as any other IntelliJ settings. You can find my key mappings at https://github.com/hhariri/Tidbits/blob/master/resharper.jar. You can change the key mapping any time you want using Preferences and typing in ‘keymap’ for quick access to the configuration entry:

image

Creating the first Kotlin file

Once we have the project created, next step is to add a Kotlin file. To do this, right click in the Project explorer while your mouse is on the src folder to get the menu up:

image

and select Kotlin File

Give the file a name

image

You should now have an empty file with a toolbar at the top asking you to install the Kotlin runtime. If you do not have this, make sure you haven’t installed or launched the wrong version of IntelliJ.

image

Click on the Setup Kotlin Runtime. What this does is install a series of required libraries for Kotlin in the project. You project structure should now look like this

image

Write some code

Inside the HelloWorld.kt file, type fun:

image

If the installation is correct, you should get help from the IDE to complete the statement. This is pretty much like ReSharper Live Templates. You can hit Tab at this point and get the function template for Kotlin. fun in Kotlin represents a function, which can return a type or void

image

Give the function a name, no params and leave the return type blank. In the body type out println(“Kotlin: First Contact”). End result should be:

image

In this post, I’m not going to delve into the languages details as such. The objective is to get the environment up and running to make sure it all works and then later dive into the different aspects of the code. However a couple of things worth mentioning:

  • In Kotlin, a function/procedure starts with the word fun and can return a type or Unit (void), making it either a function (if it does) or a procedure (if it doesn’t). As such, writing fun foo() and fun foo(): Unit are exactly the same thing. We’ll dive more into what Unit is in a future post. For those familiar with languages such as Pascal, we had function and procedure to distinguish the two.
  • Statements in Kotlin do not need to be terminated with semi-colon

Once we have the code typed in, it’s now time to compile it and see if it works. To compile, we can right click and select Compile or press Ctrl+F7.

Making it work

If no mistakes were made, the code should have compiled correctly. However, we can’t do much with it at this point, i.e. we cannot run it. Much like C#, Java and other programming languages, Kotlin requires an entry point in order to know where a program starts. And much like these languages, the entry point is a function called main that takes an array of strings as an argument. As such, let’s rename our function and give it some arguments:

image

  • Arguments (although not present in this example) follow the Pascal style, which is argumentName: argumentType.
Note: There is also a main template that expands into the previous function to make things easier.

Now we have the ability to run the code. Right click and select Run Namespace or alternatively press Ctrl+F9.

image

This will automatically create a new Run configuration in IntelliJ called ‘namespace’, which we’ll look into later. What it does mean is that once we’ve run it the first time, the Run and Debug icons are now activated

image

If all has gone well, we can now see the output in the Run window:

image

Summary

In this first part, we’ve gone through the basics to get Kotlin installed and our environment working to start writing code. We’ve only superficially touched one aspect of the language. We’ll dive deeper into these aspects in successive posts. Until then, you now have an environment to play around with Kotlin. Make sure you check out the documentation here if you want to learn more.

Spicing up YouTrack with Workflows

Tags

I had to set up a new project yesterday on YouTrack and needed to customize some of the default status fields. One of the ones I added was a ‘Paused’ status, for those times when a task gets held up for whatever the reason. Adding a custom value is pretty simple to do: under Administration, select the project, click on the the Fields tab, and click on the Value Bundle link of the field you want to update, in my case the State field

image

Once there, select Add State and type in the new value. You can give it a description and an optional color. I chose an orange tone to indicate its paused [Resolved checkbox indicates if the state represents the issue as resolved].

image

That was pretty simple. However, there is a minor issue. I want to know why a task is paused, much like I’d like to know why an issue is closed as ‘Will not fixed’. I’d like the person pausing it to provide a comment as to why the task has been put on hold. How can I accomplish this in YouTrack? How can I force someone to submit a comment when a state is set to Paused.

Workflow Editor

This is where YouTrack’s workflow editor comes into play. I looked at this tool nearly 2 years ago and I must say, there have been some major improvements. However what really shocked me was how simple it was to get up to speed. In less than 15 minutes I had downloaded it, created a custom rule and had it working on my project.

The workflow editor is based on MPS or Meta Programming System. If you’re not familiar with this, it is an extremely powerful Open Source tool from us that allows you to create and extend languages. But it’s not limited to only creating a DSL. It also provides you with the means to create editors, complete with Intellisense, Code Analysis and Debuggers. In fact, YouTrack itself is based on a language called WEBR which is developed on MPS.

The good news of course is that you do not need to know anything about MPS to work with Workflows in YouTrack. There’s already a packaged-up, self-contained editor that provides you with everything you need.

Let’s see how we can use this to add some spice to YouTrack.

Scenario: Requiring a comment when changing a state

The problem we are going to tackle is the one mentioned previously: we want the user to fill out a comment when changing the state of an issue. Since there’s no specific workflow built for this, we need to create one. As such, we first download the Workflow editor. You can do this from YouTrack itself, under the Workflow tab

image

Once download (it works on any platform as it’s based on Java), open it up. The first time you run it, it will display a hint box that the connection settings to the server need to be defined. You DO NOT need to have root permissions to the server to define workflow. You DO NEED however Administrative privileges on the Projects you want to use your workflows with.

image

1. Define these settings by clicking on the Connection Settings link. You can always change them later by clicking on the Workflow | Connection Strings menu entry.

image

Once you verify the connection, you are ready to start defining some workflows. On first run, it will prompt you to download existing workflows from the server. If it does not or this is a second run, click on Workflow | Download Workflows from Server. A good reason to do this is that you will get all predefined workflows in YouTrack which serve as great examples for defining new ones.

If all goes well, you should end up with your Workflow explorer having some entries:

image

2. Define a new workflow

The next step is to define a new Workflow. Every workflow we define is imported in to YouTrack as its own package. As such, a workflow allows us to group several specific rules together. We’ll get into what rules are in a moment.

To create a new Worfklow click on the Create Workflow icon on the toolbar

image

Give it a name. I’ve followed the convention to use server_name-project_name-description_of_workflow:

image

Next step is to decide what type of workflow this is:

image

In this scenario, we’re going to create a Stateless Rule (we’ll cover the other two options in a future blog post). A Stateless Rule means it doesn’t hold any state. In our case, we want to make sure every time a field holds a specific value (Paused) a comment is required. We’re not interested at this point, what the previous value of the field was, so we won’t need to hold state.

Here’s where it gets interesting. When you create the rule, a new editor is opened up. This is the rules editor. It’s a complete IDE (the power of MPS at work) that provides us with all the goodies such as syntax highlighting, code analysis and other things. First thing it prompts us for is a name.

image

We’re going to call this rule Changing to pause requires comments. Note that for the rule name, spaces are allowed:

image

The next step is to define the actual rule. Now as a newbie, it would kind of hard to know what can be done here. Fortunately, when we downloaded all the workflows, these all serve as examples. Added to that, we have Intellisense available too. Placing our cursor on the <issue…> and hitting Ctrl+Space, we get:

image

This has been filtered down to everything starting with ‘S’ because we’re interested in dealing with a State change. We can see that we have the State entry available. If you’re wondering where these values come from, much like YouTrack Search Facility, it provides us with information not only on fields, but also on values of these fields. Entering State now displays:

image

and we can select the becomes entry, which as the hint (albeit incorrectly) says, is an event that occurs when the value changes to a specific value. Unsurprisingly, becomes takes a value:

image

which is the new value of the field. In our case this would be ‘Paused’. A couple of powerful things to notice before we continue. If we enter ‘Paused’ prior to creating that as a value on the server, the workflow editor will warn us that this value does not exist. It will even provide us with an Intention (in ReSharper known as QuickFix) to create this value for all projects:

image

image

The next part is to define the actual action we want to take place when this condition is met. Here we can use the assert statement

image

filling in the condition and the message appropriately. In our case it would be

image

With that, we’re pretty much done defining our rule. The only thing left to do is push it to the server to make it available and then use it in the project.

3. To upload the workflow with the server, we can select the Workflow | Upload Workflows to Server menu entry

image

waiting for the upload to finish

image

4. Once that is complete, we then go back to YouTrack and attach the newly created workflow to the project. We select again the Workflow tab on the corresponding project and click on Attach Workflow

image

If the uploading in Step 3 succeeded, we should now see our new Workflow in the Dialog box.

image

We’re done. Now when we change the state of an issue to Paused, it should display a message prompting for a comment

image

Summary

In this post I gave you an introduction to the YouTrack Workflow editor and we saw how to create a simple rule, upload it to YouTrack and put it in action. What’s more, the editor is based on MPS and hopefully you have seen the power that MPS can offer us. In the next posts I’ll show you how to create more complex workflows that involve scheduling and state machines.

Submit a patch

Tags

We love to complain, and Twitter has just made is so much easier. By merely including a handle or keyword of some company or product, we can attract the attention of those we’re moaning about and have them run to try and solve our problem. The speed at which they run is proportionally direct to the number of followers we have or the ‘people we know’ (I have 10 followers but my best friend is a celebrity with 300K followers and RT’s anything I ask him to). Apparently it’s called Social Media Damage Control.

When it comes to software products, we’re quite good at it too. After all, that’s why we pay for software, to have someone to hear our roar on the other end of a phone, a forum or a twitter handle.

But that only applies to commercial software.

When it comes to OSS however, it seems different rules apply. Specially when it’s free. Complaining about OSS is often viewed as ungrateful behavior. Numerous times I’ve seen reactions from OSS developers, contributors or merely a simple passer by, responding to a complaint with: submit a patch or well if you can do better, write your own framework. In other words, put up or shut up.

We’re not all Einstein’s

It’s not always a patch they are after. At times, when you find a bug, an OSS team member can ask you for a failing unit test. Now granted that we all strive to unit test and promote unit testing, feeling that every developer should know, understand and practice unit testing, the reality of the matter is that it’s not all green pastures out there. For one reason or another, not everyone has that knowledge, the ability or the opportunity to. So often, sending a failing unit test can seem daunting.

Of course, coming back to patches, there’s the added issue of figuring out how to work with the given source control the project is using, get the right unit testing frameworks to run, creating new unit tests, making the necessary changes, submit them and wait for your pull request to be accepted.  And that’s if the project is using a DVCS and you can figure out what Pull, Push, Clone, Fork and Checkout mean. All this doesn’t even take into account that you need to figure out how the actual code-base works. And we all know understanding other people’s code isn’t easy.

For someone that is merely using an OSS project, all this can be overwhelming, not to mention intimidating at times.

Lowering the barrier to adoption

The OSS community often complain how big “Enterprise” and “Microsoft” shops don’t buy into OSS. It seems they go for commercial software in order for their legal departments to have someone to sue in case things go wrong. A little far-fetched of course, but nonetheless something you hear often. These shops also go for commercial software because it provides them with someone to call, someone that won’t tell them to submit a patch or provide a unit test. Someone they can call when they need support and not be judged (or at least not humiliated publicly on a forum or mailing list). Of course, the somewhat sad irony of this is that often, the support provided on OSS projects outdoes commercial products by a long shot, and that’s not to mention OSS projects that offer the possibility of commercial support.

However, we need to look at ourselves and see how much of this low adoption of OSS that we’re so passionately fighting for is our fault. If we expect all the users of our projects to know how to work with our source control or compile the source and deal with dependencies, submit patches or work with our testing framework, all we’re doing is raising the entry barrier to OSS.

Before shouting that I’m stereotyping OSS projects, I’m not. I’m well aware that there are amazing projects out there with beautiful and thoughtful teams and communities around them that make many commercial support alternative envious. However, I’ve seen the submit a patch attitude often enough, over the many years I’ve been involved in OSS to warrant mentioning it.

What about me? What about my time?

Now there is the opposite side to all this. You. The Project Lead. The Core Contributor. The guy that has spent several years of his life giving to the community, contributing to OSS projects, helping others. Why should you, despite having given so much, take more of your time to help others. The minimum, that someone that is using your project (for free might you add), owes you, is a failing unit test. No? Not just some lousy steps to reproduce…

Here’s the thing. If you’re working on OSS, you’re doing it because you are benefiting from it. You benefit because you enjoy it. You benefit because you learn. You benefit because you potentially can rise to fame (albeit a micro-celebrity), and you benefit because it can ultimately provide you with potential consulting and training opportunities.

Nobody owes you anything for working on OSS!

Per Project Settings or How to have different naming styles for my test project

Tags

 

One nitpick that I myself and many have had with ReSharper is not being able to have different naming styles for types based on different projects. In my code I normally name classes using CamelCase

 

image

 

and in my test project I use all_lowercase

 

image

 

Unless you add all_lowercase as a valid naming style, you’ll always end up with those squiggly lines under all your tests. And let’s admit it, it’s not a big deal but it’s annoying. #FirstWorldProblem

 

Say hello to my little layer

With ReSharper 6.1 we introduced the concepts of layers, which open up many new possibilities, including sharing settings on DropBox and or setting company wide standards. What you might not know is that it allows Per Project Settings too! No big deal if you didn’t know, since we currently do not support it via the User Interface so it would be hard to figure it out. However it’s pretty simple to do and I’m going to show you how.

 

Our goal here is to allow all_lowercase settings for classes in our test project (Tests) and not permit the same in other projects (Project). This is the sample project layout we’re going to be working with

 

image

To make this happen, we need to create specific settings for the Tests project and allow the possibility of classes being all_lowercase. That is, the Tests project needs its own DotSettings file.

 

Since there’s no specific button or option to add Per Project settings in the UI, this is where we need to kind of use a workaround. We need to have a Settings file for the project and then edit the options and save it to this file. There are many ways to create this new settings files. We can copy the solution one and rename it, we can export the current settings, we can mount a new layer and have ReSharper create it for us, etc.

We’re going to use this last method. Why? Because since ReSharper mounts it when it creates the file, it will allow us to edit the settings too.

 

 

1. With the Solution open, click on Manage Options under ReSharper

 

2. Under This Computer, click on the Add Layer icon (on the right) and select Create Settings File

 

image

 

 

3. Save the file to the Tests project folder, in our case that would be under SolutionDir\Tests and name it (and here’s the important part) Tests.csproj.DotSettings. That is, it should be named with the ProjectName, followed by csproj or vbproj based on the type of project and with the extension DotSettings.

 

4. Now that we have the settings file mounted, we need to change the required settings, which in our case is to allow classes to have all_lowercase (this obviously works for other settings too). As such, double-click the recently mounted file or right click and click on Edit

 

image

 

5. The Options dialog comes up. We want to edit the naming styles

 

image

 

Modify any other settings you wish at this point and once done, hit Save on the Options dialog.

 

image

 

At this point, we can remove the mounted settings as its not required for it to actually work. We can also leave it in order to easily access the settings for the project in the future. If you do leave it, make sure you uncheck the checkbox so that settings are not applied to the entire solution.

 

[Recommendation: If you decide to leave the settings mounted, mount these under Solution Shared or Solution Personal as opposed to This Computer so that you don’t end up with a long list of different settings files]

 

 

As soon as we hit Save, the new settings automatically are picked up by ReSharper and take effect. We can now see that the naming style no longer appears incorrect under the Tests project

 

image

 

and if we try and use the same style in the actual Project we do get the warning

 

image

 

The UI will come

Once you do this once, you can pretty much copy the same file over to your different projects and rename it to match the project name. In one of the next versions of ReSharper we will provide a more intuitive UI (or should we say we’ll provide an actual UI) for this. For now however, I think this minor hack will make a few people happy!

The tangibility syndrome

Tags

 

I was reading a post by Phil Haack about Recognition Compensation which was somewhat in reference to recent news over MVP renewals. I feel there’s no further comments required on all the rewards and compensations surrounding this and other programs. This post is not about that, but about something he mentioned, something I’ve come across quite often:

 

The other reason folks want an MVP is to have access to the professional tools. Most companies will easily shell out the money for this, but if you’re a hobbyist or open source developer, it’s a lot of money to shell out.

 

First of all, let me make it very clear that this has nothing to do with OSS. Let me also state that at JetBrains we fully support Open Source Development, and we do this in many ways. Some of our tools are fully Open Source, others have OSS Community Editions. We also provide free licenses to OSS projects of pretty much all of our tools, as well as collaborate with the folks at Codebetter to offer free Continuous Integration and Issue Tracking software for all Open Source Projects (in fact, TeamCity and YouTrack are even provided for free for smaller teams). In addition to this, many of us at JetBrains spend quite a bit of our time working on OSS projects.

These are policies that I identify myself with and that’s why I’m very happy to be part of such a great company. Having said that, let’s move on…

Hobbies cost money

This morning I tweeted:image

Collin’s Dictionary defines Hobby as:

image

In our context, it’s an activity pursued in spare time for pleasure or relaxation.

It’s what people do to switch off. It’s what they do to get away from their daily job. It’s what they do to relax. Stamp Collecting, Photography, Painting, Knitting, Astronomy, Playing a Guitar are examples of hobbies.

Many of these hobbies cost money. Some of these are one-time investments, others have ongoing costs. Photography requires a good camera. Painting requires a constant stock-up. Things which would seem like an upfront only investment also turn out not to be. You buy yourself an electric guitar. Once you learn to play it half-decent, you want a better sounding amp. Next you need a few pedals and ultimately want a better guitar.

how is development as a hobby different?

My main hobby (after stumbling with a guitar) is learning new programming languages, frameworks and stepping outside of my comfort zone. It might be sad that I have little interests outside of my profession, but I find it somewhat fortunate because it means that I love what I do so much that if I weren’t doing it, I’d be doing it, if that makes sense.

I’m also fortunate that my hobby contributes to my career. Of course, I don’t get to play my guitar as much as I’d like to, but I do get to learn new ways of doing things that broaden my horizons. As such, I invest in my hobby, be it with books, software tools, hardware and whatever else I need. And I don’t look at it as a ROI because that’s not what a hobby is about. It’s not about how much bang you get for your buck.

Whatever the hobby, be it playing a guitar or collecting stamps, people have little problem with spending money on it. Yet why do we draw the line when it comes to software?

I do this as a hobby, why should I pay?

 

Is it because software is not tangible?

We see this outside of developer and hobbyist circles too. People will spend thousands of euros on a MacBook Pro, but then look for free password keepers instead of paying $70 to buy 1Password. They’ll use free alternatives even if they’re half as good as a paid one. And of course, in countries like Spain, where we’re ranked as second highest in software piracy in Europe, it’s just downloaded off of some torrent site.

We, developers, of all people, the ones that charge money to write or aid in writing end-user software, should be the first to know that the value of software is not measured by how much it weights or what it feels like. If we understand that, why do we suddenly feel that working on something as a hobby doesn’t deserve monetary investment?

Errors: Handle with care

Tags

,

Went to renew my driving license this morning, a process the DGT (Traffic Authority in Spain) has made extremely simple now: you just head over to a private clinic, pay quite a bit more than you actually should and have them deal with the bureaucracy.

It was meant to be a 30 minute process and quite straightforward:

1. Ask for customer’s details
2. Run some medical tests
3. Get a temporary driving authorization until your license arrives in the post

I ended up being there about an hour and not getting it renewed.

The real process went something like this:

1. Was asked for all my details at reception and waited as they were typed in.

2. Taken into examination room. Waited 15 minutes until they could start the computer since the fan was acting up. Thankfully the technician (which was actually a Doctor) came in, kicked the box (literally) and it turned on. As he walked out he said:

“these computers are scared of me…”

3. Asked for my details again. When I questioned why I was being prompted for them  a second time, the answer was somewhat expected:

“This computer has nothing to do with the other one. This one runs the DGT program. The other one runs ours. “

Stupid me!

4. Went through some appropriate tests. Again, this was delayed because the second computer failed to boot.

1st Error handling mistake  – the human

I waited patiently until my details were submitted to the DGT system. Everything seemed fine until I was suddenly asked:

Operator: “Are you sure you haven’t lost any points on your driving license?”

Me: “Em no. In fact I think I now have 14 as opposed to 12”.

Operator: “Hmm, something is very wrong. It’s giving me Undetermined Error 611

Me: “OK, so what does that mean?”

Operator: “There’s a problem with your driving license. I think….”

Me: “You think or you’re sure?”

Operator: “I can’t know exactly. As it stands I can’t process your renewal. You’ll have to leave this with me. If I don’t call you back today then you’ll need to go to DGT and do it yourself. But don’t worry, we won’t charge you anything”

Now you have to admit, that’s awfully kind of them not to charge me for something they haven’t managed to do.

2nd error handling mistake – the stupid developer

Up to now, my customer experience, as a user of this clinic has been somewhat lower than par one could say. I’ve witnessed operator incompetency, lack of care of technical equipment and overall no inspiration of confidence.

This clinic has a ER unit, in-house care, pediatricians and various other specialties. Suffice to say, it does not inspire any confidence in me for me to ever return there, specially when dealing with something serious as health issues. They’ve lost a customer.

The second user experience however comes from the developers that created the system. It was that damn undetermined error 611.

As a developer, when you see “Internal Error”, “Undetermined Error” or “Catastrophic Failure” you pretty much know what the developer was thinking at the time:

“I don’t give a shit about controlling errors in this scenario. Too many things can go wrong for me to control”

Now I am right in assuming that this error code is only valid for the developer. Otherwise he/she is really stupid to display an error message to the user making them either have to memorize error codes or look them up in some manual.

As such, that leaves one of two options: 611 is just the number they use to define what an undetermined error is (i.e. 500 Internal Server Error) or 611 provides them some valuable insight into the error, which then begs the question of why it’s undetermined.

Whatever the case though, this is yet another UX fail. Not only does it not provide any kind of valuable information to the user, but it also, as is in my case, when faced with a somewhat incompetent user, causes a certain level of concern (WTF is wrong with my license? Has it been revoked?).

Handle with care

Time and time again I’ve seen applications fail when it comes to handling errors. Most common excuses given when observing bad error management are, that it’s too complicated to know what’s gone wrong. The irony of this is that much of this complexity is caused by the way we design the system, as opposed to the underlying business rules. The only time error handling is too complex to deal with is when a human decision is required. In these scenarios, we need to also deal with the error, but using a different approach.

Providing error codes or ambiguous messages to a user should never be done. Anything that interacts with a user, a consumer of your application, should use language the user understands, not something they need to look up. That’s what computers are good for: looking up information.

Now, while writing this post, I got a call from the clinic. The undetermined error ended up being a user error. The operator had asked for my nationality and I had said Spanish. She had entered Spain as my place of birth. DGT had Iran on their records. There was a mismatch. The operator failed in using the system. But the system failed her even more by not handling errors correctly.

Much of this would have not taken place if instead of

“Undetermined error 611”

it would have displayed

“There is a mismatch between the place of birth entered and that on record”

Something as simple as this would have saved me and the clinic time, annoyance and money.

So never supply error codes?

When switching to the context of developers, it is fine to provide log details and stack traces. In this context you can provide codes. HTTP does it. It’s useful to automate error handling and machine-to-machine interaction. But in addition to these codes, you still need to provide a valuable message so that a developer can understand where to look, what’s gone wrong.

And if everything does go wrong and there’s no way to handle the situation, consider providing a more re-assuring message to the user, something that doesn’t leave him thinking he’s lost all his points on his driving license:

“It’s OK. You didn’t screw up. We did. We’ll sort it out and get back to you”

Providing Intellisense, Navigation and more for Custom Helpers in ASP.NET MVC

Tags

 

You probably are aware by now that as of ReSharper 5 we added first-class support for ASP.NET MVC. This included among many things, the ability to provide Intellisense, Create from usage and Navigation to built-in methods such as Controller.View or Html.ActionLink:

 

Navigation

Ctrl+Left Mouse Click or F12 will navigate to the corresponding View

 

image 

 

or to the Action and/or Controller

 

image

Intellisense and Create From Usage

Ability to have Intellisense when providing Actions/Controllers

 

image

 

as well as the possibility of creating from usage

image

 

However, what happens when you want to use a custom function, for instance, a better ActionLink or your own View method? Did you know that you can still get all these goodies? All you need to do is use some Annotations.

Using JetBrains.Annotations

ReSharper uses annotations via the form of .NET attributes to figure out what an ASP.NET MVC View, Action or Controller is. As such, all we need to do for our custom method and extensions to leverage this, is tell ReSharper what parameter corresponds to what.

 

Referencing the annotations

To use ReSharper annotations, we have mainly two options (with a third one hopefully coming soon):

1. We can include the library JetBrains.Annotations.dll in our project and reference it.

2. We can copy the annotations and include it as source in our project

[3. We can use nuget install-package JetBrains.Annotations] Coming soon!

 

The first option is pretty simple. The DLL is located in the ReSharper installation bin folder. For the second option, we open up ReSharper | Options and select Code Annotations entry

 

image

 

select the Copy default implementation to clipboard button and paste into an empty file.

 

Annotating custom methods

Once we’ve completed this step, all we need to do is annotate our parameters with the correct attributes. We’re interested in 3 different attributes in particular:

 

  • AspMvcView which indicates the parameter is a View
  • AspMvcAction which indicates the parameter is an Action
  • AspMvcController which indicates the parameter is a Controller

 

Here is the header corresponding to a base controller with a custom method named ExtendedView

 

image

 

and here’s the header for a custom ActionLink

image 

 

(the body of both methods are omitted and are not necessary to demonstrate the functionality)

 

As soon as we do this, ReSharper picks up these methods and offers us the same functionality that is provided for the methods that ship out of the box:

 

image

 

Notice how we still get Navigation (the underlining), Intellisense and Create from usage in our TheOnlyActionLink custom method. Its much the same for the ExtendedView method

 

image

 

That’s all there is to it.

Setting up TeamCity as a native NuGet Server

Tags

,

 

TeamCity 7.0 EAP (Early Access Program) was recently opened and one of the new features is the built-in support for NuGet. I recently blogged about setting up TeamCity to pack and publish NuGet packages via a plug-in and this plug-in is now included by default in TeamCity 7. However, the real new interesting feature is that TeamCity is now a native NuGet repository too!

Native NuGet Server?

Many of those that have been using NuGet, have most likely been using it to consume packages from nuget.org where there are currently over 3800 unique packages, most of which are open source.

image

 

What happens however if for some reason or another you do not want to submit packages to nuget.org? For instance, think that you want to use NuGet to modularize and distribute code inside your own organization, or create libraries for private consumption. In this case, publishing to nuget.org does not make sense. This leaves you with basically two options:

 

  1. Setup your own NuGet repository by downloading and installing the code that nuget.org for instance
  2. Copy nuget packages to a local share and have everyone read off of that

 

Both of these options come with their own share of overhead. With the local share you now require sharing of folders and permissions. Setting up your own NuGet repository also requires managing permissions and whatnot separately. At the end of the day, its another service to manage.

Fortunately, you now have a third option: TeamCity. The same server that builds your projects, runs your tests, packs and publishes your packages can now also serve them. The best part of it is that it is so simple, that I had to take up the rest of this blog with the previous nonsense just to give it some meat.

Enabling TeamCity as a NuGet Server

I am not going to cover how to pack and publish packages in this post. All that is covered in detail in the previous post I wrote, so please read that first if you’re not familiar with the process. Enabling TeamCity as NuGet and making packages available consists of two steps:

 

1. Enable the server to be a NuGet server

 

Go to Administration | Server Configuration | NuGet tab

 

image

Click on the Enable button to enable it. The same screen with then display two different feeds: a public and a private one:

 

image

If by chance the Public Url is not available, you will probably see a message telling you that you need to enable the Guest account in TeamCity, which can be done from the General tab.

 

2. Make your packages be your Artifacts

Since TeamCity itself is going to be a NuGet server, the step to publish a package is no longer required. However, packing the package is. In this step (NuGet Pack Build Type), we can just configure the output for the package to point to some specific folder, for instance packages

 

image

 

We need instruct TeamCity to ouput the results of this folder as artifacts. This is done in the General Settings step of the Build Configuration

 

image

 

and with that, we’re done. Next up is to configure Visual Studio to consume from this feed.

 

Configuring Visual Studio

Although this step is optional, it is recommended to add your repositories to Visual Studio to avoid having to type long URL’s in each time you want to read from a specific package repository. To do this, click on Options | Library Package Manager | Package Manager Settings

 

image

 

We need to add a new NuGet Repository. I’ve called it Local TeamCity  and the URL corresponds to the public URL provided to me by TeamCity in Step 1:

 

image

 

Notice that I have another entry which is Local TeamCity Auth which corresponds to the authenticated version.

Once we have this, we can now easily consume packages from our repository by merely specifying it in the Package Manager Console, either via the Combobox or explicitly in each call:

 

image

 

 

Summary

That’s all there is to it. By merely publishing our packages as artifacts, TeamCity now provides a full-fledged nuget server which opens up great possibilities when it comes to working and managing dependencies between projects. TeamCity is currently in EAP and much of what I’ve described here is in open to improvements. That is why your feedback is very important. Download 7 and start playing with it today. Let us know what you think.

Visual Studio Achievements: Who needs clean code anyway

Tags

,

I stumbled upon Visual Studio Achievements this morning via Maarten. The idea of combining development with game play might be enticing to some and as others have pointed out, could be a way to introduce younger generations to development and potentially get them interested. As such, the idea in itself is not an issue. What is however disturbing is the point system.

image

If you look carefully at the entries, you find that not only do some of them promote bad practices which lead to horrendous maintenance nightmares like the Region Manager

image

but a few of them are even geared more around selling higher end versions of the tool.

image

Were are the points for writing a Unit Test? Or keeping the number of lines in a method low?

As many of us have learnt ourselves through our mistakes, and are somehow trying to guide others in finding better ways to develop and write cleaner code, we are suddenly confronted with something that entices developers in the opposite direction. To those companies who waste millions having to maintain bad code or rewrite systems, this is not a game.

As it stands currently, that leaderboard should probably be renamed to “Hall of Shame”.

If this a joke, or the achievements points are not real, it would be a great opportunity for MS to really think through how they go about promoting this and what really does constitute a point.

Follow

Get every new post delivered to your Inbox.