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
7
votes
6 answers

typedef a template with all default arguments

I declare a templated class with all parameters having default arguments, for example: template class Foo {}; Then the following two are equivalent: Foo one; Foo<> two; However, I'm not allowed to just do: Foo three; Is…
Alan Turing
  • 12,223
  • 16
  • 74
  • 116
7
votes
12 answers

How to correctly format PHP 'IF ELSE' statements?

It's been a long running issue that I've come across in many-a-hot-and-steamy coding sessions. One person codes this way another codes that way. So after much push and pull I'm curious... Is there any correct way of phrasing a PHP 'IF ELSE'…
privateace
  • 1,367
  • 6
  • 16
  • 24
7
votes
3 answers

Most Pythonic way to print a newline

If I need to print a single newline, what is the most Pythonic way to write the print() statement? I am teaching someone Python and I want to do it right. The two ways that I found most likely were: 1) print("") Pros: Shorter and more…
7
votes
1 answer

Pass a custom function as template parameter within 1 statement

I successfully passed a function as parameter. // this is in a scope of a normal function class DummyClass{ public: static int dummyFunction(G& goo){ return goo.doSomething (); //non-static function //Edit 3: it calculates hash…
javaLover
  • 6,347
  • 2
  • 22
  • 67
7
votes
2 answers

Using static imports and code readability quality?

Would it be considered worsening the future readability of the code if I used them throughout the code? For example using: import static java.lang.Integer.*; so I can use this code int a = parseInt(scanner.nextLine());
The Law
  • 344
  • 3
  • 20
7
votes
4 answers

How to reduce code bloat in C from error handling & debugs

Consider this function: int get_result(int *result) { int err = 0; int number = 0; if (result == NULL) { printf("error: null input\n"); return -1; } err = get_number(&number); if (err != 0)…
Akeel
  • 301
  • 1
  • 7
7
votes
4 answers

C++ take first n elements from array

Using C++, I want to create an array which only contains the first n elements of another array. Like so in Scala: val arrayTwo = arrayOne.take(n) I know I can use a loop and copy the elements one by one, but this is much more complicated than…
Velizar Hristov
  • 662
  • 2
  • 10
  • 23
7
votes
4 answers

Coding style - keep parentheses on the same line or new line?

Suppose you are calling a function, where there's clearly a need to break down the statement into few lines, for readability's sake. However there are at least two way to do it: Would you do this: return render(request, template, { …
Art
  • 23,747
  • 29
  • 89
  • 101
7
votes
3 answers

Is there a way to use readability and python to extract just text, not HTML?

I need to extract pure text form a random web page at runtime, on the server side. I use Google App Engine, and Readability python port. There are a number of those. early version by gfxmonk, based on BeautifulSoup version by minvolai based on…
7
votes
4 answers

Flesch-Kincaid Readability: Improve PHP function

I wrote this PHP code to implement the Flesch-Kincaid Readability Score as a function: function readability($text) { $total_sentences = 1; // one full stop = two sentences => start with 1 $punctuation_marks = array('.', '?', '!', ':'); …
caw
  • 30,999
  • 61
  • 181
  • 291
6
votes
1 answer

DBT breaking up schema.yml file

We have a large schema.yml file in our DBT folders. It is not the cleanest or easiest to find what we need in it. I am curious if anyone knows of a way to split up this file. I am not trying to overcomplicate things and separate the dbt project into…
6
votes
3 answers

How can I implement Mozilla readability.js to my Website?

https://github.com/mozilla/readability (readability.js is for creating a read view for web pages) How can I implement readability.js to this test Webpage The problem is, readability.js deletes the elements of this website, that I want to keep and…
Marcel
  • 100
  • 1
  • 7
6
votes
3 answers

Reasoning behind no space between Generic brackets in Java

Looking at GenericWhitespaceCheck in Checkstyle docs, Left angle bracket (<): should be preceded with whitespace only in generic methods definitions. should not be preceded with whitespace when it is precede method name or following type…
Adwait Kumar
  • 1,552
  • 10
  • 25
6
votes
0 answers

C# 7 Nested Local Functions – easy to read?

C# 7 introduced local nested functions. They provide even better structure to the code but do they improve readability? Are there any standards, recommendations and best practices? What is easier to read for your eyes and aesthetic feelings? class…
user2341923
  • 4,537
  • 6
  • 30
  • 44
6
votes
5 answers

Optimized algorithm for converting a decimal to a "pretty" fraction

Rather than converting an arbitrary decimal to an exact fraction (something like 323527/4362363), I am trying to convert to just common easily-discernible (in terms of human-readability) quantities like 1/2, 1/4, 1/8 etc. Other than using a series…
ina
  • 19,167
  • 39
  • 122
  • 201