Kevin Smith | 1 Dec 01:25 2002

Re: Writing simple software - A Challenge!

On Sat, 2002-11-30 at 14:27, jhrothjr wrote:
> --- In extremeprogramming <at> y..., Kevin Smith <kevinxp <at> q...> wrote:
> > and avoid all needless special cases. Other folks here have suggested
> > avoiding NULL as a valid return value, for example. Steve Maguire has
> > some great advice on this for C programmers in Writing Solid Code.
> 
> One of the things I've seen on this is the "Null Object Pattern." It suggests creating a special object
instead of a null value that returns something useful for that case.

I just realized that my post was unclear. Yes, the Null Object pattern
is one of the things I was talking about.

Maguire, on the other hand, goes in to some depth about eliminating if
statements and other conditionals. He doesn't really deal with the NULL
case so much. 

As a C coder, that book changed my life. For one thing, it encouraged me
to write my first semi-test-first, fully-unit-tested code. For another,
it helped me really understand the importance of clean function
signatures. I already knew the evils of "tricky code", so he didn't help
me as much on that count.

It would be great to see an edition of Writing Solid Code updated to at
least deal with C++, if not Java. I'm afraid much of the current book
would be useless, and perhaps even incomprehensible, to people who are
not adept with C.

Kevin

To Post a message, send it to:   extremeprogramming <at> eGroups.com
(Continue reading)

Kevin Smith | 1 Dec 01:30 2002

Re: Good Design -- is it relative?

On Sat, 2002-11-30 at 14:16, Jacek Krajewski wrote:
> I am serious about my question. We gave an introduction on refactoring and
> demonstrated on small (I know perhaps not real world) example, how a
> better design could help. They said it looks, but when a guy in previous
> days tried to splitt things, they always had to open more then 10 files to
> understand the code.

I know someone like that. He prefers longer functions, and larger source
modules, because he doesn't like jumping around. I suspect it's an
artifact of living with poor editors and no browsers for so many years.
That, and dealing with code that has really terrible names, lots of
globals, and confusing function signatures, so you really have to look
inside a function to know what it's doing. Oh, and a discomfort with
objects in general.

I haven't had a chance to prove it yet, but my hope would be that a
combination of a good IDE, highly modular, well-named code, and some
pairing sessions might convince him that there is a better way.

Kevin

To Post a message, send it to:   extremeprogramming <at> eGroups.com

To Unsubscribe, send a blank message to: extremeprogramming-unsubscribe <at> eGroups.com

ad-free courtesy of objectmentor.com 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 

(Continue reading)

Kay A. Pentecost | 1 Dec 03:52 2002
Picon

RE: Writing simple software - A Challenge!

Hi, Ron,

> -----Original Message-----
> From: Ron Jeffries [mailto:ronjeffries <at> acm.org]
> Sent: Saturday, November 30, 2002 6:29 PM
> To: extremeprogramming <at> yahoogroups.com
> Subject: Re: [XP] Writing simple software - A Challenge!
>
>
> On Saturday, November 30, 2002, at 6:17:11 PM, Kay A. Pentecost wrote:
>
>
> >> "Eliminate Exceptions" reminds me of my own motto: "Question every if
> >> statement". Basically, aim for code where nothing can possibly
> go wrong,
> >> and avoid all needless special cases. Other folks here have suggested
> >> avoiding NULL as a valid return value, for example. Steve Maguire has
> >> some great advice on this for C programmers in Writing Solid Code.
>
> > Oh.  I thought that he meant exceptions like in "throwing them..."
>
> I did, but I also meant what Kevin meant.

Well, would you explain more about not throwing them?

Kay

>
> Ron Jeffries
> www.XProgramming.com
(Continue reading)

Kevin Smith | 1 Dec 04:17 2002

Eliminate Exceptions (was: Writing simple software - A Challenge!)

On Sat, 2002-11-30 at 18:52, Kay A. Pentecost wrote:
> > > Oh.  I thought that he meant exceptions like in "throwing them..."
> >
> > I did, but I also meant what Kevin meant.
> 
> Well, would you explain more about not throwing them?

