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

Wednesday, August 31, 2016

Second Time through the Quest

I just wanted to put an update out there. It has been a while since I posted, I procrastinate and if you have read any of my prior blogs you already know that.. I keep telling myself not to do this, but old habits are hard to break. Plus, I listened to a podcast today that mentioned procrastination can be good in some circumstances....posting a blog? Maybe not, but hey, let's go with it.

Anyway, the update. I am almost done with the Head First C# second lab called the Quest. If you will recall, I got frustrated last time and moved on. This time, I am getting closer. I am almost to the point where I could run the program and test what is happening in it. Maybe by the end of the week I will have a version of the game that I could post...I'm trying! (Okay, maybe not the end of the week, the first football game of the season is tomorrow so I am missing one night)


Wednesday, August 10, 2016

The joy of a pull request

Well, I have finally stopped doing most of my work for the old Sustaining team. I am now doing most all of my work for the Core Services team. That means I am writing code and tests. This week I have been working on writing acceptance tests that will test our implementation of a rest API.

A few things. I have been doing some Pluralsight videos to try and understand what it was we were actually implementing. I think I have a better understanding of what and API is and how we are actually going to use it (although there is always more learning I can do on this topic).

Next, acceptance tests.I have never written acceptance tests and needed to understand what acceptance tests were and what they test. Happy Path. You know, make sure the code is doing what we expect without the weird scenarios (other sets of tests should make sure that these scenarios are caught).

On to the writing of tests! Well, it was more pairing with one of the developers on the team for the first few tests (get, post, and patch) to make sure I understood the framework and what I was doing. After working with Jason on the tests, I took what we wrote and changed them a little, added a few scenarios, and added the delete tests without help.

All the tests were working! It was a total of seven tests, so not many, but the most code I had ever written and it felt good. The green check when running the tests makes you feel great! The code you wrote is actually testing functionality of your code and will add to the program by ensuring it doesn't get broken. What's next? Send in a pull request (I hope I have all my terminology correct, but a code review for Git). That is when it happens.

This is my first code review for anything greater than one line of code. Once Ben was done with the pull request he turned to me and said, "Sorry I was brutal." Really? I think Ben was just prepping me for all the comments he was giving me.

The pull request was great. I don't think it was brutal, but it was a learning experience for me. Should I have known and coded some of the suggestions before I sent the pull request? Maybe. Okay, the answer is yes. One of the comments was to move some code to a shared base class with the tests I wrote and the tests another tester/engineer wrote. I should have read their pull request the week before and known that there was code in both of our classes. Remember to read others pull requests or ask more questions in our daily standups to make sure I am not duplicating code. Something for me to work on, make sure I am more aware of what everyone on the team is doing.

