Uncategorized

OpenWest Conference

For the past several years, the Utah Open Source community has come together for the Utah Open Source Conference. This year, it has a different name as it grows and works to become a regional conference. Welcome to OpenWest Conference! This year, OpenWest is being held on the campus of Utah Valley University in Orem. It’s going on now through Saturday. In three days of great content you’ll hear about all sorts of Open Source goodness.

I will be speaking there too. My session, “Ooey GUI Web” is set for 11:00  11:00, in room SB276. This session will cover several Open Source web UI widgets including JQueryUI, Wijmo Open (the Open Source version of Component One‘s great Wijmo line), and JQuery DataTables. Come and find out how easy it is to add these great widgets to your web pages.


Why Kyro Beshay should shut up about “Metro”

Kyro Beshay (who ever he? is) should shutup. In a recent blog post, Kyro (I can’t use Mr. Beshay because I have no idea if Kyro is a man or a woman. A quick web search didn’t provide an answer, nor any background of qualifications on UI design), blasted Microsoft’s “Metro” UI in Windows 8 of running against millions of years of evolution of how the human eye sees things. The biggest complaint in the blog post is that the “Metro” UI is flat and doesn’t distinguish between things you can click on and those you can’t. But take a look at Kyro’s own blog. See that logo at the top? Can you click on it or not?

I’m not saying Microsoft hit a home run with “Metro”. I have several issues with it, but I am not a designer. However, “Metro” in Windows 8 is an almost exact copy of “Metro” in Windows Phone that has won several design awards. My biggest complaint about Kyro’s post is what I pointed out above regarding the logo. Before you start complaining about something other people or companies do, take a look at yourself first.  Oh, and back it up with qualifications.


Entity Framework Code First Basics

Entity Framework (EF) marked a big step forward for application developers, but early versions were met with complaints that many important features were missing. Many of those big issues were addressed in EF 2. And when Code First came along, pretty much all the big issues were gone.

This is part one in a series on EF Code First basics. I’ll cover working with a single table, one-to-one, one-to-many, and many-to-many relationships. The series came out of my needs to understand how to setup and work with EF. Just a heads-up. There is A LOT to EF that I won’t cover. I recommend Julia Lerman’s great book, “Programming Entity Framework Code First”.

To get started, I created Visual Studio Console project named EFLab. When I experiment with something, I always put Lab in the solution name. Next, I used NuGet to add EF to the project. Because I’m working with VS 2012, EF 5.0 was automatically selected for me. Now it’s time to create the entity. To make things easy for the example, I created a single .cs file called Entities. But, I renamed the class. I intend to put all the code needed to make EF work inside this class.

using System.Data.Entity;

namespace EFLab
{
    public class Person
    {
        public int Id { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
    }

