Saturday, April 23, 2016

Topics...who needs them? (I do)

So, I pretend I know about technology. I actually only know a little about a lot. I need to tell the truth to all my readers. I have been very fortunate, and very lucky, to get my job with my current company. I have been writing about my experiences learning code but lately I have been going to work with challenging days and not enough time to do learning at work. Once I get home I have been wanting a little time with my wife and daughter and then taking down time. 

The reason for such the difficult times at work is that both of implementation specialists (my old role) are moving to new teams. I am moving to another engineering team and the the other specialist is moving to the client operations side of the business. Technically he isn't moving until June 1 and up to that date he should be working 50% as an implementation specialist and 50% in his new role. It has turned out that he is spending a lot more time with his new role and less time with the implementation role.

The time spent is in no way Tim's fault. This is a new role for him on a different team, and we all know that once you are leaving a department/job that you are done and ready to move on. Since I am staying in the same department it is much easier for me to keep doing the work and help to keep the team floating. It is wearing on me. I have been doing a bigger work load and just surviving. I should have brought this up to managers sooner, but I didn't and thought I could handle the load.

Taking time out of my nights to learn, when I just needed to unwind wasn't going to happen. I know there are ways to learn, outside or reading my C# book, but I don't know of these places as readily as pulling out a book. Similar to my previous blog about the communities we all belong to, there are places we can learn that will provide quick learning environments, like Code Wars or reading a blog on technology. Anyone know some good technology blogs or coding blogs that would be good for a newbie coder? I know at this point I shouldn't be as newbie, but I haven't been able to spend as much time as I would like to further my knowledge of coding and C#, life gets in the way.

I hope that once my replacement is hired (he starts on May 10th) and trained that I can get the rest of the sustaining team to help pick up the slack until we are able to get another implementation specialist hired for Tim's position and that I will be able to start working on the new team, which will be more coding and using different technologies. Until then, I need to find a list of topics that I can write about for the weeks where I haven't been able to do much learning or even looking at my C# book. So, what are the topics that a newbie programmer should be talking about?

P.S. thanks to Brett for starting to write a blog again, I am hoping it will help keep me motivated to write mine even after I don't sit next to him anymore. You can catch his blog at: http://technophiletester.hintonweb.com/

Saturday, April 2, 2016

Time sure goes by quick...

I recently made a decision. I decided to put the lab on hold because I was running into roadblocks and have been stuck for a while (it appears three weeks have passed since I last wrote!). So, I am moving on in the book and will come back to the lab to complete after I have been working on something different. When I was working on the lab, I would write code and it would do nothing like I would expect and so I would search, change the code, and find it also did not work. Frustration was growing until I finally said I need to take a break and learn something new. So, chapter nine hear I come. I think this will be an interesting chapter, it is teaching me how to read and write to objects, like a file or database. This is nice, we write to databases at work and I think it will be nice to understand how we are doing it.

This has brought me to think about coding in general. How do you know when you need to reach out to someone for additional help? Yes, I can continue working on the lab (and I will return to it) to finish and ask others around me for help on what needs to be done. I have done some bug fixes and small feature work for my job. I have received help all along the way while doing these. Usually, I would search on Stack Overflow or other forums reading to see if I could find the solutions I need. Then I would try some of the code and if it didn't work after a few times I will reach out to someone. The person I reach out to can usually answer my question and show me what to do in a short 15 - 20 minutes. I have just spent a couple hours working on it myself without getting somewhere.

OK, sometimes I do find the answer and I think I am better for it. I will probably remember the answers I took a few hours to find than those that are shown to me by someone at work. There has to be a balance, but what is the right balance? I find that sometimes I find the answer after just asking someone for help and talking through my issue. It makes me think about what I am trying to do and say what the code is doing out loud to someone else.

Sorry for the disappointment on the many weeks between blogs and not having the lab done. Maybe I didn't disappoint you, but I am bummed.

On a side note, I got a new job at work. I have been an Implementation Specialist. I would mostly work with clients to install our product and trouble shoot tier 2 issues. Well, they asked me to move to be a Software Engineer in Test. A lateral move, but I will be testing our product and possibly even coding more. I am excited for the change. I have been doing the implementations for almost two years and it has been great. I like working with the customers and really digging into our product. I will be moving teams and focusing on one specific function of our products so I will be deep diving into the code and how that portion works. I know I will start by writing tests and looking for bugs. Eventually, I will be coding, probably a lot more than when I was doing implementations because I won't have the tier two support to also work on. Exciting times!

Friday, March 11, 2016

Ghosts, Bats, and Ghouls...Oh my!

