Programming

From LinuxPadawan Wiki
Jump to: navigation, search

Everything related to programming. We've got something for everyone, including and especially the beginner.

You can do this

Everyone can contribute to open source code. In fact, some of the "source code" is documentation, text files, artwork, etc., that more reside in the domain of non-programmers.

For the non-programmer, you need to know:

  1. How to get the source code.
  2. How to navigate through the code to the parts you would like to change.
  3. How to get your changes applied to the software so everyone can enjoy them.

You don't need to use the command line to do these steps if you're more comfortable with GUIs. Yes, you can point and click your way through it.

If you'd like to actually code, you need to know the above as well as:

  1. How programming works. It's not important to know any particular language, but to know some of the basic terms and data structures.
  2. How to find reference documentation and how to use it. You can learn the language this way.

If you fear the command line, you can even use Integrated Development Environments (IDEs) to handle the task of coding, which will help automate some basic stuff and keep you from making really simple mistakes.

So you see, it's actually quite easy. You can do this. Start with making little changes so you can learn the process and go from there.

Automation is a wonderful way to start

Often times, we do small, repetitive tasks. Whether it's changing formats, making batch changes to images, replacing a word in a directory of files, there's always something that we could make much simpler. Or maybe there's a series of commands that do something we want to do. Wouldn't it be easier to just use one command?

This is what shell scripting is all about. Though most scripts don't require complex data structures, they do give one the sense of some basic ideas like variables, passing values, console output, etc. It's not only useful and easy to figure out, it's a great way to get used to thinking in code.

Version control is your friend

Nearly every software project out there uses some sort of version control software. It allows you to store code in a central repository (repo) and keep track of revisions. You may have heard of Github. It's a form of distributed version control software, where you can also include others in the process, which is the important part of open source. It's typically through these tools that you get the source code.

Github uses a tool called git, which is a common version control tool. Get yourself an account there and start putting something up there. Github will automatically render images including 3D images, maps, spreadsheets, and formatted text. One common use for Github is for configuration files. We have a Github oranization, btw.

You can also get a Launchpad, which is what Ubuntu uses for its development, account and get experience with bzr, which is similar to git and Github. Ubuntu's services are very tightly integrated into Launchpad, so if you wish to contribute to Ubuntu (or Debian, which is the major upstream for Ubuntu), getting an account there makes a lot of sense.

