Codecademy: Brainstorming is Hard but I Did It (And So Can You)
Published: 2023-03-07 15:25:07

_This was written as part of an assignment for the Introduction to IT Course at Codecademy.com._

## Before the Project
This assignment was a pain in the butt for me. I have one of those brains that just prefers to start an idea, no brainstorming beforehand. When I was a kid in school learning how to write essays, the teachers would have us draw bubbles with connectors and I was so confused; I just thought about what I wanted to write and then did it (I have a creepily intuitive knack for English).

But essays and codes are different beasts, and I'm well aware it's important to know what you want to make before you start, or else you wind up hours into some spaghetti code trying to figure out what does what.

Trying to write out what a code is going to do without thinking in code was really hard. Hopefully you're not like me, but if you are, maybe this simple solution will help you make something more inspired than mine.

## Planning the Algorithm
The assignment calls for searching a text for a specific pattern, such as `text = "ERROR: Network not found."` and `pattern = "ERROR"`

So of course I overthought it as I was writing. _How do I make sure the variable doesn't reset every time? What if the characters match but not in the same order? Also for the love of God why can't I use strings??_ (That one is because not all languages have string types, past Ivy.)

I realized after my meltdown (and a bit of advice from a more seasoned developer) that I needed to simplify it. Code is where you solve those things, this is just how you lay out the idea of what it will accomplish.

Following Codecademy's examples earlier in the syllabus, this was my written out algorithm.
```
1.	INPUT/OUTPUT: Input text.
2.	INPUT/OUTPUT: Input pattern.
3.	DECISION: Has entire text been searched?
FLOWLINE: If not, continue to step 4.
FLOWLINE: If so, skip to step 7.
4.	PROCESS: Move to next character in text.
5.	PROCESS: To keep track of similar characters between text and pattern, establish a match_count variable and set it to 0.
6.	DECISION: Has entire pattern been searched?
FLOWLINE: If not, continue to step 7.
FLOWLINE: If so, skip to step 8.
7.	DECISION: Does this character in text match character in pattern?
FLOWLINE: If not, return to step 4 and continue iterating through text.
PROCESS/FLOWLINE: If so, increment match_count variable, then return to step 5 and continue iterating through text.
8.	DECISION: Does match_count variable equal length of pattern?
TERMINAL: If not, the pattern is not found.
TERMINAL: If so, then the pattern is found!
```
## Drawing the Flowchart
It wasn't until I was halfway through this part where I finally circled back to simplicity. Again, following their example, and keeping it simple, I made this chart.

![A colorful flowchart detailing the same steps as the written algorithm above, in visual format.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k106og1irxnk9yjqc7c8.png)

One thing I did after much deliberation was establish the match_count variable earlier in the algorithm. I just personally felt better about that, since it wouldn't reset by accident.

## Testing the Chart
Something that shouldn't have felt so difficult, but you'd be surprised how easy it is to go too fast and forget where you were. I did this in my head though so that's probably why. I would recommend using a pencil and paper to tally your variable and slowly work through the test text.

## Produce Pseudocode
My pseudocode ended up looking a lot like the example from Codecademy. I don't like big sentences unless I really really need them. If you like to detail the _why_ in your pseudocode, go for it. This was for sure the easiest part of the process for me. I don't know if that's because it was the simplest overall or because of the previous work.

```
input text
input pattern
create match_count variable and set it to 0
if the entire text hasn't been searched:
  iterate to the next character of the text
  if the entire pattern hasn't been searched:
    if this character from the text is equal to the character from pattern:
      increment match_count by 1
  if match_count length matches pattern length:
    pattern found!
```
I keep looking at this thinking _what if the pattern isn't found?_ but I have to remind myself that the actual code will take care of that. If I kept going, I'd be iterating on that pseudocode for hours and hours, which is time better spent elsewhere. Pseudocode is just to tell you, the programmer, what your code is meant to accomplish, the nitpicky details come later.

## Writing a Blog Post (Conclusion)
You're reading it! I finished the assignment. Of all the things I thought might be difficult on my new journey to professional coding, this never once entered the running. I can't promise I'll always take such a deliberate approach-- sometimes it's fun to start with some spaghetti and slowly clean it up and untangle it (like yarn or your earbud wires). But the practice was worth it and I do think I'll return to these methods for more complex programs later on.

Just please, if there's nothing else you took from this post, remember: keep it simple!