    public class EFContext : DbContext
    {
        public DbSet<Person> People { get; set; }
    }
}

There are two classes here. The first, Person, defines the entity and maps to the actual table in the database. Note that at this point, the database does not exist. We’re using Code First, which will create the database for us.

The second class, EFContext, inherits from DbContext that is defined in System.Data.Entity. This class allows us to work with the database and will provide all the CRUD code. Let’s now see how to insert a new row into the table. Here’s the code from Main().

static void Main(string[] args)
{
       EFContext context = new EFContext();

        Person person = new Person();
        person.FirstName = "Bullwinkle";
        person.LastName = "Moose";

        context.People.Add(person);
        context.SaveChanges();
}

First, we get an instance of the context object, then create and populate the Person object and finally add the person to the People collection and save the changes. But, we’re not quite ready to run the code yet. We need to setup the database connection. Here’s the entry from app.config.

<connectionStrings>
  <add name="EFContext" providerName="System.Data.SqlClient"
       connectionString="Server=(local);Database=EFLab;Integrated Security=True;"/>
</connectionStrings>

Note the name of the connection, EFContext. This is the same name as our context object. If these two match EF will automatically wire everything up for us. Now it’s time to run the code. Remember, we haven’t done anything with SQL Server.

After the console screen closes, it’s time to look at SQL Server to see what happened. I created a new data connection in the Server Explorer in Visual Studio. The first thing you notice is that EF has created a new database named EFLab, as specified in the connection string. Drilling down further, you see that a table named People was created. Where did this name come from? It has nothing to do with the context. EF has pluralizing rules built in. Usually, it just adds an s to the name of the entity, but it also understands how to do things like add “es” for pluralization and that Person should not be Persons, but rather People. Right-click on the table and select “Show Table Definition”.

9-9-2012 1-00-13 PM

Each property of the entity has been used to create a column in the table. EF will recognize things like Id or PersonId to be the key field and automatically make it an identity and primary key column. But what about the data? Again, right-click on People in the Server Explorer, but this time select Show Table Data.

9-9-2012 1-07-06 PM

Entity Framework inserted the data, just as we asked.

Now, we have some additional questions. If we run the code again, will the database and table be recreated or will the new row simply be added to the existing table? What about Read, Update, Delete? What happens when you change the schema? Let’s find out!

First, let’s just rerun the code, then look at the table data again. We find that there are now two entries for Bullwinkle Moose, each with a different Id. So, the first question is answered. Entity Framework just adds the record without recreating the database. It also tells us that if we create the entities for an existing database, EF will just use what’s there.

Now, let’s read, edit, then save. We have two entries for Bullwinkle Moose. Let’s edit the second one to be Rocky Squirrel. We can use the id to find the row in the table. Here’s the modified code from Main().

static void Main(string[] args)
{
        EFContext context = new EFContext();

        Person person = new Person();
        person.FirstName = "Bullwinkle";
        person.LastName = "Moose";
        context.People.Add(person);
        context.SaveChanges();

        Person editPerson = context.People.Find(2);
        editPerson.FirstName = "Rocky";
        editPerson.LastName = "Squirrel";
        context.SaveChanges();
}

When you look at the data afterwards, you’ll see the changes

9-9-2012 1-20-36 PM

The requested row has been changed and because the insert code is still run, another Bullwinkle Moose row was added. Let’s delete that one, but we don’t want to add another row, so comment out or delete the insert, and edit code.

static void Main(string[] args)
{
    EFContext context = new EFContext();

    Person deletePerson = context.People.Find(3);
    context.People.Remove(deletePerson);
    context.SaveChanges();
}

Run this code and the row will be deleted. But before we modify the schema, let’s see how to read data if you don’t know the Id of the row. There are a couple of good ways to do this. Before we look at them, let’s see some things that you may be tempted to try, but don’t work.

Person person1 = context.People.Find(p => p.FirstName == "Bullwinkle");
Person person2 = context.People.Where(p => p.FirstName == "Bullwinkle");
Person person3 = context.People.FirstOrDefault(p => p.FirstName == "Rocky");

The first one won’t work because Find takes an ID, not a lambda expression. The next two won’t work for two reasons. First, People is a collection and the code specifies returning a Person. Even if you change it to List<Person> it won’t work for the second reason.. it’s a LINQ expression. Let’s look at a couple of options that will work

var people1 = context.People.Where(p => p.FirstName == "Bullwinkle");
var people2 = context.People.FirstOrDefault(p => p.FirstName == "Rocky");

Now we’ll get back something that will work. But it still isn’t a Person object. You can add .ToList() to the end of the right-hand side of the line and have a ready-made, populated list.

So, we’ve seen how to create a database, insert, read, update, and delete data. But what about schema changes? How are they handled. Let’s start with changing the schema in the code. We’ll simply add a new column to the entity.

public class Person
{
       public int Id { get; set; }
       public string FirstName { get; set; }
       public string LastName { get; set; }
       public string State { get; set; }
}

and modify Main() to insert a new row.

static void Main(string[] args)
{
        EFContext context = new EFContext();

        Person person = new Person();
        person.FirstName = "Peter";
        person.LastName = "Peachfuzz";
        person.State =
"MN";
        context.People.Add(person);
        context.SaveChanges();
}

When you run the code, you get an exception.

9-9-2012 1-49-22 PM

Code First Migrations is new to EF 5 and is explained clearly in the MSDN documentation. But there is another way to deal with this. You can make the change manually. So, not only will you need to add the table to the entity, you’ll have to manually add it to the table too. But, you have to do one other thing. Delete the file that EF uses to track the schema.

Open SQL Server Management Studio (SSMS) and drill down into EFLab and then Tables. You’ll see the table, dbo.__MigrationHistory under System Tables.

9-9-2012 2-04-46 PM

System Tables don’t show up in Visual Studio, which is why you need to use SSMS. Delete the file. Once you’ve made the manual changes, you can run your program and Peter Peachfuzz will be inserted.

Remember that I mentioned that EF uses Id or TableId as the key field. But what if you have an existing table that doesn’t follow these rules? The solution is to add an attribute to the key field. So, it would change our model.

public class Person 

