The diary of a .NET Developer, working on an unlaunched startup project. Also, I live and work in Southern Oregon.

Sunday, September 20, 2009

Where have I been?

I've been busy.

I've successfully switched to Mac, my iPhone App is done, and I'm now developing in Python and Django for web. I also managed to build a complex web service on the Google App Engine (for my iphone app).

I am setting up http://www.benford.name as my personal website and will start hosting my blog over there.

Well, that's all I have to report.






Tuesday, April 21, 2009

I've been hard at work groking the iPhone SDK. I became hungup on implementing my photo browser. It's using a UIScrollView with a few "advanced" things happening on top.

It's been fun and a challenge to learn "yet another framework". My blogging should stay pretty sparse until my brain has soaked up enough info.

Saturday, April 4, 2009

Unplugging from the borg

I feel like my life as a .NET programmer could be coming to an end. Over the next year I probably won't be starting my own new projects in .NET.

I can't tell if I just get bored of a "stack" every three years or I am truly wanting to switch again for a "better" way. Back in 2005, I felt isolated using LAMP and yearned for the apparent community of .NET. Four years later, I'm tired of the culture of .NET and the type of apps that get built. The breaking point has been the newly found group of soggy programmers (which are mostly non-microsoft people).

All of the sudden I find myself seriously playing with the idea of building a iPhone app and using google app engine (python) for the server side. I'm still in research mode, but of all my options, this is what want to do most.

In all fairness, I wanted to make an iPhone since the day the SDK was released. I even bought a mac mini about 7 months ago.

I'm plodding along each day wondering what I'll do next. I have spent the last three weeks on my mac mini and I'm loving the change of scenery (from working on windows).

Wednesday, March 25, 2009

Website Finished and What's Next?

Website Finished
Great news! The website I have been working on for the past 6 months is finished enough to go live. So where is it? It's sitting on the server waiting for official content from my business partner.

So, it's done but not live yet.

What's Next?
I started reading (and coding) through this book: Beginning iPhone Development with great success. I'm half way through in 2 days.

I do have an iPhone app in mind, but I'm not sure I can build it as easily as I think. I promised myself a two weeks to go through that book and I'll see how I feel at that point.

If I do decide to go for it, I'll also be building a server component using Google App Engine.

My alternative is to try for some freelance work to get some income going. I'll keep you posted on both the real launch and my next phase in project dev.


Saturday, March 7, 2009

Crunch Time

It's crunch time on my project. I finally have list of things to finish and also did a pretty good job of estimating each task. Entering this into fogbugz gives me a launch date of Marth 14th.

I'm working hard to get this done.

I expect just to have the site up and running to see if any interest is out there. It's not perfect and their is plenty of parts that I would like to make better, but 've spent a lot longer than I wanted to on this project so far.

Particularly, the UI is going to need some improvement, but I'm hoping it will do for now.

See you on the other side!

Wednesday, February 25, 2009

Lost Developer Time

I started adopting NHibernate on my current .NET project. In other words I've outgrown Linq-to-Sql.

I have been crawling through many blogs looking for a little advice on testing nhibernate mappings and implementing the Repository pattern etc, and it dawned upon me:

All the helpful blog posts and articles about NHibernate were written between 2005 and 2007.

Am I really that late to the game? The answer is of course, YES!

I took a brief look at NHibernate back in early 2006 but and I intentionally avoided it at all costs. Please understand: I used to work at a job where the only priority was is getting done fast (at the expense of quality). Being under constant pressure to finish projects fast, I naturally fell to using tools that supported this type of programming. The two things Microsoft has are Linq-to-Sql and Webforms.

These tools appear to make it life bearable,but over time you pay for it in the long run. You end up making crap code but launching it anyway, then having to deal with it while it runs in production.

Things are different now. I'm my own boss and I make all the rules. So, I declare the number one priority is quality.

