Wednesday, May 18, 2016

What causes bugs?

I think that developers have a good handle on the idea of bugs in the code, but the thing that I want to focus on is informing other people, who are not developers, how bugs form.   If we can help others to realize how bugs can form we can eliminate the amount of communication that is wasted trying to explain where the bug came from or why it happened all of a sudden. 

We have all had those changes because of business requirements that everyone that isn't a developer blames for creating bugs until the next major change.  What "everyone that isn't a developer" doesn't realize is that there are other variables that play a major factor in the creation of software bugs.  

As technology increasingly gets better, faster, more convenient, etc. the list of things that directly affect your code increases greatly and there is probably a formula for it that follows the Fibonacci sequence or some other fun algorithm like that.

What "everyone" might not know is that an increase in traffic to a site or server can cause things to change on the server, or cause an admin to make changes that will adversely affect your code.  You will not be notified of these changes, whether they be from traffic flow or an admin. In the ideal world, you would know the second a change happens that is going to affect your code,  you can plan for these things and you might even have alerts set up to tell you when traffic increases to your site or application, but if an admin makes a change to a server or a setting on the server, you may never know until something goes wrong with your site or application, and you will be banging your head against the wall trying to figure out why all of a sudden this bug appears out of nowhere.

Another thing that can really throw a monkey wrench into your code is something that was meant to keep bugs away or increase security,  an update.  I am not talking about the ones that "everyone" is thinking of, like the updates that you (or someone in your team/company) have made to another part of the application,  this is what "everyone" immediately thinks broke the application when something isn't working the way it previously did, this is the major update that "everyone" blames bugs on.  I am talking about updates to operating systems, IE, Edge, Cortana, text readers, PDF readers, other browsers, just about anything that needs updating that has to do with some part of your application.

Something else that "everyone" doesn't realize affects your application is the hardware that it is run on, not just your user interface but also the data server, the web server, the application server, the whatever server.  This likely won't cause issues with your application, but it is a possibility that it could cause an issue. Sometimes when we are creating a site and we use certain frameworks, those frameworks rely on a certain hardware structure or a combination of hardware structure and software settings on that piece of hardware, so when the combinations are changed, there is sometimes a chance of it causing a bug in your application.  Let's say that there isn't a lot of memory usage on the server, so someone says hey let's dial back the memory on this server and use it somewhere else (the things you can do with Virtual Machines), now something that doesn't run all the time gets run and you get an out of memory exception, it didn't happen before, why is it happening now?  now you have to do one of two things, rewrite the code to use less memory for this one process, or convince the controlling party that you need X amount of memory on call.

Knowing that bugs happen and how they happen, helps you to prepare for them to happen and how to communicate what happened to who needs to know this bug happened.

So, what causes bugs?

EVERYTHING

Wednesday, April 6, 2016

Installing XNA for Visual Studio 2015

I was asked about installing XNA into Visual Studios 2015 because I noted that it was very simple and straightforward.

I knew that there were others like me who are still using XNA so I knew that a Google search would do plenty to help me find how to get my project working in VS2015 (community)

My search quickly brought up a a Stack Overflow answer that points to an updated post by MXA with the title "XNA 4.0 Refresh (Visual Studio 2015)", which was last updated in November of 2015.

This site gives you a single downloadable .zip file to download, and then instructions on what you need to do to install all the components necessary for installing the extension itself

Once you have unpacked the .zip file, just install the pieces one by one in the order given, they don't take long at all.

Before install extension:
  1. Install DirectX
  2. Install Xna Framework 4.0 Redistribution
  3. Install Xna Game Studio 4.0 Platform Tools
  4. Install Xna Game Studio 4.0 Shared
Once the last one finishes, just double click the extension and it will install it, and you are ready to roll.  

I wasn't paying complete attention to my computer while I was doing this, so I can't give you a good estimate about how long it really took.  the download was painfully slow because of the connection that I was on, but the installing the packages didn't seem to take very long at all. 

