Can you design and implement electronic hardware without such problems?
That's an interesting question, I never thought about programming that way. I guess even complex hardware projects (i.e. when I designed a full Z80 Spectrum from scratch, with video and disk controller included
https://hackaday.io/project/1411-xor-hobby-a-vintage-z80-computer-prototype ), are still low complexity when compared to software projects.
For the hardware projects, the most agonizing tasks to me are about how to design something using only parts I already had in the inventory, without ordering anything extra. Another problem (with hardware) is to commit between something very basic, or something very generic. For example, I need to measure the I/V curve for a lightbulb, but then I want to extend it a little over other ranges, or over other types of components, and so on, adding more, but then becomes too bloated and thinking again about a minimalist project, and so on. So, for hardware is more of a problem about choice, than a problem about braking a big project into small blocks.
Your question made me think I might have a problem with decision making and committing to fixed specs. Could be. In hardware such problems are smaller, because the choices are limited by the available parts, and other limitations from the physical world, while in software the possibilities are endless. In software it is always possible to want/add more, or to switch between a completely different programming ways.
A side effect to this is that even the nicest working program still feels unfinished. There is always something more you could add, or you could improve to a program. Very frustrating.
Ever refactored something?
Usually that's where I lose control, so I need to re-arrange/redesign some parts. I've read a refactoring means better structured code, while retaining the same functionality from before. I usually end up with buggy code after a refactoring attempt, or with a broken project that doesn't work any more.
When writing code, write in small units that you can test. The smaller the amount of code a problem can hide in, the easier it is to find. Test often. You probably should spend at least as much time testing your code, as you spend writing it.
I often write tiny test programs to test a single data structure and its associated function interfaces, just so I can check it really works.
This is another thing I don't do. Sometimes I test (manually), for example when I doubt about the limit cases of a loop, or of some calculation, never wrote automated tests, and never had regression tests associated with the code I write. Testing only very brief, and the tests are always manual tests, with some inputs I suspect might be troublesome.
I've read once some book that was in fashion, about TDD (Test Driven Design). Write a test for every line seems nonsense to me. Who's testing the test, then? I recall even from one of the working places where a software team tried TDD. Very often the tests were failing because of bugs in the tests, and after struggling with the TDD paradigm for a couple of weeks, they ended up being less religious about TDD, and they only kept a few test that were making sense. It was a huge software project, and those guys were top programmers at a multinational, not amateurs.
I'm confused what should I test, and how. Many of my projs have some hardware, so I guess it will take considerable effort to mock the hardware signals.
Only replied here to a few specific question, but I want to thank you all for the help.
Sorry for the late reply, and didn't start the logger exercise because I've found a book with explained project examples, and avidly reading from it:
https://zjnu2017.github.io/OOAD/reading/Object.Oriented.Analysis.and.Design.with.Applications.3rd.Edition.by.Booch.pdf So far this book seems very close to what I'm trying to learn. Will see how much I'll be able to apply in practice.
Saying this because in teaching examples, programming seems always easy. In practice it's never as easy as in the "hello world" seen in the books.