I feel like this part of my development career is behind me and I'll try to avoid ever working under conditions where quality is ignored in such extreme ways.

I'm very curious to see how long I stay developing in Visual Studio Land. Although, my recent use of Resharper and NHibernate might change this attitude.

NOTE: I revised this post on 2/26/2009 at 1:33pm

Tuesday, February 24, 2009

I actually like Safari's font rendering over the "Windows Standard"

I downloaded Safari 4 Beta today. It looks like a native windows app to the point where they even changed the font rendering to use the windows style by default. I guess a lot of people complained.

I actually like the OSX style font rendering. Here is a comparison:

With OSX font style:

With Windows Standard font style:

I guess Apple is trying to make the windows users happy, but I still don't understand why everyone objected to the "nicer" fonts.

At least it is a configurable option:

Thursday, February 19, 2009

Thoughts on the SOLID and some goals

Wow, there has now been four podcasts regarding the SOLID principles and I enjoyed listening to them all. It was especially fun to here all the controversey. I was pleasantly surprised to here Uncle Bob was back on Hanselminutes.

Here is what I personally took away from the SOLID princples:
  • SOLID principles are all about decoupling your code.  
  • Decoupling your code helps you write good unit tests. 
  • Unit tests and (if you're up to it, TDD) are great ways to have quality software.  
All this has me thinking a lot about the quality of my code. (ie. testability, how decoupled it is etc) I'm am now trying to use the SOLID principles as a guideline to help me write better code.

This has been very enlightening and has pretty much changed the way I picture what good code should be.

Uncle Bob posted a Getting Started post on his blog. So here are my goals:
  • Focus on when I should be using SOLID in my own code.
  • Trying to make it up to Portland, OR for a PADNUG meeting
  • Practice, practice, practice and make a lot of mistakes.
I also am starting to read some of Robert Martin's books. I started with Clean Code, I hope to talk more about this topic later on.

Wednesday, February 18, 2009

How to follow high traffic twitter conversations

I have tried to follow a few high traffic twitterers and quickly had to stop.  I'm talking about people like @codinghorror, that update every five minutes.  Follow a few of these and your twitter page becomes overrun pretty quick.

To follow people like this, I subscribe to their updates via RSS feed, and view them in Google Reader.  




This works OK, but it's a little awkward to follow conversations.  I found a tip today from @shanselman that fixed this!

To follow @codinghorror's conversation, use search.twitter.com and search for their nickname,  and subscribe to that page!

For example:

and you can subscribe to this RSS
  

Now my Google Reader has a exact conversation stream.   It works perfectly!!


Sunday, February 15, 2009

.NET Developer Stereo Types

If I told a non-windows developer that I'm a .NET developer, I'm pretty sure they would label me as "Mort programmer" , even though they have no clue who Mort is.  

This disturbs me greatly.  How can I tell people I'm a .NET developer and not be ashamed for saying so?  

I can't just say, "Hey, I'm a .NET developer, but don't worry, I'm an Einstein, so please don't think I'm a Mort." They wouldn't know what I was talking about?  (Most likely they would think I was some kind of pompous ass)  

It doesn't help that I don't personally know any .NET programmers.  The programmers I do know are all non-windows developers.

I also agree with a lot of Alt.Netters that many of Microsoft's tools promtote bad software design.  (Specifically, code that is not testable and  hard to refactor.   )

I guess I can start adopting better tools (like NHibernate and MVC framework),  but this apparent stigma of being a .NET developer has pushed me to start seriously thinking about my choice to continue being a .NET developer.

I used to develop a lot of line-of-business apps and this is why I moved to .NET 3 years ago.  Over that past year, I have spent more time building public facing websites than anything else, and I'm not sure that ASP.NET is ideal tool for this.

Before doing anything rash, I'm trying to reach out to other .NET developers and get some perspective.  But in the mean time, I can't stop thinking that going back to my open source roots is looking more attractive.

Friday, February 13, 2009

Stackoverflow and SOLID Principles

I'm still shocked at how the entire Robert Martin (aka Uncle Bob) fiasco has turned out on the stackoverflow podcast.

And, I'm not sure this episode #41 has changed anything.

I've been programming for 6 years. With each new project I work on, I strive to improve my code just a little bit more than the previous project.

I'm not saying that I only write code that follows things like the SOLID principles. I'm saying that do try to think about ideas like this (and many other ideas) while I write my code.

Maybe I heard it incorrectly, but both Joel Spolsky and Jeff Atwood still seemed to think the SOLID principles were a waste of time.

I think this was more confusing than helpful to the programming community.

The idea that there is a set of engineering principles that I can incorporate into my code is invaluable to me.

Everyone that listened to the stackoverflow podcast #38 and #41 should at least listen to the hanselminutes episode with Bob Martin, and go read about the SOLID principles, and then just think about them next time you write some code.

Tuesday, February 10, 2009

Comparison<T> and IComparable<T> vs LINQ

Sorting Before LINQ:

  • Implement IComparable<T> so you can use the default sort.
  • Add a few Comparision<T> delegates so I could sort other ways
public class DrawDown : IComparable<T> : IComparable<T>
{
public static Comparison<DrawDown> DateComparison = delegate(DrawDown field1, DrawDown field2) { }
public static Comparison<DrawDown> ValueComparison = delegate(DrawDown field1, DrawDown field2) { }
public int CompareTo(DrawDown other) {}
}

And sort like this:

var list = new List<DrawDown>();
list.Sort();
//or
list.Sort(DrawDown.DateComparison);

Sorting with LINQ:

var list = new List<DrawDown>();
list.OrderBy(d=>d.Date);
//or
list.OrderBy(d=>d.Value);

Basically, I use LINQ more then anything else in the .NET framework.  It really does save hours of writing boring “sort” code.


NOTE: I am working on getting better syntax highlighting in my blog.  Live Writer  is not working out at all.

Wednesday, February 4, 2009

Char to Int vs String to Int

I spent way to much time staring at this code trying to figure this out:

int number = 10;
int firstDigit = Convert.ToInt32(number.ToString()[0]);
Assert.AreEqual(1,firstDigit) //fails: firstDigit == 49

I knew it was returning the Unicode value of 1, which is 49, but I was after the integer value.  Converting a char to an int always returns the Unicode value, not the integer value.  Converting a string returns the expected result.

int number = 10;
int firstDigit = Convert.ToInt32(number.ToString()[0].ToString()); //add an extra ToString()
Assert.AreEqual(1,firstDigit) //passes

Nothing too exciting, but I was stumped for about 15 minutes trying to figure this out.  I almost started looking for a atoi() function.



 

Tuesday, January 27, 2009

ASP.NET Ajax vs jQuery.ajax

I love jQuery but ASP.NET Ajax has some great features for calling your own webservices.  Using jQuery to call services is much simpler, and has less going on behind the scenes, but is harder to debug.  ASP.NET Ajax is creating a leaky abstraction for you, and along with that you get intellisense, helpful erorrs, and full visual studio debugging capabilities.

Calling ASP.NET Webservice with jQuery:

$.ajax({
type: "POST",
url: "PortfolioService.asmx/AddBenchmarkToCart",
data: '{portfolioId: "'+portfolioId+'", benchmarkId:"' + benchmarkId+ '", position:"'+position+'"}',
contentType: "application/json; charset=utf-8",
dataType: "json"});


Pros:
  • Simple code: not a lot of behind the scenes magic
  • Efficient: doesn’t load any extra javascript files
Cons:
  • Hard to debug: it either works or it doesn’t, you get no useful error messages
  • Six lines of code to copy/paste each time

Calling ASP.NET Webservice with ASP.NET Ajax:

<asp:ScriptManager ID="ScriptManager1" runat="server" >
<Services>
<asp:ServiceReference Path="~/Portfolio/PortfolioService.asmx" InlineScript="false" />
</Services>
</asp:ScriptManager>
PortfolioService.AddBenchmarkToCart(portfolioId, benchmarkId, position);
Pros:
  • Intellisense
  • Useful Error Messages
  • Fully functional visual studio debugging
Cons:
  • Less efficient: includes a small proxy javascript file for your webservice (which the client must download).

For more information on this, see this nice tutorial over on the asp.net site.

Javascript Class Definitions

Two ways to define a class in javascript.  

At first glance, I didn’t realize what was going on in the second example, but the code is just using JSON syntax to define the prototype.

The benefit of reading other people’s code is you always learn something new.

(I picked this up browsing through the jQuery source code.)

I placed the actual source code here so you can can see it in action.

This is the way I always defined classes:

    function Person2(name, age) {
this.name = name;
this.age = age;
}

Person2.prototype.HaveBirthday = function() {
this.age++;
}

Person2.prototype.GreetWorld = function() {
return "Hello World, my name is " + this.name + " and I am " + this.age + "years old";
}

A shorthand way using JSON syntax:

    Person.prototype = {
HaveBirthday: function() {
this.age++;
},

GreetWorld: function() {
return "Hello World, my name is " + this.name + " and I am " + this.age + "years old";
}
};

This makes a lot more sense when you realize you can even do this:

var ben3 = { 
age: 29,
name: "Ben",
GreetWorld: function() {
return "Hello World, my name is " + this.name + " and I am " + this.age + " years old"; },
HaveBirthday: function() { this.age++; }
};
 

Thursday, January 22, 2009

TDD and Private Methods: What an eye opener!

I’m continuing to practice TDD while creating a simple word search solver. I’m giving TDD a shot is because normally I don’t write testable code and find it difficult to create unit tests after getting so far into a project. This leads to little or no unit tests.

In my short time trying TDD, I’ve realized a couple things about my coding style. Although my code always works (ie. it performs the task at hand), it is full of interdependencies. This creates an environment that is pretty much impossible to write unit tests for. Any tests that I do write only cover large parts of the system, but they are not testing small units of my code—so they do not provide much value.

By sticking to TDD I’ve been forced to change this style in a drastic way!

Normally, this how my public facing code would look. The algorithm for SolveForWord would basically be hiding inside some private methods and fields of the PuzzleSolver class.

PuzzleSolver solver = new PuzzleSolver(wordSearchText);
PuzzleSolution solution = solver.SolveForWord(“dog”);
I could only test the method “SoveForWord”, which tells me nothing about how it was implemented.

With TDD, I did things much different. After a bit of “new thinking”, I created a PuzzleParser class that implements parsing and data manipulation, and left the PuzzleSolver class to perform only the solving algorithm. PuzzleSolver gets an instance to PuzzleParser in the constructor. Then I extracted an interface for PuzzleParser:

    public interface IPuzzleParser
{
string GetLetterFromCoordinate(int row, int col);
string GetLettersFromCoordinate(int row, int col, ParseDirection direction);
int MaxCol { get; set; }
int MaxRow { get; set; }
}

This is of course the DependencyInjection pattern, and I finally get why this is so valuable! In this case, I can mock the parser in a test:



            MockRepository mock = new MockRepository();

IPuzzleParser parser = mock.StrictMock<IPuzzleParser>();

PuzzleSolver solver = new PuzzleSolver(parser);


So it's certainly baby steps in the right direction, but mabye I'm starting to see the light!

Monday, January 19, 2009

My own personal version of a "Startup Company"

I'm currently working for a startup company.  I don't get paid and it's not going to make millions, so it's hard to be excited about the product.  But, I'm the sole creator and it's actually pretty cool, so it's a love/hate relationship.

Plus, their is always a chance that it will make a profit.

Obviously, their is more to a startup then a good idea.  Currently, I'm slaving away down-in-the-trenches, and this type of work is what is going to help this thing survive the first year.  

Since learning from mistakes is the best way to learn, I eagerly jumped at the opportunity be involved with this project.  I'll either succeed or gain another lesson from a failed project.

I'll post more about the product as soon as it's ready (more like as soon as I'm ready.)

Sunday, January 18, 2009

Testing private methods

I am writing a crossword word search puzzle solver for the purpose of practicing Test Driven Development.  Yep, I am only writing code after first writing a test. 

I started off with a very powerful method named SolveForWord:

   public class PuzzleSolver
{
public PuzzleSolution SolveForWord(string word)
}


Almost instantly, I had the urge to start writing private methods to help parse the puzzle into a private data-structure.   But since I’m doing TDD, I had to think about how to continue.  Since I can’t test private methods, how do I write that code? 



To be honest what I did next was find out how other people do in this situation.  After a bit of googling, I decided to try testing my private methods using reflection.  Then it hit me.  My attempt to test private methods was “test friction” right?  The PuzzleSolver class shouldn’t be doing any parsing!  By experiencing this “test friction” I changed my design. 



   public class PuzzleParser
{
public PuzzleParser(string text)
{
}
}


PuzzleSolver will use PuzzleParser to perform parsing and not actually perform parsing itself. Single Responsibility in action!



Note: I didn’t know how much code to include in my post, so I purposely left out most of it.

Create Syntax Highlighted code in Blogger using Live Writer

I found a Windows Live Writer plugin to do syntax highlighting of text.

You can install plugins by simply copying the dll to your plugin directory.

Here is a test:

    public class PuzzleSolver
{
private string[] rows;

public PuzzleSolver(string[] rows)
{
this.rows = rows;
}

public PuzzleSolution SolveForWord(string word)
{


}
}



Saturday, January 17, 2009

Test Driven Development is design

In Hanselminutes podcast #146, Scott Bellware talked about Test Driven Development being design, which I already sort of knew, but what I got out of the show is how TDD can really make a difference in my coding practices.

By practicing TDD, it's going to bring to light all sorts of "test friction". For example, the harder it is to setup tests, the harder TDD becomes. The difficulty I have in setting up tests my objects is a big reason I don't even attempt to practice TDD. Once I realized this, the idea that "test smell begets design smell begets code smell?" sort of made sense. I've got this horrible test smell staring me in the face and now I really want to do something about it.
How can I reduce test setup friction? Is single responsibility (part of SOLID) the answer? Will Structure Map help?

Scott Bellware finished the podcast with a suggestion to read the book TDD in Microsoft .NET by James Newkirk. I actually already own the book and immediately pulled it off the shelf and am re-reading it. ( I read it 2 years ago before I even knew what unit testing was.)

I'm researching this topic heavily and will post more when I find some answers.

Monday, January 5, 2009

Vista Sidebar Gadgets are HTML pages!




Yep, you heard me right, the vista sidebar gadgets are tiny html pages with images and JScript (aka javascript).  

Even the clock app is a simple background image with two clock hands as images.

They do have a gadget API which can rotate images. This is how they achieve the nice animation on the clock, for example.








You can browse the source code for every gadget that comes with Vista by going here:

C:\Program Files\Windows Sidebar\Gadgets\

 


I was amazed when I found this out!  For some reason I assumed they were fancy WPF apps.

If you're interested you can read more on msdn.

Vista Sleep Issues Solved




I finally found outhow to troubleshoot Vista sleep issues.  Specifically, how to tell what woke the computer.

By using "powercfg lastwake" on the command prompt, I could at least tell that it was a USB device.

A little peeking into Device Manager  and I noticed both my mouse and keyboard were allowed to wake the PC.  (Normally this is probably a good thing.)  I simply disabled that feature and my problem is fixed.