My Project was already created prior to installing XNA into VS2015, so I don't know how easy it is to get started or set up the different types of projects.  I look forward to doing some development in XNA though.


Windows/XboX/Windows Phone Game

With the recent Microsoft Build event showcasing a lot of mobile development and Gaming development, I really got to thinking about the game where I started with a basic tutorial and expanded the game play dramatically.  

Currently it is a 2D scroller type game, but it scrolls in all directions on a defined World(Space/Universe) map.  My goals up until now had been to further develop the 2D game with the final goal being to interpret it into a 3D game that would support online game play.  The more I thought about the game and the aspect of mobile development along with flying quadcopters I came up with the idea of creating an interactive game play where the user could control the player by turning or tilting the screen in order to turn the player piece.  I think this is a wonderful idea for the small game that I have so far and would make it very playable for the mobile platform.  my thoughts are that once I created the game for Windows phone that I could port it to the Android market immediately once I figured out the best way to do that.  

I haven't yet looked into porting to the Android devices but I don't think that it should be too difficult given that Xamarin is now free with Visual Studios and there is a current build of XNA for Visual Studios 2015 as well. 

Over the weekend I updated Visual Studios 2015 Community edition and installed the Xamarin portion, I also installed XNA into Visual Studios 2015 which was a lot easier than it had been in the past to install into other versions of Visual Studios.

I do have a lot of code to clean up, I keep trying to tell myself not to be so hard on myself, I did write the code many years ago and didn't know as much about coding standards and such as I do now.

I am also going to be looking into Azure for testing and hosting for the game itself.  I am not going to lie to you, but the main reason is because of the demo during build for Age of Ascent,  I was really impressed with what they showed there and the way that you can push out updates to the code to different servers that are all hosting the same game instance.  

I am looking forward to implementing some more code into my game and making it enjoyable for everyone. 

I am not so much of an Apple person, but I have also thrown around the idea of porting it to the iPhone market as well, but that is for another set of posts, I am sure there is going to be a lot going into that as well. 

Tuesday, March 29, 2016

Null-safe Dereference in C# 6.0

Wow, how did I make this far and not know about this?

I love these, although I am still unsure as to how clean they make the code, or if they are going to make me a lazy coder by using them as opposed to what I have been doing.

I came across the null dereference because I was reviewing some code on my favorite code review site, CodeReview.  The code is being used to track downloaded applications in a set of applications that are being downloaded at one time.


if (lastRuntimeDetails != null) //at least one application was already downloaded
    if (lastRuntimeDetails.Ip != runtimeDetails.Ip || 
        lastRuntimeDetails.Port != runtimeDetails.Port)
            _requestExecutor?.Disconnect();

As I was reviewing this code there was an awkward if statement that was nested without brackets (yuck) so that was my first line of business.  The objects that were being compared were being created from a custom class called RuntimeDetails, the first object that is created is called lastRuntimeDetails and is being used to track the last application to make sure that the same application doesn't get downloaded a second time and to keep track of the IP Address and Port for each download. 

Anyway, at first I wanted to get rid of the outer if statement, it looked to me like it was extraneous, at first I was thinking that if the properties were null that they just wouldn't be equal to each other and give a false value to the condition statement.  

Comments were made about Null Reference Exceptions and a lot of thought went into how to do this, I kept thinking about the null properties, and that's when I found Null Dereference Operator, so I set up some tests to make sure that I had a good grasp on things

I created two classes, one to create objects and the other to return comparisons on the objects



public class Class1
{
    public string One { get; set; }
    public string Two { get; set; }
    public Class1()
    {
    }
}

public static class Class2
{
    public static bool returnBoolean(Class1 inputA, Class1 inputB)
    {
        return (inputA?.One == inputB.One);
    }
    

    public static bool checkOnNullProperty(Class1 inputA, Class1 inputB)
    {
        return (inputA.One == inputB.One);
    }

}

and then I eventually came up with the following tests


