Questions for best practices for writing high quality code.

learn more… | top users | synonyms

-3
votes
2answers
182 views

Why ever use exception throw (in C#) except for Class Library development? [duplicate]

Why would I ever throw exceptions in code? (except for one specific scenario where I am developing a class library which the consumers of it, will not want / be able to change). To be more specific, ...
2
votes
2answers
244 views

Checking program robustness using static code analysis

(Building on this question) If you have a static code analyser such as Checkstyle, is it possible to to relate any of the stuff that it checks for to actual robustness? Some of the things that ...
22
votes
8answers
957 views

Is it better to use pre-existing bad practices, or good practices that don't fit well with old code?

I was thinking of this because I was trying to write an extension for an existing 3rd party software, and their database is horribly denormalized. I needed to use their existing tables and add a bunch ...
2
votes
2answers
177 views

Passing fields (instance variables) by arguments (parameters) inside an object - does it make sense? [duplicate]

I believe this is language agnostic question - if it's not then please correct me. Let's say I have a class (code snippet is a kind of 'pseudo code') class Car: private steering_wheel private ...
134
votes
31answers
14k views

Is micro-optimisation important when coding?

I recently asked a question on Stack Overflow to find out why isset() was faster than strlen() in PHP. This raised questions around the importance of readable code and whether performance improvements ...
32
votes
9answers
3k views

How clean should new code be? [duplicate]

I'm the lead designer in our team, which means I'm responsible for the quality of the code; functionality, maintainability and readability. How clean should I require my team members' code to be if ...
29
votes
12answers
6k views

How much Code Coverage is “enough”?

We are starting a push for code coverage here at my work, and it has got me to thinking.... How much code coverage is enough? When do you get to the point of diminishing returns on code coverage? ...
230
votes
25answers
32k views

How do you know you're writing good code? [duplicate]

I love programming. I've been messing around with code since I was a kid. I never went the professional route, but I have coded several in-house applications for various employers, including a project ...
36
votes
4answers
35k views

Why is #include <iostream.h> bad?

I was reading another thread where a guy asked about C++ books for beginners, and one of the programmers answering wrote this: Some warnings: avoid all books that present an "hello world" stating ...
0
votes
0answers
67 views

Is there a school of thought where while(1) or while (true) is a code smell? [duplicate]

My employer requires code reviews for all devs, and new employees are required to to have their code reviewed by a senior dev. Initially, trainees get to pick a small project they are working on and ...
1
vote
2answers
227 views

Code quality : what's the worth of the looking at the ifs?

We've all seen discussions on the ideal length of a method. My favourite litmus test for code quality is to look at the "if" statements, to see whether the values being tested belong to the current ...
-2
votes
1answer
203 views

Searching for 2 numbers that equal 10 [closed]

During an interview today I was asked to write a function that accepted an array of integers and return the positions of two values in the array that the sum was 10. My code was C# public string ...
113
votes
16answers
9k views

How can I convince management to deal with technical debt?

This is a question that I often ask myself when working with developers. I've worked at four companies so far and I've become aware of a lack of attention to keeping code clean and dealing with ...
21
votes
10answers
4k 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
5answers
551 views

Is this taking DRY too far? [duplicate]

A colleague and I are working together on a Meteor app. One of us thinks that the following code in two places should be wrapped in a function to avoid duplication -- the other thinks that it leads ...
8
votes
6answers
2k views

How to implement a property on class A which refers to a property of a child object of class A

We have this code which, when simplified, looks like this: public class Room { public Client Client { get; set; } public long ClientId { get { return Client ...
0
votes
3answers
885 views

What code smell best describes this code? [closed]

Suppose you have this code in a class: private DataContext _context; public Customer[] GetCustomers() { GetContext(); return _context.Customers.ToArray(); } public Order[] GetOrders() { ...
4
votes
2answers
146 views

Who is the Owner of Information? Memento vs. Originator

Imagine for a second that I'm implementing the Memento Pattern, using the following classes. Classes An Originator class that has public and private, properties and fields respectively A Memento ...
2
votes
1answer
118 views

How to properly manage “business” constants with AngularJS?

I'm working with AngularJS on a browser game and I have a bunch of "business" constants. These constants will be often updated during game testing (game balancing) and are used by different ...
45
votes
11answers
5k views

How do I approach a coworker about his or her code quality? [duplicate]

I work on a new venture at a large enterprise software company (3000+ programmers). In my group, we have a bunch of projects and people usually work on several projects over the course of a year. I ...
0
votes
1answer
53 views

Dealing with data containing integer overflow, rollover

I am writing a small matlab function to analyze data from a laser probe. The data to be analyzed is basically: x-data: Position. y-data: Laser (light) intensity. ...
2
votes
2answers
103 views

How to reduce redundancy in a service implemented using multilayer architecture while maintaining consistency across the system?

Currently our service is implemented using a multilayer architecture dividing the whole service into three: API Business Persistence However this introduces a lot of redundancy within our system. ...
6
votes
3answers
374 views

Fine Line: Readability Vs Speed [duplicate]

Is there a line between readability vs compile or processing speed? Aside from the extreme cases, I wouldn't think it would be even worth saving that little bit extra in favor of legibility... For ...
4
votes
1answer
159 views

Should a web service return an error message if it receives unknown parameters?

I have a web service which allows to retrieve users: http://example.com/users. It returns a list of users. That service accepts a number of parameters (age, gender) to select which users to retrieve. ...
9
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 ...
1
vote
1answer
164 views

Right-aligning code [closed]

I recently was looking for a CSS solution to vertically-align elements, and I found one here. One thing that I thought was nice was the right-justified code; example: .vertical-center { // ... ...
2
votes
3answers
70 views

Order of terms in a conditional expression [duplicate]

Consider the following loop (in Swift - but my question is language independent): var index = standardizedTimeSpans.count - 1 while index >= 0 && timeSpan < ...
2
votes
0answers
73 views

Is a long XSLT file a code smell? [closed]

Is a long XSLT file a code smell? In imperative programming languages it's generally acknowledged that very large classes and/or sub-routines are an indication of possible problems, e.g. a class ...
0
votes
2answers
413 views

Is cyclomatic complexity density a good software quality metric? [duplicate]

Where I define Cyclomatic complexity density as: Cyclomatic complexity density = Cyclomatic complexity / Lines of code I was reading previous discussions about cyclomatic complexity and there seems ...
2
votes
2answers
134 views

What is the proper way to handle this workflow in TFS

A client of mine is using TFS and asks people to operate in this manner: The developer in India writes the first draft of code The code is published to a workspace (eg 10.1.1.1\TFSName ...
0
votes
2answers
105 views

Built-in the separate thread execution inside of the method or wrap the method by the thread

Let assume, I have some resource and time-consuming code, which I want to arrange as a separate method. In order to optimize the performance, this code should be executed in the separate thread. Now ...
16
votes
6answers
689 views

How can I judge whether a project is particularly complex or if I'm just slow in picking it up?

I'm making little progress on a major project. The source is massive, many layers of objects, macaroni code, double-diamond graphs of multiple inheritance, half-baked features frozen when the ...
14
votes
14answers
2k views

how to find out if spelling mistakes in source code are a serious issue or not? [closed]

I find very troubling amount of spelling mistakes I see everyday in our codebase, from which I will reproduce a very short but representative example: ArgumnetCount Timeount Gor message from queue ...
47
votes
7answers
5k views

What is the actual value of a consistent code style

I am part of a consultant team implementing a new solution for a customer. I am responsible for the majority of code reviews on the client-side codebase (React and javascript). I have noticed that ...
7
votes
6answers
572 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 ...
1
vote
0answers
76 views

Managing interdependent project reference in solution file

Context for question I am working on a legacy product, that has multiple projects - Class libraries, websites, windows services, web services etc.. I have a single solution file that contains all ...
1
vote
2answers
171 views

What about source code homogeneity?

As time passes I think that one valuable aspect of maintenable and escalable software is to be homogeneous. The same problem should be solved in the same way everywhere in the application. If there is ...
8
votes
3answers
616 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 ...
0
votes
1answer
94 views

Is a number used only once and directly bound to a function parameter a magic number? [duplicate]

I want to avoid numbers used directly in expressions without obvious meaning. However, if a number is used only once, as an argument passed into a function, and that number can be easily changed ...
28
votes
9answers
3k views

What are the disadvantages of writing code before writing unit tests?

I have always seen the recommendation that we should first write unit tests and then start writing code. But I feel that going the other way is much more comfortable (for me) - write code and then the ...
12
votes
7answers
584 views

Where do you draw the line between quantity and quality? [duplicate]

My manager has talked with me and says that the quality of my work is excellent, but I need to step up the quantity of how much I crank out. I've only been working for a couple of years, so I still ...
6
votes
6answers
770 views

What are the most used pattern to manage a lot of interconnected parameters?

I recently start to work on an application that drive different measurement device. Before the user start a measure, she sets the parameters of it. Actually, considering all measurements type there ...
3
votes
2answers
1k views

Class becoming God Object what pattern to use

I am developing Android app and my MainActivity is becoming God Object. By the way native Activity class implementation is some sort of God Object already. The problem is that my activity class is ...
34
votes
6answers
4k views

How can I write unit tests that simplify feature implementation? [duplicate]

I'm a newbie to working in software development and I read a lot about how cool unit tests are. Now, I've made my first steps into a project where I'm working with a number of equally unexperienced ...
10
votes
6answers
980 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 ...
58
votes
18answers
6k views

How to tell your boss that his programming style is really bad? [duplicate]

I'm a student and in my spare time I'm working for a big enterprise as Java developer. The job is good, but the problem is, my boss writes very strange code. I don't want to complain, but some issues ...
13
votes
2answers
1k views

Is an NPath complexity of over sixteen octillion realistic? Or have I broken the tool?

I have just measured a large chunk of PHP code (1153 lines) using PHPMD (http://phpmd.org/) and it tells me the code has an NPath complexity of 16244818757303403077832757824. That looks like a ...
34
votes
9answers
2k views

At what point does “constructive” criticism of your code become unhelpful?

I recently started as a junior developer. As well as being one of the least experienced people on the team, I'm also a woman, which comes with all sorts of its own challenges working in a ...
0
votes
0answers
37 views

Defensive Programming - “Return” placement [duplicate]

Sometimes I see myself writing code in the following way: if(value == null) return null; //... I will have here as many defensive conditions (and returns) as I need //... Continue to execute method ...
54
votes
9answers
10k views

Bad sign if nobody can comprehend one's code? [duplicate]

If a coder writes code that nobody other than he can understand, and code reviews always end with the reviewer scratching his head or holding their head in their hands, is this a clear sign that the ...