What To Do When Inheriting A Code Base: Part 2 Understanding The System

Alright Last Article we got the code base working and now we are ready to actually understand what our system does. The first step that I take is to not look at the provided Diagrams for the project. Why you may I ask because I have found that most of the time they are not completely correct which only causes confusion when you don’t know the system. So what would I do:

First check if I have a functional environment that I can thinker with. If I do then I try to figure out what is the main point of entrance for the main function of this system and what is the output the orange boxes. After Identifying that I try to find Where does the workflow happen and this I what I really care about.

image

By Watching the Workflow happen slowly either debugging or reading a log in verbose you can get a pretty good picture of what goes on in the system. This is really easy to do on WCF service and SQL in particular. In SQL people have a task table which is a common pattern well lets place the profiler to see the changes then make sense of what all that means. On the WCf service watching the messages come in and the responses it gives should give a fairly clear idea of what the routing it looks like.

After you understand the system routing is easy to dissect what happens in each component in a need to know basis.

Normally after I understand this I look at the documentation and see how close it is to what I understood from analyzing the system.

To understand the support system to me is important to isolate them and see them individually to be able to gather the reason for them and not just the side effects they cause or the support they give.

This is a really time consuming action and you should document everything you find during this for your own sake.

-Alfredo Out

What To Do When Inheriting A Code Base: Part 1 Inspecting the code

Hey Everyone,

I’ve been on more than one occasion on the situation in which I inherit a gigantic code base and its my job to support it and write some new functionality for it. I want to outline a few steps and practices I like to follow in order to get to the point that I’m confident making changes to the system in place. Note is that I use MS products in most of my development so I’m doing the article with those in mind.

My Steps are the following and I will discuss them in different articles.

1.Inspecting the code

2.Understanding the system

3.Preparing to make changes.
-Legacy
-NonLegacy

1.Inspecting the code base
A.Create A New Branch

Making a new branch allows you to be able to check out files and work with them in a manner that is easy to see the changes you have done. When you actually got something that is worth you can reverse integrate into the main branch and delete yours.

B.Make sure the code compiles on the first download or lets you know how to set up the machine.

If the projects has a dependency check script run it. If it does not this is the first thing that needs to be done create a script that looks into the build machine and makes sure that all the dependencies that are needed for compilation are install and in the right place in reference with the script. By dependencies I mean libraries or GAC dll’s or simply cross compile configurations in your settings. In the case that the script is not provided a bit of investigative work will have to occur inside of the compilation errors which leads to the next point.

Make sure that all the projects that I have been given compile. It’s my practice to actually have a local compile script. This script just makes an entire build of all the project one for VSTF using batch could look as follows:

  for /R %%i in (*.sln) DO (
REM echo %%i
msbuild /clp:ErrorsOnly /nologo "%%i"
)

In the case that compilation is not occurring I make a list of all the problems and try to see which ones group together for example a library is missing. An important part during this step is to look out for orphaned solutions. If proper procedure are not followed sometimes in the branch you can find solutions that are no longer used. There is no easy way of finding this out. Except opening the projects and see duplicated projects in a solution.

C.Make sure that the leftover solution bindings in visual studio are correctly installed.

Try editing a file in each of the projects that are relevant and see if you get auto check out in the IDE if it does not work. You need to refresh the bindings.
Todo this follow this steps :
Open the solution
Go File>SourceControl>Change Source Control Remove the bindings
Then Go back to the same location and on the screen that lets you bind per project do binding for each one of them and the solution
Checkin

D.Make sure the unit test runs
You can do it by following the steps to compile but using the mstest tool on the mstest projects the files should be the same is normal that some dependencies on the test project might be broke and some investigation will need to happen.

E.Create a dependency script Now that you went through all the work and figure what needs to be installed in a machine make it easy for everyone else. My example of that script in batch checking for Pex to be installed.

  REM VALIDATING DEPENDENCIES TO BE ABLE TO COMPILE CODESIGN

SET /a NumberOfErrors = 0

SET /a NumberOfErrors +=1

Echo %NumberOfErrors%

del temp1.txt temp2.txt

REM CHECK FOR PEX

reg export HKEY_CLASSES_ROOT\Installer\Assemblies\Global temp1.txt

