RSS 2.0
# Wednesday, October 28, 2009

The tag line of the book is refactor your wetware, and after reading it, you will.

Andy Hunt explores how the brain works and try to point us (the readers) into ways to improve our use of it.

For me the first five parts; Introduction, Journey from novice to expert, This is your brain, Get in your right mind and Debug your brain; is where I found the book most useful. This is not to say that the last four parts weren’t interesting, but for whatever the reason I took some effort on my part to concentrate and finish them.

The book had several a-ha moments. The Dreyfus model was specially interesting and the idea of carry around a pad to write any idea you may have has serve me well so far. (Note: My journalism teachers all insisted that we always carry a pad to take notes and make observations, but I never extended the practice as a developer.)

If you are into continuous improvement this is a book that you should read. I’m sure you will find some or all of it useful.

kick it on DotNetKicks.com Wednesday, October 28, 2009 4:31:00 AM (Eastern Standard Time, UTC-05:00) by Hernan Garcia #    Comments [0] - Trackback
Books
# Sunday, October 25, 2009

I got my tickets the first week the conference was announced, not really knowing what to expect but exited on the opportunity to learn new things and talk to people that work in other languages/technologies beside the .net world.

Once the sessions were announced my excitement decreased a little bit.

Friday morning was miserable in the weather department, so going to the conference was a nice proposition. I print my ticket, pack my laptop into the bag and took the TTC. I arrive a little after 8:00, the registration process was fast and everything was really well organized. There was coffee, water and muffins in the breakfast area. Good vibes in the air and a general feeling of excitement in the public. I crossed path with some faces I know from other similar gatherings while getting my second cup of java of the day.

After entering the auditorium Joel Spolsky addressed the audience with a key note about designing software products. He talk about how to make good products, the constant struggle between simplicity and features and how to achieve a balance. It was a vey interesting keynote.

The first session was on Asp.Net MVC, Joe DeVilla and Barry Gervin give us a good overview. Nothing knew to learn for me, but the presentation was good, and a lot of the developers in the audience weren’t .net developers.

After each brake, the conference resumed with some video from FogCreek, short but good, presenting some aspects of FogCreek or software development in general.

The other session I enjoyed and the one that justified the ticket price was the one by Greg Wilson. He is not just an excellent presenter but he also has something to say. He talked about doing scientific analysis of development methodologies and use real data to make decisions on what practices are really beneficial to our profession.

As a summary: one of five sessions + the keynote were relevant for me. For $99 it’s not bad value and I probably will go again next year if they decide to come back to T.O. Just hoping they rise the level of the sessions, maybe 2 at the 100 level, 2 at the 200 level and 1 at the 300 level.

kick it on DotNetKicks.com Sunday, October 25, 2009 8:14:02 PM (Eastern Standard Time, UTC-05:00) by Hernan Garcia #    Comments [0] - Trackback
General
# Thursday, October 15, 2009

Some time ago I heard about the intent of putting together a package manager for .net ala gems or pear. I wasn’t aware that this project was actually under way. The name of the project, Horn.

Please check the links in the project home page on how to get started with Horn. It’s very simple and actually works as promised. One thing you need to remember is that you will have to install a subversion client and a Git client for Horn to check out the source code from the projects you want to build.

I had two issues in my Win7 machine, where I tested. The first issue is related to Git really and not to Horn and/or Win7. Make sure that you have the path to your git.cmd into the PATH of your computer.

It’s usually %PROGRAMFILES%/Git/cmd, if you don’t when trying to do a horn –install on a project using Git, Windsor (the Ioc container used by Horn) will throw an exception.

The other issue seems to be a concurrency issue when trying to read a Temp file. Not sure how this files is been created just yet. This happens while trying to build complex projects like MvcContrib. Re-issuing the install command will “resume” the build. It took me three attempts to build MvcContrib.

Even with this issue (that may not be a Horn issue at all) I think that this is a very important project for the .Net community. It makes building this complex projects with all the dependencies a routine task. You don’t have to spend hours tracking down the project, the source code and pray that everything builds and works well together.

kick it on DotNetKicks.com Thursday, October 15, 2009 9:19:19 PM (Eastern Standard Time, UTC-05:00) by Hernan Garcia #    Comments [0] - Trackback
Frameworks | Programming | Tools
# Thursday, October 01, 2009

The other day at the office my boss took a look at our configuration files and he expressed his concern about breaking DRY with all the ConnectionStrings. One for Ado.Net, one for NHibernate, one for our caching db and another for Log4Net. Not only that but they are all over the place in the file, not all together.

On top of that,, some of those are the same, so changing a username or a password means changing them all over. Of course he was right.

NHibernate solution