There are other version control tools out there, too, like svn which is what SourceForge uses (that's where e.g. Lubuntu does development) as well as Google Code. Or you could use hg which is what Bitbucket uses. By far, though, git is #1.

Both Launchpad and Github have tutorials available. In fact, there are whole books written on the subject. You don't need to read these books to use them generally, but they may be useful as resources when you do more complex things over time.

Finding the source code

First, you have to question what version of the software you have. Did you get your software by downloading the source code and compiling it (I doubt it, but if that's the case, this is pretty simple) or did it come through your distro's software repos?

If it's the latter, then you need to look "upstream" which is to say that you need to find the original origin of that software. Sometimes it gets kind of convoluted. If you're on Mint, you're often using Ubuntu repositories, which are mostly pulled down from Debian, and before that they're often software projects hosted elsewhere on the web. Each of these has the source code, but the major changes happen in the (most) upstream version.

Once you've found that, you need to find the source code. Every open source project has a link to the source code on their home page (that's what open source means, right?). This is generally a link to the repository of their source code, typically through a web interface.

Then you need to figure out how to get the code, generally first by figuring out what version control software they use and how to use it.

Understanding the source

This is the hardest part. Constructing a program (not necessarily scripting a simple linear process) involves several layers of abstraction. It's not easy to see this structure without something like a UML diagram. Since the control of the program jumps from point to point in the code in a non-linear fashion (being shuffled around by conditionals and loops, referring to function definitions and classes, etc.) and since variables present in different levels of the code are being changed through the process, it's not easy to just read through the code like a book.

There is a way to understand it, though. There's a discussion on reddit that offers some great advice. Basically, the suggestion is to start with some context you're interested in or at the point of entry (typically the call to the main() function) and follow the flow of the program. It will be best to do this in an editor or an IDE so you can search for the different parts. The best suggestion is using a debugger to actually better keep track of this and the various variables.

The unfortunate thing is that, especially for large programs, it will take time to grasp the whole structure. Luckily, to contribute to open source you usually don't need to go to this level. For example, if you wanted to make a small fix to a particular module in the Linux kernel, you wouldn't need to understand every module or every part of the kernel.

Flowing downstream of the source

Assuming you have the problem fixed upstream, but the right version is not in your favorite distro (or it's not in the distro at all), you will likely have to package it. You will need to consult your distro's documentation for the tools you need to do this as well as the process. Often times, it means you need to find a sponsor to sort of give it the official blessing.

Basically, this involves setting up a build environment and then compiling the software and then creating the binaries packages that are typically housed by your distro's repositories. Typically, upon upload, the disto's automatic build system will build for other architectures and/or versions.

While you wait for integration into the distro, you may be able to make the package available to other users. Launchpad, for example, has so-called Personal Package Archives that you can upload to and other uses can use standard package management tools to get them.

Learning to program

There's plenty of resources to learn how programming works. See below. You might wonder where to start. That kind of depends on which domain you're interested in.

If you're interested in programming for the web, you'll certainly need to understand HTML and CSS, and should understand JavaScript as well. If your goal is to provide extremely dynamic content, generally one would use PHP, but the up and coming framework is Node.js (read: JavaScript), and would reduce the need to learn another language. Nearly every other language provides some sort of web framework at present. If you know Ruby, there's Rails. If you know Python, there's Django, etc. However, since beginners generally need to know JavaScript, Node is probably best. JavaScript can be blocked by client browsers, and that may be a reason to explore elsewhere, but so much of the web uses Node now, that's kind of an edge case.

If your goal is to simply understand programming, it might be useful to look at something that will work equally well on all types of machines without having for forcibly compile it for that architecture. These are called interpreted languages. Historically, Java has been the go to product (at least among learning institutions), but Python is gaining ground and is often used by the open source world (arguably due to the fact that Java wasn't open source until the mid 2000s and the fact that Python has a very easy to understand syntax, almost readable to a non-programmer).

Learning is usually not enough, though. You need something to practice them on. Find a piece of software you use and love and add features to it or fix bugs. Alternately, find a simple idea for a piece of software and make it. However, if the all-mighty Eric S. Raymond is correct, then this won't really help you learn like fixing existing software will. Read more on that in the Hacking HOWTO.

An even better thing you can do is find a mentor. Of course, that's why we're here. Using pair programming (also see Tools below), we can help you work through your particular programming problem so you don't have to struggle with trying to figure things out on your own. Start with wxl and he can put you in touch with someone else if need be.

Links [1]

Learning

All levels

Coursera
MOOC with free, actually accredited college level classes on an ever-expanding list of subjects, from basic Python to data science to signal processing, etc.
CodeCall Tutorials
CodeCall is a forum on programming, but this particular part of the website is useful as it has a lot of user-contributed tutorials on a variety of languages.
Learn X In Y Minutes
Community supported crash courses for a variety of languages, tools, and algorithms. Languages other than English supported!

Beginners

Code.org
mainly aimed at the youngest of programmers (K-8), this is the force behind the "Hour of Code" and includes very simple tutorials
Codeacademy
interactive beginning programming tutorials, mainly focused on web programming
Code Combat
collaborative Python/JavaScript programming disguised as a game, aimed mostly at grades 4-12

Intermediate

w3schools
the web is not about HTML anymore, but JavaScript, SQL, PHP, etc. are all included here.

Advanced

Mashape API tutorials
an expanding list of tutorials on Application Programming Interface design, organized by language (note Mashape is a directory of Cloud APIs, which is valuable, too)
Systems Programming course
a college course whose lecture notes are great for learning about the inner workings of Linux, with assignments included

Conferences

hack.summit()
free virtual conference via Google Hangouts that gives donations back to coding non-profits

Tools

StackOverflow
ask a question on programming and quickly get an answer (also answering questions can help you learn things, too!)
Koding
free virtual machines with superuser-level access for development; guides available on various subjects; online pair programming available; tightly integrated with Github
Cloud9
free virtual machines with superuser-level access for development; online pair programming available. great for playing with shell, too. wxl is running a "cli-party" everyone's welcome to join (assuming the servers can scale).
Floobits
online pair programming tightly integrated with Github; free with public repositories (we have a linuxpadawan organization on there)
pair programming via tmux
tmux can be thought of as a window manager for the command line interface (much like screen but with other benefits) and now it's possible to share a session so you can do pair programming that way!!
Stypi
collaborative text editor with chat and syntax highlighting

Puzzles

Eudyptula Challenge
challenge yourself to become a Linux kernel hacker!
Matasano Crypto Challenges
a series of challenges dealing with real world cryptography
Advent of Code
holiday-themed problems to be solved by the programming language/methodology of your choosing (great for all levels)

Mentor opportunities

Google Summer of Code
university students get mentored to contribute major code to open source projects!
Google Code-In
contest where teens can help open source projects (coding not required, great for beginners)

Where to contribute

Open Hatch
non-profit dedicated to matching prospective free software contributors with the tools they need to contribute

Licenses

Choose A License
makes it easy to select from a variety of common open source licenses
tl;dr Legal
licenses in plain english

Lifehacking

Code for America
making government open source
Open Source Ecology
making economics libre

Notes

  1. focused on free resources since that reduces the barriers to participation