Questions for best practices for writing high quality code.

learn more… | top users | synonyms

10
votes
7answers
2k views

Is it beneficial to read old Java programming books? [closed]

Many of my Java books are 5 - 10 years old. Does it still help to read them, or should I use something within 2 years.
10
votes
6answers
861 views

Which is more maintainable — boolean assignment via if/else or boolean expression?

Which would be considered more maintainable? if (a == b) c = true; else c = false; or c = (a == b); I've tried looking in Code Complete, but can't find an answer. I think the first is more ...
10
votes
5answers
504 views

Methods for testing a very large application

I have a PHP app which is very large. There are usually 2-3 developers working on it full time and we are getting to the point where we are making changes and creating bugs (cough features!). The ...
10
votes
6answers
1k views

Need to make my code more readable to the other programers in my team

I am working a project in delphi 7 and I am creating a installer for the application, there are Three main parts. PostgreSQL installation/uninstallation myapplication ( setup of myapplication is ...
10
votes
5answers
776 views

Is adhering to one assert per test foolish consistency in this case?

I have a class that I'm testing. The class has a function: apply(List<IRule> rules, List<ITarget> targets); In one test I want to ensure that each target has been passed to one rule, a ...
10
votes
5answers
5k views

Why have a method that returns a bool/int and has the actual object as an output parameter?

I see the following code pattern all over the place in my company's codebase (.NET 3.5 application): bool Foo(int barID, out Baz bazObject) { try { // do stuff bazObject ...
10
votes
7answers
543 views

How do I go from being able to write code to being a good developer?

I'm frustrated by the lack of concrete explanations on how to go from being able to script (bash, awk) and write simple applications (c, php, python) to designing and developing larger, more ...
10
votes
9answers
293 views

What mistakes in managing software products must be avoided to keep people from hating the vendor?

A previous question about why people hate Microsoft was closed. This is an attempt at a somewhat more constructive question along the same general line. This one is both broader and narrower though. ...
10
votes
6answers
3k views

Prefer class members or passing arguments between internal methods?

Suppose within the private portion of a class there is a value which is utilized by multiple private methods. Do people prefer having this defined as a member variable for the class or passing it as ...
10
votes
3answers
2k views

How to write manageable code with functional programming?

I just started with functional programming (with JavaScript and Node.js) and from the look of things it looks as if the code I am writing would grow to be one hell of a code base to manage, when ...
9
votes
14answers
1k views

How do I (tactfully) tell my project manager or lead developer that the project's codebase needs serious work?

I just joined a (relatively) small development team that's been working on a project for several months, if not a year. As with most developer joining a project, I spent my first couple of days ...
9
votes
7answers
3k views

What is beautiful code in C++, and why do most programmers care that much?

As most projects use a C++ API, they deal with constraints of the API and constraints of the project itself. I'm a beginner at programming, I don't like to use OOP at all because nobody clearly ...
9
votes
7answers
970 views

Entry level engineer question regarding memory management

It has been a few months since I started my position as an entry level software developer. Now that I am past some learning curves (e.g. the language, jargon, syntax of VB and C#) I'm starting to ...
9
votes
5answers
1k views

Is it bad coding practice to create something in a get if it does not exist?

So I have a webservice that has something like a getAccount where it would return an identifier to the account if it got it, else throw an exception. The client will always want to create an account ...
9
votes
8answers
370 views

As a student, what techniques used by faculty helped you learn the most? [closed]

I'm getting into the more advanced programming classes at my university, and feel like I am running into some obvious shortcomings with producing quality code. For example, my data structures class ...
9
votes
7answers
3k views

Keep my classes and methods as small as possible?

A few days ago, I was talking to a Software Engineering PhD candidate and at some point she said to me: Keep your classes and methods as small as possible And I wonder if this is always a good ...
9
votes
5answers
704 views

How to handle flag in multiple if-else's

I seem to see this often enough in my code and others. There's nothing about it that seems horribly wrong, but it annoys me as it looks like it can be done better. I suppose a case statement, might ...
9
votes
7answers
6k views

What is the difference between Static code analysis and code review?

I just wanted to know what the difference is between static code analysis and code review. How are each of these two done? More specifically, what are the tools available today for code review/static ...
9
votes
8answers
745 views

How to balance code quality vs strong developer personalities

On code reviews at work I have been seeing code & patterns that I consider "clever" though not necessarily adding to the overall quality or maintainability of the code base. I point this out on my ...
9
votes
4answers
2k views

In MVC is it considered good practice to have private, non-action, functions in a controller class?

Sometimes action functions in the controller class can become huge and nasty, with many-many lines of code to simply control the flow of data from the Model to the View. At some point these huge ...
9
votes
2answers
600 views

How to deal with too much pragmatism in the project? [duplicate]

My team and I took over a medium sized codebase over a year ago when the previous tech lead left the company. Originating from the lack of man power I fear we favored pragmatic solutions over best ...
9
votes
5answers
3k views

How strictly do you follow the “No Dependency Cycle” rule (NDepend)

A bit of background: As a team lead I use NDepend about once a week to check for the quality of our code. Especially the test-coverage, lines of code and cyclomatic complexity metrics are invaluable ...
9
votes
4answers
323 views

Should I insist that we perform code reviews before merging back to trunk?

Requested re-post from StackOverflow: I'm working in a small development time with very limited time for development. We develop a tool that is important for the result of our work, but not used ...
9
votes
2answers
812 views

Unit Testing: “It's a code smell if you're refactoring and there are no collaborators”?

I'm reading The Art of Unit Testing by Roy Osherove. I'm at section 7.2 Writing maintainable tests where the author has this note about code smell: NOTE: When you refactor internal state to be ...
8
votes
6answers
842 views

Are there any benefits to checking in commented out code into version control? [duplicate]

I've found, what I personally believe to be a bad habit that a lot of developers seem to have adopted. Code in various places in the applications I have seen are commented out (lots of it) and checked ...
8
votes
8answers
1k views

Copy-and-Pasted Test Code: How Bad is This?

My current job is mostly writing GUI test code for various applications that we work on. However, I find that I tend to copy and paste a lot of code within tests. The reason for this is that the areas ...
8
votes
5answers
853 views

Is it OK to repeat code for unit tests?

I wrote some sorting algorithms for a class assignment and I also wrote a few tests to make sure the algorithms were implemented correctly. My tests are only like 10 lines long and there are 3 of ...
8
votes
7answers
1k views

Why would an employer ask for a 'long' code sample? [closed]

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?
8
votes
6answers
2k views

Warranty or guarantee clause for code breaking

Should I guarantee or add a warranty clause to my contract in the event code breaks or an anomaly occurs outside the client's hand or act of God? If so, what should that language say?
8
votes
2answers
1k 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 ...
8
votes
6answers
718 views

How to write good code with new stuff? [closed]

I always try to write easily readable code that is well structured. I face a particular problem when I am messing around with something new. I keep changing the code, structure and so many other ...
8
votes
3answers
882 views

Are there any good use-cases for variable variables?

Today I encountered this little PHP gem called variable variables. $literal = "Hello"; $vv = "literal"; echo $$vv; // => prints "Hello" Are there actually any real use-cases for this language ...
8
votes
6answers
784 views

If you learned formal methods for software, how useful have you found it?

If you have been trained in the use of formal methods (FM) for programming: How useful have you found it? What did your FM training involve (e.g. a course, a book)? What FM tools do you use? ...
8
votes
4answers
506 views

How can you get constructive criticism for your code?

My team rarely does code review, mainly because we don't have enough time and people lack the energy and will to do so. But I would really like to know what people think about my code when they read ...
8
votes
4answers
2k views

How should I test my TEST code?

One of the few things that most software developers agree on is that you shouldn't rely on code to work correctly unless you test it. If you don't test it, it may have hidden bugs that are only ...
8
votes
5answers
411 views

When developing on an old code base, should I use Best Practices or go for Consistency [duplicate]

Possible Duplicate: Code maintenance: keeping a bad pattern when extending new code for being consistent, or not ? As my experience in programming increases with each project, I look back ...
8
votes
3answers
510 views

Cleanest way to write logically procedural software in an OO language

I'm an electrical engineer and I don't know what the hell I'm doing. Please save the future maintainers of my code. Recently I've been working on a number of smaller programs (in C#) whose ...
8
votes
3answers
869 views

Is 'using' appropriate in a context where there is nothing to dispose?

In C#, using statement is used to dispose in a deterministic manner the resources without waiting for garbage collector. For example, it may be used to: Dispose SQL commands or connections, Close ...
8
votes
6answers
359 views

Is looking at random code snippets useful to quickly determine the quality of a project?

To get an idea of the quality of a project that I've never seen before (usually open source projects that I'm considering whether or not to use), I often start by opening random files and eyeballing ...
8
votes
5answers
212 views

Gathering all data in single iteration vs using functions for readable code

Say I have an array of runners with which I need to find the tallest runner, the fastest runner, and the lightest runner. It seems like the most readable solution would be: runners = getRunners(); ...
8
votes
2answers
2k views

How is technical debt best measured? What metric(s) are most useful? [duplicate]

Possible Duplicate: How can I quantify the amount of technical debt that exists in a project? If I wanted to help a customer understand the degree of technical debt in his application, what ...
8
votes
4answers
197 views

Advice/Approach for distilling homogenous code and building common code for a team

I work for the State of California. Our programming team in my opinion is not really a 'team' in that we usually work solo on projects throughout the application/systems complete life-cycle. The end ...
8
votes
1answer
358 views

Are there any empirical studies about the effects of commenting source code on software quality, maintainability and developer productivity? [closed]

I am an advocate of commenting on source code and documenting software products. It is my personal experience and observation that working on source code that is rigorously commented has helped me in ...
8
votes
6answers
2k views

Should we exclude code for the code coverage analysis?

I'm working on several applications, mainly legacy ones. Currently, their code coverage is quite low: generally between 10 and 50%. Since several weeks, we have recurrent discussions with the ...
8
votes
3answers
2k views

What is the difference (if any) between (null != $object) and ($object != null) when using PHP?

I am used to Java and therefore always think conditions are interpreted from left to right, i.e. there is a vital difference in null != $obj and $obj != null Now this seems not to be the case with ...
7
votes
14answers
1k views

Are software developers who ignore quality/standards better for the company?

Do software developers who choose not to put code optimization, standards and best practices as top priority, create more useful code than those developers who choose to worry about optimization, ...
7
votes
10answers
1k views

Overcome clumsiness in writing code

I believe this is a little related with this question: How to be a zero-bug programmer?. But I believe this is more regarding clumsiness in programming because I know it is impossible to become a zero ...
7
votes
6answers
5k views

What's the benefit of having a private repository for personal projects?

So I just created my first GitHub repository and started to wonder if there would be any reason why somebody shouldn't post their code. I don't mean the obvious, such as code that is IP of somebody ...
7
votes
6answers
560 views

What can go wrong with composing a method name out of a string?

I have a piece of code that composes method name to call from a string parameter. I don't feel it's a good thing to do but I'm not sure what can go wrong with this. Here is a simplified snippet of ...
7
votes
5answers
1k views

Is code duplication a necessary evil in C?

I'm rather new to C, and I'm wondering if code duplication is a necessary evil when it comes to writing common data structures and C in general? I could try to write a generic implementation for a ...