For NHibernate I just use the connection.connection_string_name property instead of the connection.connection_string. This points to a connection string defined in that section of the configuration file with the provided name.

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
	<session-factory>
		<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
		<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
		<property name="connection.connection_string_name">ConnectionString</property>
		<property name="show_sql">true</property>
		<property name="use_proxy_validator">false</property>
	        <mapping assembly="ACME.Model"/>
	</session-factory>
</hibernate-configuration>

Log4Net solution

For Log4Net was not so easy. I found references to a patch that provides similar functionality to the one observed in NHibernate and references to that patch been applied to the latest release, but It doesn’t seem to be there.

So the solution I came with is to extend the default AdoNetAppender and in the constructor of the new class try to read the connection string from the configuration file, the only problem with this approach is that I’m hard coding the expected name of an AppSetting that will contain the name of the connection string.

Note: Utils.GetAppSetting and Utils.GetConnectionString are utility methods that I use to read from the configuration files.

using log4net.Appender;
namespace ACME.Logging
{
	public class CustomAdoNetAppender : AdoNetAppender
	{
		public CustomAdoNetAppender()
		{
			var stringKey = Utils.GetAppSetting("Log4NetConnectionStringName");
			if (string.IsNullOrEmpty(stringKey)) return;
			var connectionString = Utils.GetConnectionString(stringKey);
			if (!string.IsNullOrEmpty(connectionString)) ConnectionString = connectionString;
		}
	}
}

In your configuration file you need to have and appSetting that look like this:

<add key="Log4NetConnectionStringName" value="ConnectionString"/>

Them you will need to tell Log4Net to use this appender for logging so in your log4net.config file you should do something like this:

<appender name="AdoNetAppender" type="ACME.Logging.CustomAdoAppender">

kick it on DotNetKicks.com Thursday, October 01, 2009 9:16:18 PM (Eastern Standard Time, UTC-05:00) by Hernan Garcia #    Comments [0] - Trackback
Programming
# Saturday, September 19, 2009

Hopefully gone are the days were you considered ok the use of single letter names for your variables or your arguments and you are giving informative names to all the artifacts in your code.

But what about generics? What about the <T> in them? Are you paying attention? More and more you will see that programmers are shying away from the single letter placeholder and are using more explanatory names. If you look at the code in FubuMvc you will see things like this.

public TFlashModel Load<TFlashModel>() where TFlashModel : class, new()

That is more informative than Load<T>.
I used to do the single letter naming for generics in my code, but I’m trying to avoid it as much as possible today. The same way I won’t tolerate bad names for my functions anymore. I still have a problem with the T in there. I was also doing that, but lately I have dropped the T altogether as well. I see the use of the T as a kind of Hungarian notation.

In the Lambdas department the single letter variables are all over the place.

var cities = citiesRepository.GetAll();
cities.Select(c => c.Name.Length > 10);

Why “c”? Why not say?

cities.Select(city => city.Name.Length > 10);

This is a simple example, where c may be sufficient since you are properly naming the collection (cities) but I still think there is something there, specially when you have longer expressions. And certainly don’t use x. Like in

cities.Select(x => x.Name.Length > 10);

What’s x? What do you think?

Why should you care?

Making your code readable will make your code better. When you have to think about the proper name for a variable or a method, you also have to think about what that method do and what that variable represents. You can catch possible errors or misconceptions just because the name is not right. It will make your methods shorter and will help you to make your methods do just “one thing and one thing only” (since is very difficult to fins a name for something that does to many things). Oh, by the way, just in case you didn’t get the memo, anything with the word manager in it, is wrong.

Oh, I forgot, maybe the most important think of all. In a year from now when you need to do some maintenance in the code, you will be up and running in seconds and not pulling your hair of trying to understand what the hell you were thinking when you wrote that. And that, my friend, is a good thing.

kick it on DotNetKicks.com Saturday, September 19, 2009 7:02:24 PM (Eastern Standard Time, UTC-05:00) by Hernan Garcia #    Comments [0] - Trackback

# Thursday, September 10, 2009

Last week I was reading Alistair’s post about the Toronto Code Retreat. I was planning to attend but I had plane tickets for the same day so I miss the opportunity, what I regret. In that post Alistair refers to the book The Passionate Programmer by Chad Fowler. Next you know, I was ordering the book from Amazon.

On Saturday I pick it up from the post office and next day I was sitting in the backyard going through the pages while preparing a BBQ. The book reads fast. Its divided in Five sections and each section consist of a series of very short chapters that, most of the time, are no more than two or three pages .

I found that I’m doing a lot of the things that Chad recommends and I identify myself with some of the situations he mentions in the book. I particularly enjoyed the section about marketing yourself something I’m not good at doing.

