Hot answers tagged

11

In layman's terms: If you will be extracting the channelID in several places, then you should create a function. Such a function, being cohesive, should read from the state. Part of that state would be the constant with a name like DELIMITERS_BEFORE_ID. I find that this: String channelId = channelIDdWithPath.split("/")[DELIMS_BEFORE_ID]; ...is more ...


9

Your should focus on what makes your code readable and the spirit of the guidelines rather than try to prove you can write bad code even when following the guidelines. A constant named NUMBER_OF_DELIMITERS_BEFORE_ID_IN_CHAT_CHANNEL_PATH is not very clear or understandable. So yes a magic number is probably not any worse than using such a badly named ...


3

Is there any advantage here that I am missing? Yes, there is. I, along with a large number of software projects, used to follow the practice outlined in the question. Many projects, including modern ones I work on, now take the opposite approach in a source file: The header file that declares the functions being defined in the source file is the very ...


2

DAO code goes into the Model, not the controller. DAO code is actually farther away from the controller than the business logic, and that logic doesn't go into the controller either. Write a layer that contains methods that convert CRUD operations (Create, Read, Update, Delete) into DAO operations. Call the newly-created CRUD methods from your controller ...


1

This is a very broad question, as it depends on the language used, and the features that language offers: Can "plain old data structures" be made immutable? Does the language enforce encapsulation of private functions and data, or is it by convention? Is the language statically or dynamically typed? Does it allow functions outside of static classes? Does ...


1

This applies to any language. If you don't plan on doing anything with the exception, or as a result of the exception being caught, then don't bother catching it. It saves you a few lines of code and indentation. Seeing an except block could tell other programmers, who are busy and aren't reading every line of code, "Oh good. CrazyPython is handling this ...


1

See Luc's valid comment on your question re. URL templates. I would add... anytime you want a magic number that is neither 0 or 1 and is also not referring to a specific independent feature of the business domain, that is a code smell. Your issue here isn't that you're hardcoding a magic number so much as you're hardcoding something which is replicating ...


1

No rule is absolute in software development and everything depends on context. That being said, I would not consider your example to be necessarily a good case for boolean arguments. An API like show(bool isLoggedIn) does not tell me what is going to happen without me reading documentation or code, whereas functionality of show(string messageToDisplay) ...



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