The Artima Developer Community
Sponsored Link

C++ Community News Forum
The Problem with Programming

212 replies on 15 pages. Most recent reply: Dec 8, 2006 6:12 AM by James Watson

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 212 replies on 15 pages [ « | 1 ... 6 7 8 9 10 11 12 13 14 ... 15  | » ]
Rupert Kittinger-Sereinig

Posts: 21
Nickname: rkit
Registered: Dec, 2005

Re: The Problem with Programming Posted: Nov 30, 2006 1:14 PM
Reply to this message Reply
Advertisement
> >
> > > You can design around this without RAII, I suppose,
> but
> > > why would you want to unless you had to?
> >
> > Because of the problem with RAII that you have still
> > failed to address.
>
> ... which I still fail to see.
>

Maybe the problem he talks about is the following: Consider a complicated object that is expensive to construct which also holds a relatively cheap resource. Let's consider e.g. a database connection that needs to parse configuration files, perform adress resolution, etc. before an actual network connection can be made. If this object needs to be destroyed to close the connection, this is indeed suboptimal.

However, there is also the possibility of creating a lightweight resource-holder object, whose construction opens the connection and whose destruction closes it. The connection object can happily live on until the next connection. A modern c++-compiler will probably generate no code at all except for the two function calls.

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: The Problem with Programming Posted: Nov 30, 2006 1:22 PM
Reply to this message Reply
> However, there is also the possibility of creating a
> lightweight resource-holder object, whose construction
> opens the connection and whose destruction closes it. The
> connection object can happily live on until the next
> connection. A modern c++-compiler will probably generate
> no code at all except for the two function calls.

You've only moved the problem up one level and now you are managing the connection life-cycle from the client code. The client code shouldn't be concerned about the database connection. Actually, in the design I am describing, you could change the manager to pull the code from somewhere else entirely, a client side cache, or a local file for example.

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: The Problem with Programming Posted: Nov 30, 2006 1:35 PM
Reply to this message Reply
> > However, there is also the possibility of creating a
> > lightweight resource-holder object, whose construction
> > opens the connection and whose destruction closes it.
> The
> > connection object can happily live on until the next
> > connection. A modern c++-compiler will probably
> generate
> > no code at all except for the two function calls.
>
> You've only moved the problem up one level and now you are
> managing the connection life-cycle from the client code.
> The client code shouldn't be concerned about the database
> e connection. Actually, in the design I am describing,
> you could change the manager to pull the code from
> somewhere else entirely, a client side cache, or a local
> file for example.

Actually you could do these things in a custom connection object too, so lets not get side-tracked.

The fundamental issue is that RAII is that you are making cleanup the side-effect of some non-database focused code's object management. Yes, you can make it work, but I'd rather keep that logic encapsulated.

Rupert Kittinger-Sereinig

Posts: 21
Nickname: rkit
Registered: Dec, 2005

Re: The Problem with Programming Posted: Nov 30, 2006 1:46 PM
Reply to this message Reply
> You've only moved the problem up one level and now you are
> managing the connection life-cycle from the client code.
> The client code shouldn't be concerned about the database
> e connection. Actually, in the design I am describing,
> you could change the manager to pull the code from
> somewhere else entirely, a client side cache, or a local
> file for example.

What you are advocating here is simply a higher-level design that hides the resource-management from the client code. However, to actually implement such a design, RAII can be a very valuable building block.

To say it in another way: there are a lot of cases where RAII is an excellent solution, even if it is no silver bullet.

Btw, the database library I am actually using (pqxx) takes care of all the connection stuff for me.

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: The Problem with Programming Posted: Nov 30, 2006 1:56 PM
Reply to this message Reply
> What you are advocating here is simply a higher-level
> design that hides the resource-management from the client
> code.

Yes, that's it exactly. I'm not sure why I've had to explain in such depth. Maybe I'm just not being clear.

> However, to actually implement such a design, RAII
> can be a very valuable building block.

I'm sure it would be helpful, however, it's not necessary. The whole point here is that even though Java lacks an immediate destructor, it's not a huge problem because this pattern is more effective anyway. Using this approach has also lead me to abstracting out the query also. I can change the query or swap it out as needed without changes to the code.

One problem with auto-pointers that I've heard mentioned is that you can have a sudden pointer-tree collapse that causes the application to stall. Is this a common problem?

Dick Ford

Posts: 149
Nickname: roybatty
Registered: Sep, 2003