If exceptions are thrown, then they must be caught. That requires code.
So, given a chance, write methods that don't throw exceptions. If you
can catch an exception and "do something reasonable", that's often
better than propagating the exception up the chain. 

There are certainly cases where exceptions are a good idea. But there
are many cases where they are not the simplest option. I resisted
exceptions for quite a while, but then went overboard with them in a
recent project. I am now seeking a middle ground.

One example of an overuse of exceptions, in my opinion, is that Java's
stream close() method may throw. Frequently (especially after I've
already handled a thrown IOException), I just want to close the stream
as simply as possible. Even if it fails, I know there's nothing I can do
about it. I guess I want a "closeIfYouCanButIfYouCantThatsOk()" method.
But I would settle for a variation of close() that returned a result
object, instead of throwing an exception.

Another irritating example is that String.getBytes() can throw an
exception if the requested byte encoding is not supported (e.g. UTF-8).
This means that instead of putting in one test at startup to ensure that
UTF-8 is going to work on this particular system, I have to surround
every getBytes() call with a try/catch. Clutter.
(Continue reading)

Phlip | 1 Dec 04:24 2002

Re: Eliminate Exceptions (was: Writing simple software - A Challenge!)

> > Well, would you explain more about not throwing them?

Nothing personal, but this might possibly be a VB symptom. In that language 
there are plenty of things that you simply can't do without throwing an 
exception and catching it, locally, as an elaborate 'if' statement. Things as 
simple as test if a given key is found in a collection.

So VB teaches programmers to use exceptions to define normal control flow.

--

-- 
  Phlip
        http://clublet.com/c/c/why?ZenoBuddhism
  --  Founding member of NuGWa -
        Nudists for Global Warming  --

To Post a message, send it to:   extremeprogramming <at> eGroups.com

To Unsubscribe, send a blank message to: extremeprogramming-unsubscribe <at> eGroups.com

ad-free courtesy of objectmentor.com 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 

Kevin Smith | 1 Dec 04:24 2002

Re: help with TDD

On Sat, 2002-11-30 at 07:53, Carfield Yim wrote:
> I also think using smaller test case is good. However, in many time,
> some method are depend on other method. So once I write test case of
> that method, say methodA; I actually test the dependence method(s), 
> say methodB also. 
> 
> In this case, if I write test for methodA and methodB individually,
> testcase of methodB is actually part of testcase of methodA. So there is
> code duplication of testcase. 
> 
> How can I solve this problem?

Well, there may not even be a problem. If testA and testB are
approaching the problem from different directions, it might be good to
have both. But let's assume you're working with a case that does have
some needless duplication.

If methodB is only called by methodA, then you may not need testB at
all. Some folks prefer to keep testB, while others prefer to avoid it.
If methodB is private, it's less likely to need a test. Use your
judgement.

The other trick is to ensure that testA is _only_ excercising code in
methodA. Perhaps a quick example would help. We'll assume methodB is
doing something really interesting, and methodA looks like this:

methodA()
  if(something < 0)
    return "abc";
  return methodB()
(Continue reading)

ericheikkila | 1 Dec 05:01 2002
Picon

Re: Eliminate Exceptions (was: Writing simple software - A Challenge!)

--- In extremeprogramming <at> y..., Kevin Smith <kevinxp <at> q...> wrote:
> On Sat, 2002-11-30 at 18:52, Kay A. Pentecost wrote:
> > > > Oh.  I thought that he meant exceptions like in "throwing 
them..."
> > >
> > > I did, but I also meant what Kevin meant.
> > 
> > Well, would you explain more about not throwing them?
> 
> If exceptions are thrown, then they must be caught. That requires 
code.
> So, given a chance, write methods that don't throw exceptions. If 
you
> can catch an exception and "do something reasonable", that's often
> better than propagating the exception up the chain. 
> 

[snipped]