    [Key]
    public int Identifier { get; set; } 
    public string FirstName { get; set; } 
    public string LastName { get; set; } 
}

If you have a compound key, you must specify each column, and the order it appears in the key.

public class Person 

    [Key]
    [Column(Order = 0)]
    public string FirstName { get; set; } 
   
    [Key]
    [Column(Order = 1)]
    public string LastName { get; set; } 
}

 

So, there you have it, the basics of working with Entity Framework. In part two of this series, we’ll look at one-to-many relationships.


Why you should move to Windows 8

Microsoft has a long history of good and bad versions of Windows. Released in 2001, Windows XP is still used on millions of computers around the world. It was a great release. But there has been bad, remember Windows Me? Yeah, unfortunately, I do too. And while Vista was not well received, I didn’t find it as bad as people said it was.

Today, we’re close to availability of another version. Will it be good or bad? My guess is it will not be well received, primarily because it is designed for touch devices, apparently leaving the desktop and laptop behind. However, I’ve been using test versions of Win8 for several months and rarely see the interface formerly called Metro. (I will call it “tiles” in this post as it seems Microsoft hasn’t quite figured out what to call it.)

One of the biggest complaints seems to be that the start menu was removed from the desktop. This is not quite true. The start menu simply has a new look. It’s the tiles. In Win7, if you press the Windows key, the start menu pops up. Guess what it does in Win8…yeah, goes to the tiles. Search does work a bit differently. But it’s still easy. Press Windows Q (think Query), then start typing.

I can tell you, Windows 8 is pretty solid and easy to use, even on a non-touch device. But, why should you move to Windows 8? I can think of a few reasons.

  • When people ask you about Win8, you’ll be able to speak from experience, rather than heresay. This adds to your credibility.
  • You will have customers buying new machines that will be pre-loaded with Windows 8. You should be testing to ensure your applications work properly (hint, they probably will).
  • If provide any type of desktop support, you will need to know how Windows 8 works.
  • Windows 8 is a paradigm change. ARM-based tablets will not have a desktop mode, which means if you want your apps to run on those devices, you’ll have to target WinRT, a new Windows runtime. Windows 8 is required to develop WinRT apps.
  • You’ll want to be ahead of the game for Win9.
  • I can’t tell you the number of developer forum posts I see that say something like “We’re moving from XP to Win7 and my app doesn’t work. Is technology x incompatable?” These problems almost always come down to either a UAC, using Program Files folder for data, or a virtualized registry issue. If the dev would have moved to Vista years ago, at least on his machine, and done 15 minutes of research on changes and what they mean, he would have been aware of the issues. Windows 8 will undoubtedly have some issues and I expect to see “We’re moving from XP to Win8 and my app doesn’t work.” (Along the same lines I often see, “Will technology x work on 64 bit systems.”)
  • You are providing a disservice to your customers if you haven’t tried Win8 and the only way to really try it out is to use it day-in and day-out.

So, get prepared now. Start making a list of what you need to really give Win8 a spin. If you are an MSDN subscriber, you’ll be able to download Win8 next week. For everyone else, it will be available in October. The upgrade cost is cheap. You really have nothing to lose by not trying it except your customers and your reputation.


TLCTC and RMTT slides

Last week I spoke at two different events. Friday I was in Minneapolis for the ComponentOne Tech Connection Live! Then on Saturday, I was in Denver for Rocky Mountain Tech Trifecta. Slides from my presentations, Software Gardening and Branches and Merges are Bears, Oh My! are now available at http://www.craigberntson.com/presentations.html. Thanks for attended the events.


New Job, New Adventures

On Thursday, November 3rd, I arrived at work at 3M and found a 1/2 hour meeting scheduled with my boss. The subject, “1 on 1 Job Priorities”. I got a bad feeling about it and immediately started looking at her calendar. She had several other 1/2 meetings that morning, all marked “private”. I knew the ax was going to fall. We’d been having layoffs every quarter for a couple of years. Sure enough, when I walked into her office at 10:30, HR was sitting there too. After 10 years at 3M, I was going to be unemployed. I did get a great separation package. Between that and savings, I could keep myself going for several months if need be, but my plan was to be working sooner rather than later.

Fast forward to today. I have accepted an offer from Black Diamond Equipment. I’m very excited about this prospect as they quickly moved to the top of my list as I went through the interview process there. I will be developing C# applications for internal use. My first day will be December 5.