find "Microsoft.Pex" temp1.txt

IF %ERRORLEVEL% EQU 0 (

@ECHO PEX INSTALLED

)

IF %ERRORLEVEL% NEQ 0 (

@ECHO PEX NEEDS TO BE INSTALLED DOWNLOADED FROM http://research.microsoft.com/en-us/downloads/d2279651-851f-4d7a-bf05-16fd7eb26559/default.aspx

SET /a NumberOfErrors +=1

)

del temp1.txt temp2.txt

In the next part I will address how to find information about your system when no documentation is there.

A Little Experiment: Reddit Screensaver

A screen saver I made to answer this post in somebodymakethis reddit.

 

This is the thread for the request.

http://www.reddit.com/r/SomebodyMakeThis/comments/hde3z/smt_a_screensaver_that_pulls_images_linked_to/

Below the first version of the screensaver let me know what improvements I should make.

http://alfredoalvarez.com/RedditScreenSaver.zip

Ludum Dare 20

I will be commenting here about every two hours of the progress of the game that im going to create for the competition.

6:52pm

Hi Everyone. Im ready to hear the title anouncement grabbed dinner and ready to go. After the title i will think a bit what the game is going to look like and get started on the mechanics of it :D.

8:25 pm

Got the character animation running right now is just a stick figure that changes color and working on using the accelerometer for movement. At the moment having issues since i have never used the accelerometer before and he seems like he is not that much into cooperating. Will post back around 11 hopefully i can do some screenshots The game is about an australian guy fighting his way to the outback to go get to a bar.

10:23PM

Finally got the accelerometer controls down and it works in conjunction with the animation. Used the pattern to manage scene that I used in there is no place for gnomes.

Plan on adding the buttons to be able to kick, jump and change weapons now. a Screenshot of what is looking like so far is not much but it’s a good start.

Capture2

12:01 AM

Moved to work on creating buttons got 3 of them and found optimal placement for the gameplay also went ahead and added gravity in to the game since at the moment I haven’t added a floor the character falls pretty easily through the floor. I have decided that the tile space for the level is going to be as follow. 30×30 tiles with 14 tiles of height and then 40 tiles of width.

Another screenshot below has you can see not too mucho to look at the moment. I’m trying to get the mechanics solid and figure out the spots that need animations and later on I will reskin. The character is not on the screenshot since he fell through the screen.

Capture2

2:22 AM

I took a break to take a shower eat something and look at other people talking in the Ludum Dare MIRC. Is cool to see the different levels of motivations in the time that I worked I managed to complete the tile map. Planning on dedicating the next hour to making the player be aware of the tile map and add tile map scrolling so that we can see the parts that currently don’t show.

Here is the screenshot of the tile map in action.

Capture2

I’m starting to wonder if I’m going to actually get to implement weapons and different monsters Right now I feel like i;’m behind.

3:43 AM

I think this is it for me for today I got some more progress now the collision system works therefore I can stand on the tiles got a bit distracted and decided to work on a background and changed a few colors tomorrow morning I will pick up making the tile map actually scroll to the sides and adding the jumping, Changing weapons and punching functionality.

Capture2

Below is a description of what im trying to do with the game and to be with the theme the outback is dangerous to go alone so at the beginnning I’m going to have a conversation reminding him to take his hat he also gets a knife and a boomerang on the way.

Aussie Puncharoo

3rd person sidescroller

Each level basically consists of a map formatted to the phone screen’s dimensions with limited left to right sidescrolling abilities. the maps will be set on a level plane for the player to scroll from left to right. the player is centered on the screen at all times as enemies in the form of koalas, kangaroos, etc. attack from both sides. the player switches from left to right to attack depending on where an enemy is attacking from. ideally, the player’s basic movements will be walk, jump and punch (knife and throw boomerang in later stages).

I will see you guys tomorrow.

April 30

9:30 pm

I have resolved to keep working on the game after taking a power nap when I came back from my daily routine. I figured that i f I don’t sleep I still got a good 21 hours to finish the game and submit.

I will report in about 2 hours with progress and some screenshots. Going to get this character functioning completely. Wish me luck on day two and on serious sleep depravation.

11:14 pm

