There are various approaches to tackling a problem; the same is true in development of software. There are many recognized development (or design) procedures that are already being used by many software companies as per the policies of the same. I wouldn't call such a procedure absolutely essential when designing your own small applications such as a text editor, but it will surely be a great help in keeping you on track.
I would like to think of the method presented here as a refined form of evolutionary development. I use the term 'refined' because this should be slightly more visible (visibility refers to the ability of one to judge the development of a project) than the usual evolutionary method.
-
Requirements Specification:
List out all the basic essential features of the editor you wish to implement. Write it down and consider which of them are feasible.
ex.
- I want to make a new or open an existing ascii text file,
- I want to insert or delete text anywhere in the file,
- I want to scroll through the file using arrow keys and page up/down - there is a full screen display,
- I want to copy/cut text from anywhere in the file and I can paste it anywhere I want,
- I want a menu-driven interface (or command based or both),
- I want to have syntax highlighting for C/C++,
- I want to resize the text window,
- I want to do spell checking,
- ... and so on as you wish.
-
Design the Data Structure:
The data structure will hold the file in memory, and will control the way you will implement all the features that you have listed out. So this is the most important section of the design process. Making changes later on may be difficult. Examples of different possible data-structures are given below.
- ex. 1 A doubly linked list of 80-character arrays. (80 characters?? -because that is the width of your screen) This is ed!'s data-structure, very simple and straight-forward and something that you might have come up with already. But this structure does have its drawbacks, modify it to suit your purpose if you are proceeding with it.
- ex. 2 A linked list of characters. Or maybe a liked list of "linked list of characters". Not efficient, but easily implementable. It inherently supports long lines and you could perform horizontal scrolling easily.
- ex. 3 A variation on the above - instead of having a linked list of characters - do a linked list of arrays of fixed sizes and expand the list horizontally when required. The document structure/class will a linked list of these elements.
- ex. 4 Have a linked list of arrays, but the arrays are not of a constant size. Reallocate memory for the array on every character insertion or deletion.
These are some of the possible data structures you could opt for. You could come up with your own which would be excellent. Mail me if you find something radically new!
-
Design the algorithms:
Design the algorithms for all the features you have specified. This can only be done after you have perfected your data structure.
-
Go Ahead ! Code:
Start coding with the language of your choice. Mine has been C++ since I switched over from C. It is much more modular and object-orientation has a lot of benefits. But then, thats what I think. C or C++ try and code in a manner so that you can debug easily - and possible make changes to the design without corrupting the program completely. I would choose a layered approach where the data-structure is in one layer and it interacts with the interfacing layer. The interfacing layer is responsible for interacting with the user. The code for ed! can be downloaded from the home page.
-
Add new features:
Add newer features that may have come into your mind while coding which is very usual. Try to maintain the original design so that your code remains clear to the end. Try putting in a lot of comments, it helps.