The Artima Developer Community
Sponsored Link

Weblogs Forum
Library or Framework?

33 replies on 3 pages. Most recent reply: Sep 21, 2010 4:33 AM by Naeem Akram

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 33 replies on 3 pages [ « | 1 2 3 | » ]
Petr Mares

Posts: 5
Nickname: dramenbejs
Registered: Feb, 2006

Re: Library or Framework? Posted: Mar 16, 2006 3:53 AM
Reply to this message Reply
Advertisement
1) One builds an application atop of framework (or at least mod_python serves as a framework) using libraries.

So the question is not whether library or framework, right?

Could the right question be "what should a web/db framework do for itself and what should be done using libraries?"

2) I think the framework should do just things which could not be easily and quickly done with library calls - (management of application users with various mechanisms of authentication comes to mind).

3) Framework defines topology of an application and defines the way the application should be extended. So it should be modular to evade unnecessary restrictions & slowdowns.

Correct me if I am wrong.

Kay Schluehr

Posts: 302
Nickname: schluehk
Registered: Jan, 2005

Re: Library or Framework? Posted: Mar 16, 2006 4:55 AM
Reply to this message Reply
> 1) One builds an application atop of framework (or at
> least mod_python serves as a framework) using libraries.
>
> So the question is not whether library or framework,
> right?
>
> Could the right question be "what should a web/db
> framework do for itself and what should be done using
> libraries?
"
>
> 2) I think the framework should do just things which could
> not be easily and quickly done with library calls -
> (management of application users with various mechanisms
> of authentication comes to mind).

That's right. A framework will most likely define a control flow. That's what others already mentioned here with regard to the Hollywood pattern: concrete implementations get called inside of an application architecture. This application architecture can be considered as an "application with holes" as Neil Schemenauer understands it.

> 3) Framework defines topology of an application and
> defines the way the application should be extended. So it
> should be modular to evade unnecessary restrictions &
> slowdowns.
>
> Correct me if I am wrong.

The term "application" or "topolgy of an application" is a bit fuzzy. I would prefer to say that the "toplogy mediates some activity". So at the core we might have a combination of Hollywood pattern + Abstract factory.

Bruce Eckel

Posts: 875
Nickname: beckel
Registered: Jun, 2003

Re: Library or Framework? Posted: Mar 16, 2006 4:58 PM
Reply to this message Reply
I'll try:

A library component solves a part of many problems. A framework solves a specific problem.

You plug a library component into your program and ask it to do things.

A well-designed framework allows you to vary the parts of the solution that you need to vary, and doesn't force you to write the parts that are the same from solution to solution.

Dan Perl

Posts: 28
Nickname: nanov
Registered: Sep, 2004

Re: Library or Framework? Posted: Mar 16, 2006 6:14 PM
Reply to this message Reply
I think that Guido's point is about the difference between how frameworks and libraries are designed. Some of the replies, however, are pointing out differences in how frameworks and libraries are used.

I'll try to address Guido's point. And, IMO, I can pretty much only agree with him that frameworks are designed by generalization of a specific application design whereas libraries are designed just from an initial set of requirements.

A framework determines the design/architecture of the applications that use it or at least part of that design/architecture. Because of that the design of a framework starts from the application or at least from a vision of what the design of the application should be like. Then you take what would be generic to many such applications and you create the framework. In other words, you start with an application design and then you design the framework.

OTOH, libraries can evolve themselves but they do start from specific requirements for a set of functionalities. You can design a library before you know what the applications using it will be like. And libraries are usually designed that way.

