Tag Archive | C#

Dollar IDE Screenshots

I realised today that I never got round to posting any screenshots of Dollar IDE, the PHP Integrated Development Environment I made for my Final Year Project at The University of Hull, once I’d finished developing the feature complete version for submission. This meant I couldn’t show it to anyone when I was talking about it, so I’ve posted some below.

Dollar IDE Start Screen

Dollar IDE Start Screen

This is the first screen a user sees when opening the Application. They can create a new project or open one from a git repository or the local computer — a recent project list makes it easy to get back into a project you’ve been working on.

When making a new project inputs such as “Project Name” and “Save Location” are validated as-you-type so a user always knows how to resolve any problems (e.g. invalid characters or selected a directory that you don’t have write permissions for).

The “Project Type” drop down allows you to select templates for your project. E.g. A web template which has an index.html and ‘images’, ‘styles’ and ‘js’ folders included. The idea was to allow this to be extended so you that you could select, for example, a CakePHP project type and DollarIDE would download CakePHP and resolve all the dependencies, however this has not yet been implemented.

Dollar IDE Open Project from Github

Dollar IDE Open Project from Github

DollarIDE integrates with any git repository through LibGit2Sharp, but has enhanced integration with Github through their API. When you create a project you can have Dollar IDE automatically make and initialize a repository on Github for you and even set if you want it to be public or private. In the above screenshot you can see how Dollar IDE allows you to log in with you Github credentials (which are stored securely using Windows DPAPI) and then select from a dropdown which repository you wish to open and start editing.

Dollar IDE Syntax Highlighting & Autocomplete

Dollar IDE Syntax Highlighting & Autocomplete

Of course most of a developers time is spent in the code editing window itself. In the screenshot above you can see DollarIDE’s tabs, auto-completion and syntax highlighting.

Dollar IDE Settings

Dollar IDE Settings

Seen as developers spend a lot of time in their IDE I felt it was important to ensure that Dollar IDE could be customized to suit their needs. For example, in the Colour Scheme Settings window shown above the user can change both the accent colours and background colour of Dollar. This includes the obligatory dark theme.

You can also see the project pane on the right hand side of the background window in this screenshot. The project pane allows the developer to manage folders and files, and open them for editing — all from inside the same window as the code itself. Due to PHP often being deployed in a CGI setting, file locations are especially important.

Finally, this screenshot also shows that Dollar IDE currently makes no attempt to syntax highlight HTML, which is a great shame as PHP is often intermixed with HTML. This will be one of the first features I add when I eventually open source the project.

Danny

Semester 1, Year 3 draws to a close

Yesterday I had my last exam of the semester, and handed in my interim report for my final year project. Those two things being done signals the end of the first semester of the third and final year of my Bachelors degree. Exciting times.

This semester has been an interesting blend of very challenging, incredibly interesting and quite good fun — and though there have been a few times when I’ve felt slightly overwhelmed by work I’m glad I took the modules I did and felt I have learnt and achieved a lot!

I will receive the results for both “Languages and Their Compilers” and “Data Mining and Decision Systems” on the 24th of February, I will of course update the blog when I know what grades I have achieved.

Looking Forward

Year 3 Semester 2 Timetable

Year 3 Semester 2 Timetable

As you can see from the above timetable I expect to be spending a lot of my second semester of this year working on my final year project, an IDE for the programming language PHP.

Alongside my project and studies I will also be continuing in my role as an undergraduate demonstrator for the department of computer science. In the forthcoming semester I have been tasked with helping out students on the 1st year module “Programming 2” which teaches object orientation and other concepts in C#.

The two modules I will be taking in semester 2 are “Mobile Devices and Applications” and “Distributed Systems Programming”

Mobile Devices and Applications is the module concerned with developing mobile apps with a good user experience, knowledge of different mobile platforms — such as iOS, Android and Windows Phone — and technologies — such as 3G, 4G and WiFi. I am aiming to do really well in this module as I have already developed quite a few mobile apps.