[TestMethod]
public void TestMethod1()
{
    var input1 = new Class1() { One = "string" };
    var input2 = new Class1() { Two = "string B Two" };
    var test = Class2.returnBoolean(input1, input2);
    Assert.IsFalse(test);
}

[TestMethod]
public void TestMethod2()
{
    var input1 = new Class1() { One = "string" };
    var input2 = new Class1() { One = "string B Two" };
    var test = Class2.returnBoolean(input1, input2);
    Assert.IsFalse(test);
}

[TestMethod]
public void TestMethod3()
{
    var input1 = new Class1() { One = "string" };
    var input2 = new Class1() { One = "string" };
    var test = Class2.returnBoolean(input1, input2);
    Assert.IsTrue(test);
}

[TestMethod]
[ExpectedException(typeof(NullReferenceException))]
public void TestMethod4()
{
    var input1 = new Class1() { One = "string" };
    Class1 input2 = null;
    var test = Class2.returnBoolean(input1, input2);
    Assert.IsFalse(test);
}

[TestMethod]
[ExpectedException(typeof(NullReferenceException))]
public void TestMethod5()
{
    var input1 = new Class1() { One = "string" };
    Class1 input2 = null;
    var test = Class2.checkOnNullProperty(input1, input2);
    Assert.IsFalse(test);
}

[TestMethod]
[ExpectedException(typeof(NullReferenceException))]
public void TestMethod6()
{
    Class1 input1 = null;
    Class1 input2 = new Class1() { One = "string" };
    var test = Class2.checkOnNullProperty(input1, input2);
    Assert.IsFalse(test);
}

Someone pointed out that if the object itself is null it will throw a Null Reference Exception, once they said that I looked at the code again and sure enough the container was created but no object was placed inside of it.


 RuntimeDetails lastRuntimeDetails = null;

So my initial thought of removing that outer if statement was wrong, but now I had new information that could be used to make sure that the Properties didn't throw a Null Reference Exception if the object was created but the property were null.

So here is the code that I suggested to replace the original code.


if (lastRuntimeDetails != null)
{
    if (lastRuntimeDetails?.Ip != runtimeDetails?.Ip ||
        lastRuntimeDetails?.Port != runtimeDetails?.Port)
    {
        _requestExecutor?.Disconnect();
    }
}

The object could be created with null properties now and then we could remove the outer if statement entirely.  I believe that the better solution is to set the properties on creation to some default and then when they are assigned they will be different from the default so the comparison could be made without the need to check for nulls thus removing the chance that future development would have to worry about checking for nulls.  or that the initial creation of the object, instead of being set the object to a null object, we create the object with null properties and then if the object's properties are null then they will give a false when compared to anything other than null (using the Dereference)

The Code Review Question in Question

and

My Answer

Thursday, March 24, 2016

Which Coding Languages should I learn?

I read a couple of articles this morning,

1. I’m gonna puke if you compare Angular to React again; here's why!
2. Which Tech Should You Learn Now?

From the tone of these two articles it seems that JavaScript isn't going anywhere any time soon.  Another thing that I picked up from the second article is that developers with AngularJS or ReactJS experience/knowledge, on average, earn more money.  The second article also says that you should learn React (and Node) first because it is becoming more and more popular, in other words if you have the choice learn React (and Node) first then learn Angular, the article bases this on statistics given by Stack Overflow's Developer Survey and last year's JavaScript Scene Survey.

So, given that information, I am going to take it and mix it into my list.

Recall my list:
  • AngularJS
  • Ruby
  • Python
  • Java
  • C#/VB/.NET (better working knowledge)
  • JavaScript (better working knowledge)
  • Other JavaScript frameworks
  • BootStrap
  • CSS3
  • HTML5
  • BASIC
  • ALGOL
  • KTurtle
  • Programming Logic
  • Programming Design
  • BootStrap
  • CSS3
  • HTML5

