61
votes
Accepted
Do inline expressions obstruct readability of code?
Personally I prefer having temporary variables with explicit names (but don't abuse them either).
For me:
void foo()
{
int const number_of_elements = (function_1() + function_2()) / function_3(); /...
45
votes
Accepted
Are front-end state management tools an anti-pattern?
The problem with global variables is that they are difficult to reason about. Where is that global variable being modified? How would you even know?
When you pass around a context object (i.e. a ...
26
votes
Do inline expressions obstruct readability of code?
I think there are two key factors here:
How complex is the expression?
How meaningful is the intermediate variable?
Take an example where we have three elements to get a final price:
total = price + ...
23
votes
Are front-end state management tools an anti-pattern?
The quote from the book is concerned more about code that looks like this:
var data = {
some: {
huge: {
deeply: {
nested: {
object: {
...
16
votes
Do inline expressions obstruct readability of code?
“Refactoring” means changing what the code looks like, without changing what it does. A book about refactoring will tell you about changes you can make and how to make them without affecting what your ...
7
votes
Accepted
Loops for enumerated types
Let's say for some reason you want to iterate over all countries. "That's easy", you say:
for (i = Country_China; i <= Country_Usa; i++) {
// Do stuff
}
and you write that loop ...
7
votes
Do inline expressions obstruct readability of code?
Local immutable variables (const in C++, final inJava, etc.) can add useful context-dependent information for the reader of the code and are useful when debugging interactively (stepping statement-by-...
5
votes
Do inline expressions obstruct readability of code?
No language was specified, so I'll give a few examples.
In languages with const correctness (e.g., C or C++) I make more intermediate variables
Always make intermediate variables final or const ...
4
votes
Are front-end state management tools an anti-pattern?
While other answers here are completely valid I want to give an alternative perspective that frontend data stores CAN be an anti-pattern in certain situations. In the component hierarchy used by React ...
3
votes
Accepted
Type Aliasing and platform switching
Let's take the C programming language as an example.
In C, the size of the type int depends on the platform. On some platforms / compilers, it might be 16 bits, on others it might be 32 or 64 bits or ...
2
votes
Variable binding time (Steve McConnell)
Firstly, Jorg is right but pedantic that compilation and interpretation isn't a property of the language unless it's explicitly specified that way; but nonetheless most languages have a canonical or ...
1
vote
Accepted
What is the difference between detailed design and design for construction?
I was confused when the author in one case uses the term "detailed design", and in the other "design for construction".
Does he? Well, I searched through the book, and as far as ...
1
vote
Do inline expressions obstruct readability of code?
Customer customer = Customer.builder()
.name("John Doe")
.age(15)
.address(Address.builder()
.number(15)
.street("Maple street")
.build()
)
.build();
vs.
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
code-complete × 21design × 5
object-oriented × 3
object-oriented-design × 2
programming-practices × 2
software × 2
variables × 2
architecture × 1
c++ × 1
terminology × 1
refactoring × 1
dependency-injection × 1
clean-code × 1
requirements × 1
class × 1
methods × 1
state × 1
coupling × 1
application-design × 1
enum × 1
interpreters × 1
object × 1
code-formatting × 1
redux × 1
visual-studio-2010 × 1