views:

210

answers:

8

What is the best way or recommended best practice in the flow of database driven asp.net web application? I mean the database first or coding first or side by side?

+1  A: 

I guess you need first to define datamodel and only then going coding. You should plan everything carefully before actually writting the code.

FractalizeR
+8  A: 

Your data access code won't compile without an existing database - unless you stub (or Mock) it. So probably the database comes first.

But it is a bad idea to do whole chunks of the application in isolation. Ideally you should design and build slivers of the system - database and application - hand-in-hand. These slivers should be cohesive sub-sets of functionality, probably smaller than sub-systems. Inevitably, the act of coding screens and business rules will throw up problems in the data model. So it is good to have a data modeller or DBA who is happy to work incrementally alongside the developers.

edit

Stephanie makes an extremely pertinent point:

"the core tables which are persisting your app's data really can't be piecemealed. Most of the data is known at project start. It has a form, you need to find it."

I agree that the core entities are knowable at project start, and the physical data model can be derived from that logical data model. But I don't think it is ever possible to nail down completely the structure of any table, even a core table, at the start. This is because at the start of the design/build phase all we have to go on are the Requirements, and if there's one thing history tells us about the Requirements it is that they will change.

So, new tables will be needed and some existing tables will become obsolete. There will be columns which need to be added, columns which need to be modified, columns which need to be dropped. This is why Nature gave us the ALTER TABLE statement.

I am not suggesting that we don't design our tables, or assemble them piecemeal. I am merely suggesting that when we start designing the HR sub-system we need to worry about the EMPLOYEES table and the SALARIES table. We don't need to concern ourselves with INVENTORY or ORDERS until we commence work on Sales.

APC
I agree that some iteration is needed. I whole-heartedly disagree that you should build 'slivers' of your data model. Yes, you'll have forgotten about a flag on a certain table, or you'll require some processing tables as you go, but the core tables which are persisting your app's data really can't be piecemealed. Most of the data is known at project start. It has a form, you need to find it. If most of the data isn't known, you've screwed yourself with the "I can't gather requirements, I have too much code to write" mantra.
Stephanie Page
Since when data access code doesn't *compile* without a database? :)
Pascal Thivent
+1  A: 

First is a feature list. Then, detailed spec. Then test plan and design of all, including databases.

Then, it wouldn't matter which to implement first.

Pavel Radzivilovsky
We're not talking about what to implement first, but what to design first.
Stephanie Page
+1  A: 

You'll probably end up doing it "side by side".

You need some data to be able to test the application, but you need the application to be able to verify that you're storing the correct data.

Do some modelling first and then build the minimum you can for one or two features. Then when these are working add the next feature and so on.

You'll need to write some database update procedures (both the code and the rules about what and when to update) as you will have to extend your tables, but you'll need those for the final system anyway as it will have to change as new requirements come along.

ChrisF
+1  A: 

Having done it quite a few times, I find myself invariably doing it like so:

  1. Define the problem I'm trying to solve.
  2. Write out some use-cases.
  3. Have my significant other or a friend tell me if this is even a problem.
  4. Sketch out a few sample screens.
  5. Write flow diagrams for the use cases.
  6. Ask my Rubber-duck questions.
  7. Use questions to refine 1-6.
  8. Write out the 'nouns'. Those become my data Model.
  9. Write out the actions. Those become application logic.
  10. Code data Model.
  11. Code Application Logic.
  12. Realize I've gotten it a little wrong.
  13. Repeat 10-12 as many times as needed.
  14. Ask, "Have I solved the problem"?
  15. If not, rinse, lather and repeat 1-15.
George Stocker
Love step 6! Gave me a giggle.
HLGEM
I love it. (needed 4 more char to make a full comment)
Stephanie Page
+3  A: 

We personally start with the Domain and do things side-by-side. The important part is that we implement vertical slices of the application (fully working end-to-end features), not horizontal slices (e.g. first the whole database layer, then the data access, then the services, then the presentation): we build the application incrementally and demonstrate progress with working code after each iteration.

Pascal Thivent
A: 

This is a trick question. IMO, they both come in parallel during your planning and design phase. They are so closely related that it make sense to do them together. Just keep in mind that your database design will be almost fully developed while your code is still in its infancy (though your application logic should be almost fully mapped out in you head or on paper)

The idea is that you're designing your solution in the context of the problem. When you're planning out your solution you will be (or should be) defining your application as a set of things and actions (nouns and verbs).

For example, a very basic helpdesk program has people and tickets. People need to create tickets, update tickets, and close tickets. The nouns that require persistent storage will comprise your database, and the nouns + actions will be contained in your application.

Sometimes your table mappings and the relationship between tables will be obvious (IE people create tickets, ticket.creatorID = people.personID) and other times the relationship doesn't really click in your head until you start working through use cases or until you start writing your code (IE different ppl have different access levels defining what they can do. At a glance this would seem like a simple field in a table, but in practice it is better as a separate table).

baultista
+2  A: 

Applications are all about features. You don't build apps to store data, but to provide functionality. If we can't agree on that, the discussion is moot of course. Software should be developed to satisfy the needs of its users and not of its developers.

Well I have really no understanding of the second sentence. If you think my company pays me a good salary to write code that satisfies me and not my users you're crazy. So that argument is a strawman. Back to the first.

This is a common view point of application centric people (they), vs. database centric people (We). They see the entire point of the exercise to "provide features". Those are things the clients know they want and ask for them. To them, the database is just persistence required for these features. And when they are done, that's it, features delivered, database is sufficient for those features. Could be an entire Rube Goldberg inside the database with redundant data, severe violations of normal forms, constraints enforced by the application, what have you.

think overall usability alone outweighs database design

If the design of your database is affecting your usability than the design was bad. I have no doubt that one who strives for features will leave the database in such a state that it severely hampers usability.

Data Centric people, don't look at a system as a place to provide only what's been asked for, but a repository of Intellectual Capital that can be exploited by more than whatever the Application-du-jour is. I can't begin to describe the number of cases where one team has used the database of some other team's app to enhance their apps value. Just look at all the medical research that is nothing more that the meta-analysis of existing studies. None of that is possible if you believe that only the features of your app matter and subsequent uses of your apps data do not.

A good data model isn't inviolate. Sure you'll add to it, change it when requirements change. But if you don't completely understand your data, I don't know how anyone can begin to write code.

Stephanie Page
As @back2dos deleted their comment yesterday this post doesn't make a lot of sense any more, as it doesn't really address the concerns of the OP.
APC
+1 `if you don't completely understand your data, I don't know how anyone can begin to write code.`
KM