reddit is a source for what's new and popular online. vote on links that you like or dislike and help decide what's popular, or submit your own!

Table of Contents

  1. Meta
    1. Introduction
    2. Asking Questions
    3. Posting Code
    4. Offering Help
  2. Frequently Asked Questions
    1. How do I get started with programming?
    2. What programming language should I start with?
    3. What is the difference between C, C++, Objective-C, and C#?
    4. What is the difference between Java and Javascript?
    5. What is an IDE? Should I be using one?
    6. What is Source/Version/Revision Control? Should I be using it?
    7. How can I contribute to open source projects?
  3. Learning Resources
    1. Programming books
    2. Interactive Tutorials
    3. Interactive online courses
    4. Static course materials
    5. Official Tutorials
    6. Programming Challenges
  4. Programming Tools
    1. Integrated Development Environments
    2. Lightweight Text Editors
    3. Version Control Systems
    4. Repository Hosting
    5. Build Tools
    6. Documentation Tools
    7. Compilers
    8. Other Tools

Meta

Introduction

Welcome to /r/learnprogramming! On this page you will find guidelines and resources for making the most of this subreddit.

All questions are welcome here. However, some questions have been asked and answered many times over. Please make sure your question is not answered in the FAQ below before posting.

This page is a wiki and everyone is welcome to add to it. If you choose to do so, please do your best to provide quality content while staying consistent with the style in the rest of the page.

Asking Questions

When asking a question in this subreddit, please use a descriptive title and specify the language or tech you're working with. A question titled:

[C++] Segmentation fault while writing to array in for-loop

will most likely be met with quick and accurate help from experts, whereas a question titled:

OMG!! been working on this for the past 10 hours, HELP PLZ!!!!

will more likely be met with ridicule and indignation. Be descriptive of the problem.

Similarly, this subreddit is not meant to be a proxy for Google. Please put in genuine and significant effort into solving a problem for yourself first before posting it in this subreddit. Otherwise, not only are you wasting everyone's time, you are doing yourself a disservice. Finding information and doing your own research is one of the most important skills in programming and you're never going to get better at it if you constantly ask others to do it for you.

In the event that you do your own research and come up dry, be sure to mention what you've already tried/searched for as well as what the results were. This will guide people in helping you and also open up your research techniques to scrutiny and improvement.

If your problem get solved, thank those that helped you, and update your post with the solution. This helps people who see the thread later know they don't need to spend time trying to help any further and it makes the solution readily apparent for people with the same problem. Please do not delete the post. Other people are still able to learn from it.

How to ask a software question

Writing the perfect question

Guidelines for posting homework problems

How do I post a question about code that doesn't work correctly? (C++ oriented)

How To Ask Questions The Smart Way

Homework Questions

  • Do NOT ask for help the day it's due. Very likely a response will not come quickly enough. Just because it's urgent for you does not mean it's urgent for anyone else.
  • Do NOT post all of your code until it turns out to be necessary. Follow the guidelines below. This is a very serious issue. Firstly it shows lack of sincerity. Debugging your programs is an essential skill in programming and that really needs practice. It is also to protect yourself. Imagine what will happen when your TA finds your post and decides to run MOSS on your class and includes the submission he found on /r/learnprogramming in the comparison.
  • Do NOT try to bribe anyone.
  • Do show that you are interested in learning. Saying, "I am in desperate need of help otherwise I'll fail, please fix this issue for me, or just do the assignment", doesn't sound like being excited about learning. In general, people here like to help those who like to learn.
  • Do be ready to do work. If you get suggestions for solutions to your problem, try them out and report back with results.

Posting Code

When posting code on this subreddit, the best way to almost guarantee a quick and accurate response is to post a minimal, but runnable example:

  • Minimal means that it should be the smallest amount of code necessary to demonstrate your problem.
  • Runnable means that someone should be able to take the code as is, plop it into an interpreter or compiler, and reproduce your problem.

Not only will this result in better help from the community, but often times the process of isolating the problem will make the cause obvious, and you will have solved it on your own.

