Questions for best practices for writing high quality code.

learn more… | top users | synonyms

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
2answers
1k views

What is logical cohesion, and why is it bad or undesirable?

From the c2wiki page on coupling & cohesion: Cohesion (interdependency within module) strength/level names : (from worse to better, high cohesion is good) Coincidental Cohesion : ...
8
votes
2answers
1k 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
8answers
946 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 ...
26
votes
9answers
2k views

Simple vs Complex (but performance efficient) solution - which one to choose and when?

I have been programming for a couple of years and have often found myself at a dilemma. There are two solutions - one is simple one i.e. simple approach, easier to understand and maintain. It ...
5
votes
4answers
544 views

Method flags as arguments or as member variables?

I think the title "Method flags as arguments or as member variables?" may be suboptimal, but as I'm missing any better terminology atm., here goes: I'm currently trying to get my head around the ...
2
votes
1answer
623 views

Code Measuring and Metrics Tools? [duplicate]

I'm in the process of setting up a build server for personal projects. This server will handle all the normal CI stuff, including running large suites of tests (unit, integration, automated UI). ...
2
votes
6answers
329 views

C: What is a good source to teach standard/basic code conventions to someone newly learning the language? [closed]

I'm tutoring someone who can be described as a rank newcomer in C. Understandably, she does not know much about coding conventions generally practiced, and hence all her programs tend to use single ...
13
votes
4answers
1k views

How do you explain Separation of Concerns to others?

If you had a colleague who didn't understand the benefits of Separation of Concerns, or didn't understand it quite enough to apply consistently in their daily work, how would you explain it to them?
3
votes
3answers
2k views

What defines code readability? [duplicate]

Possible Duplicate: How would you know if you've written readable and easily maintainable code? It is often said that readability is perhaps the most important quality-defining measure ...
7
votes
3answers
1k 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 ...
10
votes
3answers
1k views

Experiments correlating code metrics to bug density

I'm wondering if someone has done some experiments correlating code metrics (SLOC, Cyclomatic Complexity, etc) with bug density in Object Oriented applications. I'm not looking for experiments that ...
4
votes
3answers
732 views

Is it easier to write robust code in compiled, strictly-typed languages? [closed]

I'd like to read the opinion of experts on whether compiled, strictly-typed languages help programmers write robust code easier, having their backs, checking for type mismatches, and in general, ...
3
votes
3answers
439 views

Is there a limit on how many global consts are used before an application is considered bad programming?

Basically, I develop websites, some large with many crud operations, etc... However I've gotten into the habit of storing re-usable data as a constant in my PHP applications I currently have 44 ...
9
votes
2answers
662 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 ...
9
votes
11answers
8k views

Why is using System.out.println() so bad? [closed]

Of course, it is very good use to use a logging framework for the error messages or warnings. But sometimes I use System.out.println() if I want to try something new in a short time. Is it really so ...
1
vote
1answer
173 views

Condition based function declarations