Currently the character no longer runs out of the screen and the screen tiles move in relationship to the character. It seems like my brain at this point is kind of shot and my productivity has dropped significantly. Therefore I’m going to take a bit of a break from coding and do some art. Going to draw a better main character since red head ball is annoying me and also design the health bar and the entrance window hopefully by the next update I will be able to jump and have a start screen.

C ya in about 2 hours.

1:08 Am I worked on the art for the last couple of hours and got to the conclusion that I need to take a break and drink some water which I will be doing after writing. I remade the main character , Game loading screen. Text for When the game starts and the life bar. I Need to integrate all this parts into the game still since only the character go integrated.

Capture2

Below the other two pieces of art

FirstScreen

Context

I’m going to take a break and then return will post again at 4:00 am with hopefully the actions done.

For those that are going to sleep have a good night.

3:54 AM

Took my break and came back and started coding working on making the jumping work. Sadly it has proven a lot trickier than I expected and revealed a bug in my tile map code so my character is falling through a few blocks that I can’t really tell the reason why. I’m going to be working on resolving this issues for the next few hours Confused smile. Will check in about 7:00 AM.

4:43 AM

Woot managed to get the jumping and collisions bugs resolved. Therefore you get an extra update.

To summarize a bit condition super tired. Part of the game remaining quite a lot so this is the plan:

-Do HealthBar
-Score System
-Add Enemy and ensure he gives damage
-Give main character the ability to be able to switch side is looking
-Add PunchingAbility
-Add Random Health Items
-Polish and give the game flow so that I can post it for the competition

Therefore I think I’m going to be removing from my scope the following items. Changeable weapons and variable monsters.

At least now that I don’t feel stuck. The motivation is coming back and moving some of the sleepyness away.

Will post progress at 7:00 again.

12:38 AM

It seems like the lack of sleep decided that I was it’s the master here and I crashed at around 7:00 so my last update was missed. I woke up at around 9:45 But had to do some stuff pertaining living like eating at take 1000 pund of tiles back to home depot so here we are. At the moment I’ve added the enemy kangaroo with animation the Helath bar and score point system Just need to make the kangaroos spawn by themselves. At this point there are six hours left and 4 things to do in my list so if I can kick one per hour and submit I should be ok(I don’t think I’m making it but not stopping). Latest screen shot is below:

Capture2

I will report back at around 4. Official time left in 6 hours, 16 minutes, 9 seconds…

4:06 Lets see what has gone in the last few hours from the list I had from last night I’ve tackled the following:

-Do HealthBar
-Score System
-Add Enemy and ensure he gives damage
-Give main character the ability to be able to switch side is looking
-Add PunchingAbility

Additionally added game over event and enemy destroyed event in which a dead kangaroo gets Removed. sadly I have not added any way for more kangaroos to be added. So I made a decision In order to get the game today.

The game is going to be just a fight between you and one kangaroo for now. Going to remove some tiles so that you is simpler to fight. Whoever gets the life to Zero wins.

Will post again at six. I still need to figure out exactly how to post an xna game into the Ludum dare form.

5:02

Decided to do an extra post I made the game be able to handle the flow of starting window , context , game and ending. Honestly it functions but is not a very fun game at the moment. Feel really bad that I did not get to do add weapons variety of animals or even spawning and control of the monsters but you do what you have to. Going to clean up an remove the scoreboard and Change weapons button. Then add music that I got from wolfram tones turned into mp3 by http://www.hamienet.com

That’s the progress talk to you guys at 6:00

time left 1 hour, 52 minutes, 47 seconds

6:00

I’ve spent the last 15 minutes trying to get the music to work. The game works the mechanics are still a bit quirky but you can kill a kangaroo.

It was a pretty awesome experience this whole ludum dare I’m going to submit and let people critique it.

Thanks for reading.

Handling the back button & the game crash

 

The game crash issue was simply that I was not handling the condition when the game money was Zero. That was solved easy and not worth mentioning.

Handling the back button In the case of my game I do this in a fairly trivial way and I’m only going to post it for the sake of completeness. Basically I handle scenes by using the following interface in all the class that hold a window:

public interface IScene
  {
      void Draw();
      IScene Update();

      IScene Back(Game g);
  }

 

In the update method I handle all the interactions that would move you from one page to another and in the back method I return a pointer to whatever scene called before.

