Wiredcraft / carcass

A toolbox for Node.js.
http://wiredcraft.com/carcass/
MIT License
33 stars 8 forks source link

Confusion about carcass #6

Closed ViciousPotato closed 10 years ago

ViciousPotato commented 11 years ago

I still don't understand what carcass is and what does it do. Would you please help me out?

1. What is carcass?

Is it basic infrastructure for our future web servers? How should it be used? like in ./fixture? is there any code demonstrating the use cases?

I saw carcass-auth but that doesn't help.

I hope there is some picture or sth describes the carcass architecture.

2. What is an application?

Is it some kind of middleware? I can't see what they're used for. Are they designed to run separately? since they seem to use separate express objects.

3. What is a Model?

I can't see where are they used.

4. What's the relation between constructors/Server, factories/Express and servers/Http?

I can see servers/Http extends constructors/Server, but what about constructors/Server and factories/Express?

Of course factories/Express seems to be a factory but I doubt if they have conflicting responsibilities since I see they both use express internally.

5. What does plugin means here? I'm especially confused when I see

    var plugin = this.getApplication(title);

so application is plugin?

Anyway, even I wrote some tests, I'm still totally confused. Sorry for that.

ViciousPotato commented 11 years ago

And do we need to implement another https server?

hunvreus commented 11 years ago

Carcass is a very light framework on top of Express.js. @makara will answer you questions more in details but basically it helps us have a more structured approach to developing our API. It adds a few utilities and allows us to describe models (not unlike Backbone.js) and leverage inheritance.

@makara Let's seize that opportunity to write the Wiki and README.md for carcass.

makara commented 11 years ago

OK let me try to answer your questions in the readme.

conoremclaughlin commented 11 years ago

Before I can completely comment on the structure, I have a few questions as well.

1. So constructors are base classes (abstract classes for Java) you have to extend (inherit)?

Is Server.js and http.js just examples of implementations of constructors then? If you believe factories and plugins (from what I see on the wiki) are the main functionality of Carcass, I suggest pushing folders like constructors down into a subfolder like core and state they are provided as a convenience and examples for getting started. If I was a a user of the library, this would help keep me from thinking I need to follow the constructors and servers layout. Are servers supposed to be only node.js servers, while applications holds express applications due to the change in express 3.0?

2. Are factories supposed to be a bootstrap process for constructors? Why does Carcass need these?

Why not just initialize an instance from an implemented constructor itself instead of adding one more step? I can imagine factories would be very useful if you wanted to provide them as a standard structure for interoperability between libraries. If you cannot define the initialize method other than wrapping it, factories would be a nice solution for wrapping (store the instance in a cache, add node.js support for component/model, etc.) additional functionality. Was this the intent? If not, I think it's an idea to consider.

3. What is the problem carcass solves?

For example, Bones was one solution to sharing code between the client and the server. One of the problems it had was its heaviness.

conoremclaughlin commented 11 years ago

Another question:

4. Why do applications only define initialize while servers add to the prototype?

Can applications add to the prototype as well, or does the express 3.0 structure mean I must add my express handlers inside the initialize function passed to the factory?

ViciousPotato commented 11 years ago

Hi @conoremclaughlin. I'm here to provide some information since I worked on carcass tests for some time.

But the main responsibility of clarifying lies on @makara .

  1. So constructors are base classes (abstract classes for Java) you have to extend (inherit)? @makara onced said Server constructor should be made into factories. But I failed to implement this. I'm also confused about their hierarchy (plugins, constructors, factories, servers), maybe we don't need these much concepts.
  2. Are factories supposed to be a bootstrap process for constructors? Why does Carcass need these? Personally I don't think factory here strictly means the Factory pattern. It's main use is more like return builders that create concrete objects. Why does carcass need these? don't know either. Maybe it's good programming style?
  3. What is the problem carcass solves? I always treat it as some boilerplate for server app we will write in the future. The applications/cors in quite useful in my experience. carcass-auth seems quite promising in eliminating the pain of writing oauth code. Of course there's more, but I don't get it either. A boilerplate could be more specific and clearer than the current carcass.
  4. Why do applications only define initialize while servers add to the prototype? don't know.

Makara is not too willing to tell his secrets directly, let's push him together :D

conoremclaughlin commented 11 years ago

hi @ViciousPotato,

for some reason your comment didn't show up in my notifications O.O, but thank you for your answers. I've got a couple ideas for more complicated examples to implement then....

conoremclaughlin commented 11 years ago

I think it would be good to define in the Wiki what the 'assumptions' are that the readme mentions about express applications

hunvreus commented 11 years ago

I think we could inspire ourselves from http://hueniverse.com/2012/12/hapi-a-prologue/ which sounds like a good format to define what our framework is about and would help us push things forward.

@makara Would you care to comment? They use https://github.com/flatiron/director for example and have a very strong statement at the end of their post:

hapi was created around the idea that configuration is better than code, that business logic must be isolated from the transport layer, and that native node constructs like buffers and stream should be supported as first class objects. But most importantly, it was created to provide a modern, comprehensive environment in which as much of the effort is spent delivering business value.

makara commented 11 years ago

@conoremclaughlin, thanks for the questions.

@ViciousPotato, thanks for the answers.

I'm also not sure about everything and have been thinking about it.

1. About constructors and factories.

The No.1 purpose of Carcass is about organizing code, and thus the No.1 assumption is you want to organize your code in a simple manner. I was using constructors for everything, but then I found I don't really need prototypes and I don't like the tricky "inherit" and all I want is just a way of building objects, so I started to convert constructors to factories. @ViciousPotato is right, a "factory" here is only a function that generates objects. I haven't converted "server". I agree it's confusing. Maybe we don't need "server" but something else, like a root application.

2. About the problems it solves.

I don't want it to be too much. Beside organizing code, I just want to provide some useful tools. It's not really a boilerplate, nor really a framework, but rather a package, with some carefully picked tools and some wrappers that make it easier to use them. So I say it saves time for some most common use cases, and currently we are focusing on making it easier to build a web API.

conoremclaughlin commented 11 years ago

@makara cool, thanks for the answers. I'll think about it a bit and try writing an example api module based on Carcass.

You should also take a look at https://github.com/angular/angular.js. Their documentation is overly complex and confusing, and I think the code style is ugly, but the ideas they use for factories with dependency injection is nice.

makara commented 10 years ago

Not anymore confusing factories etc. Closing.