Tag Info

New answers tagged

0

It's a bit of a code smell, and your gut feeling is right about this not being a good solution. But instead of passing the arguments, extract the method and the three parameters into a separate class. This class takes the arguments in the constructor and exposes the one method. Something tells me that this one method is actually doing something that can be ...


0

If I came across a method called AddRecord, I'd conclude - from it's name - that it was a statement, not a yes/no question. It's not asking me if I want to add a record; I'm telling it to do so. Therefore I'd expect one of two possible return types, depending on whether I'm thinking OO or functional: void - I've commanded it to do something. If there's a ...


1

You're right that it's generally best to let other code's exceptions propagate through yours unimpeded. Where I work, this is called being "exception-agnostic". Now for the hard part. The return values of your functions are part of your public API. Having a return value that doesn't mean anything is a lot like having a method that doesn't do anything when ...


3

In my opinion, methods should either return a value or have a side effect, but not both. In this answer to another question the author quotes the source of that practice. In your examples, you handle a situation in which you try to add an element to a collection that could be or could not be initialized. My suggestion is that you either throw an exception ...


2

It's basically YAGNI. All the concrete collections in the standard library are mutable, implementing or inheriting the optional operations. They don't care about general purpose immutable collections and neither do the vast majority of Java developers. They're not going to create an entire interface hierarchy just for immutable collections, then not ...


11

Look at the following interfaces: Collection List Map Set These interfaces all declare mutating methods as optional. This is implicitly documenting the fact that the Collections class is able to return implementations of those interfaces that are immutable: that is, those optional mutation operations are guaranteed to fail. However, per the contract in ...


1

This: app.route('/', method='GET')(home) ... Is the same as this: func = app.route('/', method='GET') func(home) In other words, app.route(...) returns a function, which is then called.



Top 50 recent answers are included