Questions for best practices for writing high quality code.

learn more… | top users | synonyms

5
votes
3answers
892 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 ...
97
votes
13answers
15k views

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

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
2answers
103 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 ...
1
vote
1answer
277 views

How to define dependent function in node js?

I have a nodejs project in which a sample.js include two function function A depends on function B's callback . // smaple.js Both function are included in the same file function B ( ...
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)"); ...
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 and I am creating a installer for the application, there are Three main parts. PostgreSQL installation/uninstallation myapplication ( setup of myapplication is ...
55
votes
11answers
2k views

How do you stay productive when dealing with extremely badly written code?

I don't have much experience in working in software industry, being self-taught and having participated in open source before deciding to take a job. Now that I work for money, I also have to deal ...
17
votes
16answers
2k views

Do else blocks increase code complexity? [closed]

Here is a very simplified example. This isn't necessarily a language-specific question, and I ask that you ignore the many other ways the function can be written, and changes that can be made to it.. ...
4
votes
4answers
297 views

lightweight, sustainable processes for good code/design quality? [closed]

Ok, gang, next question: what do y'all think are the best processes to improve the quality of the code the (corporate) team produces? (The cult of quality question was good, but I'm looking for ...
167
votes
25answers
16k views

How to convince my boss that quality is a good thing to have in code? [duplicate]

My boss came to me today to ask me if we could implement a certain feature in 1.5 days. I had a look at it and told him that 2 to 3 days would be more realistic. He then asked me: "And what if we do ...
5
votes
3answers
2k views

Should a method do one thing and be good at it? [duplicate]

"Extract Till You Drop" is someting I've read in Uncle Bob's blog, meaning that a method should do one thing alone be good at it. What is that one thing? When should you stop extracting methods? ...
5
votes
8answers
718 views

When do code hacks become bad? [duplicate]

When you begin a new project/function/object you mostly have an idea of the model you want to build. It can be based on the clients' wish, on your ideas for the app or whatever. In the middle you ...
6
votes
1answer
222 views

Erlang function naming conventions

I understand the general Erlang conventions for functions are using snake case or camel case, but what about exported functions? For example, say I have a gen_server module that defines a check to ...
14
votes
4answers
5k views

code review with git-flow and github

With regular git and github I can do a code review by simply creating a pull request of the feature branch I'm working on to the master branch. How would I do code reviews with git-flow? With workflow ...
8
votes
2answers
221 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 ...
1
vote
0answers
101 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 ...
28
votes
16answers
2k views

Does simplicity always improve Readability?

Recently, I was developing a set of coding standards for our company. (We're a new team branching out into a new language for the company.) On my first draft, I set the purpose of our coding ...
79
votes
20answers
14k 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 ...
31
votes
14answers
2k views

Fix bugs, or wait for the customer to find them?

Do other people fix bugs when they see them, or do they wait until there's crashes/data loss/people die before fixing it? Example 1 Customer customer = null; ... customer.Save(); The code is ...
95
votes
16answers
7k views

How can I tactfully suggest improvements to others' badly designed code during review? [closed]

I'm a great believer in clean code and code craftsmanship, though I'm currently at a job where this isn't regarded as a top priority. I sometimes find myself in a situation where a peer's code is ...
0
votes
3answers
172 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() { // ... ...
2
votes
2answers
70 views

SDK/DB isDeleted vs Integration Testing

((Using "users" as an example to represent one of many record types)) An application with user tracking typically has a User table. Many, if not all, companies mandate that a User record should ...
185
votes
25answers
22k views

When is a BIG Rewrite the answer?

Just read the question about the Big Rewrites and I remembered a question that I've been wanting answered myself. I have a horrible project passed down to me, written in old Java, using Struts 1.0, ...
190
votes
17answers
20k views

How would you know if you've written readable and easily maintainable code?

How would one know if the code one has created is easily readable, understandable, and maintainable? Of course from the author's point of view the code is readable and maintainable, because the author ...
1
vote
0answers
39 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
112 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
66 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( ...
-3
votes
2answers
146 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
226 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
950 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
154 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 ...
130
votes
31answers
13k 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 ...
31
votes
9answers
2k 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 ...
28
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? ...
223
votes
25answers
30k 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 ...
35
votes
4answers
33k 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
64 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
221 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
197 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 ...
112
votes
16answers
8k 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 ...
20
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
539 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
873 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
143 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
96 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 ...
44
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
49 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
94 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
371 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 ...