Stefan Rusek | Amazon Kindle Bathtub Reading Accessory

Amazon Kindle Bathtub Reading Accessory

Saturday, August 15, 2009

A few months ago, Aneta and I spent a week and a half travelling around Poland with our friend Jason Cisneros. Jason and I both have Kindles, and he showed me a webpage about a device that a guy had made from a coat hanger to make it easier to read the Kindle while lying in bed. This started a long (and somewhat silly) conversation about other Kindle reading accessories made from things around the house.

The idea that stuck in my head was the idea of something that would make it safe to read while doing the dishes. I often listen to Audible books while washing the dishes, but sometimes you just cannot put down a book you are in the middle of. There is a shelf above our sink, so I can prop my Kindle up on it, but it still gets damp when I push the next page button.

This morning I decided to take my first bath in a very long time. My first thought was of sitting in the warm water and enjoying a good book, which remembered me of my conversation with Jason and realized that a Kindle Dishwashing Reading Accessory would also make reading in the bathtub possible. (It would also make reading in a light rain possible too!) So I decided it was time to make my Kindle Bathtub Reading Accessory a reality.

How to make it

  1. Pick up your Kindle
  2. Put it inside a transparent polymer container
  3. Seal container
  4. Enjoy your reading

Pictures of Kindle Bathtub Reading Accessory

FrontKindle Bathtub Reading Accessory Back


Stefan Rusek | FogBugz 7 + Kanban

FogBugz 7 + Kanban

Friday, April 24, 2009

FogBugz 7 will be coming out in a few months and one of its coolest features is support for deeply integrated plugins.I have been participating in the FogBugz 7 Plugin Alpha, and It has turned out to be a lot of fun. I am working on my second plugin already. It is basically a built-in Kanban board for FogBugz. We’ve been using a Kanban board at ICHC for a few months now and it really helps to get a project organized. The main problem is that there isn’t really an online Kanban board that is as easy to use as post-it notes. My Kanban plugin is working now, but still lacks some features. Here are some screenshots. The cool draggy effects that you would expect all work. I just need to improve some other parts of the UI a bit.

You can search and sort the Kanban board information.

Search and List

You can view and edit the board as well.

View

Kanban information can be edited in the normal Case editing page, which adds a pretty cool way of moving stuff around or changing colors.


Stefan Rusek | Using ‘var’ to become a better programmer

Using ‘var’ to become a better programmer

Tuesday, March 03, 2009

When C# 3 first came out, there were a number articles written about using ‘var’ vs. explicitly typed variables. Some notable people said to use types, some notable people said to use ‘var’, and others took a pragmatic stance somewhere in the middle. In case you missed all this, here is an example:

List<int> l1 = new List<int>();
var l2 = new List<int>();

System.Web.HttpContext context1 = System.Web.HttpContext.Current;
HttpContext context2 = HttpContext.Current;
var context3 = System.Web.HttpContext.Current;

In the code above, l1 and l2 have the same types, but l2’s type is inferred from the declaration. For the declaration of l1 we specify the type twice, while in the case of l2, we don’t have to repeat ourselves. In the case of context1, we might be tempted to add a ‘using’ statement so we can use a declaration like context2, but using ‘var’ for context3 gives us a way to get the length of context2, but without polluting our global namespace. After a lot of thought and coding both ways, I have fallen into the “always use ‘var’ (except when you just can’t)” camp, because writing easily readable code as a whole outweighs the cost of possibly writing a bad assignment statement.

Much of the debate between these two methods focuses on readability of the assignment statement itself. Duplicating the type name tends to make the line harder to read, but some argue that the line is harder to read when the type does not appear on the line at all.

My contention is that the person reading the code does not actually care to know the exact type of the variable. The reader really wants to know the logical type of the variable. In every language, variables have a logical type and an exact type. The logical type is the idea that the exact type tries to represent in memory. So in other words, if you saw a call to a method CountItems(), you would know that it returned an integer, but wouldn’t really care whether it returned an int, uint, long, etc. In fact, many times uint or long make a lot more sense for the result from a method that returns the number of things. In these cases, the logical type of the variable is completely obvious, but the exact type is not. Likewise, if you had a method named GetDeletedItems(), you would know that it returned some kind of list. Many times, it does not make a lot of difference what type of list it returns, as long as you can do ‘foreach’ on it.

string Message()
{
    var items = CountItems();
    if (items == 1)
        return "1 item";
    return items + " items";
}

string ItemsToJSON()
{
    var items = GetItems();
    var sb = new StringBuilder();
    foreach (var item in items)
    {
        if (sb.Length != 0) sb.Append(",");
        sb.Append(item.ToJSON());
    }
    return "[" + sb + "]";
}

GetItems() could return an ArrayList, List<Item>, IEnumerable, or some user-defined type. We simply don’t care. The only inportant fact about GetItems() is that it returns a bunch of items we can use with the ‘foreach’ statement. In both of the above methods we have a variable named items. In both contexts, we know the logical type of the variable, but not the exact type of variable. Two things that reveal this information to us: the methods CountItems() and GetItems(), and the way we use the variables, both tell us the logical type.

You may be asking yourself how this can make you a  better programmer. Well, when a variable’s logical type is not clear, changing  the ‘var’ to an explicit type will not fix the underlying problem with the code, because it will only make the exact type clear. The real problem with the code is one or  more of the following: a bad variable name, a bad method name, or the variable  is declared too far from where it is used.

