Monthly Archives: February 2012

Seriously, Don’t Be Afraid of Code

I am loosely following the ProjectTrek example in “Beginning Microsoft Visual Studio LightSwitch Development” to create a project tracker of my own. As I was learning about calculated fields, an epiphany hit. Here it is.

LightSwitch is a great tool for modeling and displaying data, but its real value exists in its ability to empower non-coders (like me) to use code to accomplish the things they want to do when code is needed. In fact, it may be a great way to start learning how to write code.

For example, I want to add calculated fields to add total hours and total costs for a project. I can’t point-and-click to make that happen, but LightSwitch makes it very easy. All I need to do is add a calculated field to the entity (using the Computed Property button) and then click the Edit Method link in the Properties Pane for the property I just added.

When I click that Edit Method link, LightSwitch adds a method to the code for me. All I have to do is add the calculation function. Below is the code for two calculated fields. The only part I had to write are highlighted.

I didn’t know how to write those lines, but finding help on the Web is pretty easy. Also notice that LightSwitch called all the appropriate methods it needed (the first five lines) and then set up my new method for me. This may seem simple for a seasoned coder, but it probably would have taken me days to figure it out.

Tagged , ,