/Cookbook

Code snippets for various programming languages and libraries

Primary LanguagePython

Cookbook

git clone https://github.com/NanoDano/cookbook

DevDungeon Cookbook

What is the Cookbook?

The Cookbook is a collection of code snippets organized by programming language. It also includes notes, template programs, and other references. The purpose of Cookbook is to provide example code for reading, reference, or re-use. Most examples are a single file. They are building blocks for larger more complex programs. Some examples are project templates ready to go, like the Chrome browser extension template.

Cookbook is a bookmark and git repository that everyone should keep handy. If you have your own snippets I highly encourage you to create a pull request in GitHub.

The Cookbook Method

Develop Your Own Cookbook

If you are interested in learning to program, or already know how to program but want to learn new languages and build your toolbox then I recommend you give the Cookbook Method a try. It is the method I developed over time for learning new languages and preserving the knowledge learned in those endeavors in a useful way.

Steps

  • Identify the languages you want to learn
  • List the tasks you are interested in learning
  • Use your cookbook as reference
  • Contribute to our community cookbook

Identify the Languages you Want to Learn

I recommend choosing 2-4 languages that interest you. There is a lot that can be said about which languages to choose and we could debate endlessly about it but I'm going to give my own opinion with whatever biases I may have developed over the years. Some people would tell you that you should learn at least one really obscure programming language. If you are unsure about it, don't do it. That curiousity will come naturally over time as you get familiar with the mainstream languages. You'll know when you're ready for that.

List the Tasks you are Interested in Learning

Everyone will have different goals so this will depend on what you want to do with programming. Here are some examples of good things to learn. Write small programs that demonstrate how to do the following tasks to start building your cookbook

  • Hello, world - Mandatory program to learn how to compile and run a programming using the language
  • Taking command line arguments
  • Reading and writing to STDIN/STDOUT
  • Reading and writing files
  • Using TCP sockets
  • Making HTTP requests
  • Parsing JSON
  • Parsing CSV files
  • Making database connections
  • Playing an audio file
  • Drawing 2D graphics to screen
  • Drawing 3D graphics to screen
  • Make a GUI program

Things start to get interesting when you talk about playing audio, drawing graphics, or making a GUI program. Some languages like Java make all of those things quite accessible, but in C++ things are a lot more complicated. That is all part of learning the strengths and characteristics of different languages. I'm sure you've heard the old saying "choose the right tool for the job." Well, unless you at least know what tools (programming languages) are in the box, how will you know which one is the best choice for each problem?

I recommend saving any scripts or tools you write, especially if it's something you use more than once. You never know when you might want to repeat something similar and wish you still had that one script. Some of them will be specific to you and your workflow or your environment. Those are good to store in your personal cookbook. Snippets like that I commend you put in to a special folder called _personal. The underscore is so it stands out alphabetically and designates it as being different than the other folders. The DevDungeon Cookbook has a .gitignore entry for _personal so you can use the community repository but keep all your private stuff in _personal. You can put a personal repo in there to keep track of your own things.

Use Your Cookbook as Reference

I keep my Cookbook repository close at all the times. It's a step better than going to the documentation because I don't have to do an internet search for it, and I already have some code in an example I am familiar with and that I understand. This saves a lot of time from finding the best example on Stack Overflow or having to adapt the example from the documentation because you have a different coding style.

Once you get in the habit of using it, you will also get in the habit of adding to it. It will become your bible, your Cookbook.

Contribute to Community Cookbooks

You will likely want to keep many of your personal files in the _personal folder. That folder name is ignored in the Cookbook repistory so you can store your own scripts without commiting and pushing them to the community. Once you have a code snippet or file that is free of any personal things, you should submit a pull request to the DevDungeon Cookbook repo on GitHub.