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
77 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 ...
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 ...
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
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, ...
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
973 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 ...
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 ...
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
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 ...
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 ...
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 ...
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
339 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 ...
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 { ...
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 ...
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 ...
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
437 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 ...
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
431 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 ...
4
votes
2answers
251 views

Should I use properties for the properties of properties?

Sometimes I use some indirect properties to set or get some other sub-properties, I give an example class Page { public string MainText { set { MainParagraph.Text = value; } get { return ...
3
votes
2answers
350 views

How should blank/empty value objects be instantiated/structured?

I was wondering... what is considered the best practice to instantiate blank value objects? (in Java) E.g. Assume we have some value object class Foo, that could be blank. Would creating methods ...
2
votes
4answers
387 views

Two classes that behave identically yet are semantically different

I am writing a program which is a similar to Ruby's Active Record Migrations, in which that every migration has both an "Up" and "Down" in terms of creating a change to the database, "Up" meaning ...
0
votes
1answer
661 views

Clean architecture: should users go in the use case layer or the domain layer?

I recently read this article about Clean Architecture, as I'm trying to get out of some usual OO habits (interface design everywhere, but what does it do???), and program something that describes what ...
2
votes
2answers
96 views

Method for all objects for checking conditions which also includes method chaining and avoiding variables

(I am currently using groovy but it should apply to most OO languages so I also put the langauge-agnostic tag) I try to program in a function style which also includes method chaining and avoiding ...
-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 ...
0
votes
1answer
130 views

More appropriate to validate a dependency filter parameter by mock+stub or by expression compile?

My lead is enforcing TDD on our project. He says he's following Uncle Bob (Robert Martin) and SOLID principles. One of the rules he's reinforcing is what I call "the single cog rule"--there should be ...
0
votes
2answers
303 views

How to avoid spaghetti code when I have a lot of conditions? [duplicate]

I have the following problem: An user can withdraw money from 2 payment systems (but the number of payment systems can change anytime in the future). If user has a trusted account on either of ...
9
votes
3answers
968 views

Clean Code and Hybrid Objects and Feature Envy

So I recently made some major refactorings to my code. One of the main things I tried to do was split out my classes into data objects and worker objects. This was inspired, among other things, by ...
1
vote
1answer
117 views

How to keep class parameters visible while using generic argument passing

After writing some classes where class initialization requires multiple options, instead of writing several parameters into constructors or setters, I started passing an associative array of ...
0
votes
2answers
119 views

How to improve code that has to handle list-objects in general and special cases?

I do have an implementation issue that I condensed to the following code snippet, because the real code is much more complicated. The core problem is that I do have a container object that has a mixed ...
0
votes
5answers
525 views

Breaking a function into smaller ones is great… except for what about code-folding? [duplicate]

I'm currently reading Robert Martin's Clean Code book. So far I'm enjoying it. Martin talks a lot about separating long functions into short functions, each doing exactly one thing at one level of ...