When sharing code, please ensure that it is properly formatted. If people can't read it they won't be able to help you. On that note, please post code in English, regardless of native tongue. This is an English language website and, for better or worse, most programming languages and code bases are in English. If code has identifiers in another language, that only inhibits understanding for the majority of people trying to help out here, delaying responses.

Never post a screenshot of your code. Use the guidelines and tools below for actual code. Screenshots are only acceptable when the problem is a visual one and seeing the error aids in diagnosing the problem. Screenshots actually hinder diagnosis when it comes to the code itself because it is difficult for others to compile and run the code.

If the example code is small (less than ~15 lines), it's okay to include it inline with the post. To format code in the body of a post, start a new paragraph and precede each line of code with four spaces. This will preserve all text and symbols following the four spaces. To mark something as code within a sentence, such the name of a variable or a function, formatting can be escaped by surrounding the desired raw text with backticks.

If the code is long, is spread across multiple files, requires input, or must be run in order to demonstrate the problem, it is advised to use one of the tools listed below. In all cases, choose the language appropriately so that anyone helping you will have the benefit of syntax highlighting.

  • gist - for long code and code spread across multiple files. Gist supports multiple files in a single post; please do not create multiple gists when the files belong together. Gist can also track revisions, so you do not need to make a new post when you make a change. If your code requires input, especially from a file, include an example.

Every gist is also a full fledged git repository. If the code is public, and it should be, people can clone the repository to pull an exact copy locally. Because it's a clone, it is immensely helpful to name the files exactly what they should be, e.g. HelloWorld.java for a Java class named HelloWorld, or class.h and class.cpp for corresponding header and implementation files. This will allow people to compile and run the code immediately, without needing to change file names to match #include statements or class names. Making this process as quick and easy as possible for the people helping you will vastly increase the possibility of receiving an accurate response in a short amount of time.

  • ideone - for medium length code that reads from the standard input. ideone does not support multiple files or revisions, but it does allow you to provide sample input. The code will be run with the provided input, and the result will be displayed in the browser to all who view the code. In the case that the problem can be demonstrated entirely in a single file, with static input, this method is preferred. If the example requires multiple files, or the input cannot be provided easily through standard input, a gist is generally the way to go.
  • jsFiddle - for HTML, CSS, and JavaScript, especially if they work together. This allows people to actually see the problem as you do. jsFiddle, much like gist, keeps each fiddle versioned in a primitive repository, so when modifying code it is advised to use the "Update" function on the existing code rather than creating a new fiddle. (also see tinkerbin)

Offering Help

You don't have to be an expert to answer a question. If you can help, chime in, subject to the following guidelines:

  • Always be polite, never condescending or rude, even to the jackasses. It is possible to firmly put a jackass in their place without resorting to insults.
  • Make sure you understand the real question and address that. Your answer may be good, but it should also be relevant. It's okay to address things in addition to the main question, but don't start with those.
  • When providing code, try to make sure it's syntactically valid and (mostly) complete. Ideally, someone should be able to cut and paste the code and run it without errors.
  • When the question is about homework or otherwise school related, try to guide the poster to a solution instead of providing one directly.
  • Proofread your answers for clarity and correctness. You can always edit a response after the fact, but some people may see it before the edit; it's best if it's correct from the start.
  • Be prepared to respond to follow up questions. Things come up and people have lives, but try to be available for at least a little while after an answer. You may not have been as clear as you thought, or you may have raised additional issues.
  • Help the helpers. Correct bad information, provide additional insight, or pick up where someone left off when they didn't follow the last guideline.
  • Provide quality links for additional reading when fully answering a question is unfeasible or too time consuming.

Answering Technical Questions Helpfully

Frequently Asked Questions

How do I get started with programming?

First of all, thank you for taking the time to check the FAQ before posting this question (unless you were directed here by someone after posting it, in which case, shame on you!). This is by far the most frequently asked question on this subreddit.

Learning programming, like anything, is not an exact science, and as such there is no universally agreed upon way of doing so. It is generally suggested that newcomers should start with a single language, and that they should follow a single, high-quality, beginner-oriented resource. Several of those can be found in the Resources section of this page.

