I not sure whether this question belongs to the code review section so i will post here for now. I have an expression like following:if(userIds.contains(currentUserId)){     throw new Exception(Cannot delete self);}I want to make it to become more readable, so i put it like the following:if(isDeleteOwnAccount(userIds, currentUserId)){     throw new Exception(Cannot delete self);}private boolean isDeleteOwnAccount(Set<Integer>userIds, int currentUserId) {    return userIds.contains(currentUserId);}Is it better? Because i might have some other checking so it will become less readable if i don't do so, on the other hand, method with 1 line of code, is it good?
Java method with 1 line of code
java
Depends on the context, or how the rest of the method looks like.With the exception, it's clear, what the method does - but Exception messages shouldn't describe what the intention of the code is, right?If you had something like if(userIds.contains(currentUserId)){     return false;}// perform deletionreturn true;The reader is not sure, what the purpose of the contains is. If I had to change something in that code, I'd ask myself: Why can't I delete the given user, if it is present in that map?. To be honest: I would have assumed, it would be the opposite: Only delete, if a userId is present aka can't delete unknown users. To be really sure, I actually have to read through the code and check, what happens, if the given userid is present in the map. Or look at the annotations and check, who committed that and hope, he's still working for us or check, if there's a link to the issue tracker, where the requirements are described.So, your descriptive method (or a well written test case) would have saved me a lot of time.Just keep in mind: We devs often find us reading and analyzing and debugging a lot more than writing code. I have had implemented requirements, which took maybe an hour and the figuring out what to do took days. We read and try to understand code a lot more, not only because of bugs, but also to check, what the impact of our changes would be or where else we might have to change the code, to either fulfil the requirements or verify, that we do not break something else. If we try to be as clear as possible in the code, we can reduce that amount and can do more of the fun part: the coding.Hope this helps...