Programming without bugs is easy. It's just slow and expensive. so nobody wants it. It's cheaper and easier to write bad code and ship it, absorbing backlash, than to build it right in the first place.
Programming non-trivial things without bugs is very, very hard, and very often not cost-effective.
Just build clear bug-free pieces, and assemble them.
The combination of two bug-free pieces isn't necessarily bug-free. The glue code is where you typically end up with the subtle assumption and domain bugs.
Take the time and care with each line to verify intention.
What is the intention of 3rd party code? What is the *exact* intention of the code you wrote 6 weeks ago? You may have documentation. It may even be really good. It's unlikely to be 100% complete.
Use modularity and error handling.
Error handling and modularity in and of themselves do nothing to reduce buggyness, though they may make it easier and faster to find the more obvious and often-occurring ones. They are good practice though, and I strongly recommend them.
I'm sure I'll be called naieve, but at least should move the smallest error free program to a much larger size.
Sometimes being naive isn't bad - it often makes you aspire to better than the status quo, which isn't a bad thing. However, many "bugs" aren't even programming errors, they are communication failures somewhere between the customer and the developer. What the customer wants, what the customer asks for, and what the customer actually needs are three different things.
But none of that will work when given a timeline half what it should be, and inadequate budget.
A program that solves some of the problem now, even with bugs, is infinitely more valuable than a program that solves all of the problem (or more frequently, a small subset of the problem correctly) when it is too late. That goes back to the "cost effectiveness" - the solution that generates the most profit is the better one in a capitalist situation.
There are other situations, such as healthcare, or community projects (open source), where "cost" either doesn't factor or is subservient to other goals such as safety, but it's not the general case.
That still isn't a green light for cowboy coding, but if you're dead-set on bug-free you might find it hard to deliver.