Tagged Questions
16
votes
16answers
2k views
Coding standards and coding style, is it that much important? [closed]
There are a lot of ways of typing code, but I can't understand what is the good reason to adopt a certain standard or style if it does not change the way the code can be read and understood.
Everyone ...
3
votes
3answers
385 views
Refactoring previous intern's noodle code with future interns in mind
Background
I've run across this problem as I am currently an intern at a large company's local software division. I have been given the task of extending a project that several previous interns have ...
71
votes
10answers
13k views
Why do most of us use 'i' as a loop counter variable?
Has anyone thought about why so many of us repeat this same pattern using the same variable names?
for (int i = 0; i < foo; i++) {
// ...
}
It seems most code I've ever looked at uses i, j, ...
75
votes
16answers
18k views
What is the benefit of not using Hungarian notation?
One of the things I struggle with is not using Hungarian notation. I don't want to have to go to the variable definition just to see what type it is. When a project gets extensive, it's nice to be ...
8
votes
6answers
913 views
Should my team use some common well-regarded coding standard as a basis for its 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 ...
10
votes
5answers
681 views
Evolution in coding standards, how do you deal with them?
How do you deal with evolution in the coding standards / style guide in a project for the existing code base? Let's say someone on your team discovered a better way of object instantiation in the ...
0
votes
1answer
42 views
How using tab affects commands like diff
In the page at http://pear.php.net/manual/en/standards.indenting.php, it is advised to use space instead of tab as it causes issue with diff, patches. Here is the excerpt from the page.
Use an ...
19
votes
11answers
1k 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 ...
0
votes
3answers
104 views
Long vs short scripts? Big vs small scripts? [closed]
As a programmer, I have always wondered whether it is preferable to write (a) short modular functions that are each stored in their own script (i.e., file) or (b) long comprehensive scripts that ...
1
vote
2answers
108 views
Coding convention question about AS3 duplicate variable definition
AS3's got some awkward rules about variable scope, due to its use of hoisting. I don't like pointlessly leaving a bunch of compiler warnings lying around, but it's more important to me for my code to ...
1
vote
4answers
2k 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 ...
23
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 ...
0
votes
1answer
203 views
Should the helper function in class be defined before the usage or after
I need to do the code review of fellow members.
One of the member always defined the helper functions at the bottom and use them at top e,g
class Sample {
public function SendFile(){
file = ...
0
votes
4answers
462 views
Usage of magic strings/numbers [closed]
This is somewhat controversial topic, and I guess there is as many opinions as there are programmers. But for the sake of it, I want to know what are the common practices in business (or in your work ...
26
votes
15answers
4k views
Space around operators? a=b/2; or a = b / 2; What are the arguments? [closed]
Personally I prefer space around operators. For me it makes the code much more readable. What are the arguments not have space around them? Line length?
An example from the Python style guide (I ...
12
votes
9answers
1k views
How important are code formatting guidelines? [closed]
Coding standards are common in any software development organization, but how important are they to follow? I can understand the need for some consistency, but when dealing with simple things like ...
49
votes
17answers
5k views
Working on someone else's code
I have hardly a year's experience in coding. After I started working, most of the time I would be working on someone else's code, either adding new features over the existing ones or modifying the ...
26
votes
3answers
3k views
if ('constant' == $variable) vs. if ($variable == 'constant')
Lately, I've been working a lot in PHP and specifically within the WordPress framework. I'm noticing a lot of code in the form of:
if ( 1 == $options['postlink'] )
Where I would have expected to ...
1
vote
2answers
293 views
Arguments for conforming to PSR-2
I am trying to convince the lead developer of an open-source project I'm contributing to, to conform to the PSR standards (PSR-2 in particular) created by the PHP Framework Interop Group.
He is ...
3
votes
3answers
473 views
Which is the better: a <= b or a < b+1 [closed]
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 ...
3
votes
2answers
1k 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 ...
2
votes
4answers
2k 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 ...
0
votes
4answers
441 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, ...
3
votes
3answers
1k 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 ...
65
votes
19answers
12k 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 ...
17
votes
13answers
2k views
Is it an appropriate use of #define to make typing repeated code easier?
Is there any view on whether using the #define to define full lines of code for simplifying coding is good or bad programming practice? For example, if I needed to print a bunch of words together, I'd ...
0
votes
1answer
80 views
Writing contextually related control statements next to each other [duplicate]
Recently I've been messing around with this. Note that I'm not using LINQ because while this could be easily be done that way, I could do this in any language.
Allow me to exemplify:
foreach ( var i ...
1
vote
3answers
361 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 ...
3
votes
3answers
943 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 ...
6
votes
3answers
304 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 ...
3
votes
2answers
304 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 ...
7
votes
7answers
1k 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 ...
-1
votes
1answer
513 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 ...
2
votes
2answers
512 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 ...
11
votes
4answers
473 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 && ...
4
votes
5answers
512 views
How can I avoid mistakes using the same variable name again?
This isn't a rare case and occurs with me often and I spent countless time trying to debug the code.
Latest example, this PHP code where I used $email for the parameter and for object as well.
...
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 ...
0
votes
1answer
686 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 ...
8
votes
1answer
660 views
Are there well-known PowerShell coding conventions?
Are there any well-defined conventions when programming in PowerShell?
For example, in scripts which are to be maintained long-term, do we need to:
Use the real cmdlet name or alias?
Specify the ...
2
votes
3answers
273 views
using “IS” is better or checking for “NOT NULL”
In C#.NET language: This style of coding is recommended or the one below it?
if (sheet.Models.Data is GroupDataModel)
{
GroupDataModel gdm = ...
1
vote
4answers
428 views
Long lines of text in source code [duplicate]
Possible Duplicate:
Is the 80 character limit still relevant in times of widescreen monitors?
I used to set a vertical line set at 80 characters in my text editor and then I added carriage ...
10
votes
5answers
516 views
Should coding standards be enforced by the continuous integration server?
Should coding standards/style be enforced by the continuous integration server running static analysis tools (ex. PMD, StyleCop/FxCop) and failing the build if the standards are not followed? What ...
8
votes
7answers
1k views
Why would an employer ask for a 'long' code sample?
What would a large project that spanned multiple files and >1000 lines show to an employer that a few individual files and a couple hundred lines couldn't capture?
4
votes
2answers
294 views
What should my “large codebase sample” look like?
If an employer asks for a large code sample, one for an entire project, what characteristics should the project have to show architectural skills and the ability to manage a large codebase?
For ...
6
votes
3answers
242 views
How should I get my code ready for OpenSourcing it and putting it on GitHub?
In a few weeks, my project is going to be finished and I want to start getting my code ready for other people to use it.
I am going to be posting everything to GitHub so people can tweak it and ...
7
votes
6answers
1k views
Indentation: is there any evidence to show whether 2 or 4 spaces is more readable? [closed]
At the company I work for, we're trying to standardize our development practices, and we want to make the right call regarding indentation.
Is there any empirical evidence (preferably research ...
5
votes
2answers
558 views
Should you create a class within a method?
I have made a program using Java that is an implementation of this project: http://nifty.stanford.edu/2009/stone-random-art/sml/index.html. Essentially, you create a mathematical expression and, ...
8
votes
6answers
9k views
Single quotes vs double quotes [closed]
I just started a job where I'm writing Python after coming from a Java background, and I'm noticing that other developers tend to quote strings using single quotes ('') instead of double quotes (""). ...
3
votes
4answers
290 views
Create new variable or make multiple chained calls?
What is the best way to get this attributes, thinking in performance and code quality?
Using chained calls:
name = this.product.getStock().getItems().get(index).getName();
id = ...
62
votes
17answers
4k views
Recommendations for teaching junior programmers good coding style
I am a big fan of good coding style, producing clean, clear code that runs well and is easy to use and integrate into larger systems. I believe that we programmers are essentially craftspeople who ...