There are a few chapters that I market down to re-read later on, not because they are so deep that need a re-write, but mostly because are the ones that talk to my weakness and the stuff that I need to remind myself to work on to improve.

Sparkled along the book there are easies from some renowned programmers on how they build their careers. They make for an enjoyable and fun read, and provide a break from the more “to the point” writing that Chad uses.

All in all a very enjoyable book that can provide some help on achieving exactly what the tag line for the book is “creating a remarkable career in software development”.

kick it on DotNetKicks.com Thursday, September 10, 2009 6:25:51 AM (Eastern Standard Time, UTC-05:00) by Hernan Garcia #    Comments [0] - Trackback
Books
I think this has been the longest hiatus since I started the blog. I have been busy with life, talking some time of, finishing tons of renovations at home and re-focusing my priorities from a development point of view.

I'm looking forward to renew the posting pretty soon with the usual frecuency of one to two post a week.

kick it on DotNetKicks.com Wednesday, September 09, 2009 11:13:43 PM (Eastern Standard Time, UTC-05:00) by Hernan Garcia #    Comments [0] - Trackback
General
# Friday, July 24, 2009

Gestalt, the new js library release by the MIX Online labs, takes a dependency on jQuery. They use it to do some Dom manipulation (locate tags, modify the Dom).

But what happens if you already use prototype.js in your application? For example RoR apps use prototype as their javascript library by default.
Both jQuery and Prototype define the dollar sign function $(), in jQuery this is the short form of actually the jQuery() function, since the libraries define this function in the global namespace, the latest library included in order from top to bottom will have precedence. So if you already have some code based upon the prototype definition of $() you will need to add jQuery before prototype or your libraries will brake.

The problem here is that Gestalt.js internally uses the short form (the $()) of jQuery in some places. So lets say you have this lines on top of your html file

<script language="javascript" src="../Lib/js/jquery.js" type="text/javascript"></script> 
<script language="javascript" src="../Lib/js/gestalt.js" type="text/javascript"></script> 
<script language="javascript" src="../Lib/js/prototype.js" type="text/javascript"></script> 	

Once the page load you will see an error like this in your js console/debugger:

$(".xaml") is null
http://localhost/Gestalt/Lib/js/gestalt.js
Line 319