Distributed Systems Programming is a module about the “architectures, technologies and programming paradigms used in implementing and deploying distributed computing applications”. A distributed system is “a software system in which components located on networked computers communicate and coordinate their actions by passing messages”. I’m looking forward to this module because I really enjoyed networking in year 2.

I will of course keep the blog updated throughout the upcoming semester. Bring it on!

Danny

 

The Generation Game – A Simple Genetic Algorithm

Evolution with Green Sheep

Last night my housemate Hayley and I were talking about the Data Mining and Decision Systems module we took last semester, during that discussion the concept of genetic algorithms came up.

In the computer science field of artificial intelligence, a genetic algorithm (GA) is a search heuristic that mimics the process of natural selection, except that GAs use a goal-oriented targeted search and natural selection isn’t a search at all

– Wikipedia

Hayley explained the concept to me using the idea of an animal that is more likely to survive in its environment by blending in with the colour of its surroundings. So tonight, as a nice change from revision and work on my Final Year Project, I had a go at developing such an algorithm — with a somewhat humorous undertone. The result of this undertaking is a little tech demo called “The Generation Game – A Simple Genetic Algorithm”.

In the demo it is advantageous for a sheep to be green, in order to fit in with its field. However at the beginning of the game the ten sheep in the initial flock are of completely random colours.

Turns are taken, in order by

  1. A Flock of Sheep, which breeds, producing 1 new sheep for every two sheep in the flock (if there is a left over sheep it doesn’t breed). Sheep produced by the mating process are the median colour of its two parents.
  2. A Wolfpack which depending on its hunting ability can eat 10% – 60% of the heard in any given turn

The closer a sheep is to the colour green, the less likely it is the be a casualty of a wolf attack (however there are other contributing factors, and a green sheep can still be killed).

As you can see from the gif image above if the initial flock has a green sheep amongst its ranks then evolution takes place (survival of the fittest, like how Darwin described it) and within just 20 generations the flock consists of only green sheep.

Another interesting situation is when there is no green sheep in the initial flock.

Evolution with No Green Sheep

Evolution with No Green Sheep

As you can see from the example above which starts with no green sheep the flock gradually becomes a light brown colour, this is the closest colour the flock could get to green with the genes avaliable in its gene pool.

