Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #33236

Re: Never using booleans as parameters

From Martin Gregorie <martin@address-in-sig.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Never using booleans as parameters
Date 2015-11-30 00:08 +0000
Organization A noiseless patient Spider
Message-ID <n3g41b$1ep$1@dont-email.me> (permalink)
References (2 earlier) <564f55e3$0$23775$e4fe514c@news.xs4all.nl> <n2o1vd$os2$1@dont-email.me> <565310cd$0$23766$e4fe514c@news.xs4all.nl> <9993c30e-bbd7-4a87-82c9-de208d61cf39@googlegroups.com> <n3fo5g$v8t$1@speranza.aioe.org>

Show all headers | View raw


On Sun, 29 Nov 2015 15:45:39 -0500, Arne Vajhøj wrote:

> On 11/23/2015 9:10 AM, Eric Douglas wrote:
>> On Monday, November 23, 2015 at 8:12:59 AM UTC-5, Silvio wrote:
>>> That same argument could be made for every parameter to every method
>>> call. So instead of
>>>
>>> y = x.substring(0,4)
>>>
>>> I am supposed to write
>>>
>>> {
>>> 	final int beginIndex = 0;
>>> 	final int endIndex = 4;
>>> 	y = x.substring(beginIndex,endIndex);
>>> }
>>
>> You could do that, or write it with a comment as such, only if the
>  > meaning of the parameters would not be obvious to someone asked to
>  > maintain your code later.
>>
>> // beginIndex (zero-based), endIndex y = x.substring(0,4)
> 
> Documenting something like this is an indication of a problem in my
> opinion.
> 
> Commenting about what the code does is usually a bad sign - good
> comments explains why the code is doing it.
> 
>> Of course they should already be able to figure out the parameters from
>> the code complete if they edit this code with a proper IDE.
> 
> A good IDE solves many problems.
> 
> But I don't like the idea of the readability of code being dependent on
> it.
> 
> Arne


IMO well-written code *always* has a class-level comment saying what 
functionality the class provides and  method-level comments for every 
method. The method-level comments say what the method does, what 
parameters are passed to it and what they mean, what it returns and how 
it indicates that errors have been detected. 

IOW, if a system designer writes a class specification as a compilable 
Java source file containing a class-level comment followed by public 
constructor and method definitions, each being a comment as I've 
described above followed by a skeleton method (completed header with the 
body containing only the appropriate return statement), a coder can flesh 
this out by adding the required code to the methods so that the class 
fulfils its required functions as well as any additional private 
attributes or methods that the class requires. The result is a functional 
class that is also fully documented.

And, before you ask, yes I've used this approach for projects implemented 
in both Java and C. It works. The only overhead is that the designers 
*MUST* compile their module specifications to verify that the interfaces 
they've specified form a consistent set.

I have little respect for any software architect who can't do this and 
not much for any technical or project manager who doesn't require his 
designers to work to this standard.


