Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [readability]

Readability measures how easy code is to read and understand.

1
vote
1answer
64 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
118 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
100 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
78 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
156 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
56 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
80 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 to have the same ...
1
vote
1answer
202 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
159 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
221 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
253 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
448 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 ...
57
votes
9answers
8k 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
72 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....
5
votes
4answers
315 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
868 views

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

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
117 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
236 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
185 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
150 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 | +---------------+--------------...
4
votes
2answers
1k 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
265 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
644 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 ...
12
votes
4answers
4k 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
131 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 ...
139
votes
6answers
13k 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 ...
7
votes
1answer
663 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
163 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
107 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
155 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
448 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
148 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
2k 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
99 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
1k 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
941 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
470 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
239 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
1k 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
336 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
2k 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
263 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....
-3
votes
3answers
704 views

inheritance and polymorphism decrease readability

Most of financial apps have complex calculations and over time have change in calculation methods. Then you mostly create a new version for your calculator class that extends previous calculator and ...
1
vote
0answers
80 views

Updating class property inside the method vs. returning a value from the method

In a large code base, what is a good practice between: Updating class properties inside the method vs. returning a value from the method and updating the property in the place where the call to the ...
2
votes
1answer
196 views

Do extracting piece of logic to function improve or reduce code readability?

If there is some code that needs to be implemented across multiple controllers (lets say, 10), e.g.: // Inside a controller function var myField = null; var response = service.callBackend(function(){...
0
votes
1answer
183 views

What scientific support does some coding standards have?

Let's consider the rule in python PEP8, coding standard for the linux kernel etc saying that a line of code are not allowed to be longer than N characters. To this rule there is normally a few ...
3
votes
1answer
185 views

Why do we use architecture-specific types in C

I think that the type names in Rust are much better than the ones in C. I'd choose f64 over double and u32 over unsigned int or uint_32t any day. Is there any reason (other than tradition) to use ...
40
votes
15answers
9k views

Is it inadvisable to make a function that essentially renames a built-in function?

I get confused over min and max functions, in certain contexts. In one context, when you're using the functions to take the greater or lesser of two values, there is no issue. For example, //how ...
20
votes
6answers
3k views

How to remove a function or feature when using TDD

In texts about TDD I often read about "remove duplication" or "improve readability" during the refactoring step. But what makes me remove an unused function? For example let's say there is a class C ...