Questions tagged [readability]

Readability is a subjective parameter used to measure an aspect of code quality. It is based on the assumption that code should be easily comprehensible by humans, both in its form and in its meaning.

Readability is a subjective parameter used to measure an aspect of code quality. It is based on the assumption that code should be easily comprehensible by humans, both in its form and in its meaning.

To improve code readability, the following is usually considered:

  • The code is written such that a person with poorer programming skills will be able to understand what is written.

  • Adding descriptive comments to explain every step of the way.

  • Using proper indentation and white spaces.

  • Choosing object\variable names that describe their purposes.

  • Referencing the algorithm and the responsible authors.

730 questions
0
votes
1 answer

A loop for log transformation

My task is to write a function, which aims to calculate logarithms of given variables (vars) in a given data set (dset) by levels of a declared variable (byvar). If the minimum of a given variable for a given level of byvar is greater than 0, a…
kaksat
  • 709
  • 1
  • 7
  • 18
0
votes
1 answer

Constants while testing equality / inequality placed left

I just finished my Master degree, and I had a really technical teacher which always told us: The oracle should always be at the left of equalities and comparisons As I am French, the exact sentence would be: L'oracle doit toujours être à gauche…
Yassine Badache
  • 1,810
  • 1
  • 19
  • 38
0
votes
0 answers

Better conditional insertion of new data entries (rows) in a data.table with R

The following data table contains returns (RET) of 5 portfolios (portfolio numbers are factors NOT integers) for two dates. set.seed(123) DT <- data.table(date = rep(as.Date(c("2005-05-02", "2005-05-03")), each = 5), portfolio = factor(rep(1:5, 2),…
conighion
  • 180
  • 7
0
votes
1 answer

Readablility in RSpec tests/output

I'm fairly new to using RSpec. I'm wondering what the best practice is regarding test/output readability. Here I have two examples of testing a class method. The first has straightforwardly (?) readable tests, but the output is a bit ambiguous. …
istrasci
  • 1,331
  • 1
  • 18
  • 40
0
votes
1 answer

How can i optimize my entity framework query for better performance and more readability

There is a heavy page in my site called HotelDetail, that several things related to hotel will be load in this page. hotel, hotel's services,destinations of places to hotel,user's comments,hotel's room with their Services, prices and capacity. All…
0
votes
1 answer

How should I deal with multiple order-dependent conditions?

I have multiple concurrent conditions in which the order is dependent on the conditions. I've come up with multiple approaches to deal with this issue and I need help choosing the best possible solution out of several that I have prepared. Things to…
yosefrow
  • 2,128
  • 20
  • 29
0
votes
2 answers

Where to put CSS pseudo classes?

There are several tips about writing better CSS on the Internet, like sorting properties alphabetical for example, but no one has mentioned about pseudo classes' best practice, e.g. nav ul { /*main styles*/ } nav ul:hover li.selected { …
bobD
  • 1,037
  • 2
  • 9
  • 17
0
votes
1 answer

How do I name members of a parent class (library) for readability in both parent and child classes?

I created a custom library that is usually used as a parent class. After I used it for 1 month, I begin to face difficulty about its readability. It is better described by a simplified real example. Library Level There is my c++ library to manage…
javaLover
  • 6,347
  • 2
  • 22
  • 67
0
votes
3 answers

What is the most efficient and readable way to pass/format lots of variables to a large string?

I have a couple "lengthy" lines like this one: content = "\n\n\n \n {0} - {1}\n
user5870134
0
votes
1 answer

How can i extract images and articles from an html using readability-lxml?

url = 'http://edition.cnn.com/' req = urllib.request.Request(url, data=None, headers={ 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36' } …
Anand VL
  • 19
  • 5
0
votes
1 answer

Code smell - passing boolean control argument to function

Below is the code fragment, there is something which I don't like: function insert(el, child, before){ if ( before ) { el.insertBefore(child, el.childNodes[0]); } else { el.appendChild(child); } } Why not instead have two separate…
CodeYogi
  • 1,352
  • 1
  • 18
  • 41
0
votes
2 answers

Inline Tuple Creation - Which is More Readable?

I'm trying to decide how I should handle creating tuples inside method calls from a readability perspective. The standard way seems to make it easy to overlook the parentheses of the tuple, especially if it's inside several nested calls: Foo(a,…
Christopher Sheaf
  • 185
  • 1
  • 3
  • 13
0
votes
4 answers

How can I simplify or improve readability in complex logic statements?

So I have this monster of a logic statement: (((ncode[i]+key[ikey])>90 && (ncode[i]+key[ikey])<97) || (ncode[i] + key[ikey])>122) I was always told that if you have logic statements that require a new line you might be doing something wrong. I…
FactorialTime
  • 147
  • 12
0
votes
1 answer

Is it better to assign a boolean variable to a condition, or put a "true" boolean assignment within a conditional if statement?

I've recently started on a new development team. I spend a lot of time coding individual projects in my free time, and the last team I worked on at this company my work was mostly individual. At the moment I'm spending most of my time maintaining…
NickSS
  • 35
  • 7
0
votes
1 answer

How to put 'tk.' in front of every Tkinter object the right way?

I threw together a very quick proof of concept python application (~1000 lines) and it now has potential to be taken more seriously. It says for best programming practices, don't use from import * (I did this for the proof of concept)…
user3000724
  • 651
  • 3
  • 11
  • 22