-- 
martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Never using booleans as parameters Cecil Westerhof <Cecil@decebal.nl> - 2015-11-20 09:29 +0100
  Re: Never using booleans as parameters Martin Gregorie <martin@address-in-sig.invalid> - 2015-11-20 11:54 +0000
  Re: Never using booleans as parameters Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-11-20 08:30 -0500
    Re: Never using booleans as parameters Eric Douglas <e.d.programmer@gmail.com> - 2015-11-20 05:57 -0800
      Re: Never using booleans as parameters Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-11-20 09:17 -0500
  Re: Never using booleans as parameters Eric Douglas <e.d.programmer@gmail.com> - 2015-11-20 05:34 -0800
  Re: Never using booleans as parameters Silvio <silvio@internet.com> - 2015-11-20 18:18 +0100
    Re: Never using booleans as parameters Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-11-20 16:08 -0500
      Re: Never using booleans as parameters Silvio <silvio@internet.com> - 2015-11-23 14:12 +0100
        Re: Never using booleans as parameters Silvio <silvio@internet.com> - 2015-11-23 14:23 +0100
          Re: Never using booleans as parameters Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-11-23 08:42 -0500
            Re: Never using booleans as parameters Silvio <silvio@internet.com> - 2015-11-23 15:14 +0100
        Re: Never using booleans as parameters Eric Douglas <e.d.programmer@gmail.com> - 2015-11-23 06:10 -0800
          Re: Never using booleans as parameters Arne Vajhøj <arne@vajhoej.dk> - 2015-11-29 15:45 -0500
            Re: Never using booleans as parameters Martin Gregorie <martin@address-in-sig.invalid> - 2015-11-30 00:08 +0000
              Re: Never using booleans as parameters Arne Vajhøj <arne@vajhoej.dk> - 2015-11-29 19:32 -0500
              Re: Never using booleans as parameters Arne Vajhøj <arne@vajhoej.dk> - 2015-11-29 19:39 -0500
              Re: Never using booleans as parameters Brixomatic <brixomatic@yahoo.com> - 2015-12-20 15:08 +0100
                Re: Never using booleans as parameters Eric Douglas <e.d.programmer@gmail.com> - 2015-12-21 05:00 -0800
                Re: Never using booleans as parameters Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-12-21 08:53 -0500
            Re: Never using booleans as parameters Gene Wirchenko <genew@telus.net> - 2015-11-30 10:33 -0800
              Re: Never using booleans as parameters Jukka Lahtinen <jtfjdehf@hotmail.com.invalid> - 2015-12-02 15:51 +0200
      Re: Never using booleans as parameters Kevin McMurtrie <mcmurtrie@pixelmemory.us> - 2015-11-23 21:55 -0800
        Re: Never using booleans as parameters Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-11-24 08:23 -0500
          Re: Never using booleans as parameters Kevin McMurtrie <mcmurtrie@pixelmemory.us> - 2015-11-27 22:52 -0800
        Re: Never using booleans as parameters Arne Vajhøj <arne@vajhoej.dk> - 2015-11-29 15:55 -0500
  Re: Never using booleans as parameters leif.roar@dimnakorr.com - 2015-11-20 11:44 -0600
    Re: Never using booleans as parameters Eric Douglas <e.d.programmer@gmail.com> - 2015-11-20 10:08 -0800
    Re: Never using booleans as parameters Arne Vajhøj <arne@vajhoej.dk> - 2015-11-22 14:03 -0500
  Re: Never using booleans as parameters Gene Wirchenko <genew@telus.net> - 2015-11-20 10:14 -0800
    Re: Never using booleans as parameters Eternal Hope <laughingspam99@gmail.com> - 2015-11-22 14:27 +0000
  Re: Never using booleans as parameters Kevin McMurtrie <mcmurtrie@pixelmemory.us> - 2015-11-20 20:13 -0800
    Re: Never using booleans as parameters Eric Douglas <e.d.programmer@gmail.com> - 2015-11-23 04:59 -0800
      Re: Never using booleans as parameters Arne Vajhøj <arne@vajhoej.dk> - 2015-11-29 15:53 -0500
  Re: Never using booleans as parameters galt_57@hotmail.com - 2015-11-22 09:02 -0800
    Re: Never using booleans as parameters Arne Vajhøj <arne@vajhoej.dk> - 2015-11-22 12:20 -0500
  Re: Never using booleans as parameters Arne Vajhøj <arne@vajhoej.dk> - 2015-11-22 12:41 -0500
    Re: Never using booleans as parameters Martin Gregorie <martin@address-in-sig.invalid> - 2015-11-22 18:06 +0000
    Re: Never using booleans as parameters Gene Wirchenko <genew@telus.net> - 2015-11-25 14:21 -0800
      Re: Never using booleans as parameters Arne Vajhøj <arne@vajhoej.dk> - 2015-11-29 15:58 -0500
        Re: Never using booleans as parameters Gene Wirchenko <genew@telus.net> - 2015-11-30 10:39 -0800
    Re: Never using booleans as parameters Brixomatic <brixomatic@yahoo.com> - 2015-11-29 16:40 +0100
      Re: Never using booleans as parameters Arne Vajhøj <arne@vajhoej.dk> - 2015-11-29 16:00 -0500
        Re: Never using booleans as parameters Arne Vajhøj <arne@vajhoej.dk> - 2015-11-29 19:26 -0500
          Re: Never using booleans as parameters Eric Douglas <e.d.programmer@gmail.com> - 2015-11-30 06:16 -0800
  Re: Never using booleans as parameters Arne Vajhøj <arne@vajhoej.dk> - 2015-11-22 14:01 -0500
  Re: Never using booleans as parameters Fredrik Jonson <fredrik@jonson.org> - 2015-11-24 18:50 +0000
  Re: Never using booleans as parameters Sir Hugh Jarce <hugh@example.com> - 2015-11-27 10:07 +0000
    Re: Never using booleans as parameters Arne Vajhøj <arne@vajhoej.dk> - 2015-11-29 15:49 -0500
  Re: Never using booleans as parameters Brixomatic <brixomatic@yahoo.com> - 2015-11-29 16:33 +0100
    Re: Never using booleans as parameters Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-11-29 15:57 -0500
      Re: Never using booleans as parameters Arne Vajhøj <arne@vajhoej.dk> - 2015-11-29 16:01 -0500
      Re: Never using booleans as parameters Brixomatic <brixomatic@yahoo.com> - 2015-12-20 15:00 +0100
        Re: Never using booleans as parameters Gene Wirchenko <genew@telus.net> - 2015-12-21 10:50 -0800
    Re: Never using booleans as parameters Gene Wirchenko <genew@telus.net> - 2015-11-30 10:48 -0800
      Re: Never using booleans as parameters Brixomatic <brixomatic@yahoo.com> - 2015-12-20 15:44 +0100
        Re: Never using booleans as parameters Gene Wirchenko <genew@telus.net> - 2015-12-21 10:56 -0800
        Re: Never using booleans as parameters Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-12-21 15:30 -0500
          Re: Never using booleans as parameters Eric Douglas <e.d.programmer@gmail.com> - 2015-12-21 12:47 -0800
            Re: Never using booleans as parameters Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-12-21 16:29 -0500

csiph-web