Coding style is a set of guidelines that helps readability and understanding of the source code.
11
votes
12answers
1k views
Correct comment to put for boolean function arguments that are “false”?
From some open source projects, I gathered the following coding style
void someFunction(bool forget);
void ourFunction() {
someFunction(false /* forget */);
}
I always have doubt about what ...
2
votes
3answers
399 views
Which is the better: a <= b or a < b+1 [on hold]
For loops are usually inclusice, exclusive, meaning that you start at the bottom, and stops when you reach, but don't to the top.
In Python:
for i in range(0,a):
print(i)
would print 0 through ...
-1
votes
1answer
70 views
Embed images into code comments [closed]
Intent: I am referring to code editors for languages like PHP, ruby, etc where front end is HTML, CSS or a mobile app.
Especially while data binding / applying templates, it would be nice to have a ...
2
votes
2answers
281 views
Excessive use “this” keyword in Java [duplicate]
The this keyword is primarily used in three situations.
The first and most common is in setter methods to disambiguate variable references.
The second is when there is a need to pass the current ...
1
vote
1answer
139 views
Is nesting typedefs a good style?
Let's say I have a namespace my and this namespace contains a class foo.
What should I prefer nesting typedefs into my class or hold it in my namespace?
namespace my {
class foo {
// some stuff
...
6
votes
6answers
425 views
Should my team use some common well-regarded coding standard as a basis for own own?
The R&D team I'm in has decided to adopt a coding standard. We have only recently formed, and have too little code and common coding time of our own to base our standards/conventions document on ...
5
votes
4answers
330 views
How can I stop myself overwriting member variables with 'new' ones?
The bulk of my programming experience has been with C++ and (shudder) FORTRAN (I'm a scientist not a programmer as such, but I do my best). I've recently started using python extensively and find it ...
43
votes
3answers
976 views
Coding Style for Visually Impaired Programmer
I am visually impaired. With glasses I see well enough to drive, but at the font size I'm comfortable working at I can only see about 15 lines of 100 characters at a time. This has affected my ...
2
votes
2answers
208 views
Avoiding boilerplate in PHP classes
I am working on a PHP code and as it grows getting more and more tired of repeating the same standard pattern again and again and again:
class BolerPlate
{
protected $property1;
protected ...
0
votes
2answers
215 views
Defensive Programming vs. Exception Handling
I have a question about defense programming and handling of exceptions.
Here is a pseudo-code snippet first:
try {
// do some core logic;
} catch (BadException e) {
ErrorCode ec = ...
0
votes
2answers
219 views
What is the exact syntax of inline?
CASE 1 (Definition and declaration in same source file)
Suppose both my prototype and definition of global function is in .cpp file. Where should I write inline keyword to make compiler know?
In ...
1
vote
2answers
211 views
How much functional programming expertise can programmers be expected to have? [closed]
I'm coding in a non-functional language with functional mechanisms (C# to be specific, but you could substitute, say C++ and use function pointers, or what have you) on a small team. It's my habit to ...
2
votes
1answer
139 views
Maintaining code-style conventions for large projects [closed]
For a while I've been maintaining an ad-hoc script to check code style against our project's guidelines.
I'm aware of AStyle/Uncrustify and have used them, but they are best for once-off code-style ...
2
votes
3answers
196 views
Should I make a variable readonly when I modify it, but I don't actually set it outside of the constructor?
Background:
I was writing some code. It looked something like this:
class X
{
private List<int> _myList = new List<int>();
public void MyMethod(int x)
{
...
3
votes
2answers
157 views
C++11 Header-only Library: in-class body vs. out-class body code?
BACKGROUND:optional
Since 2002 I've been slowly building my own Windows Native C++ library. And let's just say that I have jumped 150KLOC (reusable code) having everything I need and the kitchen sink ...
3
votes
6answers
538 views
Clarification of “avoid if-else” advice [duplicate]
The experts in clean code advise not to use if/else since it's creating an unreadable code. They suggest rather using IF and not to wait till the end of a method without real need.
Now, this if/else ...
-1
votes
1answer
55 views
What should always be mentioned in the first lines of a file released as open source code? [closed]
I am looking for standards regarding open source code release. Most of the time, one may find a copyright statement and a few lines about the project at the beginning of each file, but I am having a ...
0
votes
1answer
122 views
How to format this line according to PEP 8? [closed]
I'm trying to adhere to PEP 8, with a 78 character limit on the length of my lines.
I have the following statement:
startTime = time.strptime(request.GET.get('st', (dt.datetime.now() - ...
6
votes
3answers
232 views
Is there any situation in which it would be appropriate to use unless… else?
This construction is considered wrong
unless
#..
else
#..
end
This is for the general reason of double-negative confusions. It translates to:
if not
#..
if not not
#..
end
We all agree ...
1
vote
4answers
139 views
Coding convention regarding the usage of underscores [closed]
There seems to be divided opinion on this subject, and I wanted to get people's insights on whether they've found using underscore prefixes and suffixes to be helpful with coding or not.
You know, ...
2
votes
2answers
137 views
Should I use semicolons to delimit Scala statements?
I'm used to delimit statements by a semicolon from Java, so naturally I do it in Scala code too. I also feel that the code is easier to read, because it's evident where one statement ends and another ...
3
votes
3answers
258 views
Blank lines in C
I'm working through K&R and I notice that their code is extremely tightly spaced.
I haven't developed C since at University, but professionally most source from other languages I've worked in has ...
3
votes
2answers
191 views
How can I keep current with Python coding style?
I've been using Python since version 2.2. I do pick up new language constructs like for example with statement or dictionary/set comprehensions. However, I've realized that even though I'm being ...
2
votes
3answers
210 views
Placeholders in strings
I find that I sometimes use placeholders in strings, like this:
$ cat example-apache
<VirtualHost *:80>
ServerName ##DOMAIN_NAME##
ServerAlias www.##DOMAIN_NAME##
DocumentRoot ...
0
votes
3answers
131 views
which style of member-access is preferable [duplicate]
the purpose of oop using classes is to encapsulate members from the outer space. i always read that accessing members should be done by methods. for example:
template<typename T>
class foo_1 {
...
-5
votes
1answer
102 views
Brackets at the end of the line vs brackets after the line [duplicate]
My boss keeps telling me that I should use this kind of brackets:
if(condition) {
// instructions..
}
but I find way more readable to use this:
if(condition)
{
//instruction
}
since you have ...
3
votes
3answers
436 views
articles in variable names and hard-coding strings
re-edited by author: no this is not 2 questions. This is one question about code review questions containing two separate points. Please do not edit my question.
For naming variables, the two sides ...
5
votes
3answers
305 views
Coding Convention: C++ Header/Interface Files
I'm reading through a PDF on C++ programming from this page on Stanford's site. It says that when you're creating a C++ header file for a library interface, use a #ifndef preprocessor command to make ...
2
votes
4answers
89 views
function exit condition on parameter consistency check [duplicate]
When checking for parameter consistency a the top of a function body, what is the best strategy?
This one:
protected void function(Object parameter)
if (parameter == null)
return;
...
58
votes
15answers
4k views
Should I use parentheses in logical statements even where not necessary?
Let's say I have a boolean condition a AND b OR c AND d and I'm using a language where AND has a higher order of operation precedent than OR. I could write this line of code:
If (a AND b) OR (c AND ...