Questions tagged [readability]

Readability measures how easy code is to read and understand.

Filter by
Sorted by
Tagged with
0
votes
1answer
76 views

CQRS for avoiding heavy joins

I've been wondering about what is a perfect use case for CQRS where the benefits overcome the complexity and the cost with come with the package. So for me to better understand it, I want to share ...
0
votes
2answers
118 views

DRY Violation for Logical Code Organization and Readability

I have a block of code that branches into 2 pathways, let's call them the "simple" and "complex" branch, based on user input. Either the simple or complex logic has 4 steps, let's call them A, B, C ...
-4
votes
1answer
148 views

Is using yoda conditions with c# justified?

It's mind bending experiencing reading code like : "Aggregation".Equals(evt.Id)) I was unsuccessful in trying to talk the person out of this style, maybe I'm wrong? Or maybe I wasn't articulate ...
0
votes
2answers
102 views

Design pattern for executing and reverting the tasks in same order

I have a Task in my project , to complete that i have call(REST) multiple external systems. If my call fails at some level , i have to rollback all my previous calls(making call with undo action) . ...
1
vote
1answer
195 views

Using “magic” strings for single-use error reasons?

I'm writing a fairly large piece of logic, during which there are 6 points where things could go wrong and execution should stop after logging the error. The error is also stored in an object. ...
-2
votes
4answers
346 views

Is judicious & plausible selection of class fields a valid refactoring step?

I'm a great fan of refactoring but I've been wondering about the issues raised by refactoring. Fowler advises refactoring to make code readable to all users to make the code structure more sensible, ...
3
votes
2answers
111 views

Explicit type and final in stream lambdas