So, what about Mojo Sofware Worx, the consulting company that I started? I’ll keep that for side work. I do have one project with it that I should soon be starting on. I’m just waiting for all the details on it.

So, from layoff to employed, one month and two days. There will be new challenges at the new job, but I’m excited about them. Sometimes we need to get out of our comfort zone to grow. After 10 years of comfort at 3M, it’s time for new growth.


Software Gardening Part 4: Light

This is part 4 in a series on Software Gardening. If you’re just jumping in, you can find Part 1 here.

Light is a critical part of growing any garden. For us as developers, light helps us see things in a new way or with newer technologies or methodologies. At the end of my last post, I said that we neelightd to take the responsibility to do our own learning. So, as developers, our light is Personal Development.

There are two types of skills we need to develop as professional developers. The first is technical. Since you are reading this post, you are already taking a step toward your technical development. Reading blogs is an excellent way to learn about new techniques and skills. Pick a few blogs to follow, set them up in an aggregator, and check them daily. Make a list of topics to follow up on later.

But there is other types of reading in the form of magazines and books. Some will say that hard copy is outdated in this internet age, but I find them invaluable learning tools. Some books give you a quick overview of a new technology while others dig deep into a single topic. Magazines have an advantage over a book in being able to quickly get information about new stuff out to you, but they lack the depth needed for deep understanding.

Podcasts are another excellent form of learning. There are dozens of podcasts that give you broad overviews. One advantage of a podcast is that you can listen to them while on your commute. A few minutes each day is all that you need to learn about something new.

The last place to get technical knowledge is from conferences, user groups, code camps, and training events. Do not overlook the importance of in-person events. The networks you establish will give you contacts when you are looking for your next gig or to find an expert to help solve a particularly nasty issue. Even a Code Camp, that is run by your local community will bring you great topics, friendships, and learning.

The second area of personal development is soft skills. As technologists, we often get caught up in the technology and overlook things like business acumen, public speaking, technical writing, and even things as simple as how to write a good email. It’s these skills that many employers value over our technical ability. But as technologists, we often don’t look to these skills. Whether it’s doing a presentation to our development team or writing an email to the boss’s boss’s boss about our current project, these skills are highly important.

If you don’t have one now, put together a list of topics for your personal study. Set aside some time every week or every day to learn something new. Oh, and remember, this is personal time. It’s your responsibility to keep your skills up to date, not your employer.


Book Review: Apprenticeship Patterns

I don’t know how I missed not posting a review of Apprenticsehip Patterns: Guidance for the Aspiring Software Craftsman by Dave H. Hoover and Adewale Oshineye (OReilly, 2010), but somehow I did. I read this book quite some time ago so this review will somewhat limited as the material is not fresh in my mind.

The book says it is targeted to the aspiring software craftsman, but I found it the book full of wisdom and good ideas for the most seasoned developer. The book uses the Manifesto for Software Craftsmanship as a basis on what skills you should develop and how you go about gaining those skills. The book is short, only about 140 pages and an easy read, but don’t think it’s something you can just breeze through. Along the way you will take many retrospectives of your own career, see new things you should be doing, and be reminded of concepts you had either forgotten or ignored.

Chapter One gives an overview of Software Craftsmanship. One paragraph lays out the theme for the book:

One of the lessons we’ve learned from the Agile development movement is that just telling people to do things doesn’t create lasting or sustainable change. When people you’ve advised encounter a situation that isn’t covered by the rules, they’re lost. However, if those same people have imbibed the values that underpin the rules, they can come up with new rules to fit any situation. Our goal here is not simply to hand people a rule book, but to give them the ability to create new practices for new contexts, which in turn drives the discipline of software development forward.

The authors then layout a path to move the reader from apprentice to journeyman to master and define an Apprenticeship Pattern as a pattern that “attempts to offer guidance to someone working with the craft model on the ways in which they can improve the progress of their career.”

The remainder of the book is laid out as patterns you can follow to grow and improve as a developer.

Chapter Two, Emptying the Cup, discusses learning your first language and how to move on to learn the second, third, and more. For example, you may have to unlearn something. If one language implements a specific construct one way, you may have to unlearn that and adopt a new way of doing something. Another pattern is Expose You Ignorance. You many be unfamiliar with the technology you are required to use. The solution is to show that you can learn it. Don’t be afraid to let people see you struggle, but showing that you can learn and overcome is important.

