Explore Free Money, Apps That Pay, and more!
5 stars based on
This article provides a walk through of a couple of iterations of designing and implementing a form of binary search algorithm using the Code Rocket plug-in for Visual Studio. It will demonstrate Code Rocket's automated flowchart and pseudocode design support and resultant benefits in areas such as code design, development, maintenance and review. Along the way you will see how Code Rocket automatically synchronises changes in code with design documentation and also changes in designs being synchronised with code.
Code Rocket is the newest kid on the block in terms of documentation tools. Like other tools it can pick up documentation from header comments above functions, but Code Rocket can also delve deeper into the actual internal workings of the function too, and allows you to visualize and document the function contents in both flowchart and pseudocode formats. See Figure 1 below for an example.
It shows a sample C function which has the Code Rocket visualization views docked beside it. Code Rocket Sample Screenshot. Purpose of Article I wanted to provide a simple walkthrough of using Code Rocket during a typical development task to show you a bit of what it can do.
I use it for C development and I find that it provides some really valuable benefits such as: Code Rocket can be downloaded here. You can obtain a free trial licence key via email. OR just click 'Continue' if you have already entered your license key. See Figure 2 below. The Code Rocket components are just like any other tool window inside Visual Studio. They can be resized, positioned and docked into the IDE.
Or, if you have your desktop spread across several monitors you could do what I do and have Visual Studio running in one monitor and have binary options screenshot thumbnail 1 Code Rocket components floating and displayed in a separate monitor. I wanted to use a code example that may be fairly common from the world of data structures and algorithms — conducting a binary search. You may recall that a binary search allows you to traverse a list to locate an item of interest by attempting to halve the search space each time, therefore promoting efficiency in the search.
In my code I have declared the prototype of a method which accepts the following parameters: Initially the start position will be 0 the start index of the array and the end position will be whatever the length of the array is. The method will binary options screenshot thumbnail 1 an integer representing the position within the array that the item being sought was located at, or -1 if no item was found. The method will be called recursively, halving the search space each time until it finds the result or not.
I will now implement the code for this function aided by Code Rocket. NET framework classes which could be the focus of an entire article in its own right. However this article is about Code Rocket and not binary searches per se. I will just work through one or two iterations of design and coding to demonstrate Code Rocket. Design the algorithm using pseudocode and flowchart Conducting the binary search requires traversing a list of items, attempting to halve the search space each time, usually by calculating the midpoint of the search space and deciding whether to look within the items prior to the midpoint or after the midpoint.
It has been a wee while since I have used this algorithm therefore I want to have an opportunity to think it through prior to coding by laying out my thoughts in pseudocode. First, I need to select the method in the code I want to view or edit the design of, and then type the pseudocode. See Figure 3 below. When you enter pseudocode into Code Rocket it automatically creates a fully editable flowchart representation of the design too.
I usually like to refer to the flowchart to get an alternative view of the design, to check for any obvious mistakes. You don't need to insert pseudocode to get the diagram, Code Rocket automatically creates the diagrams directly from your code too, i. Figure 4 below shows what Code Rocket provided me with for the above pseudocode. As mentioned the diagram is fully editable. You can drag and drop new items into the diagram or move items into new locations. Code Rocket provides ways of dealing with larger diagrams, e.
You can select groups of elements which you want to group together into a single higher level element to reduce noise in the diagram for less interesting areas of code. There is also refactoring support, e. You can also print the diagram in various ways, e. One key benefit for me about the diagram is that you don't have to fiddle around with moving lines and boxes, you just drag and drop items where you want them and Code Rocket takes care of the layout for you.
Figure 5 below shows the resultant code skeleton. Multi-line comments are accommodated. You can have multiple lines of code underneath a single comment. If you don't have comments in the code Code Rocket will still provide binary options screenshot thumbnail 1 with pseudocode and diagram representations for it and won't put comments in your code unless you specifically create or edit them through the design views. It also allows you to group things together at a higher level.
You can enclose a whole group of code statements within Code Rocket comment tags so they only appear as a single larger element in the design views, rather than having a separate design element for each separate line of code. So there's quite a bit of flexibility here.
I have added a brief example of this towards the end of the article. Continuing with the example Figure 6 below shows version 1 of my attempt to complete the code for the binary search method. After doing some testing, binary options screenshot thumbnail 1 seems to be working reasonably well, but I have discovered a few binary options screenshot thumbnail 1 with edge cases.
One of these is that I need to check for the eventuality that both the start point and the end point to seek within have become zero.
This could result in an infinite loop which will attempt to continually inspect the array item at index zero. Therefore I decide to add an extra check into the binary search algorithm to mitigate this case.
Alternatively, I can just add the new logic directly into the code itself. One of the benefits of this is that Code Rocket will automatically detect the changes to the code and will automatically update its design components to reflect the latest state of the code — therefore making sure the design documentation is always up to date.
See Figure 7 below. I find this code synchronisation feature particularly useful. It means that I can write my code the way I want and Code Rocket will automatically pick up the information it needs to capture in its design views. Binary options screenshot thumbnail 1 can then bring forward and consult the Code Rocket design views any time I want during coding, to visualize and explore the code in different ways. The colors provide a simple overview binary options screenshot thumbnail 1 how much of the design has actually been coded up.
Code Rocket can do lots of other things including standard documentation generation tasks, e. The generated documentation will include the pseudocode and flowchart visualizations but you can configure options to binary options screenshot thumbnail 1 or hide these and select different generation modes. I mentioned earlier that I would provide a brief example of some of the flexibility Code Rocket provides for grouping lines of code into elements within its design views.
One of the options available are RQS binary options screenshot thumbnail 1 tags which allow you to group multiple lines of code into binary options screenshot thumbnail 1 single design element. Consider the imaginary code snippets below, not related to the binary search. Binary options screenshot thumbnail 1 say we have some steps in a web-based system for processing customer binary options screenshot thumbnail 1. Here is a code extract:.
However, now consider the same code but into which we have added RQS region tags. Any lines of code between the tags will be grouped together into this region. As you can see all lines of code within the region tags have been grouped together into larger elements in the diagram, rendered as 3D boxes.
This can be useful for methods which contain sections of small basic details that aren't necessarily relevant to see displayed explicitly in the abstract design views. Instead you may want the diagram to highlight some of the other more complex paths within the same method in greater detail. Code Rocket's diagram view will allow you to expand into these grouped elements should you wish to explore their contents more specifically.
I demonstrated the following: Using Code Rocket to Design and Implement a Binary Search This article provides a walk through of a couple of iterations of designing and implementing a form of binary search algorithm using the Code Rocket plug-in for Visual Studio.