Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [readability]

Readability measures how easy code is to read and understand.

Filter by
Sorted by
Tagged with
3 votes
4 answers
1k views

Representing vectors as arrays of points vs. as data structures

I'm writing a program in Java where I need to represent the position, scale, and other 3-dimensional properties of objects in a world using vectors. I can use either of these two approaches: ...
AcinonX's user avatar
  • 613
0 votes
4 answers
346 views

Code quality: expressiveness vs. conciseness

I've been wondering about code expressiveness vs. conciseness lately. What I mean by that is that a lot of modern programming languages offer features to express statements in a very short manner, ...
Sir Falk's user avatar
1 vote
2 answers
166 views

What is an appropriate length for function names? [closed]

I'm writing a C++ class, CBookSpellDef which has the following methods: int GetIndexOf(const char *psz); char* GetNameAtIndex(int index) { return m_spellTypes[index].szName; } char* ...
AcinonX's user avatar
  • 613
0 votes
5 answers
257 views

When, if ever, should a private member variable, used in one function, be made into a local static variable?

Lately, I have been playing with this idiom: Changing a private member variable into a local static variable when: member to singleton class used in only one function member is mutex for a shared ...
Anon's user avatar
  • 3,613
1 vote
0 answers
54 views

golang: pattern for handling message queues? Are named functions anti-idiomatic somehow?

Had a discussion today in how to implement services that work with messages coming in from event queues. We call these services processors. One of us argues for using several functions, while the ...
Albert Balbastre-Morte's user avatar
0 votes
1 answer
82 views

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
4 votes
2 answers
1k views

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
  • 43
3 votes
5 answers
716 views

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
2 votes
1 answer
446 views

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
137 views

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
469 views

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
140 views

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
234 views

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
313 views

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
13 votes
6 answers
5k views

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
8k views

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
  • 1,039
1 vote
4 answers
220 views

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
  • 451
1 vote
3 answers
220 views

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
3k views

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
2k views

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
289 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 ...
Atef's user avatar
  • 109
0 votes
2 answers
196 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 ...
Dragonsheep's user avatar
-4 votes
1 answer
747 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 ...
krul's user avatar
  • 93
1 vote
2 answers
661 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) . ...
Jeevi's user avatar
  • 159
1 vote
2 answers
1k 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. ...
Forumpy's user avatar
  • 147
-2 votes
4 answers
354 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, ...
Trunk's user avatar
  • 135
3 votes
2 answers
231 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()....
Julian Durchholz's user avatar
1 vote
1 answer
116 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 ...
retnikt's user avatar
  • 119
2 votes
2 answers
144 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 ...
ocomfd's user avatar
  • 5,712
1 vote
2 answers
124 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 ...
trichoplax is on Codidact now's user avatar
1 vote
2 answers
339 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, ...
Kamafeather's user avatar
3 votes
3 answers
523 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 ...
Kricket's user avatar
  • 723
0 votes
2 answers
396 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 ...
Gonzalo.-'s user avatar
  • 161
2 votes
1 answer
164 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 ...
LouizFC's user avatar
  • 31
1 vote
1 answer
428 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 ...
James K J's user avatar
  • 129
1 vote
2 answers
3k 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 ...
StaticBeagle's user avatar
-1 votes
5 answers
617 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 ...
Mamoon Ahmed's user avatar
-2 votes
2 answers
731 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 ...
John V's user avatar
  • 4,936
4 votes
5 answers
1k 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 ...
leonz's user avatar
  • 226
63 votes
10 answers
12k 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, ...
Dominique's user avatar
  • 1,766
0 votes
1 answer
171 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....
comiventor's user avatar
4 votes
4 answers
449 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() ...
Jules's user avatar
  • 17.8k
6 votes
6 answers
2k 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 ...
Aulaulz's user avatar
  • 289
0 votes
1 answer
308 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# ...
Krupip's user avatar
  • 1,300
1 vote
4 answers
264 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 ...
RalphD's user avatar
  • 21
0 votes
5 answers
196 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) { ...
Mark's user avatar
  • 662
1 vote
1 answer
190 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 | +---------------+--------------...
I am the Most Stupid Person's user avatar
6 votes
2 answers
3k 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 ...
jwimberley's user avatar
5 votes
3 answers
456 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 ...
Ubernator's user avatar
  • 169
9 votes
5 answers
694 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 ...
Michael Tsang's user avatar

1
2 3 4 5