Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

binary enums and lightweight parameter enums.

0 views
Skip to first unread message

Roedy Green

unread,
Nov 9, 2011, 8:36:43 AM11/9/11
to
Does this sort of code look familiar?

CSVReader r = new CSVReader( new BufferedReader( new
FileReader(
DISTRICT_TAX_FILE ), 8092 ),
',', '\"', "#", true, true, true, false );


You can add comments like this to make it more readable:

CSVReader r = new CSVReader( new BufferedReader( new
FileReader(
DISTRICT_TAX_FILE ), 8092 ),
',', '\"', "#", true /* hide comments */, true /*
trimQuoted */, true /* trimUnquoted */, false /* no multiline */ );

Buth there is nothing that says the commens are in sych with the
definition. Any signature changes will likely make the comments
invalid.


What you could your write you call something like this:


CSVReader r = new CSVReader( new BufferedReader( new
FileReader(
DISTRICT_TAX_FILE ), 8092 ),
',', '\"', "#", hideComments, trimQuoted
,trimUnquoted , noMultiline );

Imagine those as sort of miniature enums, on class per parameter.

Very few programmers would create enum classes for each of their
parameters just to get type checking. Further the bits and bytes guys
would roll their eyes at passing an enum constant when a primitive
boolean would do the job so much faster easier.

What if instead, inside the JVM all worked as before- passing
booleans. It in just that you could give names to true and false that
were valid only for that parameter.
E.

void doSomething( boolean( good, bad) evalulation, boolean ( male ,
female ) gender) { ... }

then you could write

doSomething ( bad , female );
but you could not say

do Something ( male, good );

You might extend this for lightweight enums that act the same as 0. 1
2 etc.

e.g.

doSomething ( int (kind, fun, sexy) what )

doSomething (sexy);

For very little weight it gives much of what you need Ada for.



--
Roedy Green Canadian Mind Products
http://mindprod.com
Capitalism has spurred the competition that makes CPUs faster and
faster each year, but the focus on money makes software manufacturers
do some peculiar things like deliberately leaving bugs and deficiencies
in the software so they can soak the customers for upgrades later.
Whether software is easy to use, or never loses data, when the company
has a near monopoly, is almost irrelevant to profits, and therefore
ignored. The manufacturer focuses on cheap gimicks like dancing paper
clips to dazzle naive first-time buyers. The needs of existing
experienced users are almost irrelevant. I see software rental as the
best remedy.

John B. Matthews

unread,
Nov 10, 2011, 12:41:10 AM11/10/11
to
In article <etvkb7tqpidlqv9mr...@4ax.com>,
Roedy Green <see_w...@mindprod.com.invalid> wrote:

[...]
> Very few programmers would create enum classes for each of their
> parameters just to get type checking. Further the bits and bytes guys
> would roll their eyes at passing an enum constant when a primitive
> boolean would do the job so much faster easier.

Would a static factory or builder be useful in this context?

<http://drdobbs.com/java/208403883?pgno=1>
<http://drdobbs.com/java/208403883?pgno=2>

[...]
> For very little weight it gives much of what you need Ada for.

I can see the appeal. For reference, Ada supports named parameter
association, as shown here.

<http://www.adaic.org/resources/add_content/standards/05rm/html/RM-6-4.html>

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>

Roedy Green

unread,
Nov 10, 2011, 6:46:55 PM11/10/11
to
On Thu, 10 Nov 2011 00:41:10 -0500, "John B. Matthews"
<nos...@nospam.invalid> wrote, quoted or indirectly quoted someone who
said :

>I can see the appeal. For reference, Ada supports named parameter
>association, as shown here.
>
><http://www.adaic.org/resources/add_content/standards/05rm/html/RM-6-4.html>

that's another good approach to the problem that also helps swapping
int parms that ane not enums in any sense.


A related problem is inconsistent meanings for a boolean returned from
a method, is true ok or bad or something else entirely. The value
itself does not have name other than the name of the entire method,
and unless the name of the method is chosen cleverly, the convention
is not obvious.

I deal with the problem in the HTTP class by setting parms with
separate calls. They are all optional, with an initial default.
Each call has a name, so there is no way you can swap values for
different config parms. It is somewhat slower and more cumbersom to
write, but at least you can read the code unambiguously without having
to study the method signature.

--
Roedy Green Canadian Mind Products
http://mindprod.com
HP makes a dozens of quite different printer models all called the 1200.
Mine has a GO button, which is not needed since it runs anyway if nothing
is blocking it. However, it has no STOP, FLUSH or OFF button.
0 new messages