Fremus.co.za

Demistifying Life and Web Development

Archive for the 'Application Development' Category

Recent conversations on CMS’s

A recent conversation with a colleague around the nature of content management systems got me thinking about the nature of these systems and some of the trends going around. The first thing that seems to be a systematic “issue” is that a lot of systems are legacy systems and do not really seem to always consider current development practices, but rather focus on adding more and more features in the existing system. Often this approach leads to bloated systems that require more effort to maintain. Lets be honest about development practices – they change quite rapidly. I think we are no longer living in the days of classical analysis and design – but rather in a world where rapid (read agile) development seems the way to go. Rapid, agile, to me means that you spec a system one bit at a time and the focus is on getting those bits working. Thus if development practices change and the practice of developing a particular CMS used an older development practice then surely its no longer reflecting relevant thinking. It can also be said that relevant thinking is relative to the problem a particular CMS is solving, but the point I am making is that a key fact in defining a good CMS is in its ability to adjust the needs of today and not yesterday. Its also true that you cannot truly get to today possibilities without knowing what you did yesterday.

Do CMS’s only solve the matter of making sure websites are displayed or rendered consistently? Surely a CMS’s is more than that and should ideally expose one or more API’s – in fact I believe if your CMS does not expose some sort of core API it will not get the traction it needs, and you cannot really improve the code in your system without others using it. Other factors that contribute to the nature of a CMS include SaaS (Software as a Service) and PaaS (Platform as a Service) models, and the question that comes to the fore, in my mind, is whether a CMS embraces the nature of a service or platform-oriented environment.

I also gave the idea of designing a content management system in terms of presentation management some thought and initially I conceptualised that the presentation management part of it can be defined in a class hierarchy. The presentation management core will have a Page class and it might have a many-to-many relationship with a PageElement class. Thus a single page might have many page elements. A page element is a block element such as a paragraph, header or video. I still have to think a little bit further but my thinking was around being able to create pages and being able to add page elements to that page. Each element would be of a type and a type could be a paragraph, header or video, but it can also be another page element. The HtmlTextWriterTag class contains a whole list of enums and potentially it can be used in a dynamic sort of way. This still needs some thinking though.

  • Share/Bookmark
posted by fr3dr1k in Application Development and have No Comments

Trying to turn a new development leaf

I’m not sure development teams do the testing they are suppose to do, or follow the advice of what proponents of testing say you should do. As a matter of fact I know that most teams do not practice any form of formal testing, or rather make testing a key component of their development. Test Driven Development in an Agile scenario prescribes that you write code, write test code, test it and iterate if necessary. Essentially TDD forces you into a discipline of making sure your code works, which incidentally is one of the key objectives of an agile development methodology – you must always have a working portion of your code. In other words if you have to release code immediately then there should be code of sufficient working quality available to make everything work. That is my understanding anyway.

The reason I am looking at using agile as a development methodology is because I want to develop a commercial product using ASP.NET MVC and as Phil Haack says in this article:

Notice that at this point, we’re focusing on the behavior of our app first rather than focusing on the UI first. This is a stylistic difference between ASP.NET MVC and ASP.NET WebForms. Neither one is necessarily better than the other. Just a difference in approach and style.

And from that I gather that ASP.NET MVC was designed to work well as a unit testing platform as well. I started about 3 weeks ago to formalise my development process and I started out by defining agile to have the following steps:

  • Start off by Planning a work item
  • Do a requirements analysis of the work item and identify what you will need to do to get it working correctly
  • Design the code/program
  • An iteration then begins:
    • Write the code
    • Write a unit test
    • Do an acceptance test

I am having to change my development process though, because I intend to use Team Foundation Server (TFS) as my source control system, and I was thinking that maybe I need to consider using MSF (Microsoft Solution Framework) to drive my development process. MSF is integrated into TFS, and it essentially means that you can build applications and do source control within a development methodology. I started off looking for stuff on MSDN and searched for this and came across this presentation. From this presentation I understood that the agile process is structured a little differently to what I did in my initial process definition. Each iteration in a MSF consists of:

  • Envision
  • Plan
  • Build
  • Stabilize
  • Deploy
  • Continuous