This argument has been going on for weeks: Bot.getGuild().getMembers().stream() .filter((final Member m) -> m.getRoles().size() == 0) .filter((final Member m) -> !m.getUser()....
1
vote
1answer
89 views

How to avoid confusion with possible referenced before assignment when it won't be (Python) [closed]

I have some code equivalent to this: state = True if xyz: state = False try: value = foo() except: handle_exception() state = False if state: bar(value) On the last line it will ...
2
votes
2answers
131 views

How should I call splitted functions? centralize them? or call it one next to one?

According to Is it OK to split long functions and methods into smaller ones even though they won't be called by anything else?, I should split long functions into smaller functions even if they ...
2
votes
2answers
110 views

How to profile before optimising for readability

When optimising for speed, profiling first can help focus the effort on the parts of the code that bring most benefit. Since speed can be measured objectively, the benefit can also be measured ...
0
votes
2answers
133 views

Reuse domain entity logic

Usually the domain logic should be contained in the domain entity, rather than being put in specialised external classes called from the entity. This is good to prevent that somebody comes later, ...
3
votes
3answers
171 views

Drawing lines with dashes in logs

It can sometimes ease readability to "draw" lines in a logfile. For example: noise noise ----------------------------- Starting Operation ABC blabla blabla ----------------------------- End of ...
0
votes
2answers
77 views

Should default values be explicitly stated in configuration files for libraries or frameworks?

In one of the projects I work for, we have just added karma to run unit tests. When reviewing the MR of a coworker, I noticed the karma.conf.js (the configuration file) has 120 lines, which seems to ...
2
votes
0answers
87 views

Is “equivalent” functions / methods readability worth its maintanability cost?

First of all, I am sorry if it is a duplicate, I could not think of any "correct" wording to search about this. Second let me clarify: By "equivalent" I mean methods that are meant ...
1
vote
1answer
275 views

Metrics that measure the readability of the function

Functions are the first line of organization in any program.I believe writing them well improves the readability of code to some extent.I am working on metrics that describe how readable the function ...
0
votes
2answers
755 views

Using the same name for setter and gettter methods for a boolean member variable

Say I have class with a boolean member variable fancy: public class MyClass { private boolean fancy; } Case 1. I could the define the setter and getter as follows: // getter public boolean ...
0
votes
3answers
237 views

less functions and complex code or more functions and readable code?

I am currently making an html-based editor, i know there are lots of editors out there especially html based but i want to do it myself once. What i am concerned about is, for e.g, when a user press a ...
-2
votes
2answers
450 views

Code readability vs extensibility and flexibility, what is the relation?

I have been reading a bit about code readibility and found conflicting information about the following: some say that flexibility (and-or extensibility) actually increase readability, while some ...
4
votes
5answers
459 views

Is it a bad practice to use conditionals with functions that change program's state?

The title might be a bit vague, so let me explain. Let's assume we have a function that does something (changes state of the program), for example a function that creates a file. That function returns ...
59
votes
9answers
9k views

Readability versus maintainability, special case of writing nested function calls

My coding style for nested function calls is the following: var result_h1 = H1(b1); var result_h2 = H2(b2); var result_g1 = G1(result_h1, result_h2); var result_g2 = G2(c1); var a = F(result_g1, ...
0
votes
1answer
93 views

Logging parametrized logs while maintaining readability

I have a LogFormatter class which looks like below @Sl4j class LogFormatter { public static String format(String taskType, String taskId, String message) { return String....
4
votes
4answers
333 views

Why are functional-style chained map operations considered hard to read?

In the comments to an answer of another question, I proposed the following Java code as a better way of writing a more procedural-style variant of the same operation: employeeService.getEmployee() ...
6
votes
6answers
999 views

DRY principle often makes my code more complicated and/or more difficult to understand [duplicate]

This often happens in my projects. Sometime I have this part of code that is very similar to this other part, yet a few lines makes it complicated to keep the code clean and without duplication. Here ...
0
votes
1answer
188 views

Do all Get/SetAccess, Access, and Dependent property attribute combinations have valid use cases?

If You are Unfamiliar with OOP Matlab For those not familiar with matlab, matlab provides a variety of access attributes when creating member variables. All member variables are essentially C# ...
1
vote
4answers
241 views

When is it justified to write implicit conditions? [duplicate]

As a rookie programmer, I've only recently been digging into benchmarking, and have been comparing various ways of accomplishing the same task in terms of speed. Most of the time, the result is ...
0
votes
5answers
187 views

Is setting field's fields in a submethod without passing argument a good pattern?

Simplified a little, I have this code: public class TaskProcessCases{ private Assessment assessment ; public void execute() { // the actual name for (Case case : cases) { ...
1
vote
1answer
181 views

How to write Readable Comment when we have to deal with IDs?

How to write Readable Comment when we have to deal with IDs? I will explain this with example. +---------------+-----------------+ | permission_id | permission_name | +---------------+--------------...
6
votes
2answers
2k views

Using lambdas to improve readability of a C++ function

I'm looking to improve the readability of a lengthy C++ function. This function contains a number (> a dozen) variables that are used throughout. The main logic of the code is a long list of condition ...
5
votes
3answers
423 views

How to avoid falling into the trap of not commenting code? [duplicate]

I've been working on a project for about a month now. I am extremely familiar with the code and understand it to the extent where I feel that it is so easy to understand, that most methods don't need ...
9
votes
5answers
663 views

Is it possible to make long code representing a computation easier to read?

Long methods are generally considered bad, however in my code I have some hard-to-understand long methods (more than 50 lines). I have trouble making those methods easier to read because a single ...
13
votes
4answers
5k views

Is it wrong to use flags for “grouping” enums?

My understanding is that [Flag] enums are typically used for things that can be combined, where the individual values aren't mutually exclusive. For example: [Flags] public enum SomeAttributes { ...
-1
votes
2answers
133 views

Database optimization vs readibility

I'm working on some code that checks for some invariants in the database. For example to check that an element is not repeated the code checks for a database error since the invariant is coded at ...
143
votes
6answers
14k views

Are private methods with a single reference bad style?

Generally I use private methods to encapsulate functionality that is reused in multiple places in the class. But sometimes I have a large public method that could be broken up into smaller steps, each ...
6
votes
1answer
679 views

Use `ref` merely for clarification?

I wrote a FillSomeData(ParameterData param, Result res) method, which populates res with some data (just like it says on the label). Result is a class, not a struct, so FillSomeData actually affects ...
1
vote
3answers
165 views

Optimizing polymorphic objects when there's only one implementation

Let's say I have an interface called ParentClass. ParantClass has two implementations, ParentClassA and ParentClassB. There is also the ChildClass interface, with a ChildClassA and ChildClassB ...
0
votes
1answer
108 views

Maintainable architecture for a series of concurrent and serial processing

I have a matrix of values that is anywhere from a few dozen to a few hundred rows and columns (always square). I have a series of tasks that need to be performed on the matrix. (I'm using the ...
1
vote
2answers
158 views

Does sending parameters around inside a class suggest that I should refactor to a new class?

I have noticed a pattern when I refactor my code for readability. When I refactor a method into several smaller methods, I often have to introduce parameters which sometimes (too often) makes the code ...
3
votes
6answers
512 views

Is it an anti-pattern to use the return type of an assignment as part of a condition?

I must set a bool to be passed down from a controller to a view in my MVC solution as well as do something (as part of an if). I thought, in order to keep the code concise, I could kill two birds with ...
1
vote
3answers
152 views

Should conditionals be embedded in the function whose execution is contingent on them?

I have a large data structure that is about to be persisted to the database. Before that can happen I have to validate it and then update a bunch of it's properties based on various specific ...
13
votes
4answers
3k views

How should I write a test for a pure method which doesn't return anything?

I have a bunch of classes which deal with validation of values. For instance, a RangeValidator class checks whether a value is within the specified range. Every validator class contains two methods: ...
1
vote
2answers
101 views

How can I reorganize others' code shared in source control repository, just for my own purpose?

When several persons work together on a project shared in repositories in github, it happens quite often that I feel that someone else's code is hard to read, and want to change and reorganize his ...
26
votes
8answers
2k views

Is there a programming paradigm that promotes making dependencies extremely obvious to other programmers?

I work in a Data Warehouse that sources multiple systems via many streams and layers with maze-like dependencies linking various artifacts. Pretty much every day I run into situations like this: I run ...
5
votes
4answers
1k views

Why do some APIs simply throw Exception?

This year I started using several Third-Party-Libraries (all open source) and I noted that some throw exceptions in a proper way (i.e. declaring exactly which checked Exceptions can be thrown by a ...
2
votes
2answers
741 views

Choose best function name in repository [duplicate]

In my code, I'm using repository pattern. For example, I got deal repository. I just curious how you decide the name of the function when the function itself doing so many things. I think when the ...
3
votes
1answer
306 views

How to make my educational dynamic array C library less verbose to use?

I really like to make tools prior to starting some assignment, so for the C programming assignments I have prepared dynamic array library. We are restrained to only using C99 standard. Note that all ...
0
votes
2answers
87 views

Use spaces between parameters? [closed]

Is it poor practice to not use spaces between parameters in a scripting language (or any for that matter)? With spaces: def does_a_thing(x, y): ... does_a_thing(5, 9) Without spaces: def ...
1
vote
5answers
2k views

Do increment and decrement operators decrease readability? [closed]

I understand what increment and decrements operators are (++ and --) and the difference between post and pre (i++ vs ++i) but should they be avoided as they do increase the difficulty of reading the ...
4
votes
3answers
344 views

Is it reasonable to write worse debug code in order to improve production code?

The title pretty much speaks for itself, but I'll provide the current decision I am facing. I am migrating python code towards the use of generators. The current code looks like this: ... l = ...
1
vote
2answers
3k views

SonarQube is complaining about: “Use isEmpty() to check whether the collection is empty or not.”

So as my the title says, SonarQube is complaining whenever you use list.size() == 0 or list.size > 0 However I started changing to isEmpty() and !is.Empty() and noticed the code becomes way ...
0
votes
3answers
268 views

Should i use a more functions to increase readability?

Should I use an easy readable code like this if (var.isServicePGM() || var.isStandardPGM()) { //Much code if (var.isServicePGM()) { //Some code } else if (var....