Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #24514
| Date | 2013-06-22 19:41 +0100 |
|---|---|
| From | lipska the kat <"nospam at neversurrender dot co dot uk"> |
| Organization | Trollbusters 3 |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: About java program. |
| References | (10 earlier) <kpsfn7$k9k$1@dont-email.me> <oYOwt.19280$9m5.18160@newsfe26.iad> <kq1nda$fbk$1@dont-email.me> <lf7xt.83078$1p2.22506@newsfe25.iad> <kq4mdh$fbm$1@dont-email.me> |
| Message-ID | <l_WdnQVSU6BKcljMnZ2dnUVZ8jOdnZ2d@bt.com> (permalink) |
On 22/06/13 18:25, Daniele Futtorovic wrote:
> On 22/06/2013 03:39, Arved Sandstrom allegedly wrote:
>> On 06/21/2013 11:24 AM, Daniele Futtorovic wrote:
>>> On 21/06/2013 04:33, Arved Sandstrom allegedly wrote:
>>>> On 06/19/2013 11:42 AM, Daniele Futtorovic wrote:
>>>>> I'm all for defensive programming, but I think that there's a limit
>>>>> where it can be on the verge of silliness, and that that limit has been
>>>>> grazed here.
>>>>>
>>>>> Less-than-bright programmers IMO cannot be a justification for crossing
>>>>> that line; less-than-bright programmers have more ways to mess
>>>>> things up
>>>>> than you could possibly ever guard against. "Do not underestimate the
>>>>> ingenuity of complete fools", as the saying goes.
>>>>>
>>>>> And for me, there is an additional aspect: if a piece of code does
>>>>> something simple, something basic, then I will want it to be short, and
>>>>> vice-versa. Verbosity of code, to me, should hold a first-glance
>>>>> indication of the complexity of the algorithm. In other words: be terse
>>>>> IFF it's basic, be verbose IFF it's not.
>>>>>
>>>>> Perhaps your mileage does vary. No beef with that. Just throwing in my
>>>>> two cents.
>>>>>
>>>> It's a good discussion. I'm not personally convinced that verbosity adds
>>>> complexity, as a rule. There's really two types of complexity here:
>>>> maintainability complexity - as in, can Joe Blow 12 months later
>>>> understand the code best if it's compact versus unrolled, and formal
>>>> complexity, cyclomatic and otherwise.
>>>>
>>>> I'll admit that verbosity does usually add maintainability complexity,
>>>> if not the other kind. But not always. I've seen plenty of code that is
>>>> conceptually quite complex but very terse.
>>>
>>> Sorry to nitpick, but I don't think you understood me right. I'm not
>>> saying that verbosity adds complexity; I'm saying: if the piece of code
>>> does something tricky, something complicated, tend to make it verbose,
>>> otherwise, tend to make it terse. Thus, seeing a big blob of (e.g.
>>> unrolled, step-by-step) code holds the message "here be dragons". (And
>>> if it cannot be made verbose, then it means it absolutely requires an
>>> in-line comment).
>>
>> We're very much in agreement, on all points you just made.
>>
>>> At least the way I perceived it, this discussion was about making stuff
>>> verbose indiscriminately, viz. basic code as well. I disagree with that
>>> in the above sense.
>>>
>> I won't speak for anyone else, the argument I was making was for
>> verbosity in support of defensive programming. I see Java code all the
>> time where exceptions are try-caught with no thought placed into
>> handling the problem somewhere - defensive coding fail...and handling it
>> properly would add verbosity.
>>
>> I see main methods all the time where someone assumes the number and
>> type of arguments. Defensive coding fail. I see methods all the time -
>> like I said - where the same coder wrote the calling code and called
>> code, and makes assumptions about what the calling code will do.
>> Defensive coding fail.
>>
>> Or they make the naive assumption that people read Javadocs thoroughly.
>> It's not the calling code's responsibility to protect the called code,
>> after all. Given that we have to consider the bounds of parameters
>> carefully, I don't see how some verbosity in the form of defensive code
>> is objectionable.
>>
>> "Here be dragons" often means simply that there is - that we have to
>> guard against what the calling code is doing.
>
> I see. Thanks for clarifying.
>
> It looks like I had not understood the discussion about verbosity in the
> same sense as you do. In my view, when talking about verbosity, we talk
> about a measure on, and that's the important point, an iso-functional
> basis. To illustrate, when I switch on a "verbose" flag on my command
> line, I do not expect the command to perform any differently than before
> -- only that it should be more talkative about it. But the functions it
> performs should not be impacted by it.
>
> To illustrate with code, and to pick some of the original examples
> again, take the following two methods:
>
> boolean method1( String input ){
> return "yes".equals( input );
> }
>
> boolean method2( String input ){
> final boolean ret;
> if( input == null ){
> ret = false;
> }
> else if( input.equals("yes") ){
> ret = true;
> }
> else {
> ret = false;
> }
>
> return ret;
> }
>
> This is what I mean. Both methods perform exactly the same for any
> input. The only matter in which they differ is their verbosity.
> And to pick up the argument again: it could be argued that the latter
> form is preferable, because it is more obvious what happens in each
> case. I argue against that. Not generally, but in this case. Because
> what's going on there is a very basic operation (making sure the input
> is exactly the String "yes"). The second form is too verbose -- that is,
> so verbose that it becomes clutter. The first (non-verbose) form
> expresses the intent clearly enough. If there is a "programmer" who does
> not understand that (especially the null-implication), then I'm sure Lew
> would have some poignant recommendations as to what avenues of
> employment they rather ought to pursue, and I would happen to be in
> agreement with him.
Why am I not surprised.
> Some of what you are talking about, on the topic of defensive
> programming, on the other hand, I would call functional defects. I do
> not perceive those as being matters of verbosity or not, but of whether
> the code is functionally complete or not. To your hypothetical
> programmer who does not handle exceptions because it would supposedly
> add verbosity, "verbosity" is but a pathetic front to mask either their
> lack of professionalism.
>
> The other examples you give definitely fall in the realm of defensive
> programming. Yes, a method should not make hidden assumptions as to its
> parameters (OTOH there would be nothing wrong per se with what I'd call
> an explicit assumption along the lines of: if( argumentNotValid ) throw
> new IllegalArgumentException(); ). Yes, every caller should be defensive
> about what the callee might return (within the boundaries of its
> contract). It should be noted that annotations have given us a potential
> tool forcibly to impose more stringency in these regards, although the
> way I see it it won't really be usable until teh Oracle makes the effort
> to formalise them and adds them to the core lib (I mean things like
> @NotNull). It still needs to mature a bit I think.
>
> The aforementioned is mitigated in code that is internal to a component
> (in the spirit of encapsulation, code ought to be divided into
> components such that the density of interrelation of code within a
> component is always strictly greater than that of interrelation of code
> in different components).
You mean it should be cohesive (the code in a component), still, why use
one word when fifty will do.
as you say.
"verbosity is but a pathetic front to mask either their
lack of professionalism" [sic]
> Think private or package-private methods. It
> is often impractical and counter-productive to have
> to forego any hidden assumptions in those parts of the code.
Hidden from whom???
This is what encapsulation *means* for goodness sake. Callers code to
your published contract. You contract that your component behaves in a
certain way. If the caller breaks the contract then it's the callers
responsibility, you are stating the obvious. To what end?
> Then again, it is precisely the combination of these two aspects, that it is
> impractical and that it would be necessary, which makes OO and esp.
> encapsulation such a virtuous tool: by structuring code and data flow,
> you *can* relegate, notably, input checks to the boundaries of the
> component and operate on assumptions within the component.
It's called programming by contract. Or maybe compile time type checking
... what does any of this have to do with the original issue
> (Granted,
> this does not help the case where multiple programmers who are not in
> relation with each other work on the internals of the same component,
> which is why such a situation should be avoided).
I hardly know where to start. Oh, I know, *documentation*
What about maintenance. It will nearly always be the case that
programmers who have no knowledge of or contact with the original author
will be required to maintain the code at sometime in the future.
*This* is why code should be unambiguous. Truly enlightened developers
understand this without needing to be told.
... and BTW. Enlightenment is not the same as 'cleverness'
lipska
--
Lipska the Kat©: Troll hunter, sandbox destroyer
and farscape dreamer of Aeryn Sun
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
About java program. rajbhaumik@gmail.com - 2013-06-15 13:38 -0700
Re: About java program. Arne Vajhøj <arne@vajhoej.dk> - 2013-06-15 16:50 -0400
Re: About java program. Robert Klemme <shortcutter@googlemail.com> - 2013-06-16 01:12 +0200
Re: About java program. lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-06-16 14:21 +0100
Re: About java program. Robert Klemme <shortcutter@googlemail.com> - 2013-06-16 17:28 +0200
Re: About java program. lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-06-16 19:52 +0100
Re: About java program. Arne Vajhøj <arne@vajhoej.dk> - 2013-06-16 15:50 -0400
Re: About java program. lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-06-17 09:36 +0100
Re: About java program. Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-06-17 09:49 -0300
Re: About java program. lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-06-17 14:46 +0100
Re: About java program. Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-06-17 13:32 -0300
Re: About java program. Joerg Meier <joergmmeier@arcor.de> - 2013-06-17 20:32 +0200
Re: About java program. Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-06-17 14:49 -0400
Re: About java program. Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-06-17 18:38 -0300
Re: About java program. Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-06-17 18:30 -0400
Re: About java program. Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-06-18 17:33 -0300
Re: About java program. Arne Vajhøj <arne@vajhoej.dk> - 2013-07-04 22:56 -0400
Re: About java program. Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2013-06-18 00:13 +0200
Re: About java program. Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-06-18 17:50 -0300
Re: About java program. lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-06-19 08:50 +0100
Re: About java program. Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-06-19 15:16 -0300
Re: About java program. Lew <lewbloch@gmail.com> - 2013-06-19 16:20 -0700
Re: About java program. Jeff Higgins <jeff@invalid.invalid> - 2013-07-07 13:31 -0400
Re: About java program. Jeff Higgins <jeff@invalid.invalid> - 2013-07-07 18:16 -0400
Re: About java program. Jeff Higgins <jeff@invalid.invalid> - 2013-07-07 19:21 -0400
Re: About java program. Jeff Higgins <jeff@invalid.invalid> - 2013-07-07 20:07 -0400
Re: About java program. Jeff Higgins <jeff@invalid.invalid> - 2013-07-07 20:21 -0400
Re: About java program. Jeff Higgins <jeff@invalid.invalid> - 2013-07-07 20:40 -0400
Re: About java program. Jeff Higgins <jeff@invalid.invalid> - 2013-07-07 22:20 -0400
Re: About java program. Lew <lewbloch@gmail.com> - 2013-07-07 21:47 -0700
Re: About java program. Jeff Higgins <jeff@invalid.invalid> - 2013-07-08 06:58 -0400
Re: About java program. Jeff Higgins <jeff@invalid.invalid> - 2013-07-08 08:07 -0400
Re: About java program. Jeff Higgins <jeff@invalid.invalid> - 2013-07-08 08:58 -0400
Re: About java program. Jeff Higgins <jeff@invalid.invalid> - 2013-07-08 09:18 -0400
Re: About java program. Jeff Higgins <jeff@invalid.invalid> - 2013-07-08 09:47 -0400
Re: About java program. Jeff Higgins <jeff@invalid.invalid> - 2013-07-08 10:07 -0400
Re: About java program. Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2013-06-19 16:42 +0200
Re: About java program. Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-06-20 23:33 -0300
Re: About java program. Martin Gregorie <martin@address-in-sig.invalid> - 2013-06-21 04:16 +0000
Re: About java program. Joerg Meier <joergmmeier@arcor.de> - 2013-06-21 12:27 +0200
Re: About java program. Martin Gregorie <martin@address-in-sig.invalid> - 2013-06-21 21:14 +0000
Re: About java program. Joerg Meier <joergmmeier@arcor.de> - 2013-06-21 23:37 +0200
Re: About java program. Martin Gregorie <martin@address-in-sig.invalid> - 2013-06-21 23:42 +0000
Re: About java program. Gene Wirchenko <genew@telus.net> - 2013-06-24 13:00 -0700
Re: About java program. Martin Gregorie <martin@address-in-sig.invalid> - 2013-06-24 21:29 +0000
Re: About java program. Martin Gregorie <martin@address-in-sig.invalid> - 2013-06-24 21:42 +0000
Re: About java program. Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-06-21 23:59 -0300
Re: About java program. Martin Gregorie <martin@address-in-sig.invalid> - 2013-06-22 13:30 +0000
Re: About java program. Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2013-06-21 16:24 +0200
Re: About java program. Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-06-21 22:39 -0300
Re: About java program. Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2013-06-22 19:25 +0200
Re: About java program. lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-06-22 19:41 +0100
Re: About java program. Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2013-06-23 03:53 +0200
Re: About java program. lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-06-23 09:21 +0100
Re: About java program. Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2013-06-24 18:57 +0200
Re: About java program. lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-06-24 18:14 +0100
Re: About java program. lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-06-22 09:03 +0100
Re: About java program. Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2013-06-22 19:26 +0200
Re: About java program. lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-06-22 18:51 +0100
Re: About java program. Arne Vajhøj <arne@vajhoej.dk> - 2013-07-04 22:58 -0400
Re: About java program. Joerg Meier <joergmmeier@arcor.de> - 2013-06-19 00:38 +0200
Re: About java program. Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-06-18 18:56 -0400
Re: About java program. Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-06-18 21:26 -0300
Re: About java program. Robert Klemme <shortcutter@googlemail.com> - 2013-06-19 21:20 +0200
Re: About java program. Sven Köhler <remove-sven.koehler@gmail.com> - 2013-06-20 11:23 +0300
Re: About java program. Robert Klemme <shortcutter@googlemail.com> - 2013-06-20 19:18 +0200
Re: About java program. blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2013-07-15 20:20 +0000
Re: About java program. lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-06-19 09:14 +0100
Re: About java program. lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-06-19 09:11 +0100
Re: About java program. Arne Vajhøj <arne@vajhoej.dk> - 2013-07-04 23:11 -0400
Re: About java program. lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-07-05 09:13 +0100
Re: About java program. Robert Klemme <shortcutter@googlemail.com> - 2013-07-05 23:15 +0200
Re: About java program. Arne Vajhøj <arne@vajhoej.dk> - 2013-07-05 22:03 -0400
Re: About java program. Robert Klemme <shortcutter@googlemail.com> - 2013-07-06 13:01 +0200
Re: About java program. lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-07-06 13:43 +0100
Re: About java program. Martin Gregorie <martin@address-in-sig.invalid> - 2013-07-06 14:17 +0000
Re: About java program. Arne Vajhøj <arne@vajhoej.dk> - 2013-07-06 16:18 -0400
Re: About java program. lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-07-06 21:42 +0100
Re: About java program. lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-07-06 09:16 +0100
Re: About java program. Robert Klemme <shortcutter@googlemail.com> - 2013-07-06 13:14 +0200
Re: About java program. Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-07-06 08:22 -0400
Re: About java program. Robert Klemme <shortcutter@googlemail.com> - 2013-07-07 20:43 +0200
Re: About java program. Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-07-07 18:07 -0400
Re: About java program. Arne Vajhøj <arne@vajhoej.dk> - 2013-07-07 19:35 -0400
Re: About java program. Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-07-07 20:42 -0400
Re: About java program. Robert Klemme <shortcutter@googlemail.com> - 2013-07-08 20:50 +0200
Re: About java program. Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-07-08 15:01 -0400
Re: About java program. Robert Klemme <shortcutter@googlemail.com> - 2013-07-08 23:29 +0200
Re: About java program. Arne Vajhøj <arne@vajhoej.dk> - 2013-07-06 16:27 -0400
Re: About java program. Lew <lewbloch@gmail.com> - 2013-07-06 13:41 -0700
Re: About java program. Arne Vajhøj <arne@vajhoej.dk> - 2013-07-05 21:59 -0400
Re: About java program. lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-06-17 21:06 +0100
Re: About java program. Joshua Cranmer 🐧 <Pidgeot18@verizon.invalid> - 2013-06-17 17:36 -0500
Re: About java program. Robert Klemme <shortcutter@googlemail.com> - 2013-06-18 08:24 +0200
Re: About java program. lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-06-18 09:03 +0100
Re: About java program. Joshua Cranmer 🐧 <Pidgeot18@verizon.invalid> - 2013-06-18 13:07 -0500
Re: About java program. Lew <lewbloch@gmail.com> - 2013-06-18 14:48 -0700
Re: About java program. lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-06-19 08:36 +0100
Re: About java program. Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-06-18 23:33 -0300
Re: About java program. lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-06-19 08:34 +0100
Re: About java program. Arne Vajhøj <arne@vajhoej.dk> - 2013-07-04 22:53 -0400
Re: About java program. Roedy Green <see_website@mindprod.com.invalid> - 2013-06-16 07:04 -0700
Re: About java program. Jeff Higgins <jeff@invalid.invalid> - 2013-06-18 04:06 -0400
csiph-web