All things are lawful, but not all things are profitable.
Knute Snortum wrote:I don't know about the others, but would like to see the actual code you are running, not just snippets.
All things are lawful, but not all things are profitable.
Campbell Ritchie wrote:Don't declare unchecked Exceptions. Simply describe them in the documentation comments with a @throws tag (or, I think, @exception). Say it is an IndexOutOfBoundsException rather than one of the more specialised subtypes, otherwise you are giving away implementation details.
All things are lawful, but not all things are profitable.
Campbell Ritchie wrote:Your charAt method and getNext have throws clauses, which really should only be used for checked Exceptions.
In getNext, consider whether it is better (or worse) to return null instead of the Exception.
In addToRear you are using Exceptions as flow control which is not what they are intended for. You should be able to tell whether you are at the end of the List, because its next node will be null. When you know that, you can add things at the end of the List secure in the knowledge you aren't going to suffer Exceptions.
No, that is not quite how they work.Derek Nickerson wrote: . . .
I was reviewing the implementation of exceptions and from what I understand, unchecked exceptions (RuntimeException and subclasses) do not need to be declared because they're built into the system(?) because they're the result of programmer error; alternatively, checked exceptions deal with logic errors where the programmer might expect a user error.
I thought from the name that they were subtypes of IndexOut…Derek Nickerson wrote: . . . they are very similar if not identical to IndexOutOfRangeException... . . .
Thank you. Very helpful to discuss.
Knute Snortum wrote:MySinglyLinkedList implements SinglyLinkedList, which we don't have, but before you post it -- is this working code? I ask because you use methods like empty() which aren't in the class but can't have any implementation in SinglyLinkedList because it's an interface. In other words, you don't have an implementation of empty(), so how can it compile?
My advice is to start with a fully implemented SinglyLinkedList and write some tests just for that.
Derek Nickerson wrote:Yes, for the most part, there are a few bugs -- but more specifically empty() has worked for me in the code thus far.
empty and getSize are not included in the SLL interface -- could that be why my substring while loop in the StringX class is not working? I know I have a lot of debug code in there, but it seems there should be a simpler way to execute this method. hhmmmmmm
All things are lawful, but not all things are profitable.