The moral of this story is that Ben thought he was being brutal. I think he was being very helpful. I am still refactoring the tests to implement all of his comments (I already have a few of the tests working again using the new initialization from the base class). Everyone needs to be continuously learning. That is what helped get me from finance to the software industry (although I still feel I am lucky and maybe don't belong in a coding role). The pull request is a learning tool. As I continue to grow the comments will come back and be different then the "brutal" comments I got from Ben. I hope they are all brutal and continue to help me improve my coding ability.

I saw a great quote today on Twitter. It said, "It takes time to get good at coding." And it does. I will get there, eventually, and the pull requests that are rejected help me see how I can improve and help me get there quicker.

P.S. My wife goes back to work on Friday. No more morning C# on the treadmill at work! I hope to still wake up early enough to get some learning in before I take my daughter to day care.


Tuesday, July 12, 2016

Starting from scratch...

The title is misleading, I guess. I am not starting from scratch. I actually decided to restart the C# book and there are a few reasons that, I at least think, are good enough to start at the first page. I decided to do this probably two weeks back. There had been a large amount of time between me actually opening the book and working on the activities that I felt I would benefit from going back and playing again. Reinsert enough credits to play again.

Two weeks have now passed and I am to the first lab between chapters four and five. Seems pretty quick, right? I will say that the first four chapters went faster the second time around. I did not have to spend as much time looking things up or going back to reread. I guess the first time through those chapters did something, I could remember most of what was going on. I hope that my knowledge from last time will help me finish the first lab before too long. I also guess that if I get really stuck I could reference my pooping dog app from last time, I am going to try not to leave a trail behind the dogs as the run this time.

Although I could remember a lot, I still tried to take better notes this time around in hopes that I won't have a situation requiring me to start from the beginning again. I may have to reference the book, or maybe just my notes. Who knows? Perhaps, after I know how to really code, I won't need to reference the book or my notes (will I ever be that good and make it through the level with all my hit points?).

The next series of blog posts will be me going through my notes and putting them on the blog as a reminder of what I did to have a reference that will be forever immortalized in the cloud as everything in this day and age will soon be (does anyone else use Office 365 to have access to all their computer files?).

Why not start now on posting the Cliffs notes? I hope someone finds this useful and not too redundant from my previous posts.

The first item I found useful, that I did not use before, was the class diagrams. I thought last time I would skip making those and just type everything in code itself. These are easy, and easy to make in any program really, and help to visualize what should be in each class. Here is one class diagrams for the start of my second round at Off to the Races

A few pieces on classes that I wanted to point out:
  • Classes can do anything but generally only do one specific function
  • Classes contain methods that perform actions
  • The way you pass input into a method is through parameters
  • Program will start with a method called Main(). - You can change the main entry point of a program
  • Two classes can be named the same in the same namespace
  • A class can span multiple files but you must use the partial keyword when you declare the namespace

Hello, variables! Variables MUST be declared before they can be used. Visual Studio will give you a red squiggly line if you don't declare it first. You can use the debugger to watch how the variable is changing. This will probably be useful when you are getting some output you aren't expecting.

Loops:
Every loop has three statements.
  • Set up the loop
  • Second tells the true statement
  • Third is executed after each time through the loop

If/else statements use logical operators to check if a condition is true. For all conditional tests you have == (equals), != (does not equal), > (greater than), < (less than), as well as >= and <= to use for checking your conditional statements. A few more points on conditionals:
  • You can combine conditional tests by using the OR || operator and the AND && operator
  • Set your variable prior to running the conditional test

Enough for today. I hope that writing these down, and maybe for the second time, helps cement them in my brain. I also hope that I didn't miss anything important. Oh, and my Git is still there with all the projects this time and I think I know how to use it a little better now (I better! we are starting to use Git for work).


“It's never too late to start over!” 
― Lynne Gentry, Reinventing Leona

Thursday, June 9, 2016

Today I decided to exercise...

Well, hello there. I decided that I would exercise today and run a few miles. I like to run, okay, maybe I only like to run because it is a form of exercise that feel works me and I have semi-motivation to do. It has been a while since I have run and boy can I tell! It is amazing how quickly you get out of shape but how long it takes to get back in the shape you were once in. I can see the translation to your coding skills.

It obviously has been a while since I wrote a blog. That most likely (and does) mean that I haven't been able to code much. My wife is now on summer break (yeah!) and I don't need to take our daughter to day care in the mornings. This means that I am able to come in to work earlier and get some stuff done before anyone else gets there (except Levi, I can't seem to get in the office before him).

I have made good use of the time in the mornings. For Monday - Wednesday I did a course on Pluralsight called C# From Scratch by Jesse Liberty. I know, I know, I am not starting from scratch, but I wanted a refresher course. It was good to jump back in the code and feel like I might be able to make some progress.

Today I started with a Code Kata from codewars.com. Let's be honest, even the basic ones take me a while to complete. This one, even though I couldn't get exactly what the kata was looking for, took me about an hour. I think the kata was looking for me to implement something that didn't use the built in Math functions. Well, I took the kata and decided to make a console application that will help you determine if a number is a square root and if it is a square root, find the next square root number. Simple app, I know. And, have I ever heard of a calculator? Or course I have, but who wouldn't want to use a console application to find if a number is a square root.

I ran into some issues while creating this app. I tried to use too few methods and one time got stuck in an infinite loop. I was trying to determine what key was pressed to see if you wanted to try another number. Well, it turns out it was true every time, no matter what you pushed. I decided to try breaking out my the piece that determines what key was pressed into a new method called start(). Hey! No longer an infinite loop!

        public bool start()
        {
            Console.WriteLine("Press 'n' to start again");
            var restart = string.Empty;
            restart = Console.ReadLine();
            if (restart == "n")
            {
                return true;
            }
            else
            {
                return false;
            }
        }

I know my if statement isn't the most efficient code, eight lines of code (inlcuding the bracket lines). I did a little research (okay, Visual Studio told me) that I could do a switch statement and take out a few lines. I could have also written:

            return restart == "n";

Much better! One line! I like it.

Well, I hope this summer I can spent a lot more time on learning C#. Not only can I go in early and use  the start of my day to learn, but I also will be moving to a team that I will be working with our code base a lot more.

Program:
Download the Zip
GitHub Repository:
https://github.com/robertjorg/SquareRootsConsole/tree/master/SquareRoots

Happy reading, don't be a square!

Wednesday, May 4, 2016

Vivaldi...no longer just a composer

Oops, I was drafting this and must have hit publish. Ten people saw my not even half written blog. I need to get better at this whole process. Sorry to those ten readers that probably won't reread this post.

About a week ago I read an article about internet browsers. There aren't many new entrants into this realm and the players seem to be pretty stable. I moved from Internet Explorer to Firefox to Chrome way back in the day. I apparently don't have a good track record with my browsers. Give me one the has better functionality and I will at least look at it. I don't feel there have been many other options come into the market since the release of Chrome in 2008 (granted I am most likely wrong). Well, in comes Vivaldi (don't worry it doesn't play classical music the entire time it is open). Vivaldi was created by the same people that brought us Opera (see a theme here?). I never used Opera, I know that I wasn't as into tech when it came out, 21 years ago! I thought I would give Vivaldi a try, the slogan is "A browser for our friends"

A little on the build of Vivaldi. It is built off Chromium, an open source project, along with other open source software. Given that, it looks a lot like Chrome, but with a few extra options and customizations to help you get the browser you really want. You are able to use all the plugins that you love so much in Chrome I believe that since it is built on Chromium.



I am writing this in the Vivaldi browser now. I really like all the options that Vivaldi offers. The first is the grouping of tabs. Tabs are great, but don't you ever get so many tabs that you have no idea what each tab is and you have to go through each one in order to find what you are really looking for? Well, you can now group them together (I think Opera allowed this as well, but never used it). The attached image shows the two grouped sites I have, blogger and gmail.


Once you have your tabs grouped you can then tile each tab into the same window. It is helpful if you don't want to have two windows open with the different pages open. Okay, not that big of a deal, but who really wants to have two windows open?


You will notice I have a dark theme for the browser, just one of the many options. There are also great options if you don't like using a mouse. You can set a keyboard shortcut for almost anything! In order to best utilize real estate on my screen I have two shortcuts, Alt + t and Alt + a to remove the tabs (at the bottom of my screen and not the top) and the address bar. There are so many other options for key board shortcuts.

There are also mouse movements that will do actions as well. The one I like the most would be the "Rocker" movements. You quickly press the right mouse button and then the left in order to move back to the previous page. Or, do left then right to move forward in the pages. Pretty nice that the browser is build to accommodate those that like to only use the keyboard and those that like to use the mouse as often as possible.

So many other options that can be done. Like how pressing Ctrl + Tab works. You can have it rotate through the order that the windows were last glanced out or go straight down the line. But not everything is good about the browser.

Really the most glaring downfall is that the browser doesn't appear to be as quick as Chrome. Pages load quicker in Chrome, but not too noticeable. You may lose a few seconds of productivity, but nothing that will keep me from using the browser.

I will continue using Vivaldi.Maybe I will find out more that I like about it. The slogan says "A browser for our friends." I have read they mean this to be a browser for those that were power users and wanted something beyond Chrome. I would venture to say that it is a browser for everyone. Even if you aren't a power user, there is something here for you.

"If you don't like this, I'll stop writing music." - Vivaldi (or maybe I'll stop writing blogs)