Iterations occur at various steps and its up to the project manager to determine how many iterations occur. MSF also promotes a daily work cycle, which essentially makes sure that your code is of an acceptable standard. Essentially you check-in each day, make a build, make sure its an acceptable build and then you continue the develpment process within an iteration. This process repeats daily. Within the iteration cycle there are several other iterations which aim to achieve a pre-determined level of quality, based on planning of feature sets. The iterations also act as a mechanism to correct a project plan if there are deviations. The iteration is broken up into iteration cycles, with iteration 0 consisting of a project setup plan followed by a first iteration that involves planning, developing, testing and getting feedback followed by an nth number of iterations that involve planning, developing, testing and feedback. The last iteration is a set of nth iterations that involve developing, testing and releasing the product. You have to view these iterations as a set of ‘refinement’ iterations, each iteration is intended to refine the solution. You also have to view these iterations in relation to the iteration steps mentioned above. In the powerpoint presentation they present a very cool view of the iterations as they happen.

Iteration 0

At the top they start off with the envision stage that includes the writing of a vision statement and the identification of personas within your system. Once that is defined you have to determine an iteration length. At the planning stage of the iteration you have to access/assess project progress, which is a continual thing I assume. Within the build stage you must start off by creating a scenario through brainstorming. You must also create a Quality of Service scenario through which you create a QoS. At this stage you must also refine the personas. The scenario that you created previously requires that you prioritise the scenario list, each with a scenario description. You need to prioritise QoS as well and write a QoS requirement. From the scenarios that have been written you need to create a solution architecture that partitions the system. You also need to storyboard the scenario, and develop a performance model. You also have to identify the security objectives, and then you need to test the scenario by defining a test approach.

On the next level you have to determine the interface. Does this mean the actual UI? You also need to plan an iteration at this stage by estimating a scenario or QoS. Then you need to develop a threat model. On the next level you need to plan an iteration around scheduling a scenario. From this you can develop an architectural prototype. You also need to plan an iteration around QoS and then create a infrastructure architecture. At the next level/step you plan an iteration around dividing the scenario into tasks, that make up a dev task which is then costed, and the same strategy is applied to QoS.

From the diagram in the powerpoint I assume that you can repeat as many iterations as you want.

Iteration 1

Iteration 1 includes writing a QoS test and writing a validation test for testing your scenario. It also includes doing a code check-in to your source control. It contains stages/levels that require you to write code for a development task, as well as creating an update of a unit test. It also covers fixing bugs:

  • Reproducing the bug
  • Locating the bug cause
  • Deciding on a bug fix strategy
  • Reassign the bug
  • Create of Update unit test
  • Code the fix
  • Perform unit test

Implementing a development task covers the following:

  • Create of Update Unit Test
  • Write code for dev task
  • Perform Unit Test
  • Perform Code Analysis
  • Refactor code
  • Integrate Code Change

After this stage there has to be a build and an accepted build. In the build there will be:

  • Start a build
  • Verify a Build
  • Fix a build
  • Accept Build

An accepted build will revolve around testing scenarios and in particular:

  • Conducting an exploratory test
  • Select and run a test case
  • Open a bug
  • Share/Bookmark
Tags: ,
posted by fr3dr1k in ASP.NET MVC,Application Development and have No Comments

C# and streams

C# uses a lot of streams, or at least it seems so in some of the code examples I have looked at.
Having said that I felt the need to read up on the Stream class. The stream class is an abstract class and an abstract acts as a type of base class from which other classes can inherit. And just to recap, abstract methods do not have a method body and must be implemented by the class inheriting from it. A method marked as virtual can be overridden but it does not have to be implemented. Methods that are marked as abstract can be overriden.

So the stream class is an abstract base class for a set of other classes that do various operations such as reading content from files, reading files in a directory, etc. Each of the classes that inherit from the base stream class can be seen as a type of stream. Streams can be read from, written to and they support seeking.

The classes that inherit from the Stream class can be divided into three broad categories:

  • Classes that are used for File I/O
  • Classes that are used for reading and writing to streams
  • Common IO stream classes

