Click to See Complete Forum and Search --> : General Programming Question...


NoAssmblyReqdGA
07-16-2009, 09:59 AM
This is a very random question, but I was just curious...(tried it out on the JS board with no response - go figure)

Do the better programmers write code in sequence, like a writer writes a book (Meaning as they are typing out the code, the end of the script is already conceived)? Or do they (from the beginning) kind of go in and out of statements, functions, etc (haphazardly until it works) when creating new projects?

Thanks! :rolleyes:

criterion9
07-16-2009, 11:55 AM
This would depend on the scope of the project. As my team works on new developments we always start with analysis and design including diagrams and descriptions so we know what to expect as we start finalizing what the code needs to accomplish. Then from there we begin coding staying true to our plan we laid out in the previous step. This helps to ensure that we deliver a solution for the problem at hand rather than a solution that may be for a problem we don't have. When experimenting with new concepts or trying things out to see if a theory would work I fiddle with the code but I would never code a project without figuring out exactly what I wanted it to and at a minimum the framework for the solution from a high level viewpoint. Without knowing in advance you end up going back and recoding big chunks when you find out you missed a part or it doesn't work as desired.

svidgen
07-16-2009, 02:28 PM
I think the most typical design style among "good" developers is "incremental development." In other words, you start with a basic solution that doesn't do anything near what needs to be done. You then proceed in adding the necessary features/modules/structures/control. This development assumes that you already have the specification and basic database schema figured out--you probably have the initial database created as well (if one is necessary).

So, an an idiotically simple example, suppose you need a database driven Hello World web app. Let's zoom in and break the development down into increments--much smaller than is even necessary. Start with this:
<?php
print "Hello world.";
?>
Next, we might establish and test a database connection.
<?php
if ($db = mysql_connect('localhost', 'app_user', 'app_password')) {
print "Hello world.";
} else {
print "Connection failed.";
}
?>
Next, we might make sure the query we have in mind doesn't fail.
<?php
if ($db = mysql_connect('localhost', 'app_user', 'app_password')) {
if ($result = mysql_query("select message from helloworld.app_data")) {
print "Hello world.";
} else {
print "Query error!";
}
} else {
print "Connection failed.";
}
?>
And lastly, we actually grab the "first" row returned and display the value. For our application, we're assuming the "first" row is the only row:
<?php
if ($db = mysql_connect('localhost', 'app_user', 'app_password')) {
if ($result = mysql_query("select message from helloworld.app_data")) {
if ($row = mysql_fetch_assoc($result)) {
print $row['message'];
} else {
print "No message found!";
}
} else {
print "Query error!";
}
} else {
print "Connection failed.";
}
?>
So, you might say it's like writing a book, if by that you're thinking of a process wherein you incrementally expand on outline or table of contents. In fact, your first version of the application may not be written in an actual programming language at all. You may write it in a generalize english/spanish/etc.-equivalent outline, which you then "translate" into code and expand on later.

If you were to take an intro to programming class (in college), this is likely [part of] the process you would learn. You would probably also be taught to write that "pseudocode" (english/spanish/etc. "code") first.

NoAssmblyReqdGA
07-17-2009, 02:41 PM
Thanks guys for the input. I started reading a textbook on programming basics and logic - which recommended exactly what you said Jon. In all programming books you see things so well laid out (i.e. variables declared before functions, etc) and I wondered if they knew to declare the variables first, then followed with the functions that would use them, or the other way around.

Anyways, thanks again for the input.:D