My work recently did a day called Open Space (I believe the thought was that it would replace what we previously did called Hack-a-thons). I had no idea what to think going to Open Space and it turns out to be a great idea. Whatever happens was meant to happen. Anyway, if you haven't done an Open Space, it is a cool idea and worth doing. What happened at our first Open Space is that I decided to host a session about learning C#. Turns out it was a popular session, I think we had 15 people in the session. I better know my stuff! 

At the session I talked about what I was doing with the C# book, Code Newbies, Code Wars, and just trying to pick up stories at work. We walked through an example of the last program I wrote and everyone was interested in my blog. Well, it has been a couple weeks since I wrote a post on my coding. I have been working on the latest and greatest game, The Quest. I have been slow going and spending time when I can find it to work on this project. This is a lab though and there is no help. I have been making sure I understand what I am doing with the code and it is taking a while. So far, I believe I have most of it written, I need to write what each of the available weapons do and then wire up the Windows Form to start working. I neglected to write more about the process while I was doing and it turns out that people are actually reading my blog. I was asked today if I was going to blog about the time I was spending on this project. Short story, people read my blog and about the adventures I have embarked on.

Now, onto The Quest.
The picture is the base for the form, it contains all the pictures that will be needed for each level. The form will control when the weapons are picked up and which enemies are present for the level. Well, I get to use inheritance quiet often in this project. I have a Mover class, and abstract Enemy class (which inherits from Mover), three different types of Enemy (inherits from Enemy class), a Player class (inherits from Mover), and the weapon classes (also inherits from the Mover class). My move class controls a large number of what the game does.

To make sure I have good encapsulation, I have the form that will only call the Game class and the Game class will call the correct methods from each of their respective classes. Now, I am having a problem, I am having a hard time deciding which class that methods best fit and if I need to have a private object or public objects. 

I talked to my team lead about the problems I was having with this. I just needed a gentle reminder, Private objects will only be used in their class. Objects should only be public when they will be called by another class. To better encapsulate our objects we call the public object, but the private is the only one that can change our public object.

As I have been writing the code and following the "hints" I am given from the book, I have gotten a few errors, like I created a method using public abstract string Name. I had the lovely red squiggly lines in VS. Hey, you can't have an abstract method when the class isn't abstract! The error was pretty helpful, it still took me a few minutes to realize what the error was telling me. I got it. Another error I got while working on the Weapon class. Below is the picture:

 The NearBy class only has two arguments. I remembered this one pretty quick, I need to overload this method and have it use have one method with two arguments and the overloaded method taking three arguments. 

I am also overriding a method called Move for each of my enemy types. Honestly, this confuse me for a minute on what I needed to call. I had the example the book gave me for the Mover class with the Move method. The enemies need to find out where the player is to determine which direction to move. I forgot that I had method in the Game class that determines where the player is at and the enemy class instantiates a game class. 

 
Things are starting to come together and, after I think about what needs to be done for a while, I have started realizing what needs to be done. It is slow going, but I hope I become better and more efficient with the coding and realizing what needs to be done. Maybe I can give you The Quest in the next week.

Thanks for reading, I'm off to read The Marian.

Thursday, February 25, 2016

Anyone hungry?

So, I was almost done with chapter 8. It was just a few more collections that act similar to lists. They are queues and stacks. The book used language I was used to hearing in my prior job, LIFO and FIFO (last in first out and first in first out). LIFO refers to stacks and FIFO refers to queues. I thought about those and how I choose how to treat my lots when buying stocks, do I want to pay taxes on those I first bought when I sell or those that were the most recent purchase. Okay, an easier way to think about it queues: treated like a line, the people who get in line first are the first to get their food or be seated. Stacks are take the top, like Pringles. You have to take the top Pringle in the can to get to the ones at the bottom.

Alright, seems simple. Let's take a look.To create a queue you add some code like:

Queue myQueue = new Queue();

Then to add to the queue:

myQueue.Enqueue("Piece of data");

Or remove:

myQueue.Dequeue;

Remember FIFO. That "Piece of data" we put in will be the first out. And now to show stacks:

Stack myStack = new Stack();

A little different to put in a stack, we push the piece of data in:

myStack.Push("Stack data goes here");

Then to remove data from the stack we pop it out:

myStack.Pop;

Both stack and queue inherit from IEnumerable and, pretty easily, we can move our data from a queue to a stack to a list and back (probably any combination you can think of) by overloading the constructor. Example:

Queue myQueue = new Queue();
*enter data into the myQueue*
Stack myStack = new Stack(myQueue);
List myList = new List(myStack);

