Bug free isn't a requirement for the vast majority of applications. Attaining it is very expensive, and most people/companies are not willing to pay the price.
Probably the closest the world has ever come to bug-free code of substance is that produced by NASA for their space shuttles, and it cost ~$1,000 per line. (http://history.nasa.gov/sts1/pages/computer.html) This would make the typical YC app cost tens or hundreds of millions just to launch, and would put something like e.g. the operating system for your cell phone outside of the budget of most nations.
There are a host of other engineering tradeoffs that have to be made, too. In addition to prioritizing cost over bugs, shipping speed over bugs, feature set over bugs, being able to actually hire programmers over bugs [+], etc, are all important.
[+] Many programmers would consider the type of work environment you need to get bugs down to zero to be an oppressive place to work in. Among other things, it will quite literally try to crush any creativity out of you, turning you into an automaton which exactly implements the specs given to you. Those specs were dictated by Really Important People. You're not one. Write your function. Your last function was non-compliant with rule 436 2a subsection b. Improve your performance or we'll find someone who is not a threat to our software quality.
Yes, but remember that (Plain)TeX has very few features, so most people use LaTeX that is not bug free.
Moreover, it's very common to use many LaTeX packages that are slightly incompatible, or have to be loaded in a fixed order, or don't handle accented letters, or ...
I think it can be formally proved that software that is non-trivial cannot be written to be 100% bug free in all cases, in all contexts, and I think that's a by-product of how software runs.
We have so many layers that software has to run on-top of: You have raw hardware, but a layer above that is the BIOS, and a layer above that is the OS, and a layer above that are the SDKs like .NET/GTK/Ncurses/Shell, and above that you have the layers that are built into software itself as abstractions, and on top of that ...
If anything on any one of those layers changes, you have the potential of introducing bugs. Not all interface contracts are honored by all developers/engineers. There have absolutely been cases where changes are made at one level and that has an effect on everything that runs on top of it.
So even if you can reliably say that your program is 100% bug free for a specific OS running on a specific set of hardware at Time T, that has the potential to break during the next release of any of those products.
The software the Patio11 mentions (NASA systems) is running in a very specific context. It's running on hardware that has a high level of formal verification, and it's running on a RTOS or running directly on hardware, such that there isn't anything that can interfere with the software, because otherwise even the CPU scheduler could introduce bugs into your system.
Anyway, that's my view of things, I'd love for someone to tell me if I'm wrong, since that's all based on observations I've made during my industry experience.
There are methods that can be applied to software that formally prove properties of software so that those pieces are free of bugs. These are called formal methods and require heavy use of math. Some of them are ASM and Z.
There are provers that help as well, such as Alloy.
For the typically/average project put there, the mayor problem I see is that people still rely on code coverage as the one and only metric for quality of their tests (if they even implement tests at all).
Code coverage is a lazy, flimsy and unreliable metric that has been subsumed by the more powerful metric called mutation score.
If devs utilized mutation analysis more, they would provably have much better quality software.
However, these techniques are often too computationally expensive in many practical cases. Moreover, formal verification requires one to very precisely specify how a piece of code should behave, as well as how the environment in which it operates may behave. (Think of OS, network I/O, user interaction, etc.) This is another source of often prohibitive complexity.
If we can agree that low-level hardware such as CPUs are essentially physical software, then it would seem that there are many bug-free software pieces out there. Many operating systems these days seem to have perfect or near perfect memory and thread management. Kernel mode drivers in general require a high level of quality since bugs usually mean death. User mode is where things get sloppy, and front-end Web Development is where things often get extra sloppy.
I never said they were all bug-free. I am aware that there have been some problems over the years, but the track record seems much better with CPUs than with most things having what could be called advanced programming.
It probably has a lot to do with how many users you have. 10 users, then bug-free is possible. 10,000+ well that is a different story. The more users you have, the more weird scenarios they come up with on how to break stuff.
It depends of the complexity of the software. The small Unix utilities like grep or ls are, AFAIK, bug free, because what they do is very simple, but something more complicated is more likely to have small bugs somewhere.
There was a bug in ls, long ago; it stuck around long enough that it became a feature. It was supposed to not list "." or "..", but instead it skipped all files starting with "."; which thus became the standard way to hide a file on *nix.
Probably the closest the world has ever come to bug-free code of substance is that produced by NASA for their space shuttles, and it cost ~$1,000 per line. (http://history.nasa.gov/sts1/pages/computer.html) This would make the typical YC app cost tens or hundreds of millions just to launch, and would put something like e.g. the operating system for your cell phone outside of the budget of most nations.
There are a host of other engineering tradeoffs that have to be made, too. In addition to prioritizing cost over bugs, shipping speed over bugs, feature set over bugs, being able to actually hire programmers over bugs [+], etc, are all important.
[+] Many programmers would consider the type of work environment you need to get bugs down to zero to be an oppressive place to work in. Among other things, it will quite literally try to crush any creativity out of you, turning you into an automaton which exactly implements the specs given to you. Those specs were dictated by Really Important People. You're not one. Write your function. Your last function was non-compliant with rule 436 2a subsection b. Improve your performance or we'll find someone who is not a threat to our software quality.