Feed on
Posts
Comments

Matt Darey ‘Nuff said.

MVC ActionLinks

The ASP.NET MVC framework comes with a series of helper methods that allow for the generation of links in a strongly typed fashion.

                <li><%=Html.ActionLink<ProfileController>(controller => controller.Index(), “my profile+account”) %></li>

This code results in the generation of the following html:

                <li><a href=”/Profile” >my profile+account</a></li>

The ASP.NET MVC engine looked in the routing tables for the mapping of the profile controller’s Index method and reverse mapped it to the “/Profile” URL listed above. Cool!!! Great, right?!

Well, I suppose if you’re a very developer centric shop, it’s fantastic. However, if you have designers and/or site developers, I can imagine this adding a bit of learning curve to their day to day tasks in the html (”Uhh… what’s a controller?”).

As for me, I like it… prefer it. Still, for large, multi-functional teams, it might just be easier to type out the html “<a href=…” instead of relying on yet another abstraction to generate a link, even if it is more prone to errors. *shrug*

I’m sure that this has already been posted about quite a bit already, but here’s my take.

First, have a look here.

The most significant change for me was the addition of the ability to return ActionResult from the Controller methods. Instead of spending a lot of time writing a lot of wireup code, overriding controllers and whatnot… all you have to do is examine the ActionResult and, depending on its type, you can verify what the MVC framework will do for you.

image 

 

And then in your tests:

image

 

Although the MVC framework will continue to improve, this one change alone has made testing much simpler for me.

WOW. After a week of squashing miniscule, obvious bugs (obvious only in hindsight, mind you!), I went home to 2 days of the same thing with one of my side gigs.

Arrrrrrrrrrrrrrrgggh…

Some lessons learned when rooting around for the problem, if the problem is especially problematic…

1. Don’t assume anything. Nothing. All possibilities should be on the table until 100% ruled out. Then have somebody else rule them out. ‘Nuff said on that.

2. Don’t assume the problem is with the “other guy.” Never. Ask the “other guy” to verify his stuff, but never assume. The “other guy” can be another system, another programmer, an infrastructure guy, an outside vendor… whatever.

3. Check your code. Then check it again. Then have somebody else check it. If you’re pairing, switch pairs and get a fresh pair of eyes on the problem.

4. Live by the 20 minute rule. If in 20 minutes you don’t have any insight into your problem, bring somebody else in or fire up Google.

5. Don’t assume any problem is in one specific area. Exceptions can be very limiting in the information they convey and the problem can originate somewhere else before it shows up as the exception showing up in your log. For example, check case sensitivity of parameters (yes, this was one), check other variables being sent across, look at code leading up to the problem, etc.

6. Google is not always your friend. If the exception is misleading to begin with, then sometimes when you search for the problem, you can go down many different incorrect paths before stumbling on the correct one. Be wary of this. Try to do some logical reasoning on whether or not the solution that has come up in the results even applies. Still, if you’re stuck, fire up Google right away.

7. Take a break. If you’ve stared at the screen for long enough, it’s time to take a break. Hit the gym. Get some sleep. Do anything else. Your brain needs a change of pace, so go.

8. Make sure that you have test coverage!!!!!!!!!!!!!

9. On that note, make sure you are testing the correct thing. Just because you have a test in place, doesn’t mean you have everything tested. Of course, if you’re doing proper TDD, this should not be the case… but it happens. Interaction testing via mocking frameworks are very useful.

10. Don’t assume anything. Nothing. I know… already said. I’m saying it again.

*sigh* I could’ve gotten some sleep last night. But it’s time for some Spurs action!

So I was skimming through the blogs on the Starbucks site (and their new idea site) and discovered that they offer “free” wifi service now. I love coding from coffee shops. The aroma, conversations with budding entrepreneurs holding their meetings over coffee, and the free wifi! Oh wait, Starbucks wasn’t free until recently!!

If you have an AT&T account (phone, uverse, whatever) already, you can login with your at&t credentials at no cost, but you can also get two hours for free. This one’s from one of the Starbucks IT folks (sorry, no link to the individual blog - didn’t spend any time trying to figure it out):

