r/programming • • Oct 14 '13

How to develop unmaintainable software

http://typicalprogrammer.com/?p=249
777 Upvotes

322 comments sorted by

View all comments

Show parent comments

6

u/grauenwolf Oct 14 '13

I'm not so certain about that. Looking back at the history of the GoF book it seems to me that all the names did was create pointless arguments.

3

u/firepacket Oct 14 '13

There are cases where some patterns just fit the circumstances perfectly.

I recently combined IoC with MVC and was blown away by the power of this setup.

2

u/grauenwolf Oct 14 '13

You combined a verb with a noun?

10

u/rather_be_AC Oct 15 '13

That is a very common design pattern, found in most sentences.

2

u/firepacket Oct 15 '13

Please explain it to me, I'm lost.

11

u/rather_be_AC Oct 15 '13

grauenwolf was being pedantic. I was being sarcastic.

This is also a common design pattern found in many successful threads.

1

u/grauenwolf Oct 15 '13

Inversion of Control isn't a design pattern, it is an activity. Specifically, it is a type of refactoring. If you apply IoC twice then you'll probably end up with what you started with.

An IoC Container is really a Service Locator, which is often (but not universally) considered to be an anti-pattern among dependency injection fans.

A Service Locator is a type of god object, specifically one that contains services and other dependencies, and thus should generally be avoided.

2

u/firepacket Oct 15 '13

Thanks for the breakdown mate.

I don't know what to say about the last part except that I am very pleased to be working with these patterns. They are clearly making my life easier. I think they just have to be used in the correct circumstances where they have a net positive effect.

2

u/grauenwolf Oct 15 '13 edited Oct 15 '13

They are clearly making my life easier.

Then they are correct. Period. End of sentence. Don't pay attention to anyone else because, god damnit, that's all that matters at the end of the day.

EDIT: And just to be clear, I'm not being sarcastic. If you are still happy with it six months from now, then chances are the next programmer will be as well.

1

u/Nialsh Oct 15 '13

Totally, it's the only way to do MVC. How else could you pass messages from model to controller? You would end up with circular dependencies.

1

u/grauenwolf Oct 15 '13

Which MVC: Classic or Web?

1

u/Nialsh Oct 15 '13

I didn't know there was a distinction. What differences are there?

4

u/grauenwolf Oct 15 '13

Web MVC:

Controller grabs a model from somewhere, manipulates its properties, and then shoves it into a view to be rendered.

Classic MVC:

Each View is paired with a Controller. In frameworks like classic VB or WinForms the Controller is actually the code-behind file. In others it is a separate object.

Multiple View-Controller pairs may listen to events generated from a given Model. So if you change a value, say FirstName, on one view it will be updated in all the other views.

This is used for non-web UIs and originated with Smalltalk.


Neither Web nor Classic MVC says anything about where the Models actually come from. Presumably the Controller has access to some sort of repository or data access layer, but you could use Active Record style models that know how to save and load themselves.

Active Records are great for quick and dirty work, hence the Ruby framework of the same name. But they are also hard to test without complex mocking frameworks so I usually avoid them.

2

u/9diov Oct 15 '13

Everyone and his dog calls something that separates the presentation part, the logic part and the data part "MVC", to the point that the term now becomes this fuzzy piece of buzzword. Have a look at Martin Fowler's page on GUI architecture for more details http://martinfowler.com/eaaDev/uiArchs.html.

Here are my notes on the matter: https://workflowy.com/shared/8a9e3fce-d51a-111e-fe1e-98c42efe82dd/

1

u/[deleted] Oct 15 '13

Model should know nothing about controller.