Friday, March 6, 2020

Deep Copy vs Shallow Copy

The past couple of days I have been working on creating a logging service to capture any changes that have been made to our pages. We had a logging service made for another part of our application, but this new portion wouldn't be able to use the old logger. First, the old section that was logging was coded pretty specific to that section of the app. There are a lot of reusable parts, like checking the two objects to see if there are differences, but pieces like adding the differences into a database were very specific. So, I started down adding a method to the AuditLogService that will allow any type of object to go into service and have it logged in the database.

I ran into a problem though. The specific page I was working on was designed to save over the old value instead of creating a new line. I'm not sure why it was programmed this way, but it is what I have to work with. I could redo this part of the program to add a new record in the database and add a flag to show the old record was no longer the correct record, but there was going to be a lot of places to change, and I had all the information I needed in my controller. The old data in the row and all the new data was ready for me to use. All I needed to do was pull what the data currently was on the server, remember data came back, transform and save the new data, and finally run my new service that would find and log all the differences. Should be easy!

The problems all started when my history object kept changing when I would update my new object. What was going on? As I investigated, I determined that the object I was trying to create to remember the history was just a copy of the original object (a shallow copy I would later learn). I tried two ways to copy into the history. First I did a straight copy:

Response originalResponse = responseControllers.GetResponse();
Response historicalResponse = originalResponse;

Exact same copy. And I should have know that. The second method I tried was to go back to the controller and get the object again.

Response originalResponse = responseControllers.GetResponse();
Response historicalResponse = responseControllers.GetResponse();

I did some investigating and I learned that indeed what I was doing was just a direct copy. I should have known, the simple answer is most likely the answer. So, how do you fix it? I had spent a while on this task, so I asked for a little help from my team lead. He mentioned I probably needed to serialize and then deserialize the object again in order to create a deep copy. Well, I created an extension:

    public static class ObjectExtension

    {

        public static T CreateDeepCopy(this T objectToCopy)

        {

            try

            {

                string jsonSerailizedObject = JsonConvert.SerializeObject(objectToCopy);



                return JsonConvert.DeserializeObject(jsonSerailizedObject);

            }

            catch (Exception e)

            {

                Console.WriteLine(e);

                throw;

            }

        }

    }

Now when I change my originalResponse (typing this I realized that original and historical could have been called something different, naming, that hardest part) the historicalReponse no longer changes! Perfect! I am now getting a deep copy, which is a copy of the object and all the references. And I made an extension that we could use again the application, I'm sure we will use it again, right?

I have a console program that I was experimenting with to try and get it to work here


"A true friend never gets in your way unless you happen to be going down." - Arnold H. Glasow

Thursday, December 27, 2018

Observer Pattern

I have been sitting on this blog for a while. I finished the chapter a while ago, but not sure exactly why I wasn't getting to writing the blog post. At one time I had a few blogs written so I could just post, then I got sick or something and fell behind. I am obviously not as prepared as I was at that time. I am not going to make any promises because, when it comes to blogging, I don't usually keep the promise to write once time a week. At this point I am once a month. Let's put it out there. I will write one blog a month.

Let's start (and finish) December with Observer Pattern. The thought behind the Observer Pattern is pretty simple, objects subscribe to events and when that event happens the object will get notified. It is very similar to a newspaper model (except we hope the Observer Pattern doesn't get the same fate of newspapers). The object is an observer, or subscriber, to the subject, or publisher. Each morning a paper gets published and sent to everyone that subscribes to it. One can unsubscribe from the newspaper at anytime in order to stop receiving the papers, or new people can subscribe at any time.

Each object should implement an interface subject and all observers should implement an observer interface. The concrete observer will register with a concrete subject to receive updates.The concrete subject will contain methods to add or remove subscribers.

When the observer is subscribed to the subject anytime a change in the subject happens the observer will be notified. If the observer gets tired of receiving the notifications it can unsubscribe. This pattern allows for loose coupling:

  • The only thing the subject knows about an observer is that it implements a certain interface
  • We can add new observers at any time
  • We never need to modify the subject to add new types of observers
  • We can reuse subjects or observers independently of each other
  • Changes to either the subject or an observer will not affect the other

Loosely coupling allows for a pretty flexible design and will minimize the number of changes that we have to make if any changes need to make changes.

Different frameworks already have ways to do the Observer Pattern, in Java there is a built-in observable class in the java.util package. And C# you can use delegates and events. It will take a little research to find the correct way to implement the Observer Pattern in whatever you are using, or you can implement your own (probably not the most effective way to do it) as I did in the link below:

Link to my example

Alright, next up? Good question, but I want to get Google Analytics or some sort of analytics on jorgfam.com. We will see what January brings.


"Maybe Christmas, the Grinch thought, doesn't come from a store." - Dr. Seuss

Wednesday, April 18, 2018

Strategy Pattern

I have been reading about design patterns. I realize that I often use them, but could not tell you what the are called or why the are good/bad. I decided to pick up a book, Head First Design Patterns, and look for other resources online as I read. I found a nice Pluralsight video that has many design patters included in the video called Design Patterns Library.

The first pattern in the book is the Strategy Pattern. This allows you to use a family of algorithms and the one that will be used is decided at run time. Each algorithm is encapsulated into the family and makes them interchangeable. This makes it beneficial when you have multiple classes that need an algorithm of the same type, such a speaking behavior, but not all classes implement the behavior in the same way.

Most animals have a form of speaking, dogs bark, cats meow, etc. So, if you take a class of Animal which contains a method for speaking then each class that extends animal will be able to speak. Now you have an issue, you will have to override the speak method for each class that inherits from Animal. That means a lot of extra code, and if the speak behavior ever needs to change you may miss changing one.

This is where the Strategy Pattern can come in handy. Now you have an interface for speaking Animal strategy, say ISpeaking. Then you have classes that extends the interface for different types of animal: dog, cat, etc. These classes will look something like:

public interface IAnimalType
{
   String Speak();
// other things animals need/do
}

public class Dog: IAnimalType
{
public String Speak() 
{
return "I am a dog, here me bark...woof!";
}
}

public class Cat: IAnimalType
{
public String Speak() 
{
  return "I am a cat, here me meow...if you can find me!";
}
}

We can then pull the strategies in an Animal context with code similar to:

public class Animal
{
IAnimalType iAnimalType;
// Other interfaces needed to make a true animal

public Animal(IAnimalType iAnimalType)
{
this.iAnimalType= iAnimalType;
// Your other animal interfaces go here
}

public void Speak()
{
Console.WriteLine(this.iAnimalType.Speak();
}
}

We can go to a employee now and return different request to the HRContext by selecting a strategy.

class Program
{
static void Main(string[] args)
{
Animal dog = new Animal(new DogType());
Animal cat = new Animal(new CatType());

Console.WriteLine("Here is a Dog");
dog.Speak();

Console.WriteLine("Here is a Cat");
cat.Speak();
}
}
If we were to run this program we would get out what each animal says. If we ever need to change what one type of animals speak behavior is, we just change it in one spot and don't need to worry about forgetting one.

Using this pattern also allows us to use an Open/Close principle, which is that the classes are open for extension but closed for modifications. We can add any type of animal and will not need to update our iAnimalType or Animal classes.


"You can't expect to hit the jackpot if you don't put a few nickels in the machine." - Flip Wilson

Wednesday, April 11, 2018

Sorting Objects in arrays

I finished a challenge on Free Code Camp called Inventory Update. The challenge asked you to update the first array (inventory) with either the array 2 (delivery) items if they don't exist in the inventory or update the inventory number if the item already exists in the inventory.

The arrays weren't objects with names, they came across with an integer and text. For example, my first item in array one was [10, "Bowling Ball"]. I probably could have converted each item in the array to an inventory item so then I would have [quantity: 10, name: "Bowling Ball"]. But with the all you can do with arrays I didn't find that necessary (although if this were a program for someone, it would have been beneficial to make the array into a more usable format instead of using array1[i][0].

Adding new items and updating the value of an item already in inventory seemed easy. I created a function to see if the array contained the inventory item and updated the amount. If it didn't contain it, push in the new array item.

function contains(obj) {
for (var i = 0; i < arr1.length; i++) {
if (arr1[i][1] === obj[1]) {
arr1[i][0] += obj[0];
return true;
}
}
arr1.push(obj);
return false;
}

Now came the more tricky part. The challenge asked you to alphabetize the items in the inventory. You know, make it easy to find an item in the list. I tried arr1.sort() but this seemed to just sort off the first item in the object of the array which was the quantity in the inventory. Great if I know the quantity of whatever I was looking up, but doesn't really make sense.

While reading, I found that you can create a function to sort your items in the array. This allows you to write a function to alphabetize based on the second member of my object, or the name of my inventory item.

I looked further and found a better way that didn't require me to write a function. Using String.prototype.localeCompare(). This compares the strings you have and returns a number that indicates whether the reference string comes before, after, or is the same as the other string provided. It then will sort the items for you.

This will allow for some options as well, such as case sensitivity, numeric, ignoring punctuation and more. It made the sorting pretty easy and able to use one line of code:

arr1.sort((a, b) => a[1].localeCompare(b[1]));

(if I had made each item in the array into an inventory object it would have been a.name and b.name instead of a[1] and b[1]).

I could see localeCompare coming in handy later in life.
"I have noticed that nothing I never said ever did me any harm." - Calvin Coolidge

Wednesday, April 4, 2018

Z-Index Values

Developing for different browsers can be difficult. Each browser can have it's own set of rules and coding for each browser can sure be difficult. For example when you use Flexbox you have to remember to add CSS display lines to make sure each browser will display correctly.

Recently, I was working on an informational window that will track with the question mark button. I make the window be positioned where it needed to be we ended up using NGX-Popper. Works great! You can resize the browser and the pop-up moves exactly where it needs to follow the button you pushed.

I checked how it looked in Chrome and everything was working great after adding a line in the CSS file:

.inside-popper {
z-index: 999;
}

I selected 999 just because it is a high number with the hope that a higher z-index would not be selected for another element. Looks great...until I pull it up in Internet Explorer.

When I opened this up in internet explorer, the pop-up was not the item at the front. Some elements of the pop-up were showing correctly but it seemed the background was clear and was allowing the elements behind to come to the front.

Here is a shot IE left and Chrome on the right:

I had the z-index in the CSS file but it wasn't recognizing it in IE, or so it appeared. After doing some research I found that it looks like IE generates a new stacking context for elements that are positioned. This means the z-index will have a value of 0. Z-index won't work as expected.

The work around I found was to wrap the popup in another div that had a class with a higher z-index then my pop-up:

.popper-wrap {
position: relative;
z-index: 1000;
}

.inside-popper {
z-index: 999;
}

Now IE looks the same as Chrome. Just another one of those things to watch out for when looking at the different browsers.


Wednesday, March 28, 2018

Javascript Variables

In C#, a method required you to declare the number of arguments and each arguments data type.If you declare a method requires an argument your code will not compile unless the argument is given each time the method is called. JavaScript works a little different.

JavaScript does not require you to specify the data types for each argument. It also does not perform any type of check on the arguments when the function is called. You can pass multiple arguments, or no arguments. If you declare an argument and the function receives nothing JavaScript will assume undefined for the missing arguments.

FreeCodeCamp had an algorithm where arguments were sent in different ways. For example, addTogether(2, 3) would return 5, just the sum of the two arguments passed.

 if(args.length == 2){
    if(typeof(args[0]) !== 'number' || typeof(args[1]) !=='number' ){
      return undefined;
      }
    return args[0]+args[1];
   }

But, what if you received something like addTogether(2)(3)? This confused me (and still kind of does), two sets of arguments? How do you deal with that?

I did some reading and found that it is a valid call to a function. Now I needed to figure out how to access that second variable.

It turns out that while looking at the first variable you can create another function that will look at the second variable.

if(args.length == 1){
     firstSet= args[0];
     
    if(typeof firstSet!=='number'){
        return undefined;
      }
   
    else{
       return function(secondSet){
         if(typeof secondSet !=='number'){
           return undefined;
           }
         else
            return firstSet+secondSet;
          };
      }
    }

Good to know, I'm just wondering when I will use this in real life...why would you send two sets of variables instead of just one set or an array?


"Sooner or later, those who win are those who think they can." - Paul Tournier


Wednesday, March 21, 2018

Smallest Common Multiple - using Euclid's method

I spent some time trying to figure out how I was going to solve the smallest common multiple. There are multiple ways to find this number. You can write down all the multiples and just look, you can use a grid/ladder method, prime factorization, or Euclid's method (the method I selected). If you want to see each method you can go here and see the how to accomplish through the different methods.

I decided to try and use Euclid's method. Math is used to find the greatest common divisor which is then used to find the least common multiple. Euclid's method requires you to perform the same calculation multiple times until you have a remainder of zero. You could do a while statement that looks at the remainder and stops when the remainder is zero. I also looked at a different way to do this, using recursion.

I learned about recursion a while back and figured I would give it a try here. I had a definite stopping point and needed to run the same calculations over until I got a certain number. It took me a few tries at getting the recursion to work (knowing what to put where), but I eventually landed on the below code:

function euclid(high, low) {
if(low === 0) {
return high;
} else {
return euclid(low, high%low);
}
}

I call the function and pass it the first number in an array as the high number and the second number as the low number. It then goes into the function to see that low is not at zero so it calls itself with the low number as high and the remainder of high divided by low (you use modulus to return only the remainder as the new low number. Once the modulus returns a zero, return the high number.

Euclid's method then takes the product of the first original two numbers and divides it by the number returned from our Euclid function. This will give you the smallest common multiple for the two original numbers.


"Laziness may appear attractive, but work gives satisfaction." - Anne Frank

Friday, March 16, 2018

Key Value Pair Statements - Better for the eyes, but better performance?

There have been two challenges on Free Code Camp now that I went down the road of using if statements. It started getting ugly with all those if and else if statements. You could use a case statement for each of the if statements, the case statement could possibly be easier to read and possibly have a faster performance.

Below is an example for possible DNA strings:

function pairElement(str) {
var myArray = str.split('');
var returnArray = [];
for (st in str) {
if(myArray[st] == 'G') {
returnArray.push([myArray[st], 'C']);
}
else if(myArray[st] == 'C') {
returnArray.push([myArray[st], 'G']);
}
else if(myArray[st] == 'A') {
returnArray.push([myArray[st], 'T']);
}
else {
returnArray.push([myArray[st], 'A']);
}
}

But then I got thinking, what if there were a dictionary or map that would allow someone to look up the index and see what the value output is for the item. I believe I had seen something like that before so I started searching. Turns out a map is exactly what I needed.

This technique allows me to create a map, or a key value pair, that will let me look up the value I am looking up and see it's matching string. Your first key value set G: 'C' will look up anytime your key is G it will output C.

By splitting the input string by their characters, one you are then able to use that item as the lookup for your key and return the value you need.

function pairElement(str) {
  var pairMap = {G:'C', C:'G', A:'T', T:'A'};
  var myArray = str.split('');
  
  for(var st in str) {
    myArray[st] = [myArray[st], pairMap[myArray[st]]];
  }
  
  
  return myArray;
}

The code is much easier to read and I am guessing it will have better performance as it doesn't have to check each if/else if statements.

"Nothing is work unless you'd rather be doing something else." - George Halas

Wednesday, March 14, 2018

FreeCodeCamp intermediate algorithms

I recently started FreeCodeCamp. Okay, not recently. I have been taking my time completing the challenges and tasks, but it has been pretty good. I enjoy learning the JavaScript and I am hoping I begin understanding everything more. I will be honest, I have been going slow because I am coding all day at work using Angular. Angular is great and very challenging, so why do I continue doing FreeCodeCamp?

Perhaps I feel that it will give me a foundation on the background of Angular, after all Angular uses JavaScript, right? Maybe it will help with debugging? Plus, I started FreeCodeCamp before I got hired to my team that uses Angular, and I'm not a quitter. I am to the Intermediate Algorithm Scripting and, as always, I am finding many different ways to complete the tasks they as you to do. I know that I am not the most efficient coder and there are probably much better ways to code the tasks.

I would like to go back and look at all of the tasks I have already done to see if there is something I could do better, but who knows when/if I will find time to do it. But let's start on the challenge called "Diff Two Arrays". The task seems easy enough, compare to arrays and return a new array that only contains objects that are in just one of the original arrays.

For example
arr1: [1,3,4,5]
arr2: [1,2.5,6]

My call to diffArray should return
return: [2,4,6]

My first time around I used a for statement to check each object in array1 to see if array2 included that object. Then I did the same for array2. Not the most efficient way, I know, but it worked and it was my original thought (I usually try to do the task without using the hints to see if I am able to complete the task on my own free will).

function diffArray(arr1, arr2) {
  
var newArr = [];

for(var i = 0; i < arr1.length; i++) {
   if (!arr2.includes(arr1[i])) {
     newArr.push(arr1[i]);
   }
}
  
  for(var t = 0; t < arr2.length; t++) {
   if (!arr1.includes(arr2[t])) {
     newArr.push(arr2[t]);
   }
  }
 return newArr;
}


It get's the job done. I know that I use arrow functions at work to pull data from a database, so I thought why wouldn't that work here? FreeCodeCamp mentions that you can use Array.prototype.filter() so I went to explore this in the JavaScript context. I'm going to be honest, it took me a bit to figure out how to use arr1.filter and .concat(arr2.filter). But in the end the code is much cleaner. (although it was unnerving when the FreeCodeCamp gave me a warning: " 'arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6')"


function diffArray(arr1, arr2) {
  
    return arr1
      .filter(ai => !arr2.includes(ai))
      .concat(
        arr2.filter(ai => !arr1.includes(ai))
      );
}

A much simpler solution. The filter takes from each array and will remove any object that is included in the second array. Then you use concat to add the filter from arr1 to the filter from arr2.

Sometimes our first response will get it working but sometimes we need to look a bit to find a better solution.

I will post some more of these, I have plenty of examples.


"Well done is better than well said." - Benjamin Franklin

Tuesday, October 31, 2017

Angular...a new language beginning

I have been doing a lot with Angular lately. I am really enjoying it. The entire time I should have been posting my progress, but no excuses, I haven't done it.

I will be posting my progress on Angular starting...soon :) . While you anxiously await I have started a real simple shopping tool (right now it is just the menu and navigation) that I will be updating. Don't worry, you can't buy anything and it won't take your money, yet. It can be found at https://myshoppingtool.firebaseapp.com/

Watch for more updates coming soon!


"They always say time changes things, but you actually have to change them yourself." - Andy Warhol

Tuesday, July 18, 2017

The failure to a win

My last post was about not being able to get some code to work. I declared it a failure. A failure that I should learn from. I am here, a couple weeks later, to say that I did learn something from the whole experience. I think most of us have seen the comic, or a similar comic as what I have below


That was exactly what happened except it wasn't a semi-colon. I was missing two words and an equal sign, Mode=TwoWay, where I was giving my binding information. In that particular XAML file, I was not using Mode=TwoWay in any other lines of code. However, I did use it on other pages. Why did I miss this one piece?

I came back to my solution a week later with new eyes. It took me about 15 minutes to see what my issues was. I add Mode=TwoWay and, presto!, my code is working as I expected. What was it about taking a step back from the code that helped me see what was missing?

The important lesson I feel I came away with, is that sometimes it is good to have a fresh set of eyes take a look at the code. In my case, it was taking a week off allowed me to get a fresh perspective, but we can't always do that at work. Yet, it can still be important to get a fresh set of eyes.

We look at code all day and may start missing pieces that would actually help solve our issues. Making sure we know when to ask for help and get another person looking at the code can be very beneficial.

Take that "week" off  and get fresh eyes to look at your code.

Here is a screen shot of my minimal viable product (I know the UI isn't great that will be coming...soonish). Now to see if I can get some services to the online movie providers (not looking so great, I have only been able to find an API to Plex Servers and the rest of the providers are either hidden really well, don't exist, or I am searching for the wrong things).

"It is better to know some of the questions than all of the answers." - James Thurber

Thursday, June 29, 2017

When frustration runs high...

Lately, I have been a little frustrated with the app I have been building in Xamarin.Forms. I am trying to use MVVM and I have most of it working, yeah! I just have one attribute that isn't not getting saved from the view. It is the only value that sits on a different SQLite table then all the rest. Do I blame it on that? Am I not calling the correct items in the view model?

Anyway, I have been stuck for more then a few days. And each day I don't make much, if any, progress. What happens? Frustration builds up. The first line where I say a little frustrated, that is a lie. I have been getting more frustrated. I shouldn't be getting too frustrated, I know that some frustration is good and will actually help you grow. I have been hearing a lot that failing is good and we learn from each failure. Is it time to chalk this one up to a failure?

Let's be honest, I got to the point the other night where I really just wanted to get the app to work. I did part of it in code behind (I know, I know, I won't be able to test it!) and got it partly working. You can now select the storage for the movie, but it won't save. I am missing something in the view model, but I already knew that. Using just the view model I was not able to get the data to populate or pull up the correct page.


Great! Now I can select the storage type and save my movie information! Bad news, it doesn't save the storage piece. I save the movie and come back into the detail and the storage type is missing. I need to go back and learn more about how MVVM is working. I have a cursory understanding, but not a full understanding. My app broke when I tried to add a second SQLite table into the mix. Take out the new table and you can have a list of movies, no problem. But, I also had an example of the one table scenario that used MVVM that I could model.

Maybe a failure now, but a failed project which I want to come back to after taking a step back and taking some time on another project to continue my learning, perhaps more about MVVM and a smaller project that implements it. Or, next time I am in the office I hope one of our MVVM experts are in the office as well and I can ask them. Would it be ok to use Skype to call someone up to ask help on a personal project?

The frustration may be good, but how much frustration is good? This is probably a question each person needs to ask themselves. It will be different for everyone.

"Nothing makes one feel so strong as a call for help." - Pope Paul VI

Thursday, May 18, 2017

Tracking Improvements

We all want to make improvements to ourselves. It is a long process that takes a lot of work and continuous effort towards our goals. Recently, I have been asking myself a few questions about my goals and the progress that I am making towards them.

The first question is, what are my goals? This is a question that I never have really asked before. I always knew that I wasn't going to be a truck driver like my dad, but beyond that I was always flying by the seat of my pants. It seemed to work out relatively well at first. I graduated high school and went to college. I can't even tell you how many different courses I took in college to find what I "wanted to be when I grew up." I decided finance. Well, I didn't love finance so I changed careers and now am a Software Engineer in Test. I like this job for the most part, but what is my end goal?

 I would say I want to become a full developer, this raises another question on is this a good long term goal for me? Great, I have an end goal for now. But what is the time frame for this goal? 1 year, 5 years, 10 years (better not be the later two). To reach this goal I have been setting intermediate goals. Here are a few of the goals I have been thinking of lately:

  • Build API
  • Build App
  • Deliver App to App stores
  • Speak at a conference

Great news! I have already completed the first one. I know that each of those goals have steps I need to take in order to reach them, I just need to figure them out. Not only do I need to figure the steps I need to take, but I also need to keep track of what I am doing to achieve these goals.

I recently saw part of how a person I look up to keeps track of his goals and self improvements. I look up to him as I believe he is very organized and able to keep up on everything, from sports (both U of U and BYU!) to family, and technology to his work. I can't even keep straight who the quarter back is for the U of U, how can I be expected to remember so many other things. I need to find a process that works for me that allows me to keep track of my daily activities, my goals (need to look at more and come up with a long term plan), the stuff I read, and other activities I feel will help me reach my goals.

The plan I saw was a checklist of sorts that had many different categories. I saw it and decided to try something similar in OneNote. I created different tabs, 5 year goal (nothing here yet), 1 year goal (becoming a dev and the ones you see above), monthly goals (did this for one month then forgot all about it), and daily goals. My daily goals are simple, like read a tech blog and learn some code. Really generic and I know in order to reach my long term goal of becoming a full dev I need to get more specific goals. That then shows my lack of what I don't know. What are the daily goals that will help me reach my long term goals? 

I have recently been teaching myself Xamarin.Forms using a course through Udemy and other online resources. I posted about my learning of MVVM the other day. Let's be honest, the MVVM "challenge" has been really hard. It is refactoring some code that I wrote early in the course. This let me to think that I don't know the basics as well as I maybe should. I had trouble separating out the responsibilities and seeing what each ViewModel would need in order to work correctly (it still isn't working, the app dies when I try to save and then won't start up again until I delete the SQLite Database that was created). I also took more then a few hints from the answers to find that in some parts I was doing well and had a good start and others I was totally wrong. 

I here that everyone uses Google to help with their work. But what goals do I need each day to reach my end goals and how do I keep track of them. There are some days where I am really good at keeping track of the daily goals. Other days, like Tuesday, I totally forget to even look at my goals and many of them don't get done. Questions arise such as how often should I look at the longer term goals and adjust them? I think this will be an iterative process. Find something that doesn't work and move to the next method. Keep trying, just like code, right? One day I will find something that works.

"Success is not a good teacher, failure makes you humble." - Shah Rukh Khan


Monday, May 15, 2017

Attempt at explaining MVVM

100 Days of Code is done. I may not be coding every day (last weekend we went to Moab and spend our days in Arches National Park and I didn't code) but I am still taking time to learn things. I am nearing the end of a Xamarin.Forms class on Udemy taught by Moshfegh Hamedani. I have one more activity left and then "Beyond the Basics" section to go. Then I will be a great Xamarin.Forms developer, right?

Well, I will have more tools to help me at least do some development in Xamarin.Forms. Today I did the section on MVVM (Model-View-View Model) pattern. I knew that using the code behind, like we did in all the examples, may not be the best way to code in XAML. We use MVVM in some of our applications at work and I thought this section would be great to learn for my own project and also so I can better understand what we are doing at work.

We hear that teaching is the best way to learn. And by we, I mean that I have heard that many times and again today in a video post on YouTube channel called Top 8 developer habits: Teaching - Fun Fun Function. Watching that today I thought, why not, let's blog about MVVM to help make sure I really understand what I learned.

What is the best way to describe MVVM? Well, it helps separate concerns of the front end and the back-end logic. This will ensure that the front end doesn't need to know the logic behind the data and the back end get's to do all the calculations and only give the data when it is asked for. Your view just needs to know what to pull and the model will just store the content.

Model: The model is a domain model that has both the behavior and the data. When you enter new data to be stored, the model will handle any transformations to new data and then store the data.

View: This is what the end user sees, so make it pretty. It isn't going to do much else.

View-Model: This is a layer of abstraction between the model and the views. The view model will make the calls to the model and send the data to the view to be shown. It also works the other way. It can take that data from the View and send it to the model to be stored. It will also know what to do when you change a setting or click a button (that doesn't change/add data to the model) in the View. It let's the model just know what to do with the data and the view to just continue looking pretty.

Quick lovely drawing that you probably won't be able to read:

Ok, why do you want to use MVVM? From what I have heard (I still need to do this on my own) it makes your code more testable. If you are using Xamarin.Forms and do all the code in the code behind, you can't test it. It is too tightly coupled with the XAML code and your tests won't be able to see what is happening in the UX layer. MVVM will also keep a separation of powers.

What could be a downside of MVVM? The amount of time it takes to implement MVVM may be overkill when you have a simple application or you never plan on doing testing (pretty sure this is unit tests, you will always want to have some sort of testing before you release to the wild). What is the size of the application it would be overkill? Good question, maybe a small to medium application would be fine using just code behind or using a model and view alone. Large projects you will probably want to use some framework that will allow for better testing.

That is probably an over simplification of the MVVM model, I think I am going to put some time on my team leads calendar tomorrow to discuss it with him and make sure I have it correct, isn't Ryan lucky?

"All great achievements require time." - Maya Angelou

Monday, April 17, 2017

Experience of #100DaysOfCode

I did a post at the beginning and now I am doing one at the end (I should have done in between, but I can't go back now) of 100 days of code. You think that 100 days is a long time, but it isn't even a third of the year and the time flew by! Some days coding was really difficult and I wasn't able to get a full hour of coding done while other days were much easier and I didn't feel that an hour of coding was enough (don't worry on those days I would spend more time coding). But do I feel that it was beneficial to take time out of each day to learn to code?

I often thought that it was too difficult to code everyday, after all, I do have things to do on the weekends, like go to a movie or something. Okay, honestly, I have a three year old and I can't tell you the last time I did that on a weekend. It still felt that coding everyday, including weekends was going to be too difficult, at first. I stuck to it and coded everyday (the 100 days of code does allow you to take a day off every now and again and I took advantage of that on a few occasions). I also felt that coding on Saturday and Sunday got easier as the end got closer, in fact I almost felt my day wasn't complete without doing some code for the day.

I also logged my progress every night in a log file on github and posted tweets to Twitter each night. Knowing that the people on Twitter would see my progress helped keep me motivated and a few times I actually got support from the Twitter community when I posted a question. This helped in knowing that, if I got stuck, there was someone out there in the Twitterverse that knows the answer and would be able to help. Keeping the log is very helpful and I will continue keeping some sort of log about my learning. Maybe I will keep the same format as the link above (that is what I used tonight) or maybe I will find something that will work better for me, only time will tell.

Did I learn anything while doing all this? The answer is yes, I did learn more then a few things. My first project was to learn how to build an API. I have a working API now, it is still on a local DB and hasn't been deployed, but it works! And I have made a number of Xamarin Cross-Platform apps using Xamarin.Forms, although I must admit, none of these were my own ideas and either came from Xamarin University, Pluralsight, or Udemy. Even though the mobile apps were not what I dreamed up, they did teach me so much about the different platforms available and XAML.

Why do these matter to me? The team I work on at work is over an API that was just released a few months ago. The team built it from ground up and I tested it. Often, the developers would talk about the context or the model or pretty much anything else and I was clueless. Now I hear what they are saying and am actually able to comprehend what it actually means. I have even fixed a few bugs on my own (I have been given the ability to do this, I didn't go rogue). It feels good to be able to pick up an item from our backlog and debug the issue AND actually find the root cause. Then when I send out that pull request, it feels good!

We have other tools at work that my team does not own. Some of those are written using XAML. Before 100 days of code I would have no idea how to debug anything in these products. In fact, I would avoid them at all cost, because I would not only waste my time looking for the issues, I would also waste another developers time having them walk me through the issue and how to fix it. Guess what! I have also been able to dive into these products and fix one bug in XAML code (we just got one product under our charter that is in XAML so I get the API and XAML now). This bug didn't require me going to another dev asking for hours of help to debug the issue.

Was it worth it? There is definitely something to coding every day. I was able to fix bugs before 100 days of code, but I didn't spend enough time learning for myself. 100 days of code made me think about a project or two of my own. These personal side projects kept me wanting to learn every day and kept my motivation high. The side benefits to my personal projects were that I learned better what my team and department do every day. So, yes I think it was worth coding every day for 100 days. Will I keep coding every day? I think that I will code a lot more often then I did before. I have formed new habits. I used to sit down and watch T.V. at night after everyone else had gone to bed. Now, I code. I enjoy the coding every night so much more then watching T.V. I think watching T.V. was a time filler for me. I wanted to learn how to code, but I didn't know where to start or what I should be doing. I had to actually think about what I was going to do and this was the best thing for me. I have a list of things that I need to do to continue learning to code and there is so much more to learn!

Would I do it again? That is the question. I do enjoy coding every night, but having to do it every night is rather difficult. Some nights you just don't want to do it and you have to tell yourself this is a pledge I made to myself and just do it. I may do it again in the future, we will see. For now, I will keep coding most nights and keep posting progress.

My Github Projects during 100 days of code:
100 days of code log
Xamarin Layouts
Xamarin "Essentials" Project
Movie API
Others at https://github.com/robertjorg/ (I know I need to clean them up, at least a little bit!)

Tell me and I forget. Teach me and I remember. Involve me and I learn. - Benjamin Franklin

Thursday, January 12, 2017

My next steps - My own project and 100 Days of Code

I finished the book Head First C#. What is the next step? I don't want to lose any of the information I was supposed to have learned. I have another book "Beginning C# Object-Oriented Programming." I look at the book every now and again and think I should start reading it. I probably will very soon. But, I also started thinking that there is no better way then to program my own personal project to help me feel invested in the programming and gain a benefit for something that I want to do.

I was invested in learning while going through the book, but maybe not as invested as I could have been. I took time to take notes while reading and really tried to understand what the exercises were trying to teach. I may have not always had an idea of where, outside of the written steps, would I be able to use the code. My new idea, using what I learned to create my own project. And what better way to stay accountable then posting on twitter every day on the progress I am making than making a commitment with 100 days of code.

I would be more invested in my own project as it is my idea and I would really like to see it come to life. Over the years I have had many ideas that I wanted an app that filled a "need" (or at least a need for me). Some of the ideas have apps out there and sometimes I have downloaded them (such as when I wanted an app that not only kept recipes, but made a grocery list for me). Others I have just looked at and said, I might try to create my own. The first one I wanted to try is a movie database.

I have a lot of movies and can always go look at the movies, but sometimes I want to be lazy and just pull out my phone to see what movies I have. I decided to jump in. Right away I jumped in and thought I need to do an API. Day 1 on my Twitter feed: Starting the API. The API would allow me to either later create a web, desktop, or phone app. I got going. I was reading through tutorials and watching videos, I felt I was learning and even got an API to send data back (although hardcoded data).



Learning is good. However, as I kept going, I was missing something. The tutorial of creating the API came with the database already created and the interactions between the API and the database were already created. I learned this quickly. The video I was watching talked about the data context, at work my co-workers talked about context on the API we are building as well, but I wasn't sure how the context was created (or really how the context interacted where it needed).

Time to take a step back. What is the context and how does it talk to the database? Luckily, I was talking to my co-worker, Peter, and he mentioned that Entity Framework is what we used at work. Eureka! Entity framework is the first step I should take. I found a Pluralsight course on Entity Framework 6. And this helped! Making sure Entity Framework got the correct relationships in the database took me a while. I think what I was missing was that each of the classes had to refer to each other. My "MoviesOwned" class had to have an object for "MovieTitles" and "MovieTitles" had to know about "MoviesOwned." Once I added all these relationships Entity Framework recognized my relationships.

public class MoviesOwned
    {
        public List MovieTitles { get; set; }

        public int MovieTitlesId { get; set; }
     }
public class MovieTitles
    {
        public MoviesOwned Movie { get; set; }

        public int MoviesOwnedId { get; set; }
    }

I was able to see that the relationships were in my model I used a tool called Entity Framework Power Tools. However, I use Visual Studio 2015 and this didn't show up in my list of Extensions and Updates. However, Julie Lerman had a great blog post on how to fix this issue.

I know know the context is the database context. It has an object from each of the classes so it knows what needs to be created. Entity Framework is then able to see what database objects you want and looks at the class of each of those objects to determine the structure of the database.The key is to have your context class inherit from DbContext (I believe this comes from Entity Framework)




After deployment, I see my database in SQLExpress (I need to figure out how to not use Express so I can host the database somewhere else).

The question becomes, is the structure really correct? And will I be able to write code that will communicate with the database correctly?

You can see daily progress on Twitter, @robertjorg.
You can see my daily log (called log.md) uploaded to GitHub: https://github.com/robertjorg/100-days-of-code/
I am being transparent and posting my work to Github. Maybe someone will see issues I am coding and plus I am blogging about what I am doing anyway. That link is: https://github.com/robertjorg/MovieDatabase

I hope to blog more because I should be coding every day and it is something I am choosing the project so I hope to be more attached to the code.

"The length of a file should be directly related to the endurance of the human bladder."
-Alfred Hithcock


Thursday, October 27, 2016

DevIntersection - Day 4

It was another day filled with learning and sessions. We started the day talking about a topic that everyone needs to pay attention to, Security. Cyber security needs to be our number own priority and it can no longer be a perimeter security, we need to take security to the identity level. Almost all security breaches have come from credential leaks. There are so many tools that Microsoft, Google, and Facebook have created to help in the area of security. We should try to take advantage of what they have already built to help with our own security. We need to build security that both satisfies our IT departments, but also the customers/users. This may be hard at times, but is usually do-able. Microsoft has taken some great steps and is able to determine if you are able to paste from word into outlook based off the word document and the email address you will be sending from in outlook. If it is a work document in word, you will not be able to paste to a non-work email sending address. pretty neat stuff.

The next session I went to was called Application Debugging with IntelliTrace with John Guadagno. I will be honest, there weren't many notes that I took during this session. He did mention that his slides should be posted and that his speaker notes would be really helpful. Here are some notes that i did take. A few quick notes on IntelliTrace:

  • Allows you to record events and method calls for your application. The black box for your application. See Key events and see what it is doing throughout the lifecycle. Will also keep values of variable and objects.
  • Allows you to examine its state at different points in the execution.
  • You don't have to have Visual Studio installed and can just have a collector on the machine to see what is going on

IntelliTrace can collect many different events. You can configure what to collect and save the environment to be used later or with certain projects. It can collect:

  • Debugger Events - Value in local window, auto window, and data tips
  • Exception - handled and unhandled
  • .NET framework events
  • Function name
  • Values of primitive data types passed as parameters as function entry points and returned at function exit points
  • Values of automatic properties when they are read or changed
  • Pointers to first-level child objects, but not their values other than if they were null or not

The tool seemed to be really helpful if you don't have Visual Studio on a machine, but you need to see the steps that were taken to get a certain error. I could see this being useful when we have bugs on client computers but cannot reproduce the bug locally. Install the client and see the variables and steps that were taken on the clients computer. Now we just need the clients to allow us to install on their servers...

The next session I went to was Enabling DevOps in the Cloud with Steve Lange. It was great to see that most of what Steve talked about we already do at work. He mostly talked aboutt he tools that help get to DevOps, which were Microsoft tools as he works for Microsoft. He discussed using VSTS and all the tools available through VSTS. All of which we already use. I did learn about extension called the Test and Feedback extension that allows you to record the steps you take through a browser and enter a bug directly into VSTS. Pretty nice tool.

Steve also talked about Azure App Insights (can be used by non-Azure apps to get data and do analytics on the apps.

I then jumped around from The Intro to Xamarin and ASP.NET MVC - Development to Deployment. Neither one of these sessions provided any real new information. The Xamarin session was talking about how to load Xamarin onto the your computer, but wasn't about creating any apps.

I then went to ethe ASP .NET MVC class. This was maybe a mistake. I walked in and was a little lost on what her was talking about. there were pieces that I did know form working on our applications at work, but it seems I should have been in the session the entire time.

We finished the day with a key note on Angular 2. It was called Angular 2: Released, Greased, and Increased. This was a repeat of what I was told on Monday and Tuesday in the workshops. Really, the only new information was how come Google took the direction they did on Angular 2 and the performance benchmarks they used to increase the speed of Angular 2 (which is much faster then Angular 1)

Tomorrow is the last day. I hope the sessions are great and we get to end strong.

Wednesday, October 26, 2016

DevIntersection - Day 3

Today was the first day of the sessions at DevIntersection. It started with a keynote session by Scott Guthrie of Microsoft. The title of the talk was "Movile-first, Cloud-first Development." It was a good speech by Scott. I always feel the keynotes are more about a quick glance of what the speakers can do without much team to show you what was done. I guess it leaves questions and will have you go experiment more on your own. Microsoft is coming out with some great products and I will definitely look at more information on the Microsoft products.

Then the sessions began. The first session I attended was Understanding the Windows Desktop App Development Landscape by Brian Noyes. The first topic, the mortality of the different UI frameworks. The question when looking at the frameworks that we need to ask is, what do we consider dead vs. matured. The different frameworks may be at different stages in their lives. The frameworks we currently have:

  • Windows Forms - Many will think that windows forms are dead. There are many projects that are built on Windows Forms and should not just be dropped due to thinking Windows Forms are dead, just mature. Forms are just mature. However, Brian would not start a new project using Windows Forms.
  • Silverlight - This also not dead...yet. The browsers are the ones that are killing Silverlight. It is not yet yet, but it is in the trauma unit on life support. Definitely do not start a new project using Silverlight.
  • Windows Phone - Bloodied on the battlefield. Survival: questionable. Only time will tell.
  • WPF, UWP, Xamarin, Single Page apps are all alive and well.
WPF is mature, it has been around for almost a decade. In computer time this should be gone. However, it still lives on and probably will for a long time to come. There are many features WPF that are great. Some of them:
  • Data binding validation
  • Implicit Data Templates
  • Dynamic Resources
  • Custom MarkupExtensions 
  • Multi-Bindings
  • and more!
UWP allows you to develop for many different platforms, like the desktop, mobile, and XBox. Great for touch, pen, or keyboard/mouse. UWP provides a better app security and provides isolation from other apps on a computer. You are able to sell these apps in the Windows Store. Great features available such as:
  • Cortana integration
  • Low power consumption
  • Ability to move apps into UWP using wrappers
Xamarin is a great crossplatform tool using C#. You can write an app and share it across platforms including iOS and Android. The logic code can be reused across platforms and only UI will have to be written for each platform you would like to include for your app. Finally! Windows can develop for iOS (although to develop for iOS you still are required to have an Apple computer).

Single Page apps are cross platform are well. All they require is a browser. This can be written in HTML, CSS, or Javascript (hey! My workshops were about typescript and Angular 2 which compile into JavaScript!). The single page apps can use the same architectural patterns as a well designed XAML desktop app, just using different syntax. With a responsive design you can create an app that will work on desktop and on mobile web browsers beautifully, or at least sufficiently.

The next session I attended was How to Be a Good Community Member by Contributing to OSS with Brian Clark. Apparently, I like the sessions by the Brians. Throughout college I was involved in the community and did many hours of community service. Open source allows companies to use their products/frameworks for free. Why would anyone want to do this? They probably build something they needed to solve a problem and sent it out into the world for consumption. Should companies pay to use open source? Maybe the payment should come in the form of allowing employees to contribute on work time (my own thought, not own that Brian brought up).

Well there wasn't much I didn't already know or think in this session. It actually was a shorter session and we got out a little early. I think the main take-away from this session was the resources for doing your first contribution to Open Source. Below are some resources shared:


  • github.com/code52 - starts a one week project that is easy to jump into at any point
  • upforgrabs.net -
  • firsttimersonly.com - aggregate certain projects
  • yourfirstpr.github.io
  • issuehub.io - allows you to focus on the language you are looking for
  • github.com/mungell/awesome-for-beginners

Things to think about before starting on an Open Source project: the process for the project, the rules, what are the guidelines of the project, is there a code of conduce, can you run the project locally, is it in a language you are familiar (maybe you don't want to stretch on your first pull request), and more.

Really, think about the project and find one that fits for you to contribute. Communicate with the team and make sure they know who you are and what you are doing. And, start simple to get your name out there to allow people to see you can be trusted and you do work well with others.

My third session was Create an Angular 2 app from Scratch with Dan Wahlin and John Papa. I probably should have skipped this session. It was much like the workshop I did on Tuesday. I hoped that they would start from a blank sheet and add everything we needed. Well, they started with a project that already had the needed files for an Angular 2 app to start working. In fact, they already had a page, Hello World that would pull up. I stayed to see if any new information would be given. There was no new information and I was disappointed. Still Dan and John did a good job.

The final session I went to was Automatic UI generation in .NET by Mark Miller. Mark is a great presenter and had a lot of, shall we say, love for UI. There was a lot of code that Mark had done before the session. He then went through what the code he put in before did, and showed the code a little bit. The dynamic response of the UI is pretty cool and what showed was dependent on what you clicked and the properties on the UI. It was nice to see, I just wish he would have gone more into the code of how to build the responsive UI. 

Onto the sessions for tomorrow. I hope I pick a good set of sessions.

Tuesday, October 25, 2016

DevIntersection in Las Vegas - TypeScipt, ES6, and Angular 2

Last year I started my Twitter account while I was at Visual Studio Live! in Orlando. I blogged at the end of each day. I meant to do that this year while I have been at DevIntersection in Las Vegas this year. We got to Vegas yesterday for the pre-session workshops and will be here until Friday. There is a little different feel in the Las Vegas vs Orlando environment, but I am not here for the city, I am here for the conference.

Day 1:

Yesterday I went to a session called Making the Jump to ES6 and TypeScript with Dan Wahlin and John Papa. I thought this was an ambitious decision as everything I have done has been done in C#. I was afraid that I would not be able to keep up or understand what was being said. I was in for a pleasant surprise! I was very surprised at how close ES2015 and TypeScript have many features that are very similar to C#.

First, John and Dan talked about the tsconfig.json file and how you can set sourceMap to true in order to enable debugging in TypeScript. How do you get TypeScript to work? You transpile TypeScript to JavaScript or ES. You want to use ES2015? Transpile your TypeScript to ES2015 and you have ES2015 version of your code. I guess the good news is, that if TypeScript is ever not supported, you just transpile it to ES2015, or ES5, or even ES3 if you wanted.

We then started talking about ES 2015 and some of the features now available. These are not all the functions available but the main ones that were covered. I understood most of these. Maps/Sets are like dictionary pairs you can use so that you no longer have to use arrays and splice and slice the arrays. Maps store a collection of key/value pairs with unique keys. Sets can store a collection of items where the items must be unique.

What about those classes? HEY! I use those all the time in C#. There are some that probably don't like this, but it sure helps me understand what is going on in TypeScript. And those Arrow Functions look real familiar! A few weeks ago (maybe two months, who knows) I learned about LINQ  statements and Lambda funcitons. The Arrow functions look close to the same as LINQ statements

Other features we talked about template strings (embed a variable in a string literal), destructuring (create multiple variables, along with their values, in one line of code), default parameters, and rest parameters. All look close to stuff I have done in C#.

We then went to a TypeScript playground at http://www.typescriptlang.org/play/index.html which allows you to type TypeScript and immediately get the JavaScript equivalent back. We then went into types in TypeScript. For example, you can now go:

var age: number = 5;

This will set a new variable age of type number with a default value of 5. Very similar to how variables can be set in C#.You can also used inferred types, where the variable will either be a type any or the actual type if TypeScript is able to infer what the type should be. You can do Enums, again similar to C#.

The next piece I liked talking about where the classes. They  classes look just as they do in C#. Helpful for me!

One piece I really liked in the auto generated properties. These are a little different then auto properties in C#. For TypeScript you create the auto generated property in the constructor. An example:

class CoolCode {

  constructor(public greeting: string)
   {
      this.greeting = greeting;
   }
}

This creates the property greeting in the class CoolCode and also has the value of a string in the constructor called greeting. You can also create gets and sets on properties. This is almost the same as  and auto property in C#. Here is an example in TypeScript:

class Address {
  _houseNumber: string = 0;

  get houseNumber() {
     return this._houseNumber
  }

  set houseNumber(houseNumber: number) {
    this._houseNumber = houseNumber;
  }
}

You can now do class inheritance and interfaces just as you can with C#. In order to use inheritance you need to use the keyword extends. For interfaces you have to have a class with the key word interface and then your class that is implementing the interface will do something like:

interface KillerGame() {}

class AwesomeGame implements KillerGame{}

Other things that are similar to C#:

  • Generics are now available
  • You can know use namespaces - if you use modules do you still need namespaces?

Day 2:


Today I went to Building Single Page Applications with Angular 2, again by Dan Wahlin and John Papa. The discussion started with the differences between Angular 1 and Angular 2. Since I have never used Angular 1 I did not have any reference. They then touched on what we had gone over the first day in the TypeScript and ES6 workshop.

There was not much more added from what we learned in day 1. We used a tool called Plunker (in order to avoid having to get the correct setup on all the machines in the room) to enter TypeScript and use Angular 2. What was added to our knowledge for Angular 2:

  • How to build components - importing and exporting
  • Creating and using templates
  • Angular Modules
  • Binding and Directives
  • Services and Dependency Injection
  • HTTP and ReactJS
  • Routing
Ok, I type it out and it is a little more then I thought. This post is getting really long already, maybe I will have to write another post after I have been able to research them a little more. The workshop today was nice, but they moved so quick that I would like to understand them a little better.


We went through many examples using TypeScript from the day before to create/change single page websites. Of course, we started with Hello World and went from there. I learned today that Dan and John went pretty fast while editing the code and a few times I fell behind getting to a state where my pages weren't working. Luckily, they would save their Plunker and I was able to get to a good state before we moved on too much.

In addition to examples from examples using TypeScript from the day before, I got to learn a little HTML. I did HTML years ago in a college course but nothing big. It was nice for a little refresher.

We were pointed to a tutorial on angular.io that will help getting more familiar with Angular 2.

Thursday, September 22, 2016

The progress I make...and forget to blog about

My great friend and co-worker posted a comment tonight asking when I would finish The Quest and post it for all to see. Well, I have been sitting on it for a while. There are some bugs and I moved on in the book thinking I would go back and fix the bugs. Overall, the game works. Some places it is easier for the player and other parts are harder for the player.

I believe I can find out why I have bugs and how to fix them, it is just about finding and taking the time to debug and fix it. Lately, I have been taking on bugs at work and debugging which has given me great experience on what debugging looks like. While fixing the bugs I have learned pieces of C# and .Net that the book hasn't talked about yet.

One example is that while testing and fixing bugs in our API I have learned how to use LINQ statements. In the book this aren't mentioned until chapter 15. By the way, I am now in chapter 10 which is further then I got before in the book. It is amazing how much LINQ statements help. I understand at the surface, but will save trying to describe them until chapter 15.

Chapter 9 talks a lot about streams and how to interact with files within a program. When you are using streams make sure to close the stream or you may lock the file. That can cause problems. Hey! There is a great way around having to remember closing the stream. You can wrap your stream in a using statement. (These are different from the using directives at the top of your files).

You have a lot of If/Else statements? There is an easier way to do this! Use a switch statement. Switch statements provide a mechanism for writing the variable to check once and then say what to do with each different possible output of that variable. Switch simple example:
switch(variabe)
{
case enum.value:
// code to happen
break;
case enum.value2:
// code to happen
break;
default;
// code to happen. Case statements can have the default case which will apply if none of the other cases apply.
break;

}

I also learned about serializing and deserializing your files. Serializing is like flattening your output so it can be desearialized (reanimated) later. Opening a serialized file and trying to read it is...well...impossible for me. It writes it in Binary. Actually, just write a stream reader that deserializes the file and there you go!

I ran into a collision of work and my book while reading chapter 9. At work last week, I was debugging an issue and my team lead asked if I knew what an attribute was. Deer in the headlights. Okay, not really, I did fess up and said I wasn't sure what those were. So, Ben described them to me and walked through the example in the code that we were seeing the issue. A few days later that exact topic came up! Dear Headfirst C#, I actually already knew this before reading! I felt knowledgeable! I may feel that way when I get to chapter 15 too!

Chapter 10, exceptions. I have only read the first couple pages, so not much to report here.

Brett, here is the buggy game The Quest. The github repo is located on my general github.

Hey if you need an excuse manager for work on why you can't come in, chapter 9 has you create an excuse manager so you can remember what worked with your boss and when you last used it. Get your very own excuse manager here!

Sorry for the long read. No excuses, they never go well with the readers...

It is better to offer no excuse than a bad one. - George Washington