Questions for best practices for writing high quality code.

learn more… | top users | synonyms

1
vote
0answers
18 views

Prefer self documenting code over cyclomatic complexity?

I'm interested in which approach to prefer. Consider some code which retrieves a translation for some text. It has to respect these constraints: Return translation only if the text will be used on a ...
-3
votes
2answers
98 views

What is well written code? [on hold]

Is code that runs fast but written with a bad and hard to understand syntax, good code? Is code that runs slowly but written with a good and easy to understand syntax, good code?
2
votes
1answer
117 views

Do extracting piece of logic to function improve or reduce code readability?

If there is some code that needs to be implemented across multiple controllers (lets say, 10), e.g.: // Inside a controller function var myField = null; var response = service.callBackend(function(){...
0
votes
1answer
52 views

Should I always use prefix private methods with an underscore in Python?

Prefixing methods and members with an underscore indicates internal use. For simple classes, I sometimes find the easier reading and typing of self.foo outweighing the indent of self._foo. Especially ...
2
votes
2answers
62 views

How to avoid code duplication or cascaded changes and major refactoring in business logic layer?

Let's say, I have created a business logic layer service (or a handler in Command/Query pattern) with a method DoSomething which processes a bunch of entities and stores them in database. Later on, ...
5
votes
2answers
126 views

Create a new variable to shorten code

I have often wondered about the implications of shortening code by assigning temporary variables with shorter names to data accesses with long names. It's best illustrated by an example (in Ruby, but ...
17
votes
7answers
620 views

Peer / Code Review Frustrations

I wouldn't call myself a superstar dev, but a relatively experienced one. I try to keep code quality to a high level, and am always looking to make improvements to my coding style, try to make code ...
165
votes
20answers
20k views

A large part of my code has a major design flaw. Finish it off or fix it now?

I am a high school student working on a C# project with a friend of mine with about the same skill level as me. So far, we have written roughly 3,000 lines of code and 250 lines of test code in a span ...
5
votes
3answers
325 views

Is nesting try-catch statements still a code smell if nested within a loop?

I have heard that nesting try-catch statements can often be a code smell, so I'm wondering whether this situation is an exception. If not, what would be some good ways to refactor? My code looks like ...
0
votes
1answer
38 views

Static analysis criteria different for various parts of solution

We have quite a large project where and tend to apply risk based approach to stringency of unit tests and code reviews. E.g. components classified as A need to have higher coverage than components ...
-2
votes
1answer
101 views

Duplicate code to avoid performance decrease due to function calls? [closed]

I have a simple list in Java that I need to search using one of two methods. The first method simply returns the position in the list of the first matching element. The second filters out any elements ...
7
votes
4answers
238 views

Code design: Duplicate code or good implementation

I'm working on application in C#, where I need to serialize and deserialize some classes into/from XML. This operations will be implemented in Class Library. I chose XMLSerialization class to ...
1
vote
2answers
110 views

Get variable with accessor method or just use dot notation?

So, I recently noticed something on some code I was writing. I could get a variable for a different class/object using dot notation to get the variable: object.someVarable or I could do it the way I ...
1
vote
1answer
64 views

how to measure defects per KLOC

I have been reading on the internet about the metric "number of bugs per 1000 lines of code" and what would be a good number. However, I wonder how someone would compute such a metric? The reason a ...
0
votes
0answers
32 views

What is the common practice of calculating average length of identifiers

Quoted from Ian Sommerville's Software Engineering(9th ed), page 673: This is a measure of the average length of identifiers (names for variables, classes, methods, etc.) in a program. The ...
-2
votes
1answer
151 views

Is this unprofessional when “Wappalyzer” sees all my technology? [closed]

After I installed "Wappalyzer", extension wich display technology, wich site using. I checked many sites and in most of cool projects, like "Youtube", "Github","stackoverflow" etc, wappalyzer display ...
4
votes
1answer
250 views

Help in writing more generic code

I'm doing a php MVC project using code igniter. I have two models, a and b. Each class contains four functions (insert, delete, update and view) and their implementations are almost the same with ...
6
votes
4answers
265 views

Is using nested function calls a bad thing?

In a recent homework assignment I ended up calling my functions in an ugly way uglyReceipt(cashParser(cashInput())) the program itself worked perfectly but I still felt like I was doing something ...
58
votes
5answers
7k views

Why are large amounts of magic numbers acceptable in CSS and SVGs?