A good variable name goes a long way toward making good code. It doesn’t have to make the exact type clear to the user, but it should be clear from the context what the logical type is. Good method names are even more important than good variable names. This is because many times the consumer does not have access to the source code of the method, and even when you do have access to the method’s source it can be a pain to look at the source in order to figure out what it does. It is not uncommon for a variable declaration to get separated from where it is used as code evolves. This is something that can easily be fixed, and can dramatically improve readability.

When I worked at Fog Creek, we had a naming convention for variables that completely took a different approach to solving the problem:

Dim ixUser = GetUserId()
Dim ixUser As Int32 = GetUserId()

Dim cUsers = CountAdminUsers()
Dim rgUers = GetAdminUsers()

The ix prefix says that it is a Int32 index column from the database, thus the “As Int32” in the second line is completely redundant. The c and rg prefixes are count and array, both of which imply a type as well. The emphasis was on the logical type instead of the exact type. It was not uncommon for ixUser to actually be a string representation of an integer.

In the majority of cases the actual type just does not mater. In fact, when we let go of the exact and embrace the logical type, we will end up writing cleaner more consistent code.


Stefan Rusek | OpenId fix for this blog

OpenId fix for this blog

Thursday, February 12, 2009

From almost the beginning, this blog has supported OpenId, both for users and as a provider for me. The part I use everyday works fantastic. I get to use http://stefan.rusek.org/ as my OpenId all over the place. For users though it has been a different story. If your provider supports profile information, then all is good, but if not, then you have been unable to log into this site (sorry about that!). Now if your provider doesn’t support profile information (all the big companies trying to “extend” OpenId do not: Google, Yahoo, etc.), the first time you try to log in, you will be asked for your name and email address. After that, OpenId should just work. I ask for your name and email address for the commenting system. Basically, I show your name next to your comment and send you an email if someone replies. That is all I use it for, and that is all I will ever to use it for. If you have any thoughts or feedback feel free to click the Chat link on the right, or email me at blog@stefan.rusek.org.


Stefan Rusek | Ready to Quit ASP.NET

Ready to Quit ASP.NET

Wednesday, February 11, 2009

About four years ago, I wrote a little CMS with support for plugins and a number of other neat features. I continued to work on it off and on until I went to work for Fog Creek. Since then, it has languished in a Subversion repository on my hard disk. I don't have any desire to resurrect it, so the repository will probably get converted to Mercurial and then languish for another four years.

At the time, I spent a lot of time figuring out how APS.NET ticks. It is really a remarkable system. Originally, it was designed to allow Visual Basic programmers to transition to writing web apps without having to learn much about web programming. Yet for all its power and cleverness, is just plain fails. It failed in 2001 and fails even harder now.

The idea that you can shield web developers from having to get into the nitty-gritty and learn HTML is just cuckoo. HTML is the minimum any web developer should know, and in today's web, they should also know JS and how to use jQuery or a similar JavaScript framework. While ASP.NET tries to save you from doing that, its abstractions leak so badly that all the boys in Holland couldn't plug all the holes. Even if it did, despite its powerful control library, ASP.NET does not make it easy to do something it was not specifically designed for--and it was designed pretty narrowly.

Let's look at what happens when you, a neophyte web developer, first encounter ASP.NET. If you only use the controls provided in System.Web.dll, and write all of your own controls using the UserControl abstraction and learn HTML, you can create a half-decent web app using little more than your existing VB knowledge. That is, until you create a page that has a lot of cool stuff on it, at which point your 20K page turns out to weigh in at well over 500K. After a little research, you will find the culprit turns out to be ASP.NET ViewState. So you turn it off and your page is tiny again, but now none of you controls remember their values when buttons are clicked. You do some more research and learn that each control stores is value in ViewState to pass data across page loads, so you go through and determine whether you should enable or disable ViewState for each control. When you're done, even if you have something that mostly works, you have a big page instead of a huge page--and the abstractions designed to save you from learning about the web have merely forced you to learn the arcana of how ASP.NET tries and fails to hide the web, instead of writing a well-written web application from the beginning.

The remaining source of hugeness turns out to be a list control that you databound to a giant list of things from the database. The database can give you paged data, but the list control doesn't really like to be given anything but the full list--even if the control only shows a subset. At this point, you can either dig into the inner workings of the list control and try to trick it into doing what you want, or you can write your own list control. Either way you have a ton of work ahead of you.

The basic problem is that ASP.NET is not built on top of a windowing framework, but it tries its hardest to act like Windows Forms. So the abstraction breaks down whenever you run across the two big differences between web development and windows development: state management and how to display your controls--or in other words, basically the whole thing.

In an AJAX world, ASP.NET is even worse, because the idea of rendering only part of the page just does not map well into ASP.NET. Microsoft has an AJAX library that is built around the concept of an update panel control, which allows you to specify a chunk of the page that can be replaced via AJAX. This works for small things, but before too long, you put almost all of your page inside update panels. The end result is that each time you need do an AJAX request, almost the entire page is sent to the client and replaced via JavaScript, so even if only one control needs to be rerendered and replaced, all of them are.

ASP.NET MVC which throws away most of the ASP.NET infrastructure and builds up an MVC framework on top of the IHttpHandler interface (the lowest level part of ASP.NET). The MVC design pattern as applied to web design is inherently stateless, so even though the programmer is forced to actually think about state management, he writes cleaner, shorter code. The other thing it does right is to provide a set of extension methods that encourage the programmer to generate a bunch of html strings instead of an tree of controls.

In my experience, a good VB developer should have no problem learning to write good web apps, even ones that do neat AJAX tricks. Unfortunately, ASP.NET tends to prevent those programmers from being successful rather than help them.

< Previous Page 2 of 5 Next >