2
votes
6answers
409 views

Should all classes have a default constructor as part of good coding convention

From the texts I have read so far, the conventions talk about organizing constructors, starting with the default, if any. I am wondering, should all classes have a default constructor anyway. This ...
6
votes
7answers
1k views

Making Simple IF Statements Shorter

If we assume we have this little snippet of code: string str = "checked"; bool test1; if (str == "checked") { test1 = true; } else { test1 = false; } Is it bad practice to change a simple ...
2
votes
5answers
246 views

Best practice to sort then reverse, or write “backwards” comparator?

I wrote a comparator for a custom class of mine and when I ran my code I realised the output of my list of these objects was in the reverse order as to what I wanted. It was "ascending" as opposed to ...
22
votes
8answers
2k views

Should comments say WHY the program is doing what it is doing? (opinion on a dictum by the inventor of Forth) [duplicate]

The often provocative Chuck Moore (inventor of the Forth language) gave the following advice[1]: Use comments sparingly! (I bet that's welcome.) Remember that program you looked through - the ...
3
votes
4answers
1k views

Why should one use a single-use temporary variable?

Let's say we have a class called 'Automobile' and we have an instance of that class called 'myCar'. I would like to ask why do we need to put the values that our methods return in a variable? Why ...
0
votes
2answers
241 views

What is the standard for describing functions and objects?

What is the standard for describing functions/methods (function name, number of arguments, argument type, return type, etc...) in a manner that is language independent? EDIT: More specifically, how ...
4
votes
3answers
327 views

Naming a “do X if needed” method

What is a good way to name a method that checks if X needs to be done, and does X it if necessary? For example, how to name a method that updates a user list if new users have logged in? ...
7
votes
2answers
127 views

What do you do when working with multiple languages with different capitalization schemes?

I'm making a webapp using Django. The Python convention for naming variables is lowercase_with_underscores, but the Javascript convention is camelCase. In addition, I've seen many people use ...