Managing code snippets is extremely important when it comes to doing development. Because it is extremely difficult to remember all the things a programming language can do, while trying to solve a difficult problem. Even more so if you aren’t familiar with that language and are a programming noob like me.
Having ready-baked software that you have tested makes development significantly easier. Forgot a specific syntax? Forgot how to write an algorithm in a specific language? Forgot what a function does and the language’s official documentation / examples are too hard to relate too? Can’t recall which function should be used for converting strings to array, or different data types? Can’t trust someone elses code until you’ve tested and verified it yourself on your machine?
If you have any of these problems like I do, you’ll understand the importance of having your own code repository that you can refer to.
You might ask “Isn’t that what github is for?”, the answer is both yes and no.
Github and git subversion control is extremely important when it comes to keeping track of note / changelogs of a software package over time (as well as collaboration), but it was NOT designed as a place to handle pure code snippets.
By code snippets, I am referring to short 5-10 liners of code that handle common sets of problems that you encounter.
For instance, say I use this python code snippet when reading .txt files
import os dir_path = os.path.dirname(os.path.realpath(__file__)) lines = os.path.join(dir_path, "lines.txt") def main(): fh = open(lines) for line in fh.readlines(): print(line) if __name__ == "__main__": main()
There’s no way I will distinctly remember how to write this all out from memory since I haven’t used python long enough, but if I had this snippet of code somewhere I can easily copy+paste this snippet and modify things as needed. This way I only have to remember one piece of information at ANY point in time – where that file lives at – as opposed to knowing all the semantics / syntaxes
By only having to remember one thing as opposed to many, it makes it much more difficult to completely “forget” how to do things, if not impossible.
So instead of remember everything about a specific topic, I could just remember the place I remembered how to do something. This in turn enables me to retain essentially infinite amounts of information without really forgetting it and relearning it (since those notes are personalized to me), in fact this is sometimes referred to as a mind palace.
Managing Code Snippets
Back on topic
When it comes to managing code snippets, you could always resort to snippets named by subfolders, but this would get really complicated.
Especially when you have 1000+ of these code snippets and you start having trouble finding which code snippet was placed in which directory, or it takes too long to access those files
Because of this, its imperative to have a robust solution for taking short snippets of codes that can be accessed fast and scale well overtime
Previously, I had been using an app called https://app.gistboxapp.com/, which runs off your github gists into a nice user-friendly format.
I won’t cover all the specifics of gistbox. The problem I had with gistboxapp is the following:
- I can’t really add notes that quickly
- It takes me far too long to find whatever code snippet I stashed away
- I can’t organize regular notes along with it
- Too much wasted real estate on my screen
I ended up ditching gistboxapp for dynalist.io and haven’t looked back
I wrote 2 other posts on how I use dynalist in general, as well as what tools I use to make it awesome. It also covers how to add on codesnippets into dynalist using Piotr’s PowerPack extension.
One thing that Dynalist does well with Piotr’s PowerPack extension (see previous post) is the ability to create code snippets. This, along with all the other tools I use along with it allows me to take rich notes like these:
What you see above is my conceptual understanding of how a fibonacci sequence works in python as well as the math that goes behind it. Its powerful in the fact that I can combine:
- Code snippets
all at the same time to break down information in whatever form I want. This helps me understand a specific concept much easier, in turn makes it a very personalized note that I cannot really forget because its etched in my mind now
We can even take it further by adding mathmatical gifs to help break the concept down. E.g.
But I digress. This isn’t even the most powerful features I use with dynalist to help manage my code snippets
Below are the reasons why Dynalist is a superior code snippet manager to all its competitors
1 . You can take any flavor of notes you want effectively
One issue that I have with ANY dedicated code snippet manager, is that its purely dedicated to only handling code snippets for the most part.
Dynalist is first most a notetaking tool, not a code snippet manager, so you have powerful ways of organizing pieces of information together. These include
- The ability to collapse notes you don’t want to see
- Add as many sublists as yo uwant
- Bold and highlight important text as needed
- Markdown formatting
- Latex and Math
- Ability to add images, gifs
- Ability to add embedded youtube videos / codepen snippets, and much more
By having all of these features you can customize contextual text around those snippets much easier, allowing you to make those code snippets yours and therefore easy to recall
2. You can customize code snippet colors using CSS
I didn’t like the way some of code snippets looked like when appearing on the browser, so I modified my CSS so that its easier to look at :
color: #FFEBCD; /* Blanched Almond */
color: #FF355E; /* Radical Red*/