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

-5
votes
1answer
33 views

Hiring Engineers/developers whom write code that works (with bad design skills) [on hold]

I'm currently looking for someone to help me build mobile apps. I've been working alone for the past 5 years, and I think its time to expand. The problem is, most software engineers/developers I ...
3
votes
2answers
150 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
36 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 ...
10
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 { ...
63
votes
9answers
7k 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
158 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
74 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
165 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
66 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 ...
0
votes
1answer
76 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
142 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
117 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
163 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
240 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
294 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
246 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
238 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
277 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
365 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
82 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 ...
0
votes
1answer
53 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
117 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
264 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
801 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
103 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
89 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 ...
1
vote
1answer
320 views

Complexity vs simplicity? [closed]

Been a developer for over 7 years already. Not sure if I might be called a senior, but know one or two things. Last night was trying to solve some issues with Mockito and InjectMocks, and dig into ...
0
votes
5answers
307 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 ...
16
votes
16answers
1k 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.. ...
0
votes
0answers
127 views

Better and cleanest way to bind a ICommand to a RelayCommand

By reading various source code, I see that there is different ways of binding an ICommand to a RelayCommand : From the constructor MyAwesomeViewModel() { this._fooCommand = new ...
8
votes
2answers
728 views

Applying the principles of Clean Code to functional languages

I'm currently reading Robert Martin's Clean Code. I think it's great, and when writing OO code I'm taking his lessons to heart. In particular, I think his advice to use small functions with meaningful ...
1
vote
2answers
194 views

How to know whether to create a general system or to hack a solution

I'm new to coding , learning it since last year actually. One of my worst habits is the following: Often I'm trying to create a solution that is too big , too complex and doesn't achieve what needs ...
2
votes
1answer
137 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
0answers
132 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
1answer
223 views

Equal or less than 15 lines per method(function) principle? [duplicate]

Some books or master told us this principle: Equal or less than 15 lines per method(function), and the perfect is under(or equal) 8 lines. Does the principle make sense for most conditions? There ...
2
votes
1answer
206 views

Will this “wireless” syntax for my framework make for good code structure / design?

I'm at the point where I'm getting into the freelance development of some complex web apps, and I would like to develop a light weight framework for my personal use, but I'd like to get some advice ...
0
votes
2answers
366 views

Can this code be made more concise? [closed]

I came across some code recently where in many, many places, expression evaluations were being assigned to different arrays one index at a time. A psuedo-code example: array[0] = item1[0] + item2[0]; ...
0
votes
1answer
73 views

Matching the superclass's constructor's parameter list, is treating a null default value as a non-null value within a constructor a violation of LSP? [duplicate]

I kind of ran into this when messing around with FlashPunk, and I'm going to use it as an example. Essentially the main sprite class is pretty much class Entity. Entity's constructor has four ...
2
votes
4answers
277 views

Is it normal needing time to understand code I wrote recently [closed]

By recently I mean some weeks ago. I am trying to continue a project I left 2 weeks ago and I need time to understand some functions I wrote (not copied from somewhere) and it takes me time. Normally ...
3
votes
1answer
278 views

How to handle passing multiple dependencies in a module hierarchy

So I have my application consisting of a number of modules in a module hierarchy. Furthermore let's also assume each module is a class and we have a tree of classes where the classes at the top are ...
7
votes
2answers
313 views

How to hide AOP implementation dependency without breaking encapsulation?

I have the concept of a SlowLoading thing: public interface SlowLoading { boolean hasLoaded(); } I also have a component MyComponent: public interface myComponent{ void doSomething(); } My ...
2
votes
1answer
272 views

Why does Java support brackets behind variables and even behind method signatures? [closed]

Java allows this: class X{ int i,j[]; // j is an array, i is not } and even worse, it allows this: class X{ int foo(String bar)[][][] // foo actually returns int[][][] { return null; } ...
5
votes
5answers
1k views

How should I handle exception that *should* never be thrown? [duplicate]

What is the best way to handle errors that shouldn't ever happen? My current way to do this is to throw an exception if the 'thing that shouldn't happen' does happen, like so: /* * Restoring from a ...
1
vote
2answers
596 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 ...
4
votes
4answers
575 views

How to avoid excessive method overloading?

We have quite a lot of places in the source code of our application , where one class has many methods with same names and different parameters. Those methods always have all the parameters of a ...
6
votes
3answers
274 views

Dependency Injection vs Mixing Levels of Abstraction

I've been reading Clean Code: A Handbook of Agile Software Craftsmanship by Robert C. Martin. One point he makes: G34 Functions should descend only one level of abstraction However, I'm ...
4
votes
2answers
446 views

How to use the Decorator pattern to add little functionality to big objects?

This question regards the usage of the Decorator pattern to add little functionality to objects of large classes. Following the classic Decorator pattern, please consider the following class ...
37
votes
14answers
5k views

How important is it to clean up someone else's code when faced with a tight deadline? [closed]

(I'm talking about HTML / CSS code (not programming languages) but I think we also face the same issue as with programmers.) I am the senior front-end designer in a team and I often have to re-work ...
4
votes
4answers
529 views

Choosing value in SQL query vs (Java) code

I need to choose one of three values of an integer using the value of a column on a nullable column of a table. There are at least two approaches: 1) use SQL to do all the work: test null values, and ...
3
votes
2answers
206 views

Should accessible members of an internal class be internal too?

I'm designing a set of APIs for some applications I'm working on. I want to keep the code style consistent in all the classes I write but I've found that there are a few inconsistencies that I'm ...