September 5, 2014

The Podside Project: The Design

     I started my design the same way I always have (and how most of people my experience level would) by determining the different phases that the program would need to go through which meant my code was looking something like this:

import _____;
Main{
void Main(str() args()){
     // Find the audio I/O.
     .
     .
     // Select the audio inputs.
     .
     .
     // Record input streams.
     .
     .
     // Collate audio.
     .
     .
     // Convert to MP3.
     .
     .
     // Save to hard drive.
     .
     .
     // Close broadcast stream and shutdown.
     .
     .
     }
}

     This is the way I was taught to code and there is not anything wrong with it, however, it is obvious once the code becomes long enough all of the sections start to appear to 'blend together' just because there is just so much code to look at.
During a recent trip I got to speak with a cousin of mine whom I rarely get to speak to and he, being a programmer himself, suggested an alternative method which blew my mind. He first stated programming would be much more simplified (in terms of readability for updating somebody else's code) if the code were to read like a English sentences in somewhat of a bullet-point format. To which of course I agreed. He then blew my mind when he said that it is actually possible and actually rather simple and easy to do. He then gave an example of a program/script he was writing to filter email which he described as:

        English                      Main File                        Function Definition File(s)
        Get mail.                         Get_mail();                                 Get_mail(){
        Check mail for ____.      Check_mail_for(____);               _______;
        Move to ____.                 Move_to(____);                         }
                                                                                                  Check_mail_for(string a){
                                                                                                  _______;
                                                                                                  }
                                                                                                  Move_to(string b){
                                                                                                  _______;
                                                                                                  }

     In school of course I was taught how to make functions/methods but I never was I told you could use them to (1) simplify my code nor (2) by using them to simplify and and naming them in a clear way resembling a clear and concise thought or action (not just Check_mail for example) I could increase the readability of my code exponentially.
This of course inspired me to redesign the layout and functionality of my code to look like this:

 import ____;
 Main{
     Display and select I/O();
     Capture inputs(input1, input2);
     Collate audio(input1, input2);
     Convert to MP3(Collated audio);
     Save audio(Collated audio, filename);
     Push to server(Collated audio, web address);
     }

     Each function is defined in its own separate file which helps with readability and what I did not realize at first was because all of the specific tasks are defined as functions I can fully test the code by simply commenting out any unwritten or unfinished functions! Of course if you just have everything in one large file to test specific parts you would need to comment out entire sections of code instead of just one line.

No comments:

Post a Comment