The term "clean code" is used to describe computer programming code that is concise, easy to understand, and expresses the programmer's intent clearly. Questions with this tag relate to the process of writing clean code, or refactoring old "dirty" code to be clean code.

learn more… | top users | synonyms

2
votes
2answers
76 views

Code size overhead by including unnecessarily extra header files

I have a program which includes lots of header files but it do not uses all the header files. I have removed some of them although it is working fine. I did not notice any changes in the performance. ...
0
votes
2answers
86 views

Design pattern to holds API exchanges?

I'm developing a simple application that crawls in web pages to obtain some information. For this I used and tested some libraries, like crawler4j, jsoup, jaunt and htmlunit. I exchanged several ...
0
votes
0answers
96 views

Advice on program performance after changes

So, the situation is like this: For the past two years, I have implemented a class in c# which is used to filter different fields from different tables in database (SQL), for reporting purposes. Now ...
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.. ...
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 ...
1
vote
0answers
65 views

Function to return a string - Which is cleaner? [migrated]

I was having a discussion with my coworker about a function that returns either an empty string, or a string of a css class. The function is passed an object which has an HTTP status code, and then ...
-2
votes
1answer
91 views

Pretty splitting of lines?

<?php if (in_array(exec("pboxsvc pboxlib.bin DeterminarTipoSpool' $idJob"), ['IPP','PSFORM','PBSSFORM','PDF'])): ?> How would you refactor that line to be ...
1
vote
7answers
1k views

Should you use “internal abbreviations” in code comments?

Should you use "internal abbreviations/slang" inside comments, that is, abbreviations and slang people outside the project could have trouble understanding, for instance, using something like //NYI ...
9
votes
7answers
2k views

Checking if a method returns false: assign result to temporary variable, or put method invocation directly in conditional?