Now, don’t panic the solution is very simple. You can open gestalt.js and replace all occurrences of $( with jQuery( or just get gestalt-proto.js from my Gestalt katas in Codeplex.

Technorati Tags: ,,,
kick it on DotNetKicks.com Thursday, July 23, 2009 11:00:43 PM (Eastern Standard Time, UTC-05:00) by Hernan Garcia #    Comments [0] - Trackback
Gestalt | Programming
# Wednesday, July 22, 2009

One new feature in the code editor is the ability to put sticky notes in the code while debugging. This sticky notes are actually attached to a given variable and you can see the actual value of it in the note (similar to using the watch window).

To make use of this sticky notes you just need to hover your mouse over a variable while on a debugging session and in the hint for the value of the variable you will see a little note icon.

ScreenShot005

Click in the icon and a sticky note will be placed near the location of the cursor, you can move this note around in VS so it doesn’t interfere with the code.

ScreenShot006

Notice that the value is null since the variable have not been evaluated yet. You can click in the button of the note to add a comment.

If we continue running the program we can see that the value have been updated. This variable will hold an array of squares, so the value is the Length of the array. Click in the plus sign and you can see each value, now each value has an sticky note icon besides it as well, clicking them will add this variables into the same sticky note.

ScreenShot007 ScreenShot008

The notes disappear once the debug session ends, but starting a new session will bring up all the notes back.

ScreenShot009

kick it on DotNetKicks.com Wednesday, July 22, 2009 4:41:25 PM (Eastern Standard Time, UTC-05:00) by Hernan Garcia #    Comments [1] - Trackback
Programming | Tools

A few hours ago I saw a Twit by @shanselman about having Ruby and Python scripts tags in your html pages. Clicking in the URL took me to http://visitmix.com/labs/gestalt/. I didn’t have to read much to understand the potential.
I’m myself an old web guy that still love to craft my JavaScript, Html and PHP code using a text editor. (My old time favourite was PSPad but lately I have been using e, a “clone” of TextMate for windows.

My team make fun of me since sometimes I even fire up e to fix some bug in C# files.

Don’t get me wrong, I love a good IDE and there is no way I can be as productive as I am writing C# without Visual Studio and add ins like R# or CodeRush. This post is not about IDE’s vs. Text editors anyway.

This post is about Gestalt. What is Gestalt? It’s a JavaScript library that act as a bootstrapped to load Silverlight and the DLR engine to interpret Ruby, Python and Xaml code embedded directly in your pages. (Ok, It doesn’t need to be embedded you can use linked files, what is the recommended way anyway.)

Of course, been the ADD person that I am, and such a geek, I needed to try it and see how long would take me to create a simple (emphasis on simple) video player.

11:25 PM Make a mental list of the requirements:

  1. Add a MediaElement that loads a video into a page (Xaml file linked, not inline).
  2. Add three html input buttons, one for play, one for pause and one for stop. (These are in the html page).
  3. Wire up the control of the MediaElement to the input buttons using python. (Since I’m learning the language).
  4. Have it working before midnight or go to bed.

11:26 PM

Download Gestalt and extract to my Development folder.

11:27 PM

Download the TextMate bundles provided by the Gestalt team and extract them into the Bundles folder of e (e can use TextMate bundles, if you don’t know what this bundles are, let’s put it this way, are like Resharper templates+macros+code snippets ).

11:28 PM

Create a folder under wwwroot (not a virtual directory), copy the Gestalt library and folders into it, and added a few more folders to keep the structure clean.
Start to download the interview from channel 9 program “The knowledge chamber” where Nishant Kothary and Joshua Allen present Gestalt.

11:30 PM

Launch e, create a new HTML (Gestalt) file. Check the menu to try to get a grasp on the bundles shortcuts. Type skelg+Tab and a basic html skeleton get’s generated for me.
Remove the link to the CSS file since I want be using any in this test.

11:32 PM

Open the “Designer” that the Gestalt team offers online, select a MediaElement and change the size, type something in the source and change AutoPlay to False.
Check the XAML, copy and paste inside e in a new Xaml file. (Syntax highlighter works as expected.)
Change the source to the absolute location of the video previously downloaded.
Save the file inside a Xaml subfolder.

11:35 PM

Create a link to the Xaml file in the html file (needed to consult the documentation, sample files).
Create three input elements, give them names and id’s (Id’s is the way you will access them from your code later on).

11:40 PM

Create a new Python file inside a python subfolder.
Create three methods (ClickPlay, ClickPause, ClickStop), to handle the onclick event on the input elements. (have to consult the documentation for the method signature).
Attach the this method to the proper event for each of the input elements, the code is very similar to the way that both prototype and JQuery do this.

11:43 PM

Launch the page in my browser, I got an error message that told me that I have to put the correct path for the gestalt.xap files (I remember reading about that in the Faq’s)
There is two ways to change the default path, I decided to open Gestalt.js and edit the file directly. You can also change the path programmatically.

11:44 PM

Try again, video playing, but not showing completed. Half of the frame is hidden. Open the html file adjust the size of the xml tag.
Refresh the browser. Success!

11:45 PM

Click in the buttons, nothing happens. Open FireBug Net tab to check for the traffic in the network, my python file is red. I guess IIS doesn’t know how to handle .py files. Open location in new tab, and sure enough, need to add a mime type or specify a handler.
I don’t want to do that. The good thing is that source code is text, so let’s change the name from hdplayer.py to hdplayer.py.txt.
Refresh the browser one more time. Click the button. Success!

11:47 PM

Right click on the video opens the Silverlight preferences dialog, like it should.

In no more than 21 minutes I was able to create a Silverlight player that is controlled via html controls without opening either Blend or VS. Also notice that I didn’t have to expose any properties as Scriptable, since Python code is running inside the same sandbox (I’m guessing here, but I’m pretty sure that I’m close enough :-)).

It took me longer to write this post that write the simple video player.
So, what are you saying, we don’t need blend and VS to write Silverlight applications? No, I’m not saying that. I’m pretty sure that there may be scenarios where writing you code in c# a deploy a XAP file are the way to go. But I see a lot of other scenarios where Gestalt is the way to go.

I may be do some more on top of it or something else, maybe investigate how difficult will be to implement drag and drop.

kick it on DotNetKicks.com Wednesday, July 22, 2009 12:00:47 AM (Eastern Standard Time, UTC-05:00) by Hernan Garcia #    Comments [0] - Trackback
Frameworks | Gestalt | Programming
Add The Dynamic Programmer Mippin widget
Navigation
Archive
<October 2009>
SunMonTueWedThuFriSat
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567
What I'm reading
Shelfari: Book reviews on your book blog
About the author/Disclaimer
Hernan Garcia I have been a software developer for the last 16 years or so.
I was a journalist before and I still consider myself one.
Besides baseball, programming is my other big passion.

Me on twitter. @TheProgrammer
Certified Scrum Master
© Copyright 2010
Hernan Garcia
Sign In
Statistics
Total Posts: 198
This Year: 16
This Month: 2
This Week: 1
Comments: 70
Themes
Pick a theme:
All Content © 2010, Hernan Garcia