2

I have seen many questions on whether to design data first or code first when designing a new application. I wonder if some have the same conclusions/ideas as me. I come from painting/digital design/UI background and naturally I went into Front-End. Currently I can code and build UI's quickly in HTML5,JS,jQuery and AngularJS. I have also touched on PHP and the popular stacks for it (LAMP, WAMP,XAMP etc.) and WordPress. I have also worked with Oracle SQL and TSQL on MS Server on a few different jobs.

For the last year I have been working with C# and ASPX and then for the last 6 months MVC5,JSON APIs with SOAP.

Recently I have also picked up AngularFire for Firebase.

9-5 I work for big corporations so the stack is usually .NET however outside of this I build sites for clients in open source usually and Front-end languages.

From this we can see I have touched on many different languages (some not named) and web application/software design and building but I still struggle at times to know whether to design my data first or code first? In the MVC applications (2-5 applications) I have built and worked on, the database was already created so I am starting to get a little used to (and enjoy) following the data first approach and in VS generating my model automatically (+ the T4's) then designing the Controllers and finally either Views or back to Controllers or some API.

With AngularFire showing us you CAN only code first and the database can be 100% automatically built for you (creation of the DB object and columns).

From this I wonder if many more are in this almost 'limbo' mode because of many different design practices and if any can offer tips of how to not get too confused and possibly offer one way to follow for solid practices of software/application engineering/coding/design.

Pros and cons: I do note though what I have seen so far is that AngularJS and Firebase offer application building at rapid pace as it's quick to define Controllers in JS and check data changes at real-Time in Firebase, this also allowed me to focus more on the features I want rather than looking constantly looking for library's, add JSON and the application starts to become powerful and still executes fast.

With .NET (MVC5, C#,EF5, JSON) it's quicker than a LAMP stack for CRUD operations as there is lot's available right out of the box as well as complex data pull and pushes with JSON, so still favour this over ASPX thus producing powerful web apps quite quickly too, although when the project grows execution can be slow locally and once deployed.

  • 3
    Possible duplicate of Code First vs. Database First – RubberDuck Oct 11 '16 at 13:35
  • The database is a detail friend. – RubberDuck Oct 11 '16 at 13:37
  • Thanks @RubberDuck. I could not comment on yours nor reply. However it was a great question and great answers too! I just had a slightly different view/input on it, hopefully a good addition! ;-) – Shucoder Oct 11 '16 at 13:52
  • This is wall of text. – Tulains Córdova Oct 11 '16 at 14:27
  • I know, sorry @TulainsCórdova but I am glad you find my question interesting and hopefully we can all learn from it ;-) – Shucoder Oct 12 '16 at 8:44
4

Your focus should be on what matters most to the application. Just starting with rows and columns no matter what is what an entire generation has grown up with and the damage can still be seen in a lot of business applications. You should start with your model and if your application is data-heavy, your model may be a data model like an ERD. If your application is big on behavior (using some algorithm to find a solution) your model may describe a control flow or be a sequence diagram. Once you have a model and you have your entities and terminology straight, you can start thinking about where to start implementing.

  • Thanks Martin, I am glad you mentioned ERD because since leaving university no one in the industry has talked to me about ERD nor ever use it. Also your help to remind me that having a data model first can be a great help when designing the application as well as the power of control flow or sequence diagrams. – Shucoder Oct 11 '16 at 13:40
  • ERD is unnecessarily confused because ER diagrams are used to depict both relational models and ER models. ER modeling was invented for a different purpose than relational modeling and is more relevant here than relational modeling. – Walter Mitty Oct 11 '16 at 14:39
  • ER modeling can be viewed as a specialized form of Object Oriented Analysis. Object Oriented Analysis, if carried out in a formal way, can help answer the question about code first or data first, or both in parallel, on a case by case basis, instead of coming up with a blanket "best practices" dictum. – Walter Mitty Oct 11 '16 at 14:41
  • Thanks for the further explanation and pointing out that ER modeling or OOA may be useful to follow. However if I choose to design my system with OOA (objects, and get and sets etc.) will this really tell me to use data first or code first? I believed by the stage where we decide data or code first the OOA or OOP has already been designed and it's actually a stage of choosing whether to build the database first or to code first. – Shucoder Oct 12 '16 at 8:32
2

Data first because data is "what you want to do" and code is "how to do it". If you try to do code first, you will be fully aware of how to get from A to B, but you won't know what A and B are.

And defining the data structures first will make it easier to use multiple operations on the same data. The A and B have shapes, if you don't predefine the shapes the different operations would want to use different shapes for the same data.

It's also one of the recommended practices from The Art of Unix Programming http://www.catb.org/esr/writings/taoup/html/

  • This is true and I am starting to think like this too since some of my uni lecturer's and some of the more old school folks most of the time used to ask me this when I reported a problem with any system 'Where is the data or let me see the database?'. This to me almost indicates data is the 'thing' you need to know or have access to when a system is running but also need first when designing a system. It is almost the 'bricks' of each application. Thanks Oskar. – Shucoder Oct 11 '16 at 13:47
1

The code should always serve the data. That doesn't mean there isn't data that serves the code of course, things like tables of lists of values for dropdowns, but your business data is more important than any code that acts on it.
If you're building a system to handle order processing, it is nothing without the order data... And that data will most likely already exist in a specific format that you can't change so your code will have to be designed to work with whatever format is provided by an external system or partner.

  • thats quite a narrow view. What about a sudoku solver, or image processing for example – Ewan Oct 11 '16 at 22:43
  • @Ewan you're saying that you can process an image when you have no image to start with? You can generate an image but you need some data to act as the seeds that the image is based on, which is your data. A sudoku generator has data it relies on too, being the rules for generating the puzzle and verifying it. – jwenting Oct 12 '16 at 3:37
0

Almost every application from simple games to large enterprise business applications have at least one complicated function that you better get right. Those algorithms will drive the design of the data or you will have a mess.

Finding 9 places to put your x's and o's in a tic-tac-toe game is not that difficult. Determining winners and a computer player is a little more difficult.

Billing systems can be pretty straight-forward until you have to start calculating several in batches and assigning and tracking for payment in monthly cycles.

Get that logic in place and at least cover it with automated tests because when you start building out all the other data structures and CRUD, those calcs better continue to work. People get fired for messing with other people's money.

  • Thanks @Jeffo. This is a good a way to look at it and I understand your take is to have well designed algorithms in place and then design the system (code first) or data (data first) depending on the overall complexity of the system your building while appreciating you will always have to keep ironing out the complicated functions later on. With that said I imagine you're leaning towards code first, but I may be wrong. Thanks again. – Shucoder Oct 12 '16 at 8:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.