Can humans write bad code? In my 48 years of commercial software development, I believe that the answer is a resounding yes. I do not believe that blaming the problem on a particular coding language or paradigm is really productive — though I do concur that mathematical evaluation of code is a good step and that some languages and paradigms work better for some purposes.
“The fault, dear Brutus, is not in our stars / But in ourselves" -William Shakespeare-
At the root of our problem are two things: 1) we humans must be taught to be logical, we're not born thinking that way, and 2) we teach programmers to code, not to design solutions.
Coding is but a tiny part of software development and, in my experience, too few developers are taught to design well. Most of the lines of code ever written were created to make bad designs work — an ultimately futile endeavor — and the way OOP is taught, by people who don't have a clue what Alan Kay was talking about, borders on criminal negligence.
To fix this, we have to start teaching software engineering the way we teach mechanical or electrical engineering and we have to treat software systems as the exquisitely complex machines they are.