Is it a good practice to call a method that returns true or false values in an if statement? Something like this: private void VerifyAccount() { if (!ValidateCredentials(txtUser.Text, ...
1
vote
1answer
115 views

Sorting Array before looping : best practice

I was going through JBAKE code at https://github.com/jbake-org/jbake/blob/master/src/main/java/org/jbake/app/Asset.java : 58 PFB the code. Why are we sorting the array here? if (assets != ...
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
144 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, ...
8
votes
1answer
1k views

Refactoring byzantine payment processing code on a limited budget [closed]

I've been working on a large Ruby on Rails application for several years. It was inherited in a poor state but most of the production bugs have been ironed out with time. There are some sections that ...
7
votes
3answers
964 views

Uncle Bob's clean architecture - An entity/model class for each layer?

BACKGROUND : I'm trying to use Uncle Bob's clean architecture in my android app. I studied many open source projects that are trying to show the right way to do it, and I found an interesting ...
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 ...
0
votes
1answer
40 views

Where should I log in the user based on http session: service or controller?

I know that best practice is to let everything about authentication/authorization to the service layer. Controller should not be aware of that. But how to let a service (from service layer so) to ...
1
vote
1answer
155 views

Interface Implementation: A parameter I don't need

Pseudo-Code interface IPagingInfo { int CurrentPageNo { get; } int RowsPerPage { get; } ... } interface ResultsRetriver { ResultRows GetResults(IPagingInfo pagingInfo); } class ...
2
votes
4answers
163 views

Is it a good idea to make method behavior depend on the calling thread?

I want to subclass a 3rd party class, in order to make it thread-safe. I have a good idea of how to implement this, but there is a problem: the superclass has a property, which affects the behaviour ...
2
votes
2answers
101 views

How to define what fields to check for equality?

I have an odd conceptual question, It's not about a specific incident, just a general best-practices approach. I have asked myself on occasion when defining java Equal methods, what makes two ...
2
votes
3answers
208 views

What is the most readable way of passing arguments to the function? [closed]

I'm using JavaScript but the question can be generalized to all the languages. In a nutshell - I'm checking if a browser connecting to my site is a microwave and cater for that accordingly. What ...
1
vote
1answer
133 views

Interface Design: Specific vs General parameter (A Minimal design vs anticipated use variation)

Code public interface IVehicle { string VehicleMake { get; } int MonthsSincePurchase { get; } bool IsApprovedUsed { get; } ... } public class WarrantyPopUpHandler { virtual bool ...
4
votes
3answers
1k views

ID properties on Domain objects in DDD

In my domain I have an Account object. e.g. class Account { public string Number; public string SortCode; } Within the context of DDD, should this account object have an ID property? The ...
3
votes
4answers
295 views

Minimal design vs anticipated use

Recently when performing a code review I came across something like this: Old Code: WriteLabour(useNewVersion); WritePart(); WriteNonLabour(useNewVersion); New Code: WriteLabour(); ...
1
vote
2answers
224 views

What are the justifications for annotations in a programming language? [closed]

After spending a great deal of time writing C# and looking at Java, it seems to me that annotations are just an ugly code smell that introduce another conceptual layer that could easily be replaced by ...
3
votes
1answer
171 views

Cleaner Windows Forms

Backstory: I am working on a Wizard Setup project and I've ended up with a very big(a lot of lines of code) Form class. Because my form holds a Wizard control which in turn has lots of pages and each ...
8
votes
3answers
725 views

Implementing a complexity hiding layer

As part of the dependencies that the project I'm working on has, we use several core services. These services, to which we can't make big changes, are a big mess. Depending on the method we invoke, we ...
2
votes
5answers
369 views

Are clean coding rules less relevant for large open source projects? [closed]

I've been reading Robert Martin's book "Clean Code". One of his core tenants is to remove unnecessary comments and strive to create meaningful variable/method names that are self documenting. Some of ...
69
votes
9answers
8k views

Clean Code comments vs class documentation

I'm having some discussions with my new colleagues regarding commenting. We both like Clean Code, and I'm perfectly fine with the fact that inline code comments should be avoided and that class and ...
57
votes
4answers
7k views

Is it better to call a function that doesn't have an effect at that point, IF it improves code clarity?

I have three views in my program (iOS app). Only one of them is ever active at the same time so I set the visibility off for two of them and switch visibility as the user presses buttons. The views ...
1
vote
0answers
72 views

Pointers vs IDs for “context-specific” functions

I need to be able to load, use, and free resources from a single monolithic object. I have two requirements: 1. That the resource loaded is owned by the object that created it and 2. All objects in a ...
1
vote
1answer
279 views

Is writing code chronologically the best way for readability? [closed]

So I've been writing a lot of JavaScript lately. Despite what many people say I think JavaScript can be a simple and beautiful language. What I've pondered of late is how to structure the code so it ...
8
votes
6answers
3k views

How to reduce a switch in a switch statement?

So I'm making a method to create a salutation line based on two people from a database. There are four parameters: the two names (name1 and name2) and the two genders (gender and gender2). For every ...
4
votes
2answers
2k views

“Clean Code”: How to organize named queries?

Few days ago I started to read Robert C. Martin "Clean Code" book and it encouraged me to look more detailed at my code. After I opened eclipse I saw this: ...
4
votes
2answers
336 views

How to avoid …Helper or …Manager classes

I have quite a few Helper classes in my project. I have read that this is a bad thing, but I suspect that "Helper" is the wrong suffix for them. I'll give an example. First, I have a User class. I ...
0
votes
2answers
48 views

Flag arguments in an html factory class

I have been told that flag arguments(boolean arguments) are a bad thing because it complicates the signature of the method and means that the method does more than one thing. An issue I have with ...
12
votes
4answers
1k views

Do I suffer from encapsulation overuse?

I have noticed something in my code in various projects that seems like code smell to me and something bad to do, but I can't deal with it. While trying to write "clean code" I tend to over-use ...
11
votes
6answers
1k views

Best practice boolean assignment [closed]

I came across the following conditional in a program that I have taken over from another developer: if (obj.Performance <= LOW_PERFORMANCE) { obj.NeedsChange = true; } else { ...
10
votes
6answers
950 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 ...
3
votes
3answers
194 views

How to best encapsulate features in code and enabling/disabling them at runtime?

I would like to be able to abstract each feature developed by the team in a way that it can be enabled or disabled at runtime by using a distributed shared configuration system. Features are small and ...
10
votes
5answers
724 views

Can a pure-functional solution to this problem be as clean as the imperative?

I have an exercise in Python as follows: a polynomial is given as a tuple of coefficients such that the powers are determined by the indexes, e.g.: (9,7,5) means 9 + 7*x + 5*x^2 write a function to ...
1
vote
1answer
109 views

How to name complex DAL/repository methods? [closed]

I'm beginning working with repository pattern. When it comes to simple queries I don't have problems with names. GetById GetByDay UpdateById If a method retrieves data filtered by two values also ...
0
votes
2answers
435 views

Clean code principles to jquery [closed]

A jquery code could get very long in lines and become an spaghetti code. It could bring problems like chaining functions or many lines for getting data from HTML elements. Also it may create a clutter ...
0
votes
0answers
91 views

Abstract Web API from validation and configuration management in embedded system

Im working with embedded Linux for a router. There is a web GUI for the user to configure router options. When user fill a web form this is submitted to a web server function that is responsible of ...
1
vote
1answer
83 views

Should my program be flawless at release [duplicate]

I'm building a big, very complex piece of open-source software, and it's killing me trying to make what I have as "clean" as it needs to be. What I want to know is: If there is an undetected flaw in ...
1
vote
4answers
175 views

How to make sure clean code well implemented? [duplicate]

I'm a project manager in a small team of developers (consisting 3 team leaders and 10 programmers) We're currently trying to enforce clean code for our team , we're having small frequent seminars ...
2
votes
1answer
203 views

MVC Controller - keeping methods small

I'm reading uncle Bob's Clean Code and it completely revolutionizes my programming style. In this book author claims that best methods are small methods. What about controller's action methods in ...
3
votes
1answer
152 views

Is the target of 3 dependencies per class always achievable?

I'm reading the Clean Code book and a chapter says that if a class has more than 3 dependencies is a code smell of that class isn't doing one thing. Or what is the same, it isn't following SRP. I'm ...
3
votes
3answers
196 views

Development Time: sql in UI code vs domain model with datamapper

First, sorry for my English guys. Currently this is my first programming job. I am labeled as the most incompetent programmer in my company that's because they measure the performance and ...
1
vote
3answers
429 views

Alternative to goto-statement in this case? [duplicate]

Currently I am using gotos for closing handles and general cleanup if an error occurs. Since I don't want to nest all the ifs and a function for cleanup would require a return besides the cleanup(); ...
3
votes
8answers
313 views

Creating one-line method for the single purpose of self-documenting code [duplicate]

Given the following two snippets: Snippet 1: public void foo(Data data, AbstractNode node) { int originalId = data.getCurrentId; node.execute(data); //If node changed currentId reset it ...