At the end of a chapter we created a flap jack tracker to see and feed lumberjacks (does anyone like soggy flapjacks?). A lot of concepts are starting to come together.



Next up is another lab. No help on this one, wish me luck!

Wednesday, February 24, 2016

cSharpDictionary.ContainsKey("GoFish") - Another section of chapter 8

I still am not done reading Chapter 8. Although I have been reading and coding most nights (except the nights my wife and daughter were both sick or doing my taxes which are always phone *please insert sarcasm*) it takes me a while to get through the material. 

Well, since my last post a week and a half ago, I have mostly been working on a project in chapter 8. I tried really hard not to use the help for this project and perhaps I have learned something during the week. I just finished the Go Fish project in chapter eight and I did use the code that is provided in the book. I was stuck, what was I to do? Sometimes I ask myself, is object oriented programming for me? I felt when doing VBA that I got a relatively good grasp on what I was doing and didn't have to refer to the web much after doing it for a while. Perhaps I will start feeling that way with C#. I will say there are pieces that I look at what needs to be done and a light bulb goes on. Those are the days that help me continue spending any small amount of free time I have trying to become a coder. Just code more each day I guess (I try to do CodeWars but feel sometimes they are above what I know, maybe those are the good ones to actually test my skills) and have joined some communities like codenewbie.org (full of people wanting to learn to code from all backgrounds). What helped you learn to code?

One great thing about this chapter is that it made me really look at overloaded objects. As usual, We have talked about overloading before at work and I have never really grasped what that meant. This chapter was discussing overloaded methods and I probably missed it early on in the book, but I was really feeling lost. I spent some time investigating to find out that I really didn't know much about overloaded objects. Come to find out, they can probably come in handy. I like the definition from MSDN:

Members can have the same name as long as their parameter lists differ. When two or more members in a type are the same kind of member (method, property, constructor, and so on) and have the same name and different parameter lists, the member is said to be overloaded.



Just pass the correct parameters and the code will use the correct overloaded object. The Go Fish project actually uses one so you can find what card the computer will choose and then call the method that the human player uses. pretty nifty.

Hey, you can also create a dictionary to store definitions of keys. Just do:
Dictionary kv = new Dictionary ;

You set your TValue object type and key (keys must be unique just like the dictionary you use!) and enter data. You can then count the data, see if objects are in the dictionary, remove items you don't like, and add items you do like. There seems to be a lot more you can do with dictionaries. 

GoFish! Game - I still have not won the computer, I can only tie the computer. AI must cheat.

Until next time.

"I like to fish. Fishing is always a way of relaxing." Tom Felton

Sunday, February 14, 2016

enum Ch8FirstHalf { Collections, Enums, Icomparable, IComparer }

First, let me start by staying that I may have finally figured GitHub out. I haven't deleted any projects for a while (yeah!) and I actually started using it on two computers. It was helpful this weekend as the computer I have been using my work computer to do all the coding. Well, just the other day I installed VS 2015 Community on my home computer, just in case, with GitHub. As I was coding tonight, I couldn't find my charger for my work computer so it came in handy that I had everything installed so I just cloned my chapter 8 repository and I was back in business. Worked like a charm!

Now, chapter 8, well at least the first part of it. Collections - pretty nice, they allow you to store, sort, and manage all the data that your programs need. I bet these will come in real handy when coding. Let's check them out.

First up was Enummerate Values, a.k.a. Emum. These are a data type that only allows certain values for a piece of data. I have seen those before! Actually, only a few times at work, but I have seen them and now I understand what they are used for and why. We have talked about enums in our stand-ups or in water cooler conversations and now I can actually add to the conversations! "Hey, just take that enum and assign a number value to it and BAM!"

Example to restrict the suits a card can have:
    public enum Suit
    {
        Heart,
        Spade,
        Diamond,
        Clubs,
    }

Sweet! I can make sure the correct values are the only ones used. But! Enums have their limitations. What if I have an unknown amount of items to put in, or you have objects you need to put in a list instead of just a type? *Hint* Use a list

Lists take objects and you can assign anything to it as long as it is polymorphic. That leaves it wide open. So you have your enum that tells you what suits you can use and say that you have one that tells you the values that can be used for your cards. Now you can create a list that contains a card with both a suit and a value (you need a Card class as well):

            List cards = new List();

            for (int i = 0; i <= 4; i++)
            {
                cards.Add(new Card((Suit)random.Next(4), (Value)random.Next(1, 14)));
                Console.WriteLine(cards[i].Name);
            }

Your lists will automatically resize itself when objects are added or removed. Arrays (talked about in another blog) can't do that so you will need to know how many objects to include in an array or leave the correct number blank spots to add to the array. (I understand .Net has a bunch of collections to solve these issues, but I don't know about them yet and I am told List is the most common type).