The reason for taking a look at these classes is because I was looking at a PowerPoint presentation recently. More specifically I was looking at PowerPoint 2007 (pptx) and its underlying XML. If you save a Powerpoint 2007 as XML and you look at the source you will note that there are sections called pkg:binaryData. It got me wondering that maybe that same binary data can be processed in C# code. Take a look at the following sample C# code:

            Image img = Image.FromFile(@"C:\Users\fredrike\Documents\LEGAL SUITE.bmp");
            byte[] myByte = File.ReadAllBytes(@"C:\Users\fredrike\Documents\LEGAL SUITE.bmp");
            Console.WriteLine(myByte.Length);
            MemoryStream stream = new MemoryStream(myByte);
            int lengthOfByte = Convert.ToInt32(stream.Length);
            byte[] mySecondByte = ReadFully(stream, lengthOfByte);
            Console.WriteLine(mySecondByte.Length);
            Image img2 = Image.FromStream(stream);
            img2.Save(@"C:\Users\fredrike\Documents\LEGAL SUITE3.bmp");

Notice a couple of things I have done in the code. I created a Image class instance and read it from an existing bitmap image. I then create a byte array and used the static ReadAllBytes method supplied by the File class. I then just simply wrote the length of the file to the screen because in the next couple of lines I create a MemoryStream instance using the byte array, after which I also get the length property of the MemoryStream instance because I use it in a function called ReadFully:

        public static byte[] ReadFully(Stream stream, int initialLength)
        {
            // If we've been passed an unhelpful initial length, just
            // use 32K.
            if (initialLength < 1)
            {
                initialLength = 32768;
            }

            byte[] buffer = new byte[initialLength];
            int read = 0;

            int chunk;
            while ((chunk = stream.Read(buffer, read, buffer.Length - read)) > 0)
            {
                read += chunk;

                // If we've reached the end of our buffer, check to see if there's
                // any more information
                if (read == buffer.Length)
                {
                    int nextByte = stream.ReadByte();

                    // End of stream? If so, we're done
                    if (nextByte == -1)
                    {
                        return buffer;
                    }

                    // Nope. Resize the buffer, put in the byte we've just
                    // read, and continue
                    byte[] newBuffer = new byte[buffer.Length * 2];
                    Array.Copy(buffer, newBuffer, buffer.Length);
                    newBuffer[read] = (byte)nextByte;
                    buffer = newBuffer;
                    read++;
                }
            }
            // Buffer is now too big. Shrink it.
            byte[] ret = new byte[read];
            Array.Copy(buffer, ret, read);
            return ret;
        }

I got this from Jon Skeet’s website. Be sure to check out his other C# articles. In my code I then created a second byte array which is generated by the ReadFully method. Once the bytes have finished reading I created a second Image instance, img2 and pass it the MemoryStream instance, and I then call img2′s Save method and create a second image based on the first one.

So my question is, can the binary data from Powerpoint presentations be used in the same way?

  • Share/Bookmark
posted by fr3dr1k in Application Development,C# and have No Comments

Some thoughts on Windows Forms Development

Yesterday I posted about Making static content more dynamic. I actually started developing a small C# windows forms application in combination with a MS Access database. The windows forms application will, for now, generate all the HTML needed for the website and the MS Access database will be used to centralise information. This is not the most modern or flashiest approaches but it does lend itself to saving some money and if the marketing strategy is good and accurate might even deliver good results. Obviously as soon as the customer changes hosting plans the need for static HTML content might go out the window altogether. You can still, however, incorporate the same Windows forms application, through WCF services.

Windows forms seemed so strange, because the domain is so different to web-based apps, seeing that I havent done any in a very long time. But the C# code remains very much the same, which is awesome.

  • Share/Bookmark
posted by fr3dr1k in Application Development,C# and have No Comments

Making static content more dynamic