Often times I see questions on the Hot Network Questions list like this that basically ask "how do I draw this arbitrary shape in CSS". Invariably the answer is a couple of blocks of CSS or SVG data ...
4
votes
1answer
133 views

Define “Refactoring”

Everyone has heard this term thrown around, and most people, I would imagine, have a conceptual idea of the meaning. I, myself, am in that latter group. However, I feel that the definition Google/...
99
votes
16answers
15k views

Should I add redundant code now just in case it may be needed in the future?

Rightly or wrongly, I'm currently of the belief that I should always try to make my code as robust as possible, even if this means adding in redundant code / checks that I know won't be of any use ...
5
votes
2answers
254 views

The concept of “quality gates” in software testing

We are using SonarQube for code quality testing. It tests the quality of code, and not the function of code. It has the concept of quality gates, so you can set for instance a 90% quality gate, ...
2
votes
1answer
178 views

How to respond to bizarre requests in code reviews? [closed]

I think that code reviews are great and very helpful for everyone. With that being said, from time to time I've received feedback on a pull request (leading to the PR being delayed for at least as ...
1
vote
1answer
196 views

Is defining only one method against S in S.O.L.I.D

The first version of pseudo code I consider a code smell because of (I think) the Command Query Separation principle and/or the S in S.O.L.I.D. What I like to see is in the 2nd version. Should I keep ...
3
votes
1answer
324 views

Bad c++ code design? [closed]

This is bothering me a long time. I feel like I am doing mistakes on the code design relative to the performance. I never had any teacher to indicate my mistakes so its hard to me to make it right in ...
6
votes
3answers
1k views

Is break a code smell?

I'm asking in terms of a loop, obviously break is important in switch statements. Whether or not switch statements themselves are code smells is a separate issue. So consider the following use cases ...
1
vote
2answers
114 views

Does an interface including several methods that return instances of Object make sense?

I am in the process of writing my first true API. In the process, I am defining an interface for mapping complex data structures onto other complex data structures. At the moment, the interface ...
28
votes
8answers
6k views

Is it acceptable to copy and paste long but straightforward code instead of wrapping them into a class or function?

Suppose I have a segment of code to connect to internet and show connection results like it: HttpRequest* httpRequest=new HttpRequest(); httpRequest->setUrl("(some domain .com)"); httpRequest->...
96
votes
13answers
16k views

Should we avoid language features that C++ has but Java doesn't to increase maintainability?

Suppose I am limited to use C++ by the environment in the project. Is it good to prevent the use of some language features that C++ has but Java doesn't have (e.g.: multiple inheritance, operator ...
1
vote
0answers
241 views

Can this be used to implement Post Redirect Get pattern?

I am trying to implement proper a Post Redirect Get on a PHP site (question is language agnostic in nature however). I thought about it, and realized that running this code on every request seems to ...
0
votes
3answers
190 views

Best practices in exposing interface

Let's assume I have a class that downloads data from API, cleans it and saves to database. What methods should I expose? class ApiConnector1 { public string GetDataFromApi() { // ... ...
1
vote
0answers
82 views

WMC Calculation in CK Metrics Suite

I have two classes C1 and C2. C1 has 2 methods and C2 has 3 methods each of complexity value 1. C2 inherits from C1. So, I know C2 has 2+3=5 methods in all. The question is, should I take C2 to have 5 ...
3
votes
1answer
126 views

What percentage of failed requests is “normal” [closed]

So I just launched my first "real" site that actually has a decent amount of interactions and whatnot. It's an ASP.net site with a SQL backend. We've served 130k requests in the last 12 hours but ...
1
vote
1answer
186 views

flatMap with if else vs combine with filter

When using reactive frameworks I have seen both solutions below to make a mutually exclusive selection of which stream will be forwarded (rxjava in this case) Observable.merge( Observable.just(...
-3
votes
2answers
233 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
208 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 ...
0
votes
0answers
69 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
230 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
207 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 ...
1
vote
5answers
559 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 ...
4
votes
2answers
148 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
147 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 modules/...
2
votes
2answers
117 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. ...
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 ==...
4
votes
1answer
208 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. ...
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
78 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
545 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 ...
8
votes
2answers
251 views

Do we need to validate entire module usage or just arguments of public methods?

I've heard that it is recommended to validate arguments of public methods: Should one check for null if he does not expect null? Should a method validate its parameters? MSDN - CA1062: Validate ...
0
votes
2answers
133 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 ...