Questions tagged [readability]

Readability measures how easy code is to read and understand.

Filter by
Sorted by
Tagged with
0 votes
1 answer

Assigning to fields in function or by function?

While writing the constructor for class A in Python, I calculate some of the class's fields using function fun(). This function is never used outside the constructor of instances of this class. In ...
Harm van den Brand's user avatar
3 votes
2 answers

Should a method modifying object passed as a parameter return the modified object? [duplicate]

I have some incoming request - it's an instance of class generated from api specification - POJO with public getters/setters. I would like to normalize some values. For example dimensions (to use ...
Shaolin's user avatar
  • 33
3 votes
5 answers

What is the best way to make an if statement condition itself conditional?

Apologies if this is answered elsewhere here but this specific question is somewhat hard to search for as you might see. I'm writing a script currently that essentially has a simple if-then within a ...
Rushkie's user avatar
  • 49
1 vote
1 answer

Does "happy path to the left edge" break Python conventions?

I found the short article Align the happy path to the left edge quite helpful in improving readability of functions. Briefly, reading down the left edge of the function should step you through the ...
lofidevops's user avatar
0 votes
1 answer

When to Push or Publish

I'm in the process of redesigning our entire process control system (a daunting task, really!), and want to make the right decisions to how each system in the ecosystem communicates with each other. ...
Groger's user avatar
  • 113
0 votes
3 answers

Should I send the current or previous state with my state changed event?

I have an event that is raised when my job objects change state (e.g. initializing, running, complete, etc). The event is to be invoked from my set method in the State property, but before I make it ...
Hazel へいぜる's user avatar
-3 votes
1 answer

Using braces on new line convention, but should I do this for one-line methods? [closed]

I've been using the braces on a new line convention for my java project: public String class() { something; { However I have quite a few methods, like getters, that could be written on one line ...
Scott Adamson's user avatar
0 votes
1 answer

Excessively verbose and cryptic comparisons in Java

I don't know if this is the right place to ask more of a "philosophical" question. The more I code in Java, the more I have to bear with Comparable<T>. And the more I bear with this ...
Thomas Herondale's user avatar
0 votes
1 answer

Is there a reason why you shouldn't use 'integration variables'?

I tend to create a variable whenever I need an uncircumstantially same value as to that of an earlier value more than once (the values are not happening to be the same by chance rather they actually ...
Nae's user avatar
  • 197
12 votes
6 answers

Is it bad practice create "alias" variables to not use globals or arguments with long names in a method?

Is it OK to create a variable which only purpose is to increase readability? Example: public class Example { private final HowLongCanARepositoryNameReallyBeRepository ...
Adilson Cabral's user avatar
44 votes
13 answers

Is it an (anti-)pattern for a function to have an argument to decide which other function to call?

Consider your have an enumeration that looks like this: enum ProcessingType { CONFABULATION, RETICULATION, SPLICING; } And you have a web-service that looks like this: class WebService { ...
Mathieu's user avatar
  • 980
1 vote
4 answers

When should a method depend on a data source and NOT have it declared as a parameter?

I was assigned a code review to one of my colleagues. I posed the following, which I wanted to share here in order to hear whether I am right or wrong. Consider the following code snippet: public void ...
Veverke's user avatar
  • 393
1 vote
3 answers

Is there a standard on where to put the `/` in file & directory substrings?

Let's say I have 2 variables dir_name = mydir and file_name = file1, each to be used in formatted strings. There're a few ways to insert a / in a string with those 2 variables. dir_name = mydir/; ...
ChocolateOverflow's user avatar
0 votes
3 answers

Is it any more efficient to reuse a variable than to create a new object?

In a project I am working on we load various entities from the database, do some work then attempt to save the resulting entities. If saving the result is not successful, we return a Result object ...
BakeryD's user avatar
  • 29
8 votes
4 answers

Use local or nested function for readability?

I found in the catalog of Refactoring by Martin Fowler, with Kent Beck book that they mention Extract Function refactoring. It is a good practice to wrap your related code into local functions to ...
Raikish's user avatar
  • 189
0 votes
1 answer

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 ...
Atef's user avatar
  • 109
0 votes
2 answers

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 ...
Dragonsheep's user avatar
-4 votes
1 answer

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 ...
krul's user avatar
  • 93
0 votes
2 answers

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) . ...
Jeevi's user avatar
  • 149
1 vote
2 answers

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. ...
Forumpy's user avatar
  • 147
-2 votes
4 answers

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, ...
Trunk's user avatar
  • 133
3 votes
2 answers

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()....
Julian Durchholz's user avatar
1 vote
1 answer

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 ...
retnikt's user avatar
  • 119
2 votes
2 answers

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 ...
ocomfd's user avatar
  • 5,672
1 vote
2 answers

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 ...
trichoplax is on Codidact now's user avatar
1 vote
2 answers

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, ...
Kamafeather's user avatar
3 votes
3 answers

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 ...
Kricket's user avatar
  • 693
0 votes
2 answers

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 ...
Gonzalo.-'s user avatar
  • 161
2 votes
1 answer

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 ...
LouizFC's user avatar
  • 31
1 vote
1 answer

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 ...
James K J's user avatar
  • 129
1 vote
2 answers

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 ...
StaticBeagle's user avatar
-1 votes
5 answers

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 ...
Mamoon Ahmed's user avatar
-2 votes
2 answers

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 ...
John V's user avatar
  • 4,908
4 votes
5 answers

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 ...
leonz's user avatar
  • 226
63 votes
10 answers

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, ...
Dominique's user avatar
  • 1,705
0 votes
1 answer

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....
comiventor's user avatar
4 votes
4 answers

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() ...
Jules's user avatar
  • 17.6k
6 votes
6 answers

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 ...
Aulaulz's user avatar
  • 289
0 votes
1 answer

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# ...
Krupip's user avatar
  • 1,252
1 vote
4 answers

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 ...
RalphD's user avatar
  • 21
0 votes
5 answers

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) { ...
Mark's user avatar
  • 662
1 vote
1 answer

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 | +---------------+--------------...
I am the Most Stupid Person's user avatar
6 votes
2 answers

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 ...
jwimberley's user avatar
5 votes
3 answers

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 ...
Bender Bending's user avatar
9 votes
5 answers

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 ...
Michael Tsang's user avatar
15 votes
4 answers

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 { ...
Mathieu Guindon's user avatar
-1 votes
2 answers

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 ...
gurghet's user avatar
  • 149
146 votes
6 answers

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 ...
Jordak's user avatar
  • 921
6 votes
1 answer

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 ...
Yehuda Shapira's user avatar
1 vote
3 answers

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 ...
User9123's user avatar