” This is Kevin Shawver and I work on the Wi-Fi program at Starbucks. First of all, I am excited to see all the energy around free Wi-Fi—we know it is important to our customers. I was secretly hoping that free Wi-Fi would be #1 amongst the popular ideas, but I’ll take #2.

Back in February we announced that we’re switching to AT&T as our Wi-Fi provider in our U.S. company-operated stores. As Brad Stevens mentioned in his post on March 24, we’re thrilled to be rolling out two hours of complimentary Wi-Fi service for customers who have a registered Starbucks Card. It’ll be simple to sign up. All you have to do is:

1. Register a Starbucks Card
2. Sign up for an AT&T Wi-Fi account (and limited ATT marketing)
3. Come to Starbucks and login

To keep your newly created Wi-Fi account “active” you’ll need to make a purchase with your registered Starbucks Card or add additional funds to it within the prior 30 days of logging on. We feel that the complimentary two hours is a meaningful amount of time and a fantastic way to reward Starbucks Card holders.

We have customers with a variety of needs—some want to come in and read, some want to chat with a friend and others want to use Wi-Fi. Starbucks means different things to different people and the two-hour limit helps balance the many needs of our customers so that everyone can enjoy spending time at Starbucks. This service will be available to all customers nationwide later this spring.

I love all the dialogue around Wi-Fi and look forward to hearing more. Look for me in the comment strings…my screen name is sbx_shvr.”

I’m a big fan of NHibernate. I love how it abstracts out the SQL portion of your application and allows you to work from the perspective of the domain rather than the database.

So in building my domain repositories, I have several options to query the database using NHibernate:

  • I can use HQL in CreateQuery.
  • I can use named queries in GetNamedQuery.
  • I can use SQL directly in CreateSqlQuery.
  • I can use the type of object in a CreateCriteria.

Short of using Ayende’s NHibernate Query Generator to strongly type my HQL queries, I like using the CreateCriteria call.

Simple Example

To begin with, I’m not a fan of generic repository interfaces with a ton of generics-based CRUD operations (IRepository<T>). I’d rather just limit my repository code to what is needed for operating with that aggregate root (driven by the domain, of course).

For this example, I have an interface in my domain project called CommissionPeriodRepository (yes, no ‘I’ in front of my interfaces - personal preference… lol). The implementation class, NHibernateCommissionPeriodRepository, resides in an NHibernate specific project implementing the repository interfaces. Finally, I’m assuming that the NHibernate session (Unit of Work is used here, but is very NHibernate specific) is managed by the calling application, committing and rolling back changes as necessary.

    public class NHibernateCommissionPeriodRepository : CommissionPeriodRepository
    {
        #region CommissionPeriodRepository Members
 
        public CommissionPeriod GetCommissionPeriodFor(DateTime date)
        {
            return UnitOfWork.GetCurrentSession()
                .CreateCriteria(typeof (CommissionPeriod))
                .Add(Expression.Lt("Startdate", date))
                .Add(Expression.Ge("Enddate", date))
                .UniqueResult<CommissionPeriod>();
        }
 
        #endregion
    }

Pretty much all the code is doing is:

  1. Pulling the current NHibernate session.
  2. Creating a criteria object for a CommissionPeriod domain object.
  3. Pulling the unique CommissionPeriod object that has a start date less than that passed in date and an end date greater than or equal to it.

That’s it. Simple stuff. Gotta love it.

So it is that I was thinking about… well… thinking! Specifically, what John Maxwell would call "Possibility Thinking."

As a developer in the daily 9-to-5 grind for a corporate environment, it is often easy to spend your time thinking about small tasks, the stories over the next few days, or the latest office gossip. If you’re a passionate developer, you might spend time talking about the latest design patterns in your code, the latest DI container, or the coolest blog entry - all great things, but very developer focused. Worst yet, if you’re "stuck" in an environment because you can’t move or are afraid to then it is sometimes difficult to see outside that environment.