It's important to understand that learning to program can be a long process. Many people spend years of their lives learning and practicing before they consider themselves competent enough to look for a job or contribute to a significant project. Fortunately, just getting started with programming is not difficult at all.

Breaking into programming really only involves two things:

  1. Deciding what language/technology you want to start with.
  1. Deciding what resource for that language/technology you want to learn from.

It sounds very simple, and it is, however it will take a considerable amount of research and tinkering to decide what path is right for you, and what resources you want to learn from. Some people start by learning relatively low-level programming with C or C++. Others take an increasingly more traditional route by learning Java or C#. Still others start with a high-level or scripting language like Python, Ruby, or JavaScript. There are merits to all of these approaches, and there are lots of other ways to start, these just happen to be some of the most popular. Here is a brief overview of the pros and cons of these paths:

  • Low-Level

Characteristics include: limited abstractions, strong static typing, no runtime system, and direct memory access

Examples: C, C++, Assembly

Pros Cons
Full control over everything, you only use what you require Must control everything, which can make simple tasks more complicated than one would expect
Have to manage memory, you can learn a lot about how computers really work Have to manage memory, it can get really difficult really quickly
Allows you to understand what's really happening behind the scenes in higher level languages and appreciate the abstractions Easy to get bogged down in syntax and small details rather than concepts and the big picture
Encourages thinking in terms of efficiency Encourages premature optimization
Encourages thinking about design up front Changes to poor design can be painful, and good design is hard
Relatively small standard library means one must often rely on third parties or reinvent the wheel
Often requires more boilerplate, which generally increases time to delivery
  • Mid-Level

Characteristics include: focus on abstractions, strong static typing, runtime systems, limited direct memory access

Examples: Java, C#

Pros Cons
Memory managed for you, but can sometimes take control when necessary Still need to understand memory and how the garbage collector works and affects your program, but the language doesn't help in understanding
Large standard libraries Many abstractions can hinder a beginner when it's not clear why they're designed that way
Compiles to byte code, making interaction with other languages very simple Byte code requires clients to have a run time system installed
Still requires a lot of boilerplate despite more abstractions
  • High Level

Characteristics include: strongly abstracted, dynamic and/or weak typing, full memory management and/or runtime systems

Examples: Python, Ruby, JavaScript

Pros Cons
Abstractions can make complex tasks simple Overhead built in to the abstractions can decrease performance
Generally simple and intuitive, even when making changes Design can suffer as it's easy to toss fixes almost anywhere rather than where they "should" be
Comparatively huge standard libraries mean what you want to do is probably already done and available Hidden details may make it difficult to dive deep and figure out what is really happening when something goes wrong
Reduced boilerplate - syntax makes certain things easier Dynamic typing makes it hard to detect errors without running the code

This is just an overview, and it should provide a good basis for people who are completely clueless, however the discerning beginner is encouraged to do some of his or her own research to improve their understanding of the different paths for learning programming. Keep in mind that the sheer number of pros and cons is not important so much as what you are able to learn from the given language. If you need to learn memory management, for example, you have no choice but to use a low-level language and must accept everything that goes along with that.

The wrong question: “I want to learn to code, what should I do?”

Teach Yourself Programming in Ten Years

What programming language should I start with?

There are two common misconceptions that cause people to ask this question. The first is that there actually is a "best" programming language to start with, and the second is that the first programming language you learn will decide what the rest of your programming career looks like.

The truth is that there is no "best" language to start. What really matters are the programming concepts that can be applied across languages. The rest is mostly syntax and language-specific idioms. Since concepts are what matter most, it is often recommended here that a beginner start with a high-level language like Python or Ruby since the concepts are generally more apparent in such languages. It is typically less recommended, but still possible, to start with a low level language like C and take a bottom-up approach to learning. So read the pros and cons above, decide which way you would like to learn, then pick a language and go. You can find resources for getting started down below.

Everyone should eventually have experience in all types of languages. Once you are comfortable with one, move on to another in a different category. Since the concepts will be the same, you will be able to relate the implementations of the concepts across languages, and thus grow in understanding and appreciation for why multiple languages exist and what each one can offer. You will be more equipped to choose the right tool for the task at hand, which is a hallmark trait of a good programmer.