You also have IComparable and IComparer to help sort your lists. Takes a little bit of coding, but essentially you create an integer output and tell it if it should be higher or lower by returning a -1, 1, or 0 (the same value). Create a method called Compare in IComparer and give it two object parameters then do like below:

    class CardComparer_byValue : IComparer
    {
        public int Compare(Card x, Card y)
        {
            if (x.Value > y.Value) return 1;
            else if (x.Value < y.Value) return -1;
            else
            {
                if (x.Suit > y.Suit) return 1;
                else if (x.Suit < y.Suit) return -1;
                else return 0;
            }

        }

(I know that isn't as efficient as it could be, but I didn't use the books help on this activity AT. ALL!)
Also, remember that if you are comparing Enums it will use the index number assigned. The enum above for the suit would sort by Heart, Spade, Diamond, and then Clubs.

As mentioned above, I haven't used the help yet. I have used my prior projects to check my code or find an example to modify for my new project use. I am feeling pretty good.

https://github.com/robertjorg/Ch8/tree/master/FiveRandomCards
https://github.com/robertjorg/Ch8/tree/master/ListOfDucks/ListOfDucks - I think we will be using this one later as the book had me add some methods that we haven't used yet.



Sunday, February 7, 2016

if (catchyTitle.Text == "Interface Inheritance" ) { MessageBox.Show("Chapter 7 is done!") }

This chapter took a little longer than prior chapters. Maybe it is because there is more material and the coding projects try to use the majority of code I have learned in the prior chapters. So, since a few blogs ago I decided that I wasn't going to use the "help" as much as I had been prior. I would say I succeeded pretty well in this chapter. Building a house with places to hide I did go to solution after I got stuck and was unable to make progress. I hope it helped me learn what I was actually using better. I think it also helped that I didn't have many days between actually looking at code I started and code I was finishing. Instead of having to remind myself of what I did before, I was able to remember it pretty well.

While my code doesn't look the same as the solution, and probably has more lines then what is needed, I ended up having an issue where my form wasn't updating correctly. The issue showed itself after I implemented the interface for a hiding place. I forgot to call a method when moving from one room to another called ReDreawForm(). Hence, the form was not redrawing and giving incorrect information about where the hiding place was in the different rooms.

Well, the hide and seek project (I called it long project because when I started it the book said it was going to be a long one) contains both outside rooms and inside rooms. Both inherit from the Room class. Then there are two interfaces for rooms that have exterior doors and rooms with hiding places. I had to do some searching on what to display depending on the room type (IHasExteriorDoor or IHidingPlace). In comes upcasting and downcasting (aka Polymorphism). Example of finding a class that inherits from an interface:

if (currentLocation is IHasExteriorDoor)
            {
                goThroughTheDoor.Visible = true;
            }

That brings me to another point, Object Oriented Programming has four principles (why the book waited to chapter 7 is a good question):
  • Inheritance - one class or interface inherits from another
  • Encapsulation - creating an object that keeps track of its state internally using private fields, and uses public properties and methods to let other classes work with only the part of the internal data that they need to see
  • Abstraction - When you create a class model that starts with more general - or abstract - classes and then has more specific classes that inherit from it. Cannot instantiate these
  • Polymorphism - "Many forms" Take an instance of one class and use it in a statement or method that expects a different type, like a parent class or an interface that the class implements. Upcasting or downcasting allows us to get polymorthism.

We have used all of the principles so far, it now is a matter of being able to remember each principle and how each is used (so much to remember, but I think coding more often will help that). 

This chapter also talked about access modifiers. You know, like public or private but with a few more. 
  • Public - anything can access this (as long as access to the declaring class.) Least restrictive. Only use if you have a reason to make it public.
  • Private - only other members in the class can access it (other instances of the class can use these as well). You can only mare a class private if it is encased in another class.
  • Protected - public to subclasses, private to all else.
  • Internal - public only to other classes in the assembly. Protected Internal can only be accessed from within the assembly OR from a subclass.
  • Sealed - class which cannot be subclassed. Not an actual access modified, it only affects inheritance.

I think something to help remember the implementations, inheritance from a class allows you to modify the methods or use the methods how they are written in the base class. Interfaces have abstract methods and cannot be instantiated. The methods in the interface do not have any code in the contained methods, it only tells a class that inherited from the interface that all the methods MUST be used. The class can then implement any type of code needed for the given method, but it has a framework of what needs to be implemented from the interfaces.

I am only touching the surface I know. So much to learn!