[bt-devel] Programming Techniques
Matt Andrews
bt-devel@crosswire.org
Fri, 8 Mar 2002 20:01:17 -0800 (PST)
--- David White <dave@whitevine.com> wrote:
> Hi everyone,
>
> Martin has asked me to become a BibleTime developer,
> and I have accepted
> his offer. In particular, he wants me to look over
> the BibleTime code,
> and make comment on it's robustness, style, and
> adherence to good C++
> standards, since I have a good deal of experience
> with C++ and knowledge
> about it. I just thought I'd write this email to
> introduce myself to
> everyone on the list, and to offer a few initial
> suggestions of things
> that could be done to improve the BibleTime code
> base.
Welcome, and thanks for helping us.
> A key technique I want to introduce is Resource
> Acquisition Is
> Intialization (RAII). It's a technique invented and
> popularised by
> Bjarne Stroustrup, the creator of C++. BibleTime has
> alot of code that
> looks something like this:
>
> {
> Object* ob = new Object();
> ...do stuff with ob....
> delete ob;
> }
>
> now, firstly, if possible ob should not be allocated
> on the heap like
> that, it should be allocated on the stack, as in:
>
> {
> Object ob;
> ...do stuff with ob...
> }
>
> this is because it is quicker (heap allocations are
> slow, stack
> allocations are fast), easier to read, less code,
> and there is no hope
> of there being a memory leak.
Oh hey, that's cool. I wish my professors would teach
stuff like that.
/*
* Stuff about exceptions
*/
Exceptions good.
/*
* A whole bunch of stuff my brain is still trying to
dissect
*/
Umm, ok.
>
> One minor point, I have put all this in the
> namespace util. So you have
> to go util::scoped_resource etc. I notice that
> BibleTime doesn't use
> namespaces at the moment, but I suggest we consider
> changing this.
> namespaces are a cool feature that allows much
> better division of code.
What are ways we would use namespace is this instance?
Would we use Sword::CClass instead of CSwordClass?
=====
"To them God has chosen to make known among the Gentiles the glorious riches of this mystery, which is Christ in you, the hope of Glory" - Colossians 1:27
__________________________________________________
Do You Yahoo!?
Try FREE Yahoo! Mail - the world's greatest free email!
http://mail.yahoo.com/