I don't want to get too burned out on JavaScript Learning, so I am going to season my list with JavaScript and move some things around, maybe see if I can confuse myself between using semi-colons and not using semi-colons.

  • AngularJS
  • Ruby
  • Python
  • ReactJS
  • NodeJS
  • Java
  • KTurtle
  • F#
  • BASIC
  • Scala
  • ALGOL
then I could mix in some intermediate/advanced learning of all the stuff that I already know

  • HTML5
  • CSS3
  • BootStrap
  • C#
  • VB
  • VBA 
  • JavaScript
Season these lists with Logic and Design reading as well, also various programmer's blogs as well.

Am I missing anything?  

Should I change the order of my list for some reason?

Please feel free to comment below.

Tuesday, March 22, 2016

Which Coding Languages are the most beneficial to learn, for me?

I started thinking today about what I wanted to accomplish in the week, month, year...

Someone I know through CodeReview once said in a blog of his that you shouldn't try to eat an entire elephant without cutting it into pieces, so what I have decided is that I should pick some things that I want to accomplish and then give my self some short term goals, kind of a top down approach for the planning phase.

I think that the first thing that needs to happen is that I need to find out what languages are the ones that are going to further my love and enjoyment of programming as well as give me a future in the field of web and application development.

The list I have so far in my head

I already have a working knowledge of
  • C#
  • JavaScript
  • VB
  • .NET
  • OOP
I am thinking that I might want to learn some procedural programming as well maybe
I would also like to learn LOGO (KTurtle)a bit better, I have played with it off and on since I was a child and would love to be able to teach some new youngsters how to code in it as well.

This is a good start I think, I can now take these and order them by degree of some random value to myself or to furthering my career or ... whatever value.
  1. AngularJS
  2. Ruby
  3. Python
  4. Java
  5. C#/VB/.NET (better working knowledge)
  6. JavaScript (better working knowledge)
  7. Other JavaScript frameworks
Now I have a rough game plan of what I want to do for the year, what goals I might want to achieve and what goals I might want to table until a later date.  I can break these down into pieces or sections of learning like someone would do for a college degree or something like that.

One thing that I need to keep in mind is that I need to be able to pull from knowledge different designs for creating smaller pieces that make the entire application function the way that I want it to function and to make it efficient, I would definitely be on the look out for programming logic and design principles, I might even create a web search that I could do at least once a week to find articles about different techniques for creating the most efficient applications or sub procedures or whatever.

I am going to add into this list with things like

  • Programming Logic
  • Programming Design
I would also add things to the list like
  • BootStrap
  • CSS3
  • HTML5
Just because I want to keep up on these technologies and to make sure that I am using them appropriately and not acquiring bad habits.  I am sure that I don't know everything about these things.

I think this is where I am going to leave this (for now) and come back to it another day, the more I start thinking of things I want to be incorporated in this list of goals the farther down the rabbit hole I go.

so far this is the list that I have of things that I want to learn/keep learning:

  • AngularJS
  • Ruby
  • Python
  • Java
  • C#/VB/.NET (better working knowledge)
  • JavaScript (better working knowledge)
  • Other JavaScript frameworks
  • BootStrap
  • CSS3
  • HTML5
  • BASIC
  • ALGOL
  • KTurtle
  • Programming Logic
  • Programming Design
  • BootStrap
  • CSS3
  • HTML5
So, what do I do with this list now?


Wednesday, March 16, 2016

Code Stock

There has been a lot of talk around the office about Code Stock lately because the deadline for submitting talks is Friday at midnight (EDT).

Being a contractor it is not mandatory for me to submit a talk, but that doesn't mean that I can't submit a talk, so I have been throwing around the idea of writing something up.

When I started working here I didn't have very much (read as any) experience with AngularJS, I have worked with jQuery and AJAX a little bit and that has given me a little bit of a boost working with AngularJS, so I decided that I would talk about the process that I have been using in order to catch up to the rest of the developers here.

Check out Code Stock, sounds like it is going to be an awesome get together!