Amadiere.com

Fourteen and a half crazy frog burpers

1st March 2010

4 Top Tips for portable ASP.NET MVC Apps

Filed under: ASP.NET, CSS, HTML, MVC — Tags: , , , — Alex Holt @ 10:22 pm

Loooong cat! :O

ASP.NET MVC is awesome (find out how awesome it is over dinner) and allows for some great applications to be made, quickly, while at the same time offering a high degree of maintainability over the code that is written. The danger with being able to do things too fast is that simple mistakes are sometimes made. These hopefully are nothing major, but can become an irritation at various points down the line. One of the things that occasionally gets left behind is the portability of code – and this can be a bit of a ‘damn I wish I’d done it like that to start with’ moment.

Below are a few hints that may (or may not) help you as you develop the next great slice of awesomeness.

Disclaimer: These tips are displayed as ASP.NET MVC tips, but in reality, some of them progress to general ASP.NET Websites and Applications – or just websites in general.

  1. Don’t Assume You Know Your Root
    Before I get started, let me give some background on this point. I have recently been doing some final tweaks to an otherwise great MVC application. However, one of the tweaks I did was to make sure that part of the system was securely done via HTTPS. When looking around the net, this appeared to be a lot trickier than I thought. After all, could all these people be wrong?:

    Basically, yes they can, but only because their articles are dated, not because they are fools (it should also be noted that although their articles may be dated, there are some good techniques and ideas in them, so worth a nosey). :) Bart Wullems does a good job of explaining the amazing simplicity of this new attribute that was added in MVC 2 Preview 2. I’m a little surprised as to how this maybe wasn’t given a little bit more publicity – its a useful tool that was sorely missing before. Behold, ye [RequiresHttps] attribute!

     [RequireHttps]
     public ActionResult Login()
     {
     return View();
     }

    This addition of SSL feather to my MVC Application’s bow was to prove too much for Visual Studio’s Cassini and I was forced onto my local IIS. This in itself wasn’t a great issue, but it highlighted some issues with the way the application had been developed. It had been assumed from the start that the application would live at the root of its own domain. This is true for the production version of the system and was for the large part true of the development system. When moving to IIS however, the project was set to run as a Virtual Directory – meaning the website root was no longer the same as the application root. Which lead me to trawl through the entire application tweaking things here and there, just to make it work no matter where it lived. Don’t assume you know were your application will live! It might be any number of little requirement changes that could cause you to have to rethink how you are building your application.

  2. Use ActionLinks for linking within your application
    Doing this will save you a bunch of time and is one of the core supported features of ASP.NET MVC, so why not use it when it’s so simple? There are so many good articles and posts on this, a great starting point is (as always) ScottGu’s, which part way down talks about Constructing Outgoing URLs from the Routing System

    <%=Html.ActionLink("View more details", new { Controller = "Products", Action = "Details", Id=42 })%>

  3. Url.Content for content that is URLs.
    Url.Content is to static content, what ActionLink is to your dynamic pages. If you have any Images, CSS, Script files or basically anything else that isn’t an MVC page, then this little beaut’ is for you! This allows you to negate any issues with website roots and application roots changing – without having to monitor and check any links!

    Before, you may simply have done:

    <img src="/lolcats/longcat.png" alt="To scale" />

    This would have worked until your application was moved from the webroot (Cassini) to a virtual directory (e.g. “/MVCApp” in IIS). If you do the following however, all is solved as it works out the URL and writes that out accordingly:

    <img src="<%=Url.Content("~/lolcats/longcat.png")%>" alt="To scale" />

    Would appear as the below, automagically:

    <img src="/MVCApp/lolcats/longcat.png" alt="To scale" />

  4. Relative links within your CSS
    This is something that isn’t specifically unique to MVC applications or ASP.NET in general. It’s more a good practice / make sure you are aware of guideline.
    When coding stylesheets, you’re often faced with wanted to add background-image’s to them. Without the server-side jiggery pokery that ASP.NET (and the like) allows, you are left with limited choices how to do this. But in reality, the solution is fairly simple. You need to fix two things: The location of your Images and the location of your CSS. It doesn’t really matter where they are, but just that they are fixed (or you have the patience to correct your links should you wish to restructure).

    Images from a CSS can be HTTP, absolute to the web-root or, as is awesome, relative to the CSS itself. This means that as long as all your styles are entirely located within your stylesheet’s and not intermingled with your code, you’re on to a winner. It doesn’t matter which page calls the CSS, whether it be your homepage or one that is 42 levels deep – the links are only ever relative to the CSS page (which you included via Url.Content, right, eh? yeah!?).

    In the following example, the CSS is located within a ‘Styles’ directory directly at the project root.

    .longCat
    {
     background-image: url('../lolcats/longcat.png');
    }