I'm not sure though what is the message of Guido's (or Neil Schemenauer's) observation. What I see in it is an illustration of how the two approaches (design from requirements and design through evolution/generalization/refactoring) are appropriate for different cases. It's somewhat similar to using bottom-up or top-down design.

Kay Schluehr

Posts: 302
Nickname: schluehk
Registered: Jan, 2005

Re: Library or Framework? Posted: Mar 17, 2006 4:53 AM
Reply to this message Reply
> I'll try:
>
> A library component solves a part of many problems. A
> framework solves a specific problem.
>
> You plug a library component into your program and ask it
> to do things.
>
> A well-designed framework allows you to vary the parts of
> the solution that you need to vary, and doesn't force you
> to write the parts that are the same from solution to
> solution.

In one of the most simple cases a framework can be just an event-handler encapsulated in a method m of a class A that calls methods f1,...,fk that are implemented in a subclass of A. The abstract methods fi would be the "holes" in the "application", while the implementations of those methods would be the "library plugins". The event-handler can be a libary component with a simple interface e.g. a tokenizer. It can be customized in two ways: adding new events and creating new subclasses of A. Finally a factory method is needed that provides instances of ( subclasses of ) A. That's the simple part.

Things become complicated with dependencies of f1,...,fk - they might share data or they must be executed in particular sequences or they are allowed to be called under certain circumstances only. The framework is likely not expressive enough to manage this additional logics in a deliberate way. So frameworks might not be able to solve the correct specific problems but just some general aspects of them. That's why creating frameworks that solve the right specific problems is hard - its easy to do workarounds ( setting flags / creating spaghetti code ) but than the architecture has already failed.

Dileban Karunamoorthy

Posts: 9
Nickname: dileban
Registered: Feb, 2006

Re: Library or Framework? Posted: Mar 17, 2006 10:02 AM
Reply to this message Reply
> I'll try:
>
> A library component solves a part of many problems. A
> framework solves a specific problem.
>
> You plug a library component into your program and ask it
> to do things.
>
> A well-designed framework allows you to vary the parts of
> the solution that you need to vary, and doesn't force you
> to write the parts that are the same from solution to
> solution.


That is the tricky part isn't it? "allowing you to vary parts of the solution that you need to vary" and "not forcing you to write parts". People have different philosophies and hence provide different definitions for frameworks.

The real question I guess is what is the best philosophy for frameworks? Do you need to keep its responsibilities to a minimal as possible? Do you need to make restrictions in order enforce standards across solutions? How do you decide what responsibilities lie within the framework, and what outside the framework perhaps in a library?

I guess the answers to these questions will depend on the type of problem the framework is trying to solve, the kinds of solutions that will be built on top of it and the type/nature/competency of the programmers developing the applications on top of the framework.

Bruce Eckel

Posts: 875
Nickname: beckel
Registered: Jun, 2003

Re: Library or Framework? Posted: Mar 17, 2006 12:18 PM
Reply to this message Reply
> I guess the answers to these questions will depend on the
> type of problem the framework is trying to solve, the
> kinds of solutions that will be built on top of it and the
> type/nature/competency of the programmers developing the
> applications on top of the framework.

I think the art in framework design comes down to recognizing the most important factors that need to change from application to application, and those insights do seem philosophical at times. For example, Rails "convention over configuration," which recognizes that in a large number of cases a lot of duplicated work takes place. Since a framework's goal is to eliminate the mindless duplicated work, for those cases "convention over configuration" makes sense, and I think this idea is an important contribution. But how long did it take us for someone to see that? A long time, and a lot of expense and pain. Ideally, a framework will allow you to skip over all that, but a framework that makes the wrong choices (EJB1/2, for example) can end up adding work and expense to your job.

Dileban Karunamoorthy

Posts: 9
Nickname: dileban
Registered: Feb, 2006

Re: Library or Framework? Posted: Mar 17, 2006 8:12 PM
Reply to this message Reply
> Since a framework's goal is to eliminate the
> mindless duplicated work, for those cases "convention over
> configuration" makes sense, and I think this idea is an
> important contribution. But how long did it take us for
> someone to see that? A long time, and a lot of expense and
> pain. Ideally, a framework will allow you to skip over all
> that, but a framework that makes the wrong choices
> (EJB1/2, for example) can end up adding work and expense
> to your job.


Yes, and I'm sure you would agree that time can also work against a framework, as it becomes more and more "mature", it becomes more and more restrictive, doing too many things for you, enforcing too many restrictions in the form of "conventions", with the added need of guaranteeing backward compatibility of applications.

But then, I believe this is where good design principles and "art" comes in, in which frameworks evolve through refactoring and better understanding of things. But yet, certain sacrifices will have to be made, for example, backward compatibility may no longer be guaranteed, or at least trying to do so would give rise to a "synthetic" design, something that would not seem as elegant. Plus, increased flexibility in the new design may give too much leeway, allowing programmers to easily deviate from "convention", which is also something that can work against you.

My question is, although this may seem somewhat obvious to some, are frameworks built to last? Can they last? I feel frameworks need to be kept to a minimum, providing everything else through libraries, something that lasts much longer and are much easier to extend and adapt unlike frameworks. Thoughts?

Bruce Eckel

Posts: 875
Nickname: beckel
Registered: Jun, 2003

Re: Library or Framework? Posted: Mar 17, 2006 9:06 PM
Reply to this message Reply
> I feel
> frameworks need to be kept to a minimum, providing
> everything else through libraries, something that lasts
> much longer and are much easier to extend and adapt unlike
> frameworks.

Now that's an interesting perspective -- the idea that there is a balance between frameworks and libraries. And if one could achieve the "right" balance you'd get a lot of ease and elegance.

I think I agree that a framework should start as a very minimalistic thing, using the agile approach of only solving the problem that you need to solve right now. When you need to solve a problem more than a couple of times, you incorporate it into the framework, thus slowly evolving the design.

Dan Perl

Posts: 28
Nickname: nanov
Registered: Sep, 2004

Re: Library or Framework? Posted: Mar 17, 2006 11:16 PM
Reply to this message Reply
> I think I agree that a framework should start as a very
> minimalistic thing, using the agile approach of only
> solving the problem that you need to solve right now. When
> you need to solve a problem more than a couple of times,
> you incorporate it into the framework, thus slowly
> evolving the design.

But can libraries be also designed that way? Starting with just a few functions and adding more only as users request new ones? Replacing old functions with new ones and merging some of them in order to keep the library minimal? Sure, users of the library are affected by these changes, but isn't that the case also with users of a framework? Can't you evolve a library this way and stop at almost any moment and still call it "a library"?

I think that Guido's point was that libraries have to be more thought out from the beginning based on requirements. A big design up front as opposed to an agile approach. Are frameworks and libraries so different from this point of view?

My opinion is that they are not. Guido made the emphasis that it's a "good library" that needs more. I'm beginning to think though that the issue here is not quality but size. A large and complex library does need BDUF. But so does a large and complex framework. Besides, you may design a framework by evolution and stop at almost any moment and call it "a framework", but is that a "good framework" if it doesn't have maximal functionality?

Yes, that's right, I believe that agile methodologies do not scale. I'll be glad to be proven wrong though.

Kevin Little

Posts: 1
Nickname: kcl
Registered: Jan, 2006

Re: Library or Framework? Posted: Mar 18, 2006 5:33 PM
Reply to this message Reply
Having read throught 24 posts to this thread, it occurs to me that one major difference between libraries and frameworks is the degree that the latter forces architectural decisions on the developer, while the former usually does not. If a framework is an application with holes that the developer has to (gets to?) plug, then large chunks of the fundamental architecture have been decided by the designers of the framework, not the end developer. (Ack! Now we have "end developers" as well as "end users" -- oh, my!)

Another way to put this is that when designing libraries one is most concerned with sound, broadly useful programming tactics; when designing frameworks, one is more concerned with over-arching strategy, i.e., architecture.

fiNAL Y

Posts: 1
Nickname: softboysxp
Registered: Mar, 2006

Re: Library or Framework? Posted: Mar 18, 2006 11:29 PM
Reply to this message Reply
"Don't call me, we'll call you" That is framework !

Michael Schneider

Posts: 4
Nickname: schneider
Registered: Mar, 2006

Re: Library or Framework? Posted: Mar 19, 2006 9:31 PM
Reply to this message Reply
Interesting Discussion.


I think that one starts with an application, you deliver it to a customer, and it meets their needs.

Then you get a similar gig, you refactor your app, and and ship it. This app shares ~80% of the codebase with the original app.

Then you get a third app, you refactor further, then ship. You are now up to 90% shared code base.

You get a fourth app, and refactor your code further. Domains are starting to solidify, hooks are easy to see, and there are a couple of modules that are begining to be very clean.

After the next couple of gigs, your app now looks like a framework.

Your next gig is in a different domain, and your framework does not fit. You start to notice a couple of modulues that would be very handy to use in your new app. You refactor these modules into library code.

Your next gig is in yet another domain, but look, your libs can come with you.

So I would suggest that:

1) you start by delivering an application
2) if you have several applications in the same domain, you can grow your application into a framework with a set of plug-points.
3) After 3-5 apps, libraries start to fall out.

