Lazy Programming: The Three Virtues

Three Virtues

According to Larry Wall, the original author of the Perl
programming language, there are three great virtues of a programmer; Laziness, Impatience and Hubris

  1. Laziness: The quality that makes you go to great effort to
    reduce overall energy expenditure. It makes you write labor-saving
    programs that other people will find useful and document what you
    wrote so you don’t have to answer so many questions about it.
  2. Impatience: The anger you feel when the computer is being
    lazy. This makes you write programs that don’t just react to your
    needs, but actually anticipate them. Or at least pretend to.
  3. Hubris: The quality that makes you write (and maintain)
    programs that other people won’t want to say bad things about.

via Laziness Impatience Hubris.

ReSharper, getting started again

Years ago I used to use ReSharper on a daily basis. Then I left that company and didn’t have easy access to it any more. I missed it. I finally am at a place where I have a copy again. I am in the process of relearning how to use it. Here are a few linking that I found useful:

1. This is ReSharpers PDF file the most used shortcuts
2. Pluralsights “ReSharper Fundamentals” course
3. 24 + 3 ReSharper tips by Rapid Application Development blog
4. A Code Project article with more detailed examples
5. ReSharper documentation of the various functionality

Lazy Programming: Lowercase URLs

Just so everyone knows, when it comes to programming I prefer to be as lazy as possible. This means that when I got my most recent story to render all routes in lowercase I decided fixing the Routing manually was way too much work. I spent some time on Google and discovered that the built-in lowercase functionality that is built into MVC 4 is broken and its a pain to work around. Instead I am adding a nuget package called LowercaseRoutesMVC to the project. It automatically renders routes in lowercase.  Unfortunately my coworker spent a couple hours yesterday working on updating his code to work manually.

Update: Quote from my boss to the coworker who did it manually yesterday, “hard work sometimes pays off tomorrow but procrastination always pays off immediately.”

MVC Tips n Tricks: Using a button like an action link

I had the need to display a button that works like an action link to redirect the user to a page within an Area and didn’t want to wrap the whole thing in a form just to do the redirect.  Here is what I used.  It allows the same styling and behavior as a button but redirects directly like an action link.

<input type="Submit" 
       value="Add Persona" 
       class="btn btn-primary btn-lg" 
       onclick="location.href='@Url.Action("Detail", "Persona", new { area = "ProfileInfo" })'" />

Web Dev: Using data-* attributes – Web developer guide | MDN

JavaScript Access

Reading those out in JavaScript is also very simple. You could use getAttribute() to read them but the standard defines a simpler way: a DOMStringMap you can read out via a dataset property:

var article = document.querySelector('#electriccars'),
data = article.dataset;

// data.columns -> "3"
// data.indexnumber -> "12314"
// data.parent -> "cars"

Each property is a string (even if you omit the quotes in the HTML) and can be read and written. In the above case setting article.dataset.columns = 5 would change that attribute.

via Using data-* attributes – Web developer guide | MDN.

RegEx: Validating Phone Numbers

I am horrible at writing regular expressions but, like any developer, when I need them I want a good one.  Today I needed one to validate North American phone numbers, that would allow for all different kinds of formatting by the users and also allow for extensions.

On the following blog post, by Chris Nanney, I finally found the perfect one: 


I also found this site that I used to validate that it worked as I expected:

I’ve been in the position of having to take an unnormalized database that had virtually no data validation or standardization in place, and migrating it to a normalized schema. I used regex to help me through the process.

This post will deal specifically with phone numbers. The data I was importing had many problems: First, there was no standard formatting—some numbers were stored (xxx) xxx-xxxx, some xxx-xxx-xxxx, some, etc. Second, there wasn’t a separate field for extensions—they were just tacked on the end by either ext., EXT, x, Ex, or some variation. If there were only 20 numbers or so you could just fix them by hand, but you need an automated process to deal with say, 15,000.
via Cleaning Phone Numbers with Regular Expressions : Code : Chris Nanney.