This is just a simple tech demo (written in C# with XNA) to prove to myself I understood the concept, but it worked out quite well and I think its cool. I’ll be cleaning up the code and adding some comments, so be sure to check out the repository containing the program on GitHub.

Thats all for now,
Danny

Advanced Programming Coursework Result – 100%

08227 ACW - Console and Code

Today I got back the result for my Advanced Programming Coursework.

The coursework was called “Data Structure Analysis”, and the aim was to design and develop data structures in C++, a Linked List and a C style array, and then compare them using a hardware timer to see how they compared in read from file, write to file, search and sort operations.

Once we had created both structures, making sure we kept within a coding style tested using the Parasoft Code Reviewer software and ensuring we didn’t have any memory leaks by properly implementing the gang of three, we then wrote up a 2000 word report detailing how our various algorithms worked.

I’m really happy and proud to announce I achieved a grade of 100% for my work! :D. This means that, subject to the normal exam board review, I have achieved a grade of 88.24% for the module overall! Good times.

Danny

Advanced Programming Exam Result – 90.85%

On monday I took an exam for module 08227 – Advanced Programming.

Questions ranged from being about C++ Syntax, the different ways to traverse a binary search tree to the different uses of difference types of class inheritance.

I’d spent a long time revising before the exam and was confident I would do OK, however I was still pleasantly surprised when I found I achieved a grade of 90.85%. This is a stark improvement over the 75% I achieved in the last Advanced Programming exam, obviously my hard work is paying dividends!

I am still awaiting the mark for my Advanced Programming coursework, once I have that I will of course update the blog with both that mark and my mark for the module overall.

Danny

Advanced Programming Exam and Result

C++ vs C#

Last Wednesday I had an exam for the Advanced Programming module. The exam was about the syntax and use of the C++ Language and the ability to read Assembly Language. I was fairly confident, even though I have personally developed very few C++ applications. As more of an application developer than a real time system or game developer I prefer to ease, reliability and stability of C# or other managed languages such as Java over the pure speed of C++.

Having said that, C++ and Assembly are interesting languages and by studying them I feel I have learnt a lot about programming in general, particularly optimization and how things actually work on the hardware.

The exam wen’t well, and I received a mark of 75% — a first class — which I’m very happy with 🙂

In the upcoming semester there will be a coursework and one more exam for the module. Hopefully I do as well in them as I have in this exam 🙂

Danny

An ‘Appy Christmas at Modern Jago

One of the many things I love about Modern Jago is its huge TV, which has an XBOX connected, with Kinect

One of the many things I love about Modern Jago is its huge TV, which has an XBOX connected, with Kinect

My apologies for a total lack of posts since Christmas. I’ve been busy with all sorts, but mainly revision for my exams. Normal service will now be resumed 🙂

Near the end of November I read about ‘Appy Christmas — an event set up by Microsoft to encourage the development of Windows 8 applications over the festive period — on the Microsoft UK Students Blog.

I immediately thought it could be good fun and posted about it on the University of Hull Microsoft User Group hoping that some of my fellow Hullians would join me on the trip down to Modern Jago, Shoreditch , London. It turns out that in the end 25% of the attendees were from The University of Hull, a fantastic turn out.

The two day event started for me and the two Hullians I was travelling with, Rob and James, went to catch our train at half 10 on Monday from the Hull Paragon Interchange station, just 2 and a half hours later we were at Kings Cross and boarding our Circle Line tube train to Liverpool Street — 10 minutes after alighting at Liverpool Street we’d finished the final walking part of the journey and were at Modern Jago.

This was the second time I’ve been to Jago and I really like it there, its a blend of Modern and Old that works really well, much like Windows 8 I guess Microsoft would say ;).

Over the course of the Weekend I ported my Solar System Simulation coursework for 2D Graphics to WinJS, improved the UI and submitted it to the store — quick work! You can read all about that application here. Rob developed a C# and XAML Modern UI app port of his Cheap Ass Gamer Windows Phone 7 application, which is absolutely beautifully designed and you should definitely check out by clicking here!

Other than application development  a lot of fun was had out on the town with Phil Cross, Ben Nunney and my fellow Microsoft fans and a heck of a lot of pizza was consumed. Overall we produced over 30 apps in two days, good going! No wonder the Windows Store is the fastest growing app store at the moment. Porting applications is almost effortless, bar changing the UI for the big screen.

Danny

Posting Source Code on WordPress

I’ve posted a lot of non computer science blog posts recently, but this is supposed to be “the blog of a budding computer scientist!”. So here’s a post which I hope will help a few of my fellow computer science bloggers who use the WordPress blogging platform — which by the way is fantastic.

Quite often when I see blog posts that contain source code it’s formatted in an annoying way, doesn’t have any colour coding or in a worst case scenario is a screenshot of an IDE. It’s impossible for people to copy your code if you take a screenshot of it, and in my experience if you post your code online you want people to copy and adapt it for their own use.

On wordpress you could use <pre> tags in the HTML editor to make code boxes like the following:

//Here's some <pre> formatted code
public static void Main()
{
      Console.WriteLine("Hello WordPress");
}

Thats all well and good, it keeps the code seperate from the content of the blog post and gives it a different font and background colour to differentiate it as code, however those of us who are used to working in an IDE, such as Visual Studio, with its syntax highlighting may find it less friendly to read. This is where one of WordPress’ best features comes in.

The [ sourcecode ] tag allows you to post fully colour coded source code in a variety of languages including C#, C++, JavaScript and XML. It also adds some other features like line numbering,  code printing, copy to clipboard and view source — It looks like this:

//Here's some [ sourcecode ] formatted code
public static void Main()
{
      Console.WriteLine("Hello WordPress");
}

Much better!

All you have to do is wrap your code like so

[ sourcecode language="LANGUAGECODEHERE" ]
          //Code here
[ /sourcecode ]

Without the space in front of sourcecode (Which I’ve had to put to prevent WordPress from actually making it into a source code box). You then have to replace LANGUAGECODEHERE with the code corresponding to the programming language you are posting:

  • C#’s code is “csharp”
  • XML’s code is “xml”
  • PHP is “php”
  • Java is “java”

You can see all 29 codes at this helpful wordpress help page.

I hope this helps a few of my fellow CS bloggers! 🙂

Danny

Linq to XML

My friend Rob asked me to write a blog post detailing how to use Linq to XML in C# from a beginners point of view. I hope this helps a few people because to be honest I found the documentation I found on the internet quite confusing to begin with.

What does Linq to XML do, and how?

The first thing you want to understand is what Linq to XML is used for, and how it is built to achieve this. Linq to XML is used to create and read XML documents programmatically in C#.  It does this by making XML from instances of classes and making instances of classes from XML.

An example use case for wanting to create an XML document is storing the highscores in a game like sweepy cleaner. The XML file you would want to create would be something like the following. (We’ll use this example throughout)

<?xml version="1.0" encoding="UTF-8"?>
<highscores>
	<highscore>
		<playerName>Danny</playerName>
		<playerRank>1</playerRank>
		<score>28</score>
		<timeAchieved>09/05/2012</timeAchieved>
	</highscore>
	<highscore>
		<playerName>Nick</playerName>
		<playerRank>2</playerRank>
		<score>20</score>
		<timeAchieved>08/05/2012</timeAchieved>
	</highscore>
	<highscore>
		<playerName>Rob</playerName>
		<playerRank>3</playerRank>
		<score>15</score>
		<timeAchieved>02/05/2012</timeAchieved>
	</highscore>
</highscores>

It should be quite clear what this does, but I’ll go through it anyway for people who aren’t familiar with XML. The first line declares the version of XML used and the encoding, fortunately when using Linq this is all done for us, so dont worry about it.

The next line is the first of our elements — an element is just a named area of the document. Think of it as being similar to a class structure in C# in that it holds other elements and attributes, which can be likened to fields. All XML Documents must only have one root element, so in our example we have one called ‘highscores’, which is a good name as it holds highscores. 😛

In between the opening and closing tags for the highscores element we have several ‘highscore’ elements. Think of these as instances of a Highscore class containing a string field called playerName, int fields called playerRank and score and a DateTime field called timeAchieved because as you will soon discover, this is just a text explination of just that — an instance of a class. Anyway, each ‘highscore’ element contains information about a highscore achieved by the player, the actual data we want to retain.

Creating a wrapper class for our Linq Code

Linq creates XML from objects —  sometimes referred to as classes– It also creates instances of objects from XML.  It takes a class, copies the information from it and formats it as XML and can take an XML element a throw all its attributes and elements into an instance of a particular class. Its powerful stuff.

To make an XML file which contains the data of several instances of a class, in this case several highscores, we can make a list of all the objects we wish to save which contains a few more method than an ordinary list. We can do this by making a class which extends a list of the type of object we wish to save. For example to save a list of Highscore objects we would make a class like this:


public class HighscoresList : List<Highscores>

{

        //Linq Stuff

}

whereas if you were trying to save a list of people classes to XML you would have something like the following


public class PeopleList : List<People>

{

      //Linq Stuff
}

This class can now do anything a List could do including adding and removing Highscores or even searching and more! Within this class we will have both our Saving and Loading Linq code.

Saving the objects to XML

