Monday, April 26, 2010

ASP.NET Chart Controls Without Web Forms


I started tinkering with the ASP.NET chart controls last week for a project at work, and the samples available from Microsoft are excellent, except they're mostly all using web forms. So I took it upon myself to do a few things:
  • Upgraded the existing samples from .NET 3.5 to .NET 4.0.

  • Added a sample project 'ChartsWithoutWebForms' to show one way to utilize the ASP.NET charts without using web forms at all.

  • Added a sample project 'ChartsWithMVC' to show one way to utilize the ASP.NET charts with the ASP.NET MVC framework.
The basic idea behind the two additional projects is that the chart is rendered as an image, which means you lose some interactive functionality, but my examples show that you can still fake some interactivity.

I also have an example that shows how you might create a dynamic charting system, which is actually what I'm working on now, but the work is venturing into an area where it will be specific to my employer, so I want to release the samples before that happens.

Feel free to take these updated samples and use them as you see fit. Hopefully they will help you out.

You can download the samples here:
http://www.downcastsystems.com/files/ChartSamples.zip

Tuesday, November 4, 2008

C# 4.0 dynamic Intellisense : a letter to the C# designers

I just emailed this to Eric Lippert:

I want to express my concern with the new dynamic language features in C# 4.0.

I think it is important to enable duck-typing along with this feature; possibly by enabling a "fake" cast to an interface. My proposal is below.

 
public class Person
{
public string Name { get; set; }
}

public class Fruit
{
public string Name { get; set; }
}

public interface INamed
{
string Name { get; set; }
}

public static class Program
{
public static void Main()
{
// these types may be defined in any language; possibly from Ruby, etc.
// the cast to INamed is "fake"; used only to enable intellisense since actual member resolution is dynamic
dynamic p = new Person() { Name = "John" } as INamed;
dynamic f = new Fruit() { Name = "Apple" } as INamed;

// would get intellisense after "." provided by the INamed interface
Console.WriteLine(p.Name);
Console.WriteLine(f.Name);
}
}

Monday, September 29, 2008

Balsamiq makes mocking up fun!

Robert sent me a link last week to a new mockup tool called Balsamiq.  At first, I didn't really see the point, but after using it for only a few minutes, I was totally sold.

What is it?

Have you ever tried to use Visio to mockup UI?  It's a cumbersome process, and no matter what I do, the end result just always looks like a bunch of circles and squares and nothing like what I actually envisioned.

Balsamiq has some ready-made controls that you can easily drop onto your canvas.  They look hand drawn, which is absolutely wonderful because then when I show people my mockups, there will be no doubt that they're simply looking at a mockup and not the final version.

image

Why is it useful?

I was just playing around with Balsamiq for a few minutes and made a quick screen showing a new feature we want to implement.  I showed it to Robert, and we found out instantly that I was going about it the wrong way.  Imagine if I'd mocked that up in HTML, or in Photoshop?  It would have taken me a lot longer, and it would have been harder to modify after my initial mistake.  Since I used Balsamiq, i was able to just move the controls around.  So it saved me a lot of time and aggravation.

Another Example

We have to implement a way for color blind users to use our web application, so we've been asked to add "Color Schemes" to the User Settings.  The user can have an underline or a box around particular fields on the form.  The box background color or underline color is affected by changing color schemes.

At first, I thought, the simplest thing to do would be to simply provide a drop-down list of named color schemes with a preview below, so I mocked it up, and it looked like shit.  Then I remembered the way Digsby and now the new Windows Live Messenger 9 Beta showed some of the custom UI settings, so I tried to emulate it a bit.  (The horizontal rule control in Balsamiq isn't colorable yet, but the author says he's added to his upcoming feature list.)

image 

Also, I just want to note that I've emailed the author twice, and he responded back within a few minutes each time.  That's impressive.

Check it out:

http://www.balsamiq.com

Friday, May 2, 2008

Unnecessary Iffage

A friend of mine showed me an example of the kind of bad code he finds every day where he works:

image

There are a lot of things wrong with the example above.  Le'ts pick it apart and simplify.

1. This line is unnecessary:
image 

You could just use SomeBooleanFunction in place of someBooleanValue in the example above, like so:

image

2. " = True" is unnecessary.
The function already returns a boolean value.  Get rid of it:

image

3. anotherBooleanValue is also unnecessary. We could do away with it and return the value immediately from the If statement, like so:
image
 
4. In fact, almost all of it is unnecessary:
image
 

How does this happen?

Why didn't the programmer just use the existing SomeBooleanFunction() instead of creating a new method that does the exact same thing?  I bet I know.

I suspect the original programmer didn't know that SomeBooleanFunction() existed until after he'd already duplicated the same logic in MyBooleanFunction().  Once he found out that SomeBooleanFunction() was there, he wanted to use it, but didn't want to change all the code that was already using his new MyBooleanFunction().

A simple find/replace could have solved his problem, but he may have been afraid to change too much. That's not a good excuse, I know. I'm just sayin'.

Tuesday, April 29, 2008

Programming Books Usually Suck

Jeff Atwood over at Coding Horror is always going on about how programmers don't read programming books because most of them suck, and I agree with that.  I personally have only read about three really good ones.

In Jeff's post, he mentioned (as an example of poor writing) a book called Perl for Dummies. I followed through to the linked review, and it was great. So I wanted to point out a few of the best (of the worst) examples, as I think programmers who are writing should take notice of these kinds of things.

When there are simple and difficult explanations, you can usually count on Hoffman to find the difficult explanation, and then to tell you how difficult is. For example: (page 93)

int can be a bit tricky because it rounds down for positive numbers and rounds up for negative numbers.

He's right; that is tricky. Wait, which was does it round again? Up, down, positive, negative, I can't remember. But if he had said

int is very simple: It throws away the fractional part of a number, leaving the integer part.

then it is a lot easier and you understand the name so that next week you might remember what it does.  Another example of this: In the ill-advised explanation of xor, he says

The operator returns true if the two things have different truth values but returns false if they have the same truth value. (See table 8-2.)

Here's the simple version:

$soup xor $salad is true if either $soup or $salad is true, but not both.

Then you dispense with the table.

Part of the reason Robert and I do Develocity is because we are always finding terrible sample code out in the wilds of the Internet, and it's teaching programmers the wrong ways to do things. It's scary to think people are filling books with the same sort of nonsense.

I'm not a programming expert, and I make my share of mistakes too, but before I post sample code that other people are going to look at and possibly use, I will go through it a few times, seeing if it can be made simpler and easier to understand.

Most examples have too much noise.  A "Hello, World" example should do nothing but print "Hello, World" to the screen. Don't add any for loops or random number generators to it.

Sunday, April 13, 2008

Learn and Practice LINQ With LINQPad

LINQPad is a free tool that lets you query your databases using LINQ syntax in an IDE similar to a poor man's SQL Management Studio. It comes packed with 200+ examples.

image

You can also use it as a code snippet compiler, but I think Snippet Compiler is better suited for that, as LINQPad doesn't have Intellisense at the moment.

http://www.linqpad.net/

Friday, April 11, 2008

Development-Related Uses For Screencasts

I’ve started using a program called Jing recently. It can record a video of what's currently on your screen.

Possible uses:

  1. Show managers or project sponsors the current state of your in-progress application without giving them access to the version on your machine (that you might accidentally break since you're still working on it).
  2. When a new feature is created, developers could create a video that shows the QA team what the new feature is supposed to do.
  3. When the new feature doesn't work, the QA team can show the developers the steps necessary to reproduce the problem. (Most of the time, a simple text description isn't enough.)
  4. I have a friend who wants to show his users in Asia how to use certain features of his application.
  5. I have another friend who wants to record the repetitive (yet somewhat complicated) tasks he’s currently doing, so he can show someone else how to do those tasks.
  6. Project sponsors could keep customers (internal and external) abreast of new changes to an application via a blog and show off those changes with an embedded screencast.

If you want to get really fancy, you could even create tutorial videos like the kind you see on www.asp.net, but I think a program like Camtasia Studio would probably be better suited to that, as Jing has a 5 minute limit on any videos created, and there is no way to edit the videos it creates.

Also, because I don't want to divulge any company secrets, I'm not sharing my videos to Screencast.com, Jing's default video destination. I set it up to save a file on my hard drive, so that I can attach it to an email or TFS work item.

Jing is free and extremely easy to use.

http://www.jingproject.com/