Hopefully these pointers will help someone else, if not, they will hopefully protect against my own stupidity and making similar mistakes again. Feel free to comment below if there are any more thoughts and portability ideas you think I could do with including.

14th February 2010

eBook Readers Thoughts (by a developer)

Filed under: Reviews — Tags: , , , — Alex Holt @ 10:26 pm

Amazon Kindle DXI’ve had a few discussions lately about eBook Readers with a number of people, with most people having a strong opinion either way. As a developer, a significant portion of my reading material is textbooks and other technical documents, but at the same time, this doesn’t stop me wanting to read the greatest book of our time.

In the blue corner, weighing in about 500g we have Mr Electronic!

  • You can carry hundreds, if not thousands of books around with you at any time.
  • Smaller and more compact than a single book in some instances.
  • Can provide it’s own light source and you don’t need to find a lamp.
  • You can change the font size for the book you are reading if it’s too small to comfortably read.
  • You can take notes without defacing it.

In the red corner, weighing in at a massively varying rate: Mr Paper Copy!

  • Has the “touch factor”. The intangible benefit of purchasing something solid every time you buy a book. Its smell, its feel and the excitement that can bring.
  • Significantly easier to skip to certain points in a book.
  • Harder to accidentally break or ruin.

I think the story of the book will go the way of the CD (and the Vinyl record before that). I think it is inevitable that in 10 years or so, as many people that have have MP3 players now, will have an electronic book reader then. But, in just the same way that people still buy CDs, I don’t think they will ever be able to stop making books as they offer a great deal that eBooks never will. So is now the time to start on the eReader bandwagon? Hmmm, I’d say not personally – at least, for my potential reading library it’s not.

You see, good as some of them are, eReaders are burden somewhat with a number technological problems they must tackle firstly. In general, eReaders can be broken into two categories: those with eInk & those without. Those with include the two heavy hitters of Amazon Kindle and the Sony Reader eBook, while two of the main other rivals would be a netbook (a standard laptop or PC would be ok, though less portable) and the Apple iPad (with the HP Slate coming soon it seems).

eInk is an absolutely fantastic technology which is very early in its lifespan and I imagine we haven’t seen the end of it and its children – nor will me for a number of years yet. eInk is significant because it gets around a problem that has plagued electronic devices for a long time: Battery Life. When used within eReaders, eInk only consumes battery power when the page is changed (or the display changes). This means that the device can hold its power for not just days, but weeks of usage! The other advantage of the eInk is that it causes around and about the same amount of eye strain as a standard book. Because the screen technology is not based on the intensely fast flickering of pixels, the screens appear to be paper and lack the issues of glare from other bright light sources. The article over on the manufacturers website, it works like:

The principal components of electronic ink are millions of tiny microcapsules, about the diameter of a human hair. In one incarnation, each microcapsule contains positively charged white particles and negatively charged black particles suspended in a clear fluid. When a negative electric field is applied, the white particles move to the top of the microcapsule to become visible to the reader. This makes the surface appear white at that location. At the same time, an opposite electric field pulls the black particles to the bottom of the microcapsules where they are hidden. By reversing this process, the black particles appear at the top of the capsule, which now makes the surface appear dark at that location.

Apple iPadFor about a year, another “Format War” raged between the ePub format and the standard PDF. While each format has it’s pro’s and con’s – the big thing that has become an issue is the failure of PDF to scale well with the eInk. While the Sony device does a better job, the Amazon Kindle plain old can’t be bothered to try and limits the text scalability and in some cases offers almost illegible text to it’s reader. When you way all this together, the eInk devices have a really big failing, and that is the displaying of Images and Diagrams. They just plain suck at offering zoom-able content. The quick amongst you may have realised that books also don’t offer this feature – however, this is generally less of an issue because the dimensions of the images on printed copies are within the publishers control. They can control what size their image is being viewed at, which is not true with the different sized eReader screens (the Kindle alone offers a 6″ and 9.7″ version). As a side note, as printed copies have a significantly higher DPI ratio, a magnifying class would aid in the instances that the text became too small to read on a diagram – this isn’t likely to be often true of the eReaders). This problem is where my issue with eReaders lies. I can’t read my copy of Code Complete on an eReader because I wouldn’t necessarily be able to see the diagrams that accompany the text – a potential disastrous flaw.