Within the HighscoreList class we can create a method called Save which works on each item in list to produce the output in our example. Below is the code. (Sorry for the formatting, I cannot change this, click the “View Source” button to view a better indented version.)

 //Method to save highscore class objects to XML
            public void Save()
            {
                //Create the XML Document
                XElement highscoresXML = new XElement("highscores",
                                            from h in this
                                            select new XElement("highscore",
                                                    new XElement("playerName", h.Name),
                                                    new XElement("playerRank", h.Rank),
                                                    new XElement("score", h.Score),
                                                    new XElement("timeAchieved", h.TimeAchieved)
                                                    ));

                //Save it to Isolated Storage
                using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream(XMLDocumentLocation, FileMode.Create, isoStore))
                    {
                        highscoresXML.Save(isoStream);
                    }
                }
            }

As you can hopefully see the Save Method has two clear sections. The creation of the XML and the saving of the XML to a file in Isolated Storage. Isolated Storage is the main way of saving files on Windows Phone, but you could use the same XML creation code and save to a file on Windows using an XMLStreamWriter or even save to an online service.

The first thing we see when creating the xml is an XElement. The first parameter is the name of the element, this maps directly to the element name in XML. So if you have an XElement called highscores, like we do in the above example, it will output the following XML ‘<highscores> </highscores>’. The second parameter is what we want to be contained within that element — referred to as content, this can be an object of any type and will be converted to a string using that objects ToString() method.

As you can remember from earlier every XML Document has to have a root element, Highscores is this element so the object it holds is simply the rest of the XML Document. The clever bit is how we make this. If you’re familiar with SQL database querys you will recognise the basic syntax of the following bit of code, as Linq is also used for database connection the syntax is almost identical, the reason Linq stands for Language INtegrated Query is that its not really C#, its just database commands integrated into the language.

from h in this

This line simply means from each Highscore element, which we will now refer to as h in this HighscoreList. Think of it like a for each loop going round in your list and appending the following code each time it finds a new Highscore Element.

select new XElement(highscore, 

This line means make a new XElement with the name Highscore, and within it have the following elements:

new XElement("playerName", h.Name),
new XElement("playerRank", h.Rank),
new XElement("score", h.Score),
new XElement("timeAchieved", h.TimeAchieved)

Each of these elements is the actual highscore data for that particular highscore. Each has exactly the same syntax as the previous XElements however this time they contain strings rather than other XElements. Remember, H just refers to the Highscore that is currently being written, so the first XElement would output

<playerName>Danny</playerName>

If the highscores playerName field contained the string “Danny”. Linq will loop through all the Highscore instances in the list and write out the XML, so if your list contained 3 highscore instances with the data specified in the example XML the example XML would be written out. We can now save this XML to Isolated Storage, or do whatever else we want to with it.

Reading XML to make Objects

Once we’ve saved our objects to isolated storage or wherever else we will probably want to read them back at some point, otherwise what would be the point!? 🙂 This too is carried out in a method within our HighscoresList class.


            //Method to load highscore class objects from XML
            public void Load()
            {
                XDocument highscoresXML;

                //Load XML From isolated storage
                using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream(XMLDocumentLocation, FileMode.Open, isoStore))
                    {
                        highscoresXML = XDocument.Load(isoStream);
                    }
                }

                //Cycle through the XML adding highscore objects to the list each time we find one
                var query = from xElem in highscoresXML.Descendants("highscore")
                            select new Highscore
                            {
                                Name = xElem.Element("playerName").Value,
                                Rank = int.Parse(xElem.Element("playerRank").Value),
                                Score = int.Parse(xElem.Element("score").Value),
                                TimeAchieved = DateTime.Parse(xElem.Element("timeAchieved").Value)
                            };
                this.Clear();
                AddRange(query);
            }

This method is also split into two main parts – The first of which is Loading the actual file from Isolated Storage and the second being converting each Element inthe file into an object which we can use in our program.
The first part is quite simple but also outside the scope of this blog post, you can find out more about Isolated Storage here. The second part cycles through each XElement (referred to as xElem in this code) which is a “Descendant” (a.k.a. a child) of an element called “Highscore”. The following code should explain this.

