decoration decoration
Stories

GROKLAW
When you want to know more...
decoration
For layout only
Home
Archives
Site Map
Search
About Groklaw
Awards
Legal Research
Timelines
ApplevSamsung
ApplevSamsung p.2
ArchiveExplorer
Autozone
Bilski
Cases
Cast: Lawyers
Comes v. MS
Contracts/Documents
Courts
DRM
Gordon v MS
GPL
Grokdoc
HTML How To
IPI v RH
IV v. Google
Legal Docs
Lodsys
MS Litigations
MSvB&N
News Picks
Novell v. MS
Novell-MS Deal
ODF/OOXML
OOXML Appeals
OraclevGoogle
Patents
ProjectMonterey
Psystar
Quote Database
Red Hat v SCO
Salus Book
SCEA v Hotz
SCO Appeals
SCO Bankruptcy
SCO Financials
SCO Overview
SCO v IBM
SCO v Novell
SCO:Soup2Nuts
SCOsource
Sean Daly
Software Patents
Switch to Linux
Transcripts
Unix Books

Gear

Groklaw Gear

Click here to send an email to the editor of this weblog.


You won't find me on Facebook


Donate

Donate Paypal


No Legal Advice

The information on Groklaw is not intended to constitute legal advice. While Mark is a lawyer and he has asked other lawyers and law students to contribute articles, all of these articles are offered to help educate, not to provide specific legal advice. They are not your lawyers.

Here's Groklaw's comments policy.


What's New

STORIES
No new stories

COMMENTS last 48 hrs
No new comments


Sponsors

Hosting:
hosted by ibiblio

On servers donated to ibiblio by AMD.

Webmaster
RangeCheck | 266 comments | Create New Account
Comments belong to whoever posts them. Please notify us of inappropriate comments.
Rangecheck
Authored by: TheOldBear on Thursday, May 10 2012 @ 09:51 AM EDT
Back in the dark ages of PC C compilers, I retrofitted something similar to range check to the library function memcpy(int, void *, void *) to compensate for clumsy programmers at our company.

As I recall this was needed in the supplied libraries for Lattice C, but not in Computer Innovations C [Microsoft was selling a re-labeled Lattice C in their initial release]

[ Reply to This | Parent | # ]

RangeCheck
Authored by: Anonymous on Thursday, May 10 2012 @ 09:54 AM EDT
Here's a spec for the function:

The RangeCheck function is only needed in the class it's
part of, should be useable without needing an
object/instance of the class, and
needn't return any values. It should take 3 values, all of
them being integers, the first describing the length of an
array, and the second and third respectively describing the
beginning and end of a range of array indexes within the
range of the array described by the first parameter.

The function should check the validity of these parameters,
and throw an exception where there is a problem.

[For extra points, before reading any further, what should
you test for? Fill in your answer in the space provided
below.]
-------------------------









-------------------------

Answer, and continuation of the spec for the function:

Naturally, the start and end points should be correctly
ordered. Compatibility requires the function should throw an
IllegalArgumentException if they are not. A message would be
useful.

The start index cannot be less than the beginning of the
array. For compatibility, it should throw an
ArrayIndexOutOfBoundsException with a message if it is.

The end point index cannot be beyond the end of the array.
Compatibility requires that it should throw an
ArrayIndexOutOfBoundsException with a message if it is.

-------------------------

This works exactly as you would expect something that checks
bounds to work: it checks that the beginning is before the
end, it checks that the start isn't negative, and it checks
that the endpoint isn't outside of the range. In each case
it throws an exception if it finds a problem. This takes
exactly 3 if statements, spread over 12 or 13 lines, if you
include the method declaration and the close bracket and
blank lines. The spec is longer than the code. There are no
'else' parts to the if statements in the copied code, though
there could be. But they would bring no benefit in the most
common case, so any developer who understands anything about
performance would exclude them.

There are exactly 6 ways you could
order these 3 statements. Two of these ways make slightly
more sense from a clean coding perspective because two of
the three lines should throw the same exception, but it's a
pretty marginal style issue.

So if you were to rewrite
this with the same parameter names, and throwing the same
exceptions, there's a 1 in 6 chance your implementation
would be substantially similar to the Sun implementation.
And much better than 1 in 6 if you ordered your code in the
way I ordered the specification.

This function is not rocket science. Except if you are a
lawyer working for Oracle or an expert witness working for
Oracle, apparently. The description of it is substantially
longer than the actual thing, rather like the brief Oracle
submitted, explaining how very, very important it was.

[ Reply to This | Parent | # ]

Groklaw © Copyright 2003-2013 Pamela Jones.
All trademarks and copyrights on this page are owned by their respective owners.
Comments are owned by the individual posters.

PJ's articles are licensed under a Creative Commons License. ( Details )