I recently came across a weird piece of code if(foo == bar){ function foo_bar(){ // Function definition } } Is this a good practice of coding ?
17
votes
5answers
1k views

Is it OK for a function to modify a parameter

We have a data layer that wraps Linq To SQL. In this datalayer we have this method (simplified) int InsertReport(Report report) { db.Reports.InsertOnSubmit(report); db.SubmitChanges(); ...
4
votes
3answers
427 views

how do I know I've split my program into too small pieces?

Ever since entering the world of programming, I've been bombed with tips like "file should be only x lines", which is fair since new programmers tend to stuff everything into one file. But, having ...
10
votes
5answers
391 views

In which fields does quality of the software product matter as much as the completion time?

Someone told me that if the software product meets clients expectations, it is good quality. But I've worked with Interaction Designers (the same kind of people who made Gmail's interface and ...
10
votes
5answers
487 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 ...
3
votes
1answer
825 views

How often should we launch SONAR analysis?

I successfully installed Jenkins and then Sonar to go with continuous integration. The firsts reports are not that good in term of rules violations ,comments, code duplication ... I set Jenkins to ...
9
votes
5answers
945 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 ...
23
votes
17answers
7k views

What are useful metrics for source code? [closed]

What are useful metrics to capture for source code? How can metrics, like for example (Executable?) Lines of Code or Cyclomatic Complexity help with quality assurance or how are they beneficial in ...
7
votes
4answers
955 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 ...
50
votes
7answers
3k views

Is there something wrong with how we're doing version control?

I work with a team of programmers as the business analyst. We just released version 2.0 of our product and are working on the next version to be released in 3 months (it's an internal software ...
32
votes
19answers
2k views

What do you say in a code review when the other person built an over complicated solution? [closed]

The other day I reviewed code someone on my team wrote. The solution wasn't fully functional and the design was way over complicated-- meaning stored unnecessary information, built unnecessary ...
0
votes
5answers
386 views

Does “Property” in C# cost much?

I have a class created in some namespace, like SomeNameSpace.SubNameSpace.StaticClassName Here is a code snippet from other code file where I want to use this class many more times, so I created a ...
0
votes
4answers
253 views

Is 'Protection' an acceptable Java class name

This comes from a closed thread at stack overflow, where there are already some useful answers, though a commenter suggested I post here. I hope this is ok! I'm trying my best to write good ...
21
votes
7answers
1k views

Quality of Code in unit tests?

When writing unit tests, is it worth spending the extra time to make the code have good quality and readability? When writing tests I often break the Law of Demeter, for faster writing and to avoid ...
26
votes
6answers
946 views

Unit and Integration testing: How can it become a reflex

All the programmers in my team are familiar with unit testing and integration testing. We have all worked with it. We have all written tests with it. Some of us even have felt an improved sense of ...
2
votes
7answers
682 views

After how much line of code a function should be break down?

While working on existing code base, I usually come across procedures that contain Abusive use of IF and Switch statements. The procedures consist of overwhelming code, which I think require ...
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 = ...
16
votes
9answers
1k views

Are too many assertions code smell?

I've really fallen in love with unit testing and TDD - I am test infected. However, unit testing is normally used for public methods. Sometimes though I do have to test some assumptions-assertions ...
17
votes
10answers
2k views

Is 100% code coverage a pipe dream?

Is it feasible to expect 100% code coverage in heavy jquery/backbonejs web applications? Is it reasonable to fail a sprint due to 100% coverage not being met when actual code coverage hovers around ...
1
vote
6answers
1k views

Setters or constructor for many variables? [duplicate]

Possible Duplicate: Are there guidelines on how many parameters a function should accept? I have got class with 30 variables (it is application form), so I wonder what is the best practice ...
2
votes
5answers
1k views

Is automatically checking code quality via metrics possible?

For several years now I am a big fan of using static code analysis tools for checking the source code quality. We are mostly doing C# development so NDepend was the best way to go for me. Most of the ...
42
votes
11answers
6k views

Should I reuse variables?

Should I reuse variables? I know that many best practice say you should not do it, however later when different developer is debugging the code and have 3 variables that look a like and only ...
15
votes
9answers
1k views

Dealing with a developer continuously ignoring edge cases in his work

I have an interesting, fairly common I guess, issue with one of the developers in my team. The guy is a great developer, work fast and productive, produces fairly good quality code and all. Good ...
6
votes
9answers
895 views

Review quality of code [duplicate]

I have been asked to quality review two code bases. I've never done anything like that, and need advice on how to perform it and report it. Background There are two providers of code, one in VB and ...
10
votes
3answers
1k views

What is the pattern name for using method chaining to build an object?

I frequently use a pattern where I using method chaining to setup an object, similar to a Builder or Prototype pattern, but not creating new objects with each method call, instead modifying the ...
0
votes
2answers
1k views

What are the things that you consider in reviewing an iOS source code? [closed]

We're going to do some peer reviews for our iOS projects. We're kind of inexperienced at reviewing each other's codes. The iOS developers attending the reviews will be from other projects, since ...
1
vote
3answers
5k views

how to nicely use constant std::string in c++

In my current code project, there is an awful lot of constant strings I use to print out error messages. Hardcoding such strings is generally considered to be bad practice. Now I'm searching for a ...
4
votes
6answers
504 views

How to deal with over-complication?

I often catch myself doing code unnecessarily complicated (sad but true). Is there any set of rules, discipline, etc to help avoid that? (excluding the KISS principle, because I know it but often ...
21
votes
14answers
3k views

Why do so many developers believe performance, readability, and maintainability cannot coexist?

While responding to this question, I began to wonder why so many developers believe a good design should not account for performance because doing so would affect readability and/or maintainability. ...
5
votes
6answers
384 views

How to set up a one-man research in the difference between BDD and Waterfall?

Earlier, I asked a question about how to measure the quality of a project. The outcome of that question was that the quality of the project can be divided into two parts: Internal quality (code ...
8
votes
5answers
685 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 ...
14
votes
10answers
3k views

Do ALL your variables need to be declared private? [duplicate]

Possible Duplicate: Why do we need private variables? I know that it's best practice to stay safe, and that we should always prevent others from directly accessing a class' properties. I ...
9
votes
9answers
795 views

Does code generation increase the code quality?

Arguing for code generation, I am looking for some examples of ways in which it increases code quality. To clarify what I mean by code generation, I can talk only about a project of mine: We use XML ...