I think software is a great enabler of possibilities. Software has and will continue to revolutionize the world - from the latest GPS application, to video games, to new safety features in cars. Obviously, the list goes on and on, but there’s no reason why your software can’t do the same.

So why not open your mind to the possibilities? Doing so will allow you to dream about the things that can be done with your software. Even if you are constrained by time, budgets, and what your boss wants you to do next, go ahead and dream big. You will be energized. You will keep going. And most importantly, you will break through the constraints brought on by those who don’t take the time.

So how do you do this with software development?

  • Start by not limiting yourself to "perfect code." As great as it is to have the perfect Domain Driven Design, heavy use of design patterns, and 99.99% test coverage, sometimes focusing on these parts of the application keep your focus away from the ultimate purpose of the application - the people using your application and how they are going to use it.
  • Software "experts" can limit your thinking. Read the blogs and go to the conventions, but THINK about what you’re reading. Mix in your own knowledge, expertise, experience, and creative thinking to come up with your own unique interpretation of what is being presented. Most importantly, don’t let the "experts" turn your possibilities into impossibilities.
  • Question things! Think BIG! Remember that change is a good thing. Be a catalyst for change. If you can’t bring things up constructively or productively immediately, make a note of your questions and come back after you have structured the question properly.
  • Remain passionate!!! Sometimes the grind can make things routine. It certainly does for me. Others will want to bring you down to their level. Others may not appreciate software development like you do.

Home Backup Strategy

I have wanted to setup a home backup strategy for a while. Buying my Windows Home Server was the first step.

The HP Media Server is a fairly small server, designed to sit on a home bookshelf. I picked the 500 MB version, since the 1 TB version includes two 500 MB SATA drives, and I wanted to expand the server myself as my data needs grew.

Here’s a picture of the media server next to my other home server, for scale:

P2230157

It’s pretty small. The server itself is basically a disk storage array, for storing home photos, music, videos, and backing up all your local data. It comes with a client that you install on every desktop or laptop that you want managed by the Home Server.

Once installed, the computer will show up on the Home Server console. The backup status of the computers are tracked:

image

As you can see, the first computer is currently off line, and hasn’t been backed up in 21 days and so the network status is set to critical. On my day to day computer, this status is reflected in a status tray application.

image

All this is great, and once the first computer comes back online it should be backed up to the Home Server automatically.

Backing up the Home Server

To back up the Home Server itself, I chose to use Carbonite’s online backup system. This will backup the Home Server data onto a "trusted" repository in the Internet cloud.

Normally, I would choose Mozy, because with Carbonite I’m unable to back ALL the files on the system. System files are excluded with Carbonite. However, Home Server partitions the backup data nicely, I have the original install disks, and I don’t plan to use the Home Server for anything more than backing up data so this is not a problem. If the Home Server crashes, I should be able to restore the server and reinstall everything from Carbonite without much trouble.

Final Solution

The final backup solution looks like this:

 

image

My Setup

I haven’t been blogging much… Go figure… My side business took off recently, but frankly, I’d rather be doing other things. :)

Anyways, somebody asked me about my setup at home. In short, Viiv Quad system from HP, 10k rpm drive, 2-22 inch screens, and a laptop off to the side. Here are some pics using my girlfriend’s new camera.

Laters… maybe.

Home Setup #1

My dual 22″ monitors, Logitech Wave keyboard, skype and landline enabled phone, AT&T U-Verse cable box, and XM radio off to the side. Laptop on the near side.

Home Setup #2

View from the other side, including now-archaic looking smartphone compared to the iPhone :). Ozarka did not pay me, I swear.

Home Setup #3

View from living room, diploma on back wall, printer, fish tank and sleeping cat. Funky erg chair. I’m going to put a fancy whiteboard behind that desk someday…

Foldershare is a useful tool for synchronizing, sharing, and transferring files… but… it only works when you’re logged in. To have it work when you log out, you’ll have to turn it into a service.

First, grab Foldershare. Note that they had some problems over the weekend, but that seems to be over with.

Next, follow the instructions here.

Older Posts »