Re: The Problem with Programming Posted: Nov 30, 2006 2:07 PM
Reply to this message Reply
> > Has anyone an explanation for the
> > growth of interest in VB?
>
> For front end stuff...
>
> It's simple. It works. It can be used by people without
> a degree in computer science and twenty years expeience.
> And, unlike Java, it is possible to produce usable GUIs
> s on projects that aren't IDEs underwritten by Sun or IBM.

I think you just summed up how Java got popular on the server side.

Dick Ford

Posts: 149
Nickname: roybatty
Registered: Sep, 2003

Re: The Problem with Programming Posted: Nov 30, 2006 2:29 PM
Reply to this message Reply
>
> Smalltalk isn't perfect. It is just the best thing so
> far.
>

Best thing so far compared to what - COBOL? If you're going to go that route, you might as well go all the way to Scheme or Common Lisp.

Merriodoc Brandybuck

Posts: 225
Nickname: brandybuck
Registered: Mar, 2003

Re: The Problem with Programming Posted: Nov 30, 2006 2:39 PM
Reply to this message Reply
> > What you are advocating here is simply a higher-level
> > design that hides the resource-management from the
> client
> > code.
>
> Yes, that's it exactly. I'm not sure why I've had to
> explain in such depth. Maybe I'm just not being clear.
>
> > However, to actually implement such a design, RAII
> > can be a very valuable building block.
>
> I'm sure it would be helpful, however, it's not necessary.
> The whole point here is that even though Java lacks an
> n immediate destructor, it's not a huge problem because
> this pattern is more effective anyway. Using this
> approach has also lead me to abstracting out the query
> also. I can change the query or swap it out as needed
> without changes to the code.
>

At this point I think some people see "more effective" as your opinion and how effective or not RAII is in this sort of context depends a lot on the system architecture, granularity of classes, etc. All the things you describe can be done in C++. In the case you describe I would say that RAII buys you some insurance because in addition to your own methods managing the connection, if things go to hell in a handbasket the constructors should clean up the resources anyway.

> One problem with auto-pointers that I've heard mentioned
> is that you can have a sudden pointer-tree collapse that
> causes the application to stall. Is this a common problem?

I've never actually seen it. I can see how it can be done if things are improperly scoped, but then I would think this is indicative of a bigger problem. It would be a symptom of, in my opinion, of a badly flawed design.

Is there a reason something similar but much more subtle couldn't happen in a java or C# app? A pointer collapse would be caused by a root pointer being deallocated and having its constituents not be allocated which would result in leaked resources and all kinds of other nastiness. If you disposed of a root class but still had valid references to its constituents, wouldn't you possibly end up with a case where the container got garbage collected but you were able to still access objects that used to belong to the container? If that just isn't possible, great. If it is, I could see that leading to some really hard to diagnose and fix bugs whereas the C++ app would most likely fail miserably.

Which one of those outcomes can be argued to death and I don't see one side convincing the other that their way is "right". They are both bad. Personally I'd rather have the dramatic crash and burn vs. the app limping along, but that's just me. Don't waste your breath trying to convince me otherwise. I've dealt with both situations too many times to count and the dramatic crash and burn has, without fail, been easier for me to diagnose and fix. The users are more annoyed initially but their problems are fixed much more quickly and in the long run, in my experience, they have been happier.

Dick Ford

Posts: 149
Nickname: roybatty
Registered: Sep, 2003

Re: The Problem with Programming Posted: Nov 30, 2006 2:44 PM
Reply to this message Reply
> > I'd start reading the Haskell/Ocaml tutorials/books, so
> > when these hybrid languages come along, you're not
> totally
> > in the dark.
>
> What makes you think I am in the dark?

Nothing makes me think you're in the dark.

Nemanja Trifunovic

Posts: 172
Nickname: ntrif
Registered: Jun, 2004

Re: The Problem with Programming Posted: Nov 30, 2006 3:29 PM
Reply to this message Reply
> > Then you need a specialized RAII class that would
> > call conn.open() in the constructor and conn.close() in
> > the destructor and use an object of this class to keep
> the
> > connection open in the desired scope.
>
> And how is this easier than what I have proposed?

I could answer that question if you posted complete code for your manager-handler design instead of the snippet we saw above.

>
> > In practice, though, I would rather just design to have
> a
> > connecton object live as long as the actual connection.
>
> And if it lives for an indeterminate period of time, how
> do you close it at the appropriate time and make sure it's
> refreshed at the proper intervals?

Than RAII doesn't help you (except for exception safety), but doesn't harm you as well.

I must add that I have never dealt with "indeterminate" connections. Typically I just open it (often from a cache, but thats orthogonal to this discussion), do the transaction(s) I need to do and let it be cleaned up - all in the timeframe of one http request-response cycle.

Todd Blanchard

Posts: 316
Nickname: tblanchard
Registered: May, 2003

Re: The Problem with Programming Posted: Nov 30, 2006 4:24 PM
Reply to this message Reply
>But to be fair, Java is unbeatable for general application development
> provided you need to be platform independent

See, that's also just not true.

Java is really very easy to beat for general application development - including platform independence. The python/wxWidgets people are doing great stuff. I myself would choose VisualWorks Smalltalk if faced with that kind of choice. The problem with Java is that it follows rather too closely in the footsteps of C++. Which is why Java is in decline as well.

Todd Blanchard

Posts: 316
Nickname: tblanchard
Registered: May, 2003

Re: The Problem with Programming Posted: Nov 30, 2006 4:32 PM
Reply to this message Reply
> > I really don't think C++ gets much use outside of
> embedded, drivers, and OS development.

> Sorry, but as I looked for some "new opportunities"
> recently it was at par with Java.

Perhaps I count differently. Subtract all jobs requiring use of Windows. Then count. Anyhow, a quick monster search shows Java up in my area by 25% without even throwing the windows jobs out.

Not that that matters either. The other reason I bailed on it is that almost nobody I've ever met is good enough at it to do production code in it and I don't have the patience to clean it up. If C++ were a power tool, OSHA would ban it.

Todd Blanchard

Posts: 316
Nickname: tblanchard
Registered: May, 2003

Re: The Problem with Programming Posted: Nov 30, 2006 4:40 PM
Reply to this message Reply
> >
> > Smalltalk isn't perfect. It is just the best thing so
> > far.

> Best thing so far compared to what - COBOL?

Everything since. Go back to Cameron's post about where he thinks things will go and you'll find Smalltalk has been sitting there for over 25 years.

> If you're going to go that route, you might as well go all the way
> to Scheme or Common Lisp.

I don't think you've given that statement much thought.
http://steve-yegge.blogspot.com/2006/04/lisp-is-not-acceptable-lisp.html

The same objections apply to Scheme.

Leo Lipelis

Posts: 111
Nickname: aeoo
Registered: Apr, 2006

Re: The Problem with Programming Posted: Nov 30, 2006 5:38 PM
Reply to this message Reply
I can't believe this long discussion about nothing.

I'll make it easy:

"In thousands of years we still make wheels that break. Why can't we make a wheel that doesn't break? Why do we have to reinvent it? Why can't we just invent the perfect wheel? Wheels have been around for so long...what is the problem? How do we fix it?"

"Well if wheel makes used better design and cared more about wheels and didn't try to brute force the wheels....blah blah blah blah blah"

*zzzzzzzzzzzZZZZzzzzZZZZzzzzz*

Boring.

Dick Ford

Posts: 149
Nickname: roybatty
Registered: Sep, 2003

Re: The Problem with Programming Posted: Nov 30, 2006 8:25 PM
Reply to this message Reply
> > >
> > > Smalltalk isn't perfect. It is just the best thing
> so
> > > far.
>
> > Best thing so far compared to what - COBOL?
>
> Everything since. Go back to Cameron's post about where
> he thinks things will go and you'll find Smalltalk has
> been sitting there for over 25 years.
>

Sitting where? Better than everything since COBOL? And what did Cameron say about Smalltalk? John Doe stated something where he thinks things will go, but I'm more interested in what you think where things are going and how Smalltalk fits into that.

> > If you're going to go that route, you might as well go
> all the way
> > to Scheme or Common Lisp.
>
> I don't think you've given that statement much thought.
> http://steve-yegge.blogspot.com/2006/04/lisp-is-not-accepta
> ble-lisp.html
>

Another random blogger/poster for you to proxy with. I won't blog, I'll just say it here. Smalltalk is not an acceptable Lisp.

So you think that Smalltalk is going to make a comeback? Or is this Smalltalk living vicariously through Ruby? Or maybe this an old-fashioned dynamic vs static typing thing?

Dolphin Smalltalk is a great environment. But instead of getting fanboyish, I'd say that once you look past Java as your static typing example, Smalltalk isn't looking so hot.

Maybe you should pick up the now defunct Slate project. It had some interesting ideas.

Flat View: This topic has 212 replies on 15 pages [ « | 6  7  8  9  10  11  12  13  14 | » ]
Topic: Pantheios 1.0.1 full release approaching; beta 17 just released Previous Topic   Next Topic Topic: John Ousterhout on What Limits Software Growth

Sponsored Links



Google
  Web Artima.com   

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