I was helping some with their website yesterday and the hosting package they have does not allow for dynamic languages, such as PHP or Python, and there is no database either. So basically you have a situation where you can only upload static HTML pages, which is limiting yes, but not such an entirely bad thing. Managing the content for such a website only has two or three realistic options:

  • Use IDE such as Dreamweaver, which also implies more costs
  • Manually edit the HTML pages yourself, which can become nightmarish
  • Create some managed (C#) code that can automate HTML generation

All three approaches involve content being uploaded, which is not the worst thing ever, but it does mean that updates do not occur immediately. Also remember that a budget constraint is the biggest factor here. The idea is that you do not incur any additional monthly costs. I also think you can build content updates to social networks as well.

  • Share/Bookmark
Tags:
posted by fr3dr1k in Application Development and have No Comments

Linq to XML and DataSet to XML

On Monday I started working through some LINQ to XML and it got me so excited that I misunderstood some project requirements that ended up being quite wrong. It did not, however, diminish my enthusiasm. I ended up using a small part of the code in the end anyway, even though it was not in a production environment.

Lets say you have a collection of XML documents and you would like to know what elements appear in all of them, so at the end of it all you have a single of list of elements that appear between all of them. This is how I did it:

            DirectoryInfo di = new DirectoryInfo(ConfigurationManager.AppSettings["XMLDirectory"].ToString());
            Dictionary values = new Dictionary();
            FileInfo[] fi = di.GetFiles();
            Response.Write("
");
            Response.Write("
");
            foreach (FileInfo file in fi)
            {
                //Response.Write(@"


");
            }
            Response.Write("

");
            Response.Write("
");
            Response.Write(@"


");
            Response.Write("

");
            Response.Write("
"); //Response.Write("" + file.Name + "
"); XmlReaderSettings settings = new XmlReaderSettings(); settings.IgnoreWhitespace = true; settings.IgnoreComments = true; settings.ConformanceLevel = ConformanceLevel.Fragment; //Console.WriteLine(file.Name); XmlReader reader = XmlReader.Create(file.Directory + @"\" + file.Name, settings); XDocument document = XDocument.Load(reader); IEnumerable elems = from items in document.Descendants("Bond") select items; foreach (XElement elem in elems) { IEnumerable childElems = from items in elem.Descendants() select items; foreach (XElement xelem in childElems) { //Response.Write(xelem.Name.ToString() + " " + xelem.Parent.Name.ToString() + "
"); if (!values.ContainsKey(xelem.Name.ToString())) { values.Add(xelem.Name.ToString(), xelem.Parent.Name.ToString()); } } } //Response.Write("
"); Response.Write("Combined"); var combined = values .OrderBy(kv => kv.Value); foreach (KeyValuePair kvp in combined) { Response.Write(kvp.Key + " " + kvp.Value + ""); } Response.Write("
");

I use the DirectoryInfo class on a directory, XMLPath in this instance. I then declare an array of type FileInfo, which I then use in a foreach (Enumerate) loop using the FileInfo class. I then use the XMLReader class to read the XML document that is represented through the FileInfo class to read the XML. Inside the foreach loop I create an enumerable instance of XElement called elems which uses LINQ to XML to select all the items. I then create a second enumerable instance of XElements called childElems. I then iterate (enumerate) through the childElems instance and add the Name of the element as the key and the parent as a value to a dictionary of type string,string which I declared earlier. This will loop through all files in the directory and generate a dictionary with combined values. Once its in a dictionary you can simply enumerate through it. I ordered it first by using the OrderBy extension method. Once it has been ordered I enumerate through it with a KeyValuePair and display the combined list. This approach has apparent weaknesses in that it uses the name of a node as a key and the parent as the value. What if two nodes are equal but have different parents? It served a purpose for me though.

The second piece of code I would like to show is an example of converting a dataset to xml and returning the raw XML. Let’s say you have an arbitrary function and you want to return the raw XML of a dataset, you could use:

            StringWriter writer = new StringWriter();
            transactionDS.WriteXml(writer);
            xmlizedString = writer.ToString();

            return xmlizedString;
  • Share/Bookmark
posted by fr3dr1k in Application Development,C# and have No Comments

More code vs less code vs readability vs efficiency

After my blog post yesterday on File.ReadAllLines() vs StreamReader I have been thinking that more code does not necessarily mean more, or does it? I mean syntactically the first one is a one liner and the second one is a few lines, but I do feel that the latter adds more value. Why? Well firstly because streams seem to be an important part and concept in the .NET framework and secondly the streamreader class seems to dispose of resources a bit better. It also seems as if my implementation of the streamreader class deals with something the first option has still to deal with. I mean you have to assign a string array and then somewhere you have to iterate through the content of the array, whereas with the streamreader you can do all of that once. Looping through the contents that gets read by the streamreader class instance can be achieved by either appending the results to a stringbuilder instance or by using a function that implements the IEnumerable interface and uses the yield keyword. Using a function that implements IEnumerable means that you can run a foreach against it. I do honestly find this approach a lot more expressive. Its also interesting to note that the streamreader class performs better in some cases.

  • Share/Bookmark
Tags:
posted by fr3dr1k in Application Development and have No Comments

Do we spend enough time designing?

In my current work environment it seems as if I spend way more time pushing out code than spending time making sure the quality of the code is good. Quality in this context means that you actually spend some time before you code planning the structure of the program you are about to create. In its simplest terms this is simply penciling some ideas down and drawing a few basic flowcharts. Doing this enables you to see things unfold a bit clearer, because I have found myself in a situation where I started coding and I got to a stage where the logic of the code went sour and it meant recoding everything or parts of it. With a bit of planning and design beforehand this can be avoided.

On a deeper, more complicated level, detailed specification building that incorporates requirements definitions and the full SDLC type-of-thing, obviously provides a different approach. But I think when you get to a deep and complex level you are addressing a big group of developers. Or can the same principles be applied to smaller projects?

I do find that I draw a lot of contextual diagrams in my current work, because I like having a contextual overview of what I am doing and what the system I am busy with attempts to achieve. A contextual diagram is usually a very basic diagram that just shows the system on a high level, with the idea being that you drill down to deeper detail from there. I remember using an analysis methodology called SSADM (Structured System Analysis and Design Methodology) and remember it as being very, very structured. You would start your diagram at the contextual level and drill down until the very lowest level. I do find OOAD (Object Oriented Analysis and Design) easier in a sense though, because you can directly translate objects in the real world to objects in the system. But I still draw contextual diagrams for OOAD.

The point though is that planning a piece of code is as important as the code itself and is a discipline.

  • Share/Bookmark
posted by fr3dr1k in Application Development and have No Comments

File.ReadAllLines() vs StreamReader

A couple of days ago I forced myself to memorize the C# code for reading from a file (text, html), and for it I used the StreamReader class (on MSDN):

try
{
    using(StreamReader reader = new StreamReader('filename'))
    {
            string s;
            while((s = reader.ReadLine()) != null)
            {
                   Console.WriteLine(s);
            }
     }
}
catch(Exception ex)
{
      Console.WriteLine(ex.Message);
}

This is in comparison to the File class which has a method called ReadAllLines, and its biggest benefit is that it results in less code. Is less more? I’m not sure yet. With the StreamReader class you can create a method that implements IEnumerable which allows you to use the foreach on it. I found the sample for this on http://stackoverflow.com/questions/286533/filestream-streamreader-problem-in-c.

public static IEnumerable ReadLines(string path)
    {
        using (StreamReader reader = File.OpenText(path))
        {
            string line;
            while ((line = reader.ReadLine()) != null)
            {
                yield return line;
            }
        }
    }

foreach(string line in ReadLines(file))
{
    Console.WriteLine(line);
}

It is also mentioned that the StreamReader approach works nicely with Linq. Another thing that was mentioned is that the StreamReader uses a concept called lazy evaluation and this increases performance.

Does the less code option result in better performance just because it uses less lines of code? I’m a bit undecided. Maybe I will have a better opinion in the future.

  • Share/Bookmark
Tags:
posted by fr3dr1k in Application Development,C# and have No Comments

Is JavaScript object oriented?

When I started my career about 5 or so years ago I didnt know much about JavaScript, but I knew something about object oriented analysis and design. OOAD in this case was the classical approach to OO where an object is an instance, which means that each thing or object that you create in a system must first be instantiated, and this is something that does not happen in JavaScript at all really. Everything in JavaScript is object-based, there is no class instantiating as in the classical OO approach. The other thing that is quite notable is that it takes a bit of a work around to create some sort of inheritance in JavaScript, its not something that exists in the language itself. Similarly a thing like polymorphism is not a language feature as it is in say C#. With all that being said though, it does not mean that these features cannot be created in JavaScript, it just means JavaScript kinda works better without them.

It’s amazing then to hear an experienced JavaScript developer then speak of JavaScript being object oriented because it supports basic dot notation, even though the language itself is not object oriented in the classical sense.

  • Share/Bookmark
posted by fr3dr1k in Application Development and have No Comments
Get Adobe Flash playerPlugin by wpburn.com wordpress themes