So I would propose:

Application-> framework -> library

Start trusting a framework when 3-7 apps are built with it.
Start trusting libraries when 3-7 additional apps are built on the library.

Don't trust a library that designed in an ivory tower, and not grown :-)

Mike

Joao Pedrosa

Posts: 114
Nickname: dewd
Registered: Dec, 2005

Re: Library or Framework? Posted: Mar 20, 2006 7:20 AM
Reply to this message Reply
Yes, sometimes to build a framework we need to build several applications first, but not only that, because we could be building several libraries in parallel as well. A naked framework, that is, a framework that's built without any support of new libraries, is very rare.

But once we start a framework, it becomes harder to see the tree from the forrest. Sometimes we don't abstract enough. Sometimes we don't think of new and cool ideas to use in the framework. Etc. Truth be told, it's very hard to create a framework and then to have to maintain it despite it being a bit crap. Like Ken Thompson once said:

"One of my most productive days was throwing away 1000 lines of code."

Like him, I have thrown away lots of code while I tried to create a base for applications (libraries, frameworks, examples, etc). A dynamic language like Ruby is fundamental when we need to redefine code, because the "thought process" does not get interrupted too frequently with compiler errors. And that's why the surviving libraries, frameworks and applications tend to evolve to something that other languages don't have. Though I concede that what I do is closer to research (so far). :-)

Joao Pedrosa

Posts: 114
Nickname: dewd
Registered: Dec, 2005

Re: Library or Framework? Posted: Mar 20, 2006 7:23 AM
Reply to this message Reply
I mean the forrest from the trees. :-)

Flat View: This topic has 33 replies on 3 pages [ « | 1  2  3 | » ]
Topic: The Autoproxy Plugin - Part I Previous Topic   Next Topic Topic: ScalaTest Matchers Preview

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use