Tagged Questions
13
votes
8answers
607 views
Should I write compact code or code with lots of spaces?
I have two friends that have completely different schools of thought on how to lay out their code.
The first says that code should be well-indented and use lots of spaces and to name variables ...
1
vote
2answers
155 views
Programming by Intention, Depth-First or Breadth-First?
Say I have the following graph of dependencies between procedures/functions/methods:
o
/ \
v e
/ \ / \
r f l w
That is, function o first calls function v, and then ...
5
votes
3answers
210 views
Is relying on implicit argument conversion considered dangerous?
C++ has a feature (I cannot figure out the proper name of it), that automatically calls matching constructors of parameter types if the argument types are not the expected ones.
A very basic example ...
4
votes
4answers
264 views
In which order should I do comparisons? [duplicate]
I'm a strong proponent of writing if statements like this:
variable == constant
Because to me it just makes sense, it is more readable than the inverted:
constant == variable
Which seems to be ...
18
votes
2answers
904 views
Is it a good idea to provide different function signatures that do the same thing?
Here is a C++ class that gets constructed with three values.
class Foo{
//Constructor
Foo(std::string, int, char);
private:
std::string foo;
char bar;
int baz;
};
All of ...
9
votes
5answers
757 views
Zero as a constant?
I have come across this programming idiom recently:
const float Zero = 0.0;
which is then used in comparisons:
if (x > Zero) {..}
Can anyone explain if this is really any more efficient or ...
32
votes
8answers
1k views
When using method chaining, do I reuse the object or create one?
When using method chaining like:
var car = new Car().OfBrand(Brand.Ford).OfModel(12345).PaintedIn(Color.Silver).Create();
there may be two approaches:
Reuse the same object, like this:
public ...
11
votes
11answers
292 views
Should 'mathematical' functions follow mathematical notation?
I suppose this question is going to be immediately flagged as subjective, but which do you think is better:
double volume(double pressure, double n_moles, double temperature) {
return n_moles * ...
22
votes
9answers
864 views
Intentional misspellings to avoid reserved words
I often see code that include intentional misspellings of common words that for better or worse have become reserved words:
klass or clazz for class: Class clazz = ThisClass.class
kount for count in ...
17
votes
9answers
802 views
Are long functions acceptable if they have internal structure?
When dealing with complicated algorithms in languages with support for nested functions (such as Python and D) I often write huge functions (because the algorithm is complicated) but mitigate this by ...