What is the difference between C, C++, Objective-C, and C#?

TL;DR - C, C++, Objective-C, and C# are not different flavors of the same language.

C is the smallest and the oldest of these languages. It was originally created as a systems programming language for the Unix operating system, and is still widely used today for applications programming. C's influence is seen in many of the programming languages that came after it, and it is generally considered to be the lingua franca of programming.

C++ is a massively popular, general purpose programming language which is based on C. With some tweaking, most C code can be made to compile as C++ code, however C++ adds a large set of language features which change the programming style significantly. The most notable additions are built in support for both object oriented and generic programming. It is generally considered a bad practice to write C-style code in C++.

Objective-C is a strict superset of C, meaning that all valid C code is also valid Objective-C code. Like C++, Objective-C also adds its own implementation of object orientation as well as a host of other language features on top of C. Objective-C is not nearly as popular as C or C++, and is mainly used today in development for Apple's Mac OS X and iOS platforms.

Unlike C++ and Objective-C, C# is not based on C. C# is a general purpose language designed by Microsoft in response to Java. Similarly to Java, it compiles down to an intermediate form which runs in a virtual machine (CLR), unlike the previous three languages which are all compiled to native code. While C# borrows a lot of stylistic aspects from C and C++ (as does Java), it has no real technical relation to those languages.

What is the difference between Java and Javascript?

Java is related to Javascript in the same way that a grape is related to a grapefruit.

Similarly to the previous question, Java and Javascript are not related in any technical sense. They share a bit of syntax as they are both influenced by C, but that's about it. Wikipedia has a good explanation of why the name similarity exists: Wikipedia: JavaScript and Java

What is an IDE? Should I be using one?

An IDE is an Integrated Development Environment, which is a software application that generally includes a text editor with code completion and syntax highlighting, project management features, a compiler or interpreter (either configurable or included), and many other fancy features to make writing, running, and testing code easier.

The alternative is to do what the IDE is doing for you automatically on your own, and/or through the configuration of plugins via code-friendly text editors such as Vim, Emacs, Sublime Text, etc. This method requires the programmer to have a more in-depth knowledge of the development process, and offers the benefit of allowing for extreme customization of the development environment.

For beginners, there are arguments for both of these development methods:

  • Using an IDE means that the programmer doesn't have to know as much about the development process, doesn't have to endure the learning curve of a command-line interface and its associated tools, and doesn't have to configure those tools to work correctly or in a way that the programmer prefers. An IDE offers a quick way to get code running right off the bat, and offers many more advanced tools for experienced programmers.
  • On the other hand, working from the command-line, and using minimal text editing tools means that the programmer doesn't have to endure the learning curve of an IDE, and since less of the development process is hidden from the programmer, a fuller understanding of the complete system can be gained. While some may find the high level of configurability and customization to be a burden, others feel that the limitations in configurability of an IDE are a burden.

For beginners and experienced programmers alike, it is generally a matter of personal preference (unless of course your employer/school requires the use of a specific development environment). If you've never used an IDE before, download one of the popular ones and tinker around with it. And if you've never used vim or compiled code from the command-line, try it out and see if you like it. A list of common IDEs and lightweight text editors can be found in the Programming Tools section of the page.

What is Source/Version/Revision Control? Should I be using it?

A Version Control System (VCS) is a tool which, in its most basic form, keeps track of the changes to the source code (and other resources) in a codebase. In the same way your Undo and Redo commands work in your IDE or text editor, a VCS allows you to save the current state of your code at any time, and revert back to that state if you so choose. Most systems also offer many different features which can aid in team development, feature experimentation, and advanced management of large software projects.

A common mantra in programming is: "If it's not in source control, it doesn't exist."

As soon as you're writing code that you'd rather not lose in the event of an unexpected power outage or natural disaster, you should be putting it in source control. Bonus points if you have it backed up online. No amount of local storage is going to save your code if it gets destroyed in a flood.

Some common version control systems and online repository hosting solutions are listed in the Programming Tools section of this page.

Read more about revision control.

How can I contribute to open source projects?