In Chapter Three, Walking the Long Road, the authors explain that you are responsible for your career, not your employer, your friends, or your family. You need to plan your own path and then provide the nurturing and sustain your own motivations. Sometimes you will end up in jobs that don’t seem to be taking you on the path you wanted. You then need to Stay in the Trenches and continue or take A Different Road.

The next set of patterns come in Chapter Four, Accurate Self-Assessment. This, to me, is the hardest part of the book to do. People, in general, tend to be hard on themselves and often cannot accurately give a self assessment. Sometimes you’ll find yourself the best developer on your team so to continue growing you need to Be the Worst. Take a new job where you are at the bottom of the group. You may need to find Mentors or Rub Elbows with others to learn new things and grow your network of knowledgeable Kindred Spirits to help you grow..

Perpetual Learning is the next set of patterns. When you want to learn something new, Practice, Practice, Practice. Create a Breakable Toy, some pet project that you can recreate in a new language as a way to learn. Record What You Learn and just as important, Share What You Learn and Learn How You Fail.

Now that you know what you need to do, it’s time to put the plan into action. Chapter Six is Construct Your Curriculum. Create a Reading List and Read Constantly. And just because you’re learning new languages and concepts doesn’t mean that you should give up the Familiar Tools. They often propel you to learn new techniques more quickly because you don’t struggle with the language, which allows you to concentrate on the new stuff.

So, that brings up the conclusion of the book. You then find out how to tell if you are a Master. Oh, I’m not going to give that away. You need to read the book yourself. I will say, go buy the book. Or, read it online for free. Then apply the concepts presented and you will become a better developer.


Converting code, is it a good idea?

I often see forum questions from people asking about converting code from one language to another. It’s often FoxPro to C#, FoxPro to VB, FoxPro to Java, or VB to C#. I don’t recommend converting from one language to another, especially when they are so different from each other, such as the FoxPro conversions.

Earlier this year, I had an assignment to convert C++ code to C#. Because the C++ routine was new and still under development by another team member, I decided to keep everything as close to the same as possible as I thought it would make C# changes easier when the C++ code changed. The program I had to convert took text in one proprietary format and converted it to another. The C++ code used lots of substring manipulations of each line.

But there are subtle problems that cause issues later. For example, while C# is zero-based, C++ claims to be, but isn’t fully zero based. When dealing with substrings, C# starts counting character at zero, while C++ starts at one. You can’t simply subtract one each time because you have to consider other factors such as length of the string, length of the substring, etc.

Well, the “off-by-one” errors have come back to bite me several times. I spent about four hours yesterday to fix one of these issues. I needed to verify that the incoming data was the correct format, what the C++ routine was doing at that point, what the possible side effects would be as a result of the change, compile, unit test, then integrate test the routine. This was four hours that I couldn’t spend on another, high priority project. And this was after the dev on the other team spent over a day trying to figure out where the error was happening.

The end result is that I have decided that I will never again simply convert. It’s always a better idea to understand the original code and rewrite in the second language. This will also allow you to take advantage of any constructs in the second language that don’t exist in the first.


Podcasts I listen to

Yesterday in my Software Gardening presentation at Utah Code Camp, I talked about things you can do to make you a better programmer and improve your knowledge and skills. One of those things is listening to podcasts. One attendee asked what podcasts I listen to. I couldn’t make a complete list at the time, and I commited to blog a list of them. So, here are the podcasts I currently have on my MP3 player:

  • .NET Rocks
  • Agile Toolkit
  • CodeCast
  • Community Megaphone Podcast
  • Deep Fried Bytes
  • Get-it Done Guy
  • Hanselminutes
  • Herding Code
  • Manager Tools
  • Mondays: What Sunday Threw Up
  • Polymorphic Podcast
  • Rookie Designer
  • RunAs Radio
  • Software Process and Measurement (SPAM) Cast
  • Spaghetti Code
  • The Digitial Marketers Quick and Dirty Tips for Growing Your Business with Digitial Tools
  • The Public Speakers Quick and Dirty Tips for Improving Your Communication Skills
  • The Thirsty Developer
  • This Week in Web Design

If you have a podcast that you think may be of interest to me, particulalry in the areas of software development and agile, let me know.


Copyright © 1996-2010 Developer.Blog();. All rights reserved.
iDream theme by Templates Next | Powered by WordPress