<?xml version="1.0" encoding="UTF-8"?>
<highscores>
	<highscore>
<!-- We're looking here because all of these elements are children of a "Highscore" -->
		<playerName>Danny</playerName>
		<playerRank>1</playerRank>
		<score>28</score>
		<timeAchieved>09/05/2012</timeAchieved>
	</highscore>
	<highscore>
<!-- And here! -->
		<playerName>Nick</playerName>
		<playerRank>2</playerRank>
		<score>20</score>
		<timeAchieved>08/05/2012</timeAchieved>
	</highscore>
	<highscore>
<!-- And here! -->
		<playerName>Rob</playerName>
		<playerRank>3</playerRank>
		<score>15</score>
		<timeAchieved>02/05/2012</timeAchieved>
	</highscore>
</highscores>

When we find a set of descendants we select them and constructing an instance of a Highscore to put the data in, this is done by the following line of code

select new Highscore

We then fill this temporary instance of Highscore with the data from the child elements of the Highscore Element.

Name = xElem.Element("playerName").Value,
Rank = int.Parse(xElem.Element("playerRank").Value),
Score = int.Parse(xElem.Element("score").Value),
TimeAchieved = DateTime.Parse(xElem.Element("timeAchieved").Value)

This code is fairly self explanatory it takes the Value of each element (a.k.a the content) and puts it in the relevant field of the object. The code will cycle through and make objects for every element in the XML file. Once it has done this we clear the List (to remove old content) and then add our new Highscores from the XML file to it.

this.Clear();
AddRange(query);

And voila, your HighscoreList now contains all the objects contained in your XML file, you can now sort or search it and take elements from it as you would with any other list. I hope this has helped you understand how Linq works and how powerful it can be.

Danny.

Changing Opinions – Why I Can No Longer Stand PHP

You can see my C# education has rubbed off a bit on my PHP programming, for example the use of Libraries and more comments than I would have previously used

My first experiance of programming was making dynamic web pages for Worldwide Lighthouses Version 2. Essentially all my project did was provide an uploader for images and data, which was then input to a database, and several different types of pages used to display information about different types of aids to navigation by pulling information from the database and formatting it in a specific way.

At the time I thought the language I was using to do this — PHP — was great, the syntax was simple and there was plenty of documentation avaliable online for free. I hadn’t had any formal tutoring, nor did I need it in order to get on with what I was doing, I taught myself and things worked… most of the time. Of course having no formal tuition I didn’t work under best practices and everything was absolutely linear, I had no concept of Object Orientation. These were the days when I loved PHP.

In fact, when I first started learning C# I thought it was downright stupid that you had to declare what type a variable contained, “Why can’t the stupid thing work out that ‘2’ is a number?” is a choice quote from myself.

Recently I’ve had to go back to PHP for a few projects, including 5Hives. I cannot stand it. Compared to C#, PHP is massively inconsistant — heres some examples:

  • Built in Methods – Some use Under_Score() naming, some use camelCase, some use number2syntax, some use numberToSyntax. This means you can never guess what a method you need might be called, especially annoying when dreamweaver and expression web don’t have very good intellisense.
  • Sometimes it prints errors to the browser, sometimes it puts them in an error log. Oh, and it doesn’t tell you where said error log is.
  • Some functions return null if they failed, some throw an exception causing the program to stop, some print errors… etc etc
  •  If you forget the $ sign before a variable, rather than telling you it uses the name of the variable as if it was a string
  • Don’t even get me started on sessions…

There are so many reasons that PHP isnt the nice “work place” that C# is that I cannot sum them all up — I’ll leave that to this much more in depth post, which I enjoyed reading and agreed with on the whole.

Just the other day Nick was saying how everyone loves the first language they learn, be that prolog, python or VB (ok, maybe not VB ;)) but I cannot count myself among this group. I can program in PHP quite well, I can tolerate it and I know there are some situations where it is one of the best tools to use (simple upload forms are still a joy to make in PHP) but I cannot say I’m its biggest fan.

Danny