r/programming • • Mar 11 '13

Programming is terrible—Lessons learned from a life wasted. EMF2012

http://www.youtube.com/watch?v=csyL9EC0S0c
650 Upvotes

368 comments sorted by

View all comments

Show parent comments

169

u/chazmuzz Mar 11 '13

Coming to that realisation made it so much easier for me to work out how to code applications

Step 1) Plan your data structures

Step 2) Write UI around data structures

36

u/hai-guize Mar 11 '13 edited Mar 11 '13

This is a new concept to me. Thanks, maybe now I will be able to actually code something properly.

→ More replies (1)

11

u/casualblair Mar 11 '13

I like to do it slightly different:

  1. Plan data structures

  2. Plan ui constructs

  3. WILL IT BLEND? Y = Build it. N = Unnecessary complexity exists, destroy it and try again.

3

u/kazagistar Mar 11 '13

I like that, might even use it... general case:

  1. Design separate module

  2. WILL IT BLEND?

  3. If not return to step 1.

→ More replies (1)

89

u/rabidferret Mar 11 '13

You've got it backwards...

  • Plan the general elements of your UI

  • Write tests for the code that would result in that UI

  • Create your data structures to contain what the UI has told you is needed

  • Write your code to fit the previous elements

107

u/zzalpha Mar 11 '13

Welcome to the top-down vs bottom-up battle! Today we have chazzmuzz and rabidferret. Who will win? Only time will tell!

44

u/warbiscuit Mar 11 '13

I'm not even sure why this debate keeps going.

User intent drives frontend design. Frontend design drives backend design. Backend design affects frontend design. Frontend design affects how the users think about the topic, and thus affects user intent.

It's all one large cycle, no matter where you start. I've always figured the goal was to start somewhere ("top" or "bottom" or wherever), make general design pass all the way around, bringing in external requirements as appropriate at each point (what the user wants, what the ui layer can do, what your database can do). Then keep going, until you reach a steady state where all parts generally fit together properly.

4

u/judgej2 Mar 11 '13

In other words, you need a systems architect that can see the big picture before you start anything.

3

u/renrutal Mar 12 '13

Can I get a crystal ball and a 8-ball too?

11

u/darkpaladin Mar 11 '13

but...but...but...Abstraction!

→ More replies (2)

3

u/hippocampe Mar 12 '13

Frontend design drives backend design.

Are you trolling ? Do you really believe it ?

→ More replies (1)
→ More replies (1)

10

u/maestroh Mar 11 '13

The debate isn't top down vs bottom up. If you develop code that you can test, it doesn't matter if you start at the bottom or top. In either case, you can mock the code out to make sure that each component works correctly. If you don't write testable code, you have to rely on setting up your environment before testing anything. This means the only way to test is by stepping through your code.

Writing code with tests gives you decoupled code and the ability to refactor the code later with confidence that it works correctly after the change. Writing the database layer first then building on top of that layer gives you coupled code. When a change is made, there could be a bunch of unintended side effects that can only be found by trial and error.

9

u/zzalpha Mar 11 '13 edited Mar 11 '13

The debate isn't top down vs bottom up.

Look closer. It actually is. At least up to this point it was.

TDD, done according to the orthodoxy, as rabidferrit is describing, is necessarily top-down. You are meant to write a test which exercises a feature, alter the code in the most minimal way possible to pass that test, and then repeat.

That necessarily means you never build out underlying structure until a test requires it. And that necessarily means top-down development.

If you develop code that you can test, it doesn't matter if you start at the bottom or top.

Agreed! But to actually follow the teachings of TDD, you must start top-down, since that's the way the process is specified.

Writing the database layer first then building on top of that layer gives you coupled code.

But this is a filthy lie. :)

Assuming OO development. As a simplistic example, you could build a data access layer based on a set of abstract data models and a repository interface. You then build the database driver to adhere to that interface, and build code that depends on the interface only (where that dependency is injected in some way). When you need to test the consumers of the interface, you provide mocks/stubs for it. Voila, your intermediate layer is testable and decoupled from the actual database driver implementation.

So long as you build to formal interfaces (whatever that means in your language of choice), you can basically start anywhere in your software stack.

3

u/maestroh Mar 11 '13

I think we're saying the same thing. You're basically writing decoupled code. You want to start at the bottom and write the code for the data access layer and then mock it out. You could do that, and that's fine. But you could also write the interface layer based on use cases described in the requirements, mock/stub out any underlying layer and work downward. I'm not advocating TDD at all. I'm saying writing decoupled code allows you to write testable code. And testable code is the key to happy code.

→ More replies (2)

11

u/rabidferret Mar 11 '13

I probably did a bad job of expressing this, but I'm pushing for TDD more than for top down.

19

u/[deleted] Mar 11 '13

TDD is a top-down approach.

3

u/[deleted] Mar 12 '13

I mean we can argue semantics day and night, but TDD is typically considered a bottom up approach. There's no technical definition either way but Wikipedia hints at it being a bottom up approach and Googling "TDD bottom-up top-down" brings up discussions where the overwhelming results on the first and second page refer to TDD as being bottom up.

As an aside Richard Feynman, who wrote a report on the Challenger Disaster, discusses various approaches to testing and mentions a process very similar to TDD. However, he is very explicit in saying that testing of that sort is bottom up and advocates a bottom up approach to testing in general.

Once again, it's mostly semantics but when people think of bottom up they think of going from the small to the big.

56

u/headchem Mar 11 '13

Heh, nice one. I take it one step further and write my CSS first, then design my normalized database around that. :-)

13

u/[deleted] Mar 11 '13

drink a bottle of Russian Standard, while drunk do some shitty wireframes on MS-Paint,.. then design your optimized database around that.

→ More replies (1)

0

u/[deleted] Mar 11 '13

[deleted]

→ More replies (2)

7

u/[deleted] Mar 11 '13

I can't tell if this is sarcastic or not..

4

u/smcameron Mar 11 '13

sarcasm or kool-aid drinker? I can't tell.

4

u/Failstorm Mar 11 '13

Nope. Once you have the specifications, design the data structure first.

Designing optimized and extensible data models is a self contained task in itself, not even an easy one, that should not be affected by the UI in any way. Once you have a good data structure, you can build whatever UI you want, for whatever platform you want, for any target user group.

→ More replies (76)

5

u/[deleted] Mar 11 '13

Writing UI around data structures is not always a good idea, because people often do not understand them. I.e. when you normalize well and make an 1:N connection in a new table, people often do not understand why it is needed, so you denormalize in the UI so that every record can look like having Contact Person 1, 2, 3 instead of a list which they don't understand.

3

u/corporate_fun Mar 11 '13

OMG, you've discovered MVC!

→ More replies (2)
→ More replies (48)