This problem is solved though! Along with the potential issue that eInk can only currently display grey-scale. Hurrah! The Apple iPad will allow you to zoom and otherwise get bigger versions of these diagrams and providing the document was prepared by a sane person who knows what they are doing, you’ll have absolutely no problem. Let’s all go buy an iPad! All hail Steve Jobs!… Not quite just yet, you see, they implemented a flaw. Battery life is back and although not crippling like the iPhone’s can be at times, 10 hours compared with longer than 10 days is a massive difference! The argument is that no one reads for 10 hours straight, maybe not, but people could easily use 10 hours of the device without having the chance to charge it.

A bonus however, is that with the iPad you get a plethora of other features (iPod, usable Internet, picture gallery, email, pretty much what you’d expect a low end PC to be able to achieve without too much hassle). Is this something you’d want – it would depend what you already have I guess.

So overall – what’s the bottom line? Well, I guess that the market doesn’t have a great product at the moment. If you are going to read mainly novels and you would benefit from being able to carry around a number of books around with you rather than just one or two (frequent long train journeys or other travelling), then maybe the Amazon Kindle or Sony Reader would be a great choice. However, if you prefer a device that is capable of displaying images and photographs in full colour and to the detail that they were intended, as well as offering the benefit of other multimedia functions, then the Apple iPad, HP Slate (when it arrives) or just a standard netbook (if you can cope with the discomfort and less than ideal user experience) would be the choices for you.

12th February 2010

The Biggest Bits Are The Little Bits

Filed under: Human Factors, Usability — Tags: , , — Alex Holt @ 9:56 pm

There is the excellently accurate sentence attributed to Tom Cargill that goes:

The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.

This (fairly humorous) statement is a dig at all those projects that are developed and that overrun, but with a more than significant amount of truth in it. There can be a number of reasons why the project may not appear on time. Often, it’s because someone is trying really hard to avoid accepting the fact that the Project Triangle exists for their solution. The triangle states that there are always three options: Do it Fast, Do it Cheap & Do it Good – but of the three options, you can only have two. You as project manager have to negotiate with your stakeholders, which of the three are the two most important ones – because there is flying-pig chance that you’ll be able to get all three of them. They aren’t mutually exclusive – but achieving all three is certainly something that is seldom heard of for a project.

I believe these two things are linked. I think that projects overrun because the project early on was “Do it fast & do it cheap”, but near the end and as people start to inspect the system, people (whether it be the Stakeholders, End users or development team) decide that they need to do it well at the sacrifice of doing it fast. This could be argued as bad project management – but in reality, it’s bad Stakeholders. I believe they were correct to concentrate on quality However, they were grossly wrong to have considered leaving it as the third priority in the first place – it should have always been first! Take your pick as to which of the other two is important to you, but unless your project is technically fantastic and the attention to detail is there – then you might not have bothered doing it at all!

Jeff Atwood has eluded to this in the past in response to comments that Stack Overflow would be an easy system to build. He implies that yes, while the functionality would be really simple to replicate, all the little details would be missing, all the little improvements for both technical speed boosts / efficiency savings and for ascetics and intuitiveness for the user. You can spend your time doing 90% of Stack Overflow in 1 week, but then you’ll spend the remaining 90% of time faffing with the little details that will make your site stand out.

These little things can totally ruin your project / website / company, if you do not spend the time bowing before them in homage. There are plenty of website’s out there which don’t do justice to their potential. Websites that for some reason, got to the 90% of the way into their project and implement 90% of the features and functions – but then were put off by the long hard slog of the home straight which is the last 90%. The details beat them into submission! I’m not saying you have to be a designer to produce a good looking site, (it helps and I’d recommend that people get someone on board who specialises in functional website UI design), but if you don’t set your sights too high, then patience and an understanding of CSS will normally do. If you spend this time sorting out all the little things (the font size, the position of your error messages, your link positioning etc), your project will find its bounce-rate significantly reduced (a good thing!) and the general happiness of frequent users will be improved as they don’t have to work as hard to get the same amount of work done as your system is more intuitive.

Strive for perfection, excellence will be tolerated. If you are passionate about your project and you feel that you want to produce the best “whatever” in the world – then make sure you spend your time on the details! It’s sometimes a long hard slog, but it is invariably worth it in the end.

Older Posts »

Theme designed & built for Amadiere.com by Alex Holt. Powered by WordPress