Method 2 is an ideal to strive for, but it is not necessarily possible -
it depends on the project. In some cases, you know what the program is
supposed to do, you know how to do it, and you can specify, design, code
and even debug the software before you have the hardware. There's no
doubt that leads to the best software - the most reliable, and the most
maintainable. If you are making a system where you have the time,
expertise (the customer's expertise - I am taking the developer's
expertise for granted here
, and budget to support this, then that is
great.
But in many cases, the customer does not know what they want until you
and they have gone through several rounds of prototyping, viewing, and
re-writing. As a developer, you might need a lot of trial and error
getting software support for your hardware to work properly. Sometimes
you can do reasonable prototyping of the software in a quick and dirty
way (like a simulation on a PC) to establish what you need, just like
breadboarding to test your electronics ideas, but not always. A
"development" project is, as the name suggests, something that changes
with time. Now, I am not suggesting that Method 1 is a good thing -
just that your two methods are black and white, while reality is often
somewhat grey. What do you do when a customer is asking for a control
system for a new machine he is designing, but is not really sure how it
should work? Maybe the mechanics are not finished - maybe they can't be
finished until the software is also in place. You go through a lot of
cycles of rough specification, rough design, rough coding, rough testing
with the customer, and repeat as needed. Theoretically, you could then
take the finished system, see what it does, write a specification based
on that, and re-do the software from scratch to that specification using
Method 2 above. If the machine in question is a jet engine, then that's
a very good idea - if it is an automatic rose picker, then it's unlikely
that the budget will stretch.
I think a factor that makes us appear to have different opinions here is
the question of who is the customer. For most of my projects, we make
electronics and software for a manufacturer who builds it into their
system and sells it on to end users. You, I believe, specify and design
your own products which you then sell to end users. From our point of
view, you are your own customers. It is up to the customer (i.e., the
person who knows what the product should do) to give good
specifications. As a producer of high-end technical products, you might
be able to give such good specifications - for many developers, their
customers are their company's marketing droids or external customers,
and they don't have the required experience.
Programming from specifications is like walking on water - it's easy
when it's frozen.