TechMeetup - Introducing Code Rocket
This article covers the content of a talk given at TechMeetup in Aberdeen on the 16th June 2010. We introduced you to the basic concept behind the Code Rocket software tool and how it can integrate with your development process. Then you were shown the live development of a working binary search program using Code Rocket’s pseudocode and flowchart views inside Visual Studio to assist with the implementation.
You can download the slides from the presentation here.
You can download the incomplete project here and you can download the completed project here.
Why not download the Code Rocket .NET trial to try out the examples for yourself or to work with your own code.
Contents
Video
Alan Spark talks about Code Rocket from TechMeetup on Vimeo.
What is Code Rocket?
Typically when designing an object oriented system you will use UML tools to design the overall structure of the system. You may produce class diagrams, sequence diagrams etc. What UML doesn’t allow you to do is design the algorithms and business logic at the procedural level. Code Rocket is designed to be an extension of your current toolset and supports procedural level design using two complimentary views. The pseudocode editor and the flowchart editor. Both of these views are fully editable and synchronized so that you can always use the most appropriate view for your needs.
How does it work?
Once you have designed your algorithm, we can produce a code skeleton that gives you a head start on the coding process. As well as turning your design into code, Code Rocket can also reverse engineer existing code for you to visualize in the design views. This gives you roundtrip synchronicity between code and its design and allows you to mix and match between working in the code or design without the worry of either getting out of sync.
Code Rocket comes as a plugin to Visual Studio and currently supports the C# and C++ languages. It also comes as a plugin to Eclipse for the Java language, as well as a stand-alone application called Code Rocket Designer that you can use for upfront design before you start coding.
Binary Search Example
We walked through a live coding exercise using Code Rocket’s design views to speed up the implementation process. We started with a user interface that had none of its functionality implemented and ended up with a fully functioning application.
The aim of the application is to allow the user to add numbers to a listbox, allow the listbox to be sorted and then searched using a binary search algorithm to highlight the first occurrence of a number.
Stage 1 – Adding items to the listbox
We designed this method using the following pseudocode:
This method handles validation of the input text to make sure it is an integer. If invalid text is entered then the user is alerted with an error message. We open a try statement to handle turning the input into a number and adding it to the listbox. An exception will be thrown when anything other than an integer is entered and we catch the exception to alert the user. Once we were happy with the design, we committed it to the code.
The following skeleton code was produced from the design:
We then implemented the code for the method and saw the diagram turn green to show completion of its code:
Running the application at this point allows us to add numbers to the listbox:
We went on to implement logic to sort the listbox.
Stage 2 - Sorting the listbox
The next stage was to implement the behaviour behind the Sort button. The code will populate a list in memory with the sorted list of numbers. The listbox will then be cleared and repopulated with the sorted list.
First we implemented the code to create the sorted list and populate it with the sorted numbers using the following pseudocode:
We brought forward the flowchart and proceeded to add the design steps to clear the existing listbox and then repopulate it with the contents of the sorted list:
We then committed the design to the code and implemented the finer details. We ended up with the following code:
However, there was an error in this code. If there were no numbers already in the sorted list that were larger than the one being added then it wouldn’t be added. We needed to add the number to the end of the sorted list in this case.
We brought forward the flowchart and made some changes to the design to reflect this new behaviour:
We now have a flag that is set to true only when a number is added to the sorted list. This flag is then used after we have looped through the sorted list to determine whether or not we can add the number to the end of the list.
We committed these changes back to the code and saw that the original code was still intact and the new design changes had been inserted as skeleton code, ready for implementing. We went ahead and implemented the code for the changes and ended up with the following code:
We now had the functionality to populate the listbox and sort it:
The next stage was to implement code behind the Search button.
Stage 3 - Searching the listbox
I had already implemented a method to do the binary search. The code for it is shown below.
We looked at Code Rocket’s code visualization capabilities by viewing this method as pseudocode and as a flowchart and walked through the general idea of how the binary search algorithm works.
The binary search relies on a sorted list as its source. The search space is then narrowed down by splitting the search boundaries into upper and lower portions. We first check the midpoint to see if it is the value we are looking for, if it is too small then we can continue looking in the upper half and if it is too big then we can continue looking in the lower half. If the value isn't found then -1 is returned.
All that remained to do was to call this logic from the Search button. We went on to design the Search method and realized that we had already implemented validation logic in the Add button. We copied the design from the Add method and made the necessary changes to it:
We committed this to the code, giving us a skeleton to implement but retaining the code that had been implemented for the Add method:
After implementing, this is what the code looked like:
We ended up with a fully functioning program that met our requirements set out at the beginning. In summary, the requirements were to be able to add any amount of numbers to the listbox in any order, sort the listbox and then search for a number to have the first instance highlighted in the listbox.
You can download the incomplete project here and you can download the completed project here.
Why not download the Code Rocket .NET trial to try out the examples for yourself or to work with your own code.
I hope you enjoyed the article and presentation. If you have any questions or feedback please don't hesitate to contact us.
|
|
Tweet |