COMING SOON: Participate in one of the projects in the /r/learnprogramming github group! This group was created by jfredett with the express purpose of providing projects for new programmers to learn how to contribute to open source by interacting with more experienced programmers as mentors.

The group is still in its infancy but several people are working to get it up and running.

Here are some past threads about working on open source projects.

http://www.reddit.com/r/learnprogramming/comments/t0fk4/how_do_i_actually_contribute_to_open_source/

http://www.reddit.com/r/learnprogramming/comments/swwbd/how_to_contribute_to_an_opensource_project/

http://www.reddit.com/r/learnprogramming/comments/sw209/question_about_contributing_to_open_source

http://www.reddit.com/r/learnprogramming/comments/ee6fq/opensource_projects_for_beginners/

http://www.reddit.com/r/learnprogramming/comments/cm8be/reddit_how_do_i_get_involved_in_open_source/

Learning Resources

Programming books

Free programming books

Stack Overflow is the unofficial keeper of the historical, and utterly massive List of freely available programming books

Some of the more commonly recommended free books on this subreddit, which are more geared towards beginners are:

  • AlSweigart's Invent with Python books, which teach programming through the creation of computer games with Python and Pygame.

Generally non-free programming books

Some non-free programming books which are commonly suggested on this subreddit are:

  • C++ Primer - the 5th edition, which covers C++11, is set to be released later this year
  • Head First Java - along with the other Head First books are considered decent beginner fare

The Definitive C++ Book Guide and List

Recommended Reading for Developers

What is the single most influential book every programmer should read?

Recommended Books for Software Engineering

Interactive Tutorials

Ruby - RubyMonk, tryruby, Hackety Hack

JavaScript - Codecademy, Eloquent JavaScript

Python - Try Python, learnpython, Crunchy

Other - CSS3, please!, Try Haskell, Try F#, MongoDB, SQLzoo, Open Vim

Note: The initial version of this section was sourced entirely from this great comment by robot_zombie.

Interactive online courses

coursera.org offers free online courses in many different fields from several different well-known universities.

udacity.com offers free computer science courses taught by industry experts, including reddit co-founder Steve Huffman.

redditors have also been known to teach courses on a variety of topics, including programming, at /r/universityofreddit. Check out the computer science section. Just like with anything on reddit, since anyone can contribute, these courses may vary in quality from professor to "professor".

This is an increasingly popular way for universities and professionals to help guide the next generation of programmers, and as such, new resources like this are popping up all the time. Feel free to contribute new offerings to this section as they form.

edX is a planned joint effort between Harvard and MIT to provide free online versions of some of their courses.

Static course materials

MIT's OpenCourseWare

Stanford Engineering Everywhere

redditor CarlH taught a class on C programming at /r/carlhprogramming which has ended somewhat, however his lessons are all still available at his website, highercomputingforeveryone.com

Official Tutorials

Some languages have "official" learning resources provided by the companies who contribute most or all of the development of the language:

Oracle provides The Java Tutorial

Microsoft provides various types of resources for all of the languages officially supported by Visual Studio, for instance: Learn Visual C# and Learn Visual C++

Microsoft's App Hub also provides resources for their mobile platform and XNA game development framework.

Apple provides developer resources for their mobile and desktop platforms:

Git has an official reference and book

Programming Challenges

/r/dailyprogramming - a subreddit with daily programming challenges

CodingBat - coding exercises for Java and Python

Python Challenge - combines riddles and programming puzzles to move through different levels

Project Euler - math-heavy challenges meant to be solved through code

codegolf.stackexchange.com - site for posting and discussing programming puzzles

/r/programmingchallenges - a subreddit dedicated to programming challenges, could use reviving

CodeForces, TopCoder - regularly hold programming competitions

Programming Tools

Integrated Development Environments

A general list can be found here. Below are free, commonly used IDEs for various languages and platforms.

"Recommended" IDEs are those which have been tested and are generally high quality. "Alternatives" are those which work, but are not usually recommended, typically due to a degraded user experience. IDEs "To Avoid" are ones that should not be used at all, ever. The only exception is when a class or job wrongly requires their use. No links are given for such IDEs.

C++

Alternatives