The submitted screenshots appear to be graphically enhanced.

I got this because I used the snipping tool but left the red border option on. I later removed the red border which apparently counts has alteration therefore here are the steps to correctly do it.

First step is to open your snipping tool. It looks like that is on the accessories part of the menu.

image

Step 2 is to turn off the red borders to do that click on option and you will see the image below. Unmark show selection ink after snips are captured.

image

Step3 involves using the window snip to actually photograph your emulator:

Click on new –> window snip –> then the window for the emulator.

image

Hope this was helpful happy snipping and attached is the screenshots I got for my app.

CaptureCapture2Capture3Capture4Capture5

The applications background music overlaps the users selected music

To solve this issue this was the approach that I took. I added code in the constructor for the game to call the guide and ask a what music he wants. There is a boolean to control which sound is played.

if (askForMusic && !MediaPlayer.GameHasControl)
           {
               if (!Guide.IsVisible)
               {
                   Guide.BeginShowMessageBox(“Select Music Of Choice”, “Do you want to play the game music”,

                   new List<string> { “Yes”, “No” }, 0, MessageBoxIcon.Alert,

                   asyncResult =>
                   {

                       int? returned = Guide.EndShowMessageBox(asyncResult);
                       if (returned == 0)
                       {
                           MediaPlayer.Stop();
                           playMusic = true;
                       }
                   }, null);
               }
               askForMusic = false;
           }

How to add volume control

 

I had to add volume control to my application in order to comply with the marketplace review from the first time I sent it this was the solution I decided upon to have a scroller with 4 levels for audio and just modify the SoundEffect.MasterVolume to match the scroller. I’m going to post the code since it might help people implement a scroller or implement their own window. The code will be below.

Capture

Code

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using AvatareGameLibrary;
using Microsoft.Xna.Framework.Input.Touch;

namespace NoPlaceForGnomesLibrary
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class VolumeControl
    {
        GlobalResources resources;
        GraphicsDevice device;

        private int volumeLevel;

        public int VolumeLevel
        {
            get { return volumeLevel; }
            set {
                if (volumeLevel >= 0 && volumeLevel <= 3)
                    volumeLevel = value;
                else
                {
                    throw new ArgumentException(“Volume Out Of Range”);
                }
            }
        }
        private bool isShowing = false;

        public bool IsShowing
        {
            get { return isShowing; }
            set {
                if (!value)
                {
                    alpha = 0;
                }
                isShowing = value; }
        }

        public VolumeControl(GraphicsDeviceManager game, GlobalResources resources)           
        {
            device = game.GraphicsDevice;
            this.resources = resources;
            notchControl = (int)(SoundEffect.MasterVolume * 240);
        }

        int width = 340;
        int height = 400;
        float alpha = 0f;
        int notchControl = 0;

        public int NotchControl
        {
            get { return notchControl; }
            set
            {
                if (value < 0)
                    notchControl = 0;
                else if (value > 240)
                    notchControl = 240;
                else
                notchControl = value; }
        }
        string VolumeLevelText = “”;
        public void Draw(int left, int top, SpriteBatch batch)
        {
           
            batch.Draw(resources.ScoredBoardBack, new Rectangle(left, top, width, height), Color.White*alpha);

          
            //Draw the TExt of the current musci Status
            Vector2 wordSize = resources.ScoreBoardFont.MeasureString(VolumeLevelText);
            batch.DrawString(resources.ScoreBoardFont, VolumeLevelText, new Vector2(left + (width – wordSize.X) / 2, top + 40), Color.Gold * alpha);
            //Drawing line with notch to move
            batch.Draw(resources.ScoredBoardBack, new Rectangle(left + 40, top + 210, 260, 15), Color.White * alpha);
            //Draw the Notch
            notchRectangle =  new Rectangle(left + 55 + notchControl, top + 195, 15, 45);
            batch.Draw(resources.ScoredBoardBack, notchRectangle, Color.White * alpha);
            int center = (width – 160) / 2;
            okButton = new Rectangle(left + center, top + 270, 160, 80);
            batch.Draw(resources.Ok, okButton, Color.White*alpha);
            wordSize = resources.ScoreBoardFont.MeasureString(“OK”);
            float secondCenter = (160 – wordSize.X) / 2;
            batch.DrawString(resources.ScoreBoardFont, “OK”, new Vector2(left + center + secondCenter, top + 288), Color.Gold*alpha);
        }
        Rectangle okButton;
        Rectangle notchRectangle;
        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name=”gameTime”>Provides a snapshot of timing values.</param>
        public void Update()
        {
            if(isShowing)
            {
                if(alpha – 1 < 0)
                {
                    alpha+=.05f;
                }
            }
             TouchCollection collection = TouchPanel.GetState();
                if (collection.Count > 0)
                {
                    foreach (TouchLocation tl in collection)
                    {
                         if(TouchDetector.HasBeenTouched(tl,okButton))
                         {
                             IsShowing = false;
                             SoundEffect.MasterVolume = notchControl / 240f;
                         }
                         else if(TouchDetector.HasBeenTouched(Swipes.GetFirstLocation(tl) , notchRectangle ))
                         {
                             Swipes s = new Swipes(0);
                             NotchControl+=(int)(s.GetDirectionVector(tl).X);
                             notchMoved = true;
                         }
                    }

                }

          
            if(notchMoved)
            {
                if(notchControl >=0 &&  notchControl <60)
                {
                    VolumeLevelText = “OFF”;
                }
                else if(notchControl >= 60 && notchControl <60*2)
                {
                    VolumeLevelText = “Low”;
                }
                else if (notchControl >= 60*2 && notchControl < 60 * 3)
                {
                    VolumeLevelText = “Medium”;
                }
                else if (notchControl >= 60*3 && notchControl <= 240)
                {
                    VolumeLevelText = “Max”;
                }
                notchMoved = false;
            }
        }

        private bool notchMoved = true;
    }
}

