Coding style is a set of guidelines that helps readability and understanding of the source code.
1
vote
2answers
122 views
Any suggestions on how to over-rely on Google? [closed]
I don't know whether you Google a lot while you coding. I discover my coding practise always rely on Googling. One of the reason why is I don't familiar with the framework, So, I will do How to XXX in ...
3
votes
7answers
172 views
Ensuring that headers are explicitly included in CPP file
I think it's generally good practice to #include the header for any types used in a CPP file, regardless of what is already included via the HPP file. So I might #include <string> in both my HPP ...
1
vote
5answers
166 views
Is it a good practice to write a method that gets something and checks the value? [duplicate]
Occassinally I have to write methods like this:
string GetReportOutputDirectoryAndMakeSureExist()
{
string path = Path.Combine ( ... ) //whatever logic
if(!Directory.Exists(path)) ...
2
votes
3answers
220 views
Programming Style in Large Scale C++ Applications
Recently I've been browsing source code of large applications written in C++ to learn a bit but I couldn't help but notice that most if not all use a lot of IFDEFs and class-less functions (where they ...
4
votes
3answers
264 views
What are the downsides of mixing tabs and spaces?
The advantage of using tabs for indentation is that people can configure their editor to use the tab width they are comfortable with. The only argument against this seems to be that people don't want ...
1
vote
3answers
280 views
Code Base with awful code conventions, follow them?
With no time to refactor, when you are working on legacy code, with the most awful conventions, what is the best practice?
Will trying to follow better coding style would improve readability or ...
7
votes
2answers
311 views
What does Uncle Bob mean by 'noun phrase names'?
I am reading Clean Code by Uncle Bob. Because I am not a native-English speaker, I couldn't understand following statement:
Classes and objects should have noun or noun phrase names like
...
3
votes
3answers
526 views
When are chained assignments (i.e. a=b=c) bad form?
I'm working on a VB.Net WinForms project and found myself writing code like this:
this.Fizz.Enabled = this.Buzz.Enabled = someCondition;
I couldn't decide whether that was bad code or not. Are ...
1
vote
1answer
49 views
Helper Methods Placement
Here's a question that's always bugged me. I'm going to use java as an example because I've almost never run into a problem in java where I didn't need to use helper methods in its class structure.
...
42
votes
12answers
2k views
Coding style (do more, then simplify) [duplicate]
I'm a CS student and I have been coding for a few months shy of a year now, and I seem to have developed what I think may be a "bad" habit and I'm wondering if anyone does the same (or whether it's a ...
1
vote
2answers
154 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 ...
7
votes
3answers
201 views
Dynamic typing function arguments - how to keep readability high?
Dynamic typing newbie here, hoping for some wizened words of wisdom.
I'm curious if there is a set of best practices out there for dealing with function arguments (and let's be honest, variables in ...
0
votes
4answers
225 views
Forward declaration vs include
Reduce the number of #include files in header files. It will reduce build times. Instead, put include files in source code files and use forward declarations in header files.
I read this in here. ...
2
votes
1answer
106 views
Less code or less operation
Sometimes I hesitate between "More code to avoid unnecessary operations" and "less code but with redundant operations". Let me just take an example (Win32 API):
I try to paint some controls manually ...
0
votes
2answers
150 views
unique_ptr and references - coding style question
I'm pretty sure this is a question purely about aesthetics but I wanted to get all your opinions on it before I start proliferating this type of code in my codebase. Consider the following code:
...
5
votes
2answers
230 views
Is it OK to have a method return different types based on a parameter?
I'm looking for a reference to clean coding styles that I can pass to a team member.
In particular, the rule that a method should not change its return type based on an input parameter. If you need ...
8
votes
6answers
921 views
Should my code be DRY or readable if it can't be both?
I'm writing Ruby code for a simple encryption exercise and have frequently run across this dilemma (the exercise is a solitaire cipher if you must know). It is a question of whether I should pad out ...
1
vote
2answers
223 views
Choosing between words with different spellings for function names
A question has been bothering me for a while: when developing international projects, it is common sense to use English as the reference language since it is the language that the most people ...
2
votes
2answers
153 views
Are there standard style guides for PHP?
I've been working in a very small team for PHP development and we've been using an ad-hoc, "Invented Here" style guide. Now that our team and codebase is growing, we would like to use a more ...
2
votes
3answers
458 views
Microsoft's coding standards for ASP.NET controls
I cannot find any naming standards/conventions in MSDN for naming ASP.NET controls.
One of the following standards tends to be used by programmers:
lblAddress
AddressLabel
Address
According to ...
1
vote
4answers
376 views
Is using `continue`, `break` in non-`switch` loops and `?:` bad practice? [duplicate]
Back in college I've been told that using break; and continue; outside switch statements (e.g. to escape for or while loops) is wrong, bad practice and bad habits at the same time because it only ...
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 ...
1
vote
5answers
113 views
Where to read from file?
In Java: I have a class Students. I would like to read a list of students from a file. Which one is more elegant:
Reading and constructing the list in main(), and creating a Student object with the ...
4
votes
4answers
263 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 ...
-4
votes
1answer
87 views
Check Javascript coding practice and overall performance [closed]
I have a Edit/Details form which has 4 user related fields. On click of Save, I save the edited fields to local storage (if supported) and display the same values in the Details view.
Below is the ...
7
votes
7answers
976 views
Prevent developers from using constants
I have one one software system which allows developers to specify an ID or name to create NodeReferences. Both work fine, but ID's are not guaranteed to be the same across different environments. I've ...
2
votes
3answers
133 views
About the usage of assertions [duplicate]
I stumbled upon an article named Programming With Assertions.
And beside the mechanism of turning on and off assertions after compile time, I don't get it. Why were assertions introduced on language ...
11
votes
7answers
630 views
Is there a way to support different coding styles in a development team
The Problem: Two developers => three opinions on indention, braces on new line or not etc.
We usually work with three or four people on our projects and each of those has it's own code style. I know, ...
8
votes
3answers
218 views
Is a single object to be preferred over multiple variables?
It was quite hard to put what I meant into a title, but it's easy to put into code.
C++
Is this
int offset_x = 10;
int offset_y = 40;
...
element.move(offset_x, offset_y);
To be preferred over ...
1
vote
4answers
349 views
Switching from ActionScript to JavaScript, tips for writing code?
I am quite comfortable with using actionscript3 and flash. I also have some experience with Java. But recently, I started learning JavaScript and node.js. I ultimately want to make a 3d game in ...
4
votes
3answers
341 views
Space between negative sign and variable name
I tried doing a Google search, as well as searching this Stack Exchange site but could not find a question relating directly to this.
The PEP 8 -- Style Guide for Python Code has lots of good style ...
6
votes
3answers
235 views
Throwing an exception inside finally
Static code analyzers like Fortify "complain" when an exception might be thrown inside a finally block, saying that Using a throw statement inside a finally block breaks the logical progression ...
-1
votes
1answer
190 views
What is the C++ convention, if any, for naming to differentiate between structure types and other types? [closed]
In general, should I use some sort of convention for structure names which is distinct from other type name? I was thinking about this when my professor started talking about structures.
I had the ...
1
vote
2answers
330 views
coding style for If condition [duplicate]
I came across below style of writing if statements in C#, on msdn code examples. Usually when I write if statements, the conditions I would write `(Customer != null)
I want to know if there is any ...
2
votes
1answer
206 views
Unindented elses
Been writing code since about 18 years now. Lately, I've got into the habit of not indenting elses and when I look at the code it does worry me a bit mostly that someone who might look at the code ...
10
votes
4answers
438 views
Always pull out common cases and branch separately? [duplicate]
We had a disagreement in a code review.
What I had written:
if(unimportantThing().isGood && previouslyCalculatedIndex != -1)
{
//Stuff
}
if(otherThing().isBad && ...
6
votes
3answers
223 views
Is changing the type of a variable partway through a procedure in a dynamically typed language bad style?
In Python (and occasionally PHP) where variables do not have fixed types, I'll frequently perform 'type transformations' on a variable part-way through my code's logic. I'm not (necessarily) talking ...
2
votes
2answers
155 views
Style for creating IEnumerable unions
There isn't any cool LINQ sugar for creating unions. The Enumerable.Union() method is usually called like this:
var bigList = list1.Union(list2);
The alternative is to call Enumerable.Union() which ...
5
votes
1answer
322 views
Is using '{}' within format strings considered Pythonic?
I just learned you can write
'{}{}'.format(string_a, string_b)
instead of
'{0}{1}'.format(string_a, string_b)
in Python, i.e. you can omit the numerals for the string format parameters when you ...
3
votes
5answers
315 views
In Java, should private helpers go above or below public methods?
I've noticed that a coworker and I have opposite practices regarding the ordering of methods in our Java classes. One of us begins a class with its major public methods, and then put all of the ...
59
votes
6answers
3k views
Should the variable be named Id or ID?
This is a bit pedantic, but I've seen some people use Id as in:
private int userId;
public int getUserId();
and others use:
private int userID;
public int getUserID();
Is one of these a better ...
59
votes
19answers
10k views
How important is it to reduce the number of lines in code?
I am a Software developer who works on J2SE (core java).
Often during our code reviews we are asked to reduce the number of lines in our code.
It's not about removing redundant code, it's about ...
0
votes
2answers
223 views
Need some advice and feedback on my code's design
I am looking for feedback on the design of my program.
I have a shell script call function.sh that defines a lot of helper functions. My intent is to use those bash functions defined in functions.sh ...
7
votes
1answer
401 views
Why doesn't CSS natively support variables and hierarchy?
I am new to UI development, but I feel very uncomfortable with how CSS works.
My use case is that I wanted to apply some specific styles inside a particular div on a page.
CSS attempt:
div.class1 ...
-3
votes
1answer
418 views
Why do some programmers prefer spaces over tabs? [duplicate]
Possible Duplicate:
Why do some languages recommend using spaces rather than tabs?
While reading over the style guides for PHP
PSR-0
PSR-1
PSR-2
I noticed the rule
Code MUST use 4 ...
18
votes
2answers
903 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 ...
4
votes
7answers
413 views
Should I spend time prettifying unit tests? [closed]
The company I used to work for before we had automated unit tests to test our work. However the coding standards and architecture was not very important for tests. Of course you had to indent code ...
17
votes
15answers
2k views
I hate one of our coding standards and it drives me insane, how to process it? [closed]
Disclaimer: Not as exaggerated as the title suggests, but it still makes me uncomfortable. I'm just going to express honestly, so take it with a grain of salt. Just pretend that I'm talking about that ...
3
votes
1answer
251 views
Why Doesn't Java Allow Default Parameters/Arguments [closed]
Basically something like
public void jumpToRoom(String roomName = Rooms.DEFAULT_ROOM)
would be convenient.
Many languages nowadays seem to support it (Ruby, PHP, even C#).
What is Java's ...
0
votes
1answer
171 views
Preventing override of methods in Objective-C [closed]
Objective-C lacks private methods or java-esque final methods. This means that it is possible for a subclass to (accidentally) override some of the internals of a superclass.
How does one prevent ...


