New answers tagged coding-standards
4
There are a few different considerations that come into play when we consider it for our company, as listed below:
Cost - Is the time cost for modifying it going to be greater than the time cost for developing outright? Not all components will be easily modifiable, and if it would take 8 hours of development time to custom build versus 10 hours to modify, ...
1
Instead of using a checklist I think what you're looking for is a coding standard, something that tells your team what you expect of their code and provide guidelines.
The coding standard could be something as simple as a pattern for variable naming and a convention for how the code should be laid out (for example parenthesis on a line of its own), or it ...
3
Industry standards are subjective. The field is so full of competing ideas that you can always find someone who will prefer another approach over even those that are recommended in some manifesto. What matters is consistency within the organization. That trumps industry standards.
The reason being is that sometimes organizations have good cause to take a ...
5
Well, there are the standards put forth by the PHP Framework Interoperability Group.
Then there are the standards put up in reaction to the PHP Framework Interoperability Group: The Difinitive PHP Style Guide.
And then there's Apache's style guide.
So, no. Nothing that's been agreed on by the industry.
2
Follow the existing standard.
However, if there's a genuine need to fix it (it's becoming a major problem), take a deep breath, man up and refactor the entire code base to follow a new standard. But only do this if it's truly necessary, have everyone's approval and if you have the time. It probably won't take as long as you might think, but do your ...
1
Follow the existing standards. Maybe they're outdated/odd/wrong/unpleasent. (as long as they're not being hostile as @Michael Kohne mentioned).
There could be reasons outside of the language standards to be using the naming style. I have heard of people running 3rd party applications over the code base to pull out names for use later. Eg test names as ...
16
No matter how odd you find the existing conventions, FOLLOW THEM. Having some conventions, even if you don't like them, is FAR FAR better than not having any.
Obviously that's not always true (some conventions are outright hostile to getting work done, like limiting all names to 8 characters for no good reason), but except in the most extreme cases, just ...
1
It's not necessarily bad code, but it does make your code significantly less readable. Typically, I would strongly recommend against it, although I suppose there are a few cases where it might be acceptable (or merely less bad). For example, when setting a few local variables to constant value:
// accumulators
int j = 0, k = 0;
for(int i = 0; ...)
{
...
...
4
It depends on the programming language. If you use a language where variable types are not enforced, then this could happen.
x = 1;
y = 494.0;
z = new Object();
x = y = z = "hello";
Now x,y,z are all a string. This might be confusing if found later on in the code.
The other problem is operator overloads. Some languages allow you to change what happens ...
16
I never do it. I always put each assignment on its own line. Clarity is king.
In practice, I seldom use enough state variables to make chaining assignments necessary. If I get to that point, I start looking for ways to trim the amount of state I am using.
4
Your real problem is that you're using the wrong sorter. Your comparator is correct, and (depending on the language) it may wind up being used for other cases where the comparison should not be reversed. Instead of "fixing" (actually breaking) the comparator, you should find out how to get the sorter to sort in descending order. Any decent sorting library ...
0
Start by ignoring any performance impact of reversing the list. Any sensible list-reversal will be linear in time, which means that for large lists, the sorting will dominate.
If there is a "natural" ordering of your elements (i.e. an ordering which is independent from your particular implementation), I would recommend sort + reverse. This will make the ...
1
Comparer which makes it sorted in the right order is better. When you already use comparer (and you do in this case) it is better (faster/more by-the-book) to modify the comparer (or create another one).
Although, when sorting object which have "natural" comparison (for example: int) and "standard library" (for example: BCL for .NET) which can leverage this ...
0
If you already have written a comparator, it's of course best to modify it so that the standard sort (into "ascending" order) does what you want.
The second best thing is to use whatever switches or tricks are available in your language's standard sorting methods. Such as this in Java:
Arrays.sort(array, Collections.reverseOrder());
The third option, ...
1
Use comparator with correct order for your application. Sorting and then reversing means that you are doing the sorting AND going through list again to reverse it.
When you are creating comparator, you are defining new ordering and YOU are difining what value is lesser and what higher. Eg. in reverse ordering of natural numbers, 10 is less than 9 even ...
1
I hate most standards documents as they usually try to sweat the small stuff and ignore the bigger picture.
For example, nearly all of them will say how to name variables or place brackets. This is pure style and does little to really help a group of devs code correctly. They ignore stuff like directory structure and code layout. I've seen standards ...
4
The first important thing to note is that a coding standards document is not about right and wrong. It's not about good and bad or which method is better.
A coding standards document's purpose is to make sure that all code is designed, written and laid out the same to make it easier for a developer to switch from one persons work to another without the ...
7
What are the key aspects and contents of a good coding standards document?
Being supported by tools which enable automated checking of the code. If I know that I can't commit to version control any piece of code which doesn't match some rules, I would be encouraged to follow those rules in my code. If, on the other hand, some fellow programmer have written ...
3
I was going through this process multiple times. And the most successful (although bumpy anyway) was approach was to take "Coding Standards" document from well known company and modify it to fit your needs.
For example, I just found this one: http://www.tiobe.com/content/paperinfo/gemrcsharpcs.pdf
Anyway, keep your flame-thrower handy.
Cheers,
5
Use a well-established convention, such as а leading underscore, or a pattern such as the Revealing Module Pattern.
One advantage to using a pattern that enforces visibility at the language level rather than just using a naming convention is intellisense support. Developers that are working in a IDE may not want to see the private methods and data.
The ...
0
Any code should be documented with enough information to understand it. That includes information about the variable types if necessary (and even in statically typed languages, you may need more information than is supplied by just the type keyword).
When you get used to working with a dynamically-typed language, you will find that the type of a variable ...
0
Maybe try to write it more in OOP style. For example, instead of:
var crunchSomeSessionData = function(sessionsMap, options) {
[...]
}
why can't you do
session.crunchData(options)
where session is object you have created. You will be able to take a look at constructor to know exactly how session is created and all your problems should go away
1
I think a lot of the problems that you are having can be solved with proper naming of variables and the contents of the method. For the most part it should be obvious what the parameter types are based on the names and the contents of the method. Documentation also helps.
For example:
function getSum(arr) {
var sum = 0;
arr.forEach(arr, ...
Top 50 recent answers are included