To Avoid

  • Borland C++
  • Dev-C++
  • Turbo C++

Java

Recommended

Alternatives

Objective-C

Recommended

Lightweight Text Editors

An overview and feature comparison of many editors is available here. Below are some commonly used and recommended ones.

  • Vim - based on vi, lightweight, highly extensible, keyboard driven, massive learning curve, cross-platform, way better than Emacs
  • Emacs - lightweight, highly extensible, keyboard driven, massive learning curve, cross-platform, way better than Vim
  • gedit - default GNOME text editor, cross-platform, beginner friendly
  • TextMate
  • Sublime Text
  • Notepad++
  • Komodo Edit
  • IDLE - strictly for Python, comes with a Python install

Version Control Systems

Version control systems (VCS) come in two main flavors: distributed and centralized. Distributed VCS (DVCS) have no inherently authoritative repository while a server hosts the authoritative copy of all files in a centralized VCS (CVCS). This is not to say a DVCS cannot have an authoritative copy by "blessing" a given repository, just that the notion of an authoritative copy is not built into the system. This affects a number of operations when working with other people, like who can work on a file and when, how branches and merges are handled, and when and how commits to the repository can be made.

In a distributed model, all changes and history tracking are local until pushed to a central repository or pulled by someone else. That means anything can be committed at any time regardless of network connection, branches can be made, merged, and deleted easily, and one is generally free to do as they wish with their copy of the code.

In a centralized model, specific files must be checked out from the server, which may prevent others from working on that file until the file is checked back in if the server uses a locking mechanism. All history is viewed by making requests to the server since that is the only place it is stored. Similarly, all branches much be made through the server, and one must be connected to the server in order to commit any changes.

For these reasons and more DVCS have become very popular rather quickly and are recommended for new projects. There are many older, active projects that still use CVCS, so it is worthwhile to be familiar with those systems.

Distributed

Centrialized

Compare VCSs to determine which is right for a given project.

Repository Hosting

github - free hosting for public repos, advertises "social" coding (Git)

github.com/edu - github offers their micro plan free to students from time to time (closed ATM, but rumor has it that you may still be able to get one by inquiring via e-mail)

Bitbucket - free hosting for public repos, private repos free up to 5 contributors (Mercurial, Git)

Bitbucket University Application - Bitbucket offers their unlimited plan free for students

Assembla - free public repositories, free private repos, tools are a 1 month trial (Git, Mercurial, SVN)

Google Code - free hosting for open source projects (Git, Mercurial, SVN)

CodePlex - free hosting for open source projects (TFS, SVN, Mercurial)

Build Tools

Build tools help ease the burden of managing projects. Features include dependency management and intelligent recompilation. For instance if a library is required for a piece of code to build, the tool will make sure it is available when that code is built, even if the library is located in a place completely separate from the code that requires it. Such tools can also recompile only the parts of code that have changed, as well as those dependent on the changes, instead of always rebuilding the entire project.

Some of the tools, like CMake, are more like tools for build tools. From one configuration you can set up a variety of build tools to build the same project in an appropriate way on different platforms. This is handy on cross-platform projects where one person may be developing on Linux with GCC and make while another is developing on Windows using Visual Studio. CMake can use the same configuration to create the appropriate Makefiles on Linux as well as setup the corresponding Visual Studio solution on Windows.

Read more about build automation.

Documentation Tools

Good documentation is a must for any project, and especially so if one is writing a library for others to use. These tools help create consistent, navigable webpages like the Java 7 API docs that contain descriptive, useful information about each documented class and function. Some tools have the ability to change the output format to create pdf documents, for example, instead of webpages.

Compilers

Some of the "compilers" are actually full IDEs, like Visual Studio and Xcode, because they are the easiest way to install the necessary compiler on that platform.

C and C++

C#

Java

Objective-C

Other Tools

  • Cygwin - POSIX environment for Windows
  • Wine - run Windows programs on *nix
  • Cobertura - code coverage tool for Java (cross-platform)
  • Valgrind - memory leak detection tool (cross-platform)
  • Review Board - code review tool
  • Checkstyle - Java coding standard validation tool
  • FindBugs - Java static code analysis tool