Submitted my aplication into the market and did not make it in.

Technical
I submitted my application into the windows phone marketplace(the app with the screaming gnomes). Got back a least of things that I need to fix. In this post I’m going to least them and then make a post of how I fixed each issue so that if anyone else find the same issue they can resolve it. Below are the 5 issues that were found:

  1. The submitted screenshots appear to be graphically enhanced.
  2. The application silently terminates when the user attempts to navigate to the “Power Shop”.
  3. The application does not return the user to the previous page when the device
  4. The applications background music overlaps the users selected music.
  5. The application does not provide configurable settings for the user to adjust the music volume.
  6. Ensure state is saved when the application switches and returns to it.

I will update as soon as I fix them I plan to submit my app by friday again so it should all be resolved by then.

Edit: Looking around i realized i need to do a better job of saving state and restarting it therefore added one more point to the list.

A day In My Life

dayinMylife

Hey Everyone,
I normally try to stay positive on this blog and simply show different technologies and projects that I’m working on but today. My plan is to rant and therefore I drew you guys a comic.

I’m a fairly driven individual and after graduating from Computer Engineering at the university of Puerto Rico I really thought I was going to work every day on projects with incredible impact. Truth to be told I was fairly Naïve and while I work on a project that is used by billions of people I generally get to do so little in a day that I end up in the routine of:

  • Being Excited on the morning and going through a list of the thing I mean to accomplish during the day.

  • Getting to the office either meet a co-worker or get an email about a menial task that needs to get accomplished urgently.

  • Resign myself that this needs to get accomplished and work on it for the rest of the day.

The positive thing about it is that i have gotten to realize that being a software developer in a company is about 35% time management , 30% coding and another 35% doing what you actually want to keep your fire lit. I learned a lot of important lessons in the past few years:

  • First and most important feel free to ignore meetings when you don’t think they matter
  • Order your priorities
  • Feel free to voice your concerns and discuss them depending on the culture of the workplace this can be a hard thing
  • Close your email program and set some contiguos time to code
  • Talk about your non related ideas with co-workers this normally leads to fun discussions
  • Try and enjoy the meetings since no matter what you will have to attend some
  • Its okay to be late sometimes if you could not control the externalities.Don’t give excuses just finish your job and hand it in when is done.

I like software development still hate wasting time and which i could do solve some more complex issues every day. But in the end the office is my job and i can tackle the hard problems on my off hours if i really care. Anyone got an opinion. Also I will include a comic every time with rants.