> Another irritating example is that String.getBytes() can throw an
> exception if the requested byte encoding is not supported (e.g. UTF-
8).
> This means that instead of putting in one test at startup to ensure 
that
> UTF-8 is going to work on this particular system, I have to surround
> every getBytes() call with a try/catch. Clutter.
> 
> Kevin

You could try wrappering that functionality with a little class (I 
(Continue reading)

Kay A. Pentecost | 1 Dec 05:08 2002
Picon

RE: Eliminate Exceptions (was: Writing simple software - A Challenge!)

Hi, Phlip,

> -----Original Message-----
> From: Phlip [mailto:plumlee <at> systransoft.com]
> Sent: Saturday, November 30, 2002 10:24 PM
> To: extremeprogramming <at> yahoogroups.com
> Subject: Re: [XP] Eliminate Exceptions (was: Writing simple software - A
> Challenge!)
>
>
> > > Well, would you explain more about not throwing them?
>
> Nothing personal, but this might possibly be a VB symptom.

Yeah, <grin> but that defines it as a personal problem... <grin>

> In
> that language
> there are plenty of things that you simply can't do without throwing an
> exception and catching it, locally, as an elaborate 'if'
> statement.

I think I know what you mean, but can you give some examples?  Doesn't have
to be pure vb, since I know you're not doing that now...

>Things as
> simple as test if a given key is found in a collection.

Oh... that's an example.  I see.  More?

(Continue reading)

Kay A. Pentecost | 1 Dec 05:08 2002
Picon

RE: Eliminate Exceptions (was: Writing simple software - A Challenge!)

Hi, Kevin,

Thanks!!  I get it.

Kay

> -----Original Message-----
> From: Kevin Smith [mailto:kevinxp <at> qualitycode.com]
> Sent: Saturday, November 30, 2002 10:18 PM
> To: extremeprogramming <at> yahoogroups.com
> Subject: [XP] Eliminate Exceptions (was: Writing simple software - A
> Challenge!)
>
>
> On Sat, 2002-11-30 at 18:52, Kay A. Pentecost wrote:
> > > > Oh.  I thought that he meant exceptions like in "throwing them..."
> > >
> > > I did, but I also meant what Kevin meant.
> >
> > Well, would you explain more about not throwing them?
>
> If exceptions are thrown, then they must be caught. That requires code.
> So, given a chance, write methods that don't throw exceptions. If you
> can catch an exception and "do something reasonable", that's often
> better than propagating the exception up the chain.
>
> There are certainly cases where exceptions are a good idea. But there
> are many cases where they are not the simplest option. I resisted
> exceptions for quite a while, but then went overboard with them in a
> recent project. I am now seeking a middle ground.
(Continue reading)

Phlip | 1 Dec 05:26 2002

Re: Eliminate Exceptions (was: Writing simple software - A Challenge!)

Kay A. Pentecost sez:
> >Things as
> > simple as test if a given key is found in a collection.
>
> Oh... that's an example.  I see.  More?

No. I just like busting on VB. Also a symptom. I seem to recall lots of DAO 
and ADO stuff couldn't manage to be tested with 'if', only with exceptions.

> > So VB teaches programmers to use exceptions to define normal control
> > flow.
>
> Because that's the only way to do things?  I understand that VB.Net has a
> try... catch, but in VB6 you pretty much have to check the error
> returned...

That's what I mean - either one.

> On my previous contract the GreatVB-OOGuru <grin> set the errors in the
> kernel component with vbError, instead of vbObjectError... so the errors
> looked like they were GUI errors (which I got blamed for) instead of the
> Kernel failing... he had no error trapping at all in the Kernel... so it
> always blew up at the GUI level... and of course the error would say "Error
> in GUIXXX" when it propagated up to my level... agghh.
>
> But he was a C++/Java/Lisp coder... the more I learn about VB the less I
> think he knew.

I once got a laugh at a sit-down meeting, discussing how we were all firming 
up our modules for a release. I said that I had stabilized mine "thru the 
(Continue reading)


Gmane