[Development] when to Extract Method (was Re: commas in ctor-init-lists)

Marc Mutz marc.mutz at kdab.com
Fri Jun 3 15:37:32 CEST 2016


On Friday 03 June 2016 15:14:13 Edward Welbourne wrote:
> Marc Mutz
> 
> > The three clauses should stay three clauses if the action (their
> > then-block) is independent. If the then-block, as you seem to suggest,
> > is idenitical in tokens and semantics, then you *will* find a name to
> > describe it that doesn't just transliterate the original C++ code into
> > English: shouldDeleteThing, thingIsExpired, isNoLongerNeeded(thing),
> > ...
> 
> Just to be clear, my example code's delete thing was just using that as
> "there's some random tidy-up we need to do before any early return"; so
> the three conditions are all "we need to return early from this method"
> and the need to delete thing (which was nowhere referenced in any of the
> conditionals) is incidental to the test.  In such a case I very much
> doubt there's a nice name for the method.

Ok, sorry, then I misunderstood.

In that case: the thing should have been held in a scoped pointer and the 
three guard clauses should stay separate, but with just 'return' as the 
action.

With the cleanup dealt with by RAII, I don't see a reason to combine the ifs 
anymore.

Thanks,
Marc

-- 
Marc Mutz <marc.mutz at kdab.com> | Senior Software Engineer
KDAB (Deutschland) GmbH & Co.KG, a KDAB Group Company
Tel: +49-30-521325470
KDAB - Qt, C++ and OpenGL Experts



More information about the Development mailing list