cmaster - reinstate monica
  • Member for 6 years, 8 months
  • Last seen more than a week ago
Is there a specific reason for the poor readability of regular expression syntax design?
Accepted answer
182 votes

There is one big reason why regular expressions were designed as terse as they are: they were designed to be used as commands to a code editor, not as a language to code in. More precisely, ed was one ...

View answer
Why use trailing newlines instead of leading with printf?
74 votes

On POSIX systems (basically any linux, BSD, whatever open-source based system you can find), a line is defined to be a string of characters that's terminated by a newline \n. This is the basic ...

View answer
How do I edit a chain of if-else if statements to adhere to Uncle Bob's Clean Code principles?
70 votes

The important measurement is complexity of the code, not absolute size. Assuming that the different conditions are really just single function calls, just like the actions are not more complex than ...

View answer
Should I add redundant code now just in case it may be needed in the future?
35 votes

I guess, this question is basically down to taste. Yes, it is a good idea to write robust code, yet the code in your example is a slight violation of the KISS principle (as a lot of such "future proof"...

View answer
Why are standard libraries not programming language primitives?
34 votes

In addition to what the other answers have already said, putting standard functions into a library is separation of concerns: It's the compiler's job to parse the language and generate code for it. ...

View answer
Why don't programming languages automatically manage the synchronous/asynchronous problem?
27 votes

What you are missing, is the purpose of async operations: They allow you to make use of your waiting time! If you turn an async operation, like requesting some resource from a server, into a ...

View answer
Should I initialize C structs via parameter, or by return value?
24 votes

Both approaches bundle the initialization code into a single function call. So far, so good. However, there are two issues with the second approach: The second one does not actually construct the ...

View answer
Readability versus maintainability, special case of writing nested function calls
19 votes

As always, when it comes to readability, failure is in the extremes. You can take any good programming advice, turn it into a religious rule, and use it to produce utterly unreadable code. (If you don'...

View answer
What's the difference between a variable and a memory location?
16 votes

Variables are language constructs. They have a name, reside within a scope, may be referenced by other parts of the code, etc. They are a logical entity. The compiler is free to implement this ...

View answer
Programming cleanly when writing scientific code
16 votes

I'd recommend to stick to the Unix principle: Keep It Simple, Stupid! (KISS) Or, put another way: Do one thing at a time, and do it well. What does that mean? Well, first of all, it means your ...

View answer
Is using nested function calls a bad thing?
15 votes

This really depends on how much nesting you use. After all, you are allowed to use function results directly in expressions to improve readability. Both, code that does not use nested expressions (...

View answer
const reference and const pointer. How do they work?
Accepted answer
15 votes

There are two aspects to the const in C++: logical constness: When you create a variable and point a const pointer or reference to it, the compiler simply checks that you don't modify the variable ...

View answer
In general, is it worth using virtual functions to avoid branching?
13 votes

Observations: With many cases, virtual functions are faster because the vtable lookup is an O(1) operation while the else if() ladder is an O(n) operation. However, this is only true if the ...

View answer
What does the "t" in int32_t signify?
Accepted answer
11 votes

Because all identifiers ending with _t are reserved for future additional types. The int32_t family of types was added in the C99 standard, so they used the reserved names to avoid conflict with ...

View answer
Should I create a class if my function is complex and has a lot of variables?
10 votes

Since the only apparent drawback of method 1 is its suboptimal usage pattern, I think the best solution is to drive encapsulation one step further: Use a class, but also provide a free standing ...

View answer
How do you avoid endlessly iterating through equally sub-optimal designs?
Accepted answer
8 votes

When I get to a tough decision like that, I usually ask myself three question: What are the pros and cons of all the available solutions? Is there a solution, I have not yet considered? Most ...

View answer
Why does integer division result in an integer?
8 votes

This is due to the evolution of hardware. Back in the early days of computers, not all machines had a floating point unit, the hardware was simply not able to understand the notion of a floating point ...

View answer
How to treat bugs that users thought were a feature?
8 votes

Since the bug is in a library, here is another approach that you can take: Make a clone of the erroneous library function. In many cases people just append a 2 to the function name in these cases, ...

View answer
How do you avoid getters and setters?
8 votes

TL;DR Modeling for behavior is good. Modeling for good(!) abstractions is better. Sometimes data objects are required. Behavior and Abstraction There are several reasons to avoid getters and ...

View answer
Are there known valid uses of SLOC to measure productivity?
7 votes

Here is a counterexample for your senior architect: Suppose I want to write a hierarchy of three classes, two of which derive from the third, implementing some virtual functions that the base class ...

View answer
How efficient is malloc and how do implementations differ?
7 votes

The main problem with your malloc_quick() implemenation is, that it is not thread-safe. And yes, if you omit thread-support from your allocator, you can achieve a significant performance gain. I have ...

View answer
Solutions for floating point rounding errors
7 votes

Floating point arithmetic is usually quite precise (15 decimal digits for a double) and quite flexible. The problems crop up when you are doing math that significantly reduces the amount of digits of ...

View answer
Clean Code comments vs class documentation
7 votes

The value of a comment is measured in the value of the information it gives minus the effort needed to read it and/or ignore it. So if we analyze the comment /// <summary> /// Retrieves a ...

View answer
Should I use Array or Set if both can be used to finish my task?
Accepted answer
6 votes

The use of either Array or Set by your function is equivalent: You create a container, and you push stuff into it. This leaves two areas for consideration: What does the consumer need to do with the ...

View answer
Should I refactor the code that is marked as "don't change"?
6 votes

Code with comments like the ones you showed would be top on my list of things to refactor if, and only if I have any reason to do so. The point is, that the code stinks so badly, you even smell it ...

View answer
Should Objects with lots of fields be broken up?
6 votes

The important figure is complexity, not pure object/member count. You can have a simple class with roughly up to 20 members (that's already really smelly, though), and you can have a much too complex ...

View answer
Endianness at bit level
Accepted answer
6 votes

The order in which bit fields are placed in an integer is independent of the order in which bytes are placed in an integer. Both are implementation details. That is generally not a problem, because ...

View answer
I never use pointers in my C++ code. Am I coding C++ wrong?
5 votes

In addition to Christoph's answer, there are also a few data structures that you cannot easily build and use without pointers: Trees of objects DAGs Linked lists (delegation chains, for example) Of ...

View answer
Why are data classes considered a code smell?
5 votes

What you need to understand is that there are two kinds of objects: Objects that have behavior. These should refrain from giving public access to most/any of their data members. I expect only very ...

View answer
What is generics abuse?
5 votes

I would use the no-nonsense rule: Generics, like all other programming constructs, exist to solve a problem. If there is no problem to solve for generics, using them is abuse. In the specific case of ...

View answer