Tag Info

Hot answers tagged

43

Your method should do what it says it does. This prevents bugs, both from use and from maintainers changing behavior later. It saves time because maintainers don't need to spend as much time figuring out what is going on. That said, if the defined logic isn't user friendly, it should perhaps be improved.


19

There are a few points: Your implementation must do what the documented contract states, and should do nothing more. Simplicity is important, for both contract and implementation, though more for the former. Trying to correct for erroneous input adds complexity, counter-intuitively not only to contract and implementation but also to use. Errors should only ...


13

A method's behavior should be clear cut, intuitive, predictable, and simple. By trying to be more "forgiving," you are introducing a lot more edge cases than is generally worth it. Preprocessing the string to make its format valid is something that another portion of the program should be doing. Here, you just need to validate the requirements of the method ...


11

You shouldn't. Design patterns are named, recurring solutions to recurring problems that involve complex workflows, typically involving many classes with systematic relationships to each other. What you have here is a simple task that calls for a loop or two and a simple list data structure. Ask again when you have to write a complex system with dozens of ...


6

BigInteger and BigDecimal are immutable objects. Once instantiated, if you want to do something with it, you create a new object. This isn't a problem per say, and actually avoids many other problems (especially when threading), and numbers tend to be things that are constants - you don't change them. It is very common for code that is working with ...


5

If you only change the interface as outlined here, then yes you are breaking the code. Because every implementation of the interface must now return a String, and before the change none of them does. Assuming you make each implementor actually return a String, then no, this cannot break the code because no caller of any of these methods is using the return ...


4

As others have said, making the string matching "forgiving" means introducing additional complexity. That means more work in implementing the matching. You now have many more test cases, for example. You have to do additional work to ensure there are no semantically-equal names in the namespace. More complexity also means there is more to go wrong in the ...


4

Possibly. "Classic" existing consumers do not expect a value to be returned, thus would simply ignore the string being returned. By "classic", I mean something like this: public void DoSomething(Contract contract) { contract.update(); contract.delete(); } Now, there's a possibility that there is some functionality in Java that expects a method ...


3

The short answer is that Java web developers, as a whole, seem to be happy with the tools/frameworks they currently have, and do not prefer the Rails way of working enough to make such an effort worthwhile. Feel free to start a project if you think it would help. The Java platform has many frameworks for doing web development, some provided by Sun/Oracle, ...


3

According to Wikipedia: [The carriage return] commands [...] to move the position of the cursor to the first position on the same line. You are in right to expect the behaviour you describe. However, relying on a control character implies relying on your system rather than on your code. It will mostly depend on how your display system will interpret ...


3

You mention some of the context from which this question comes. Given that, I would have the method do just one thing, it asserts the requirements on the string, let it execute based on that - I wouldn't try to transform it here. Keep it simple and keep it clear; document it, and endeavour to keep the documentation and code in sync with each other. If you ...


2

Found this on Stack Overflow: What's the difference between an “engine” and a “runtime”? tl;dr from the accepted answer: Engine usually refers to a higher level software component. We almost think of the JRE as the processor. Instead of a physical CPU running machine code, we have a virtual CPU running bytecode. Again using the database example: A ...


2

Please don't follow the advice in that article. The author is correct to advocate immutable objects. But to get the advantages of immutable objects, the object should be transitively immutable. That is, it should only keep references to other transitively immutable objects. It shouldn't be referencing data providers, and it certainly shouldn't be keeping ...


2

When should I instantiate a variable rather than grabbing it through a method? When the value returned in the method has meaning or will be use past the name of the method, then get the value and assign it to variable with the appropriate name. If metadata.getColumnCount() is constant during the loop, then you can get it and cache it in a local before ...


1

You pretty much nailed it with your comment Maybe I should not be thinking about this question now because the tutorial hasn't brought it up It looks like you're on or near lesson 5, What is an Interface. I think your answer may be found on or near lesson 67, Interfaces. (I'm looking at the Table of Contents & just counting each line) Quoting ...


1

This is easy. Walk down the tree (quad tree or R-Tree, etc) until you find the lowest node that contains the “search point”. Then look at the parent of that node, and check all points that is contained within the parent (including sub notes) If you have not found enough points, then move on to the parent’s parent etc. Remember That the nearest point ...



Only top voted, non community-wiki answers of a minimum length are eligible