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

How can I make this function more Pythonically efficient?

I am working on a script for an automated workflow. It expects a CSV and a disk image to be present in the directory that is supplied as args.input. I want to check for and handle every possible scenario: no CSV, no disk image, too many CSVs, too…
dongle
  • 599
  • 1
  • 4
  • 17
0
votes
1 answer

I Can not get Readability API parser to work

I am trying to use the Readability API parser - The readability blog post for python gives this code example: from readability import ParserClient parser_client = ParserClient('your_parser_token') parser_response = …
Raymond
  • 41
  • 1
  • 7
0
votes
1 answer

A better method for naming properties which are elements in a 3D array?

I have "Ball"s, with some properties like "x", "y" and "z", which loop over a number of "Steps". I am doing a lot math where the properties interact, so, to make my code easier to read and write, I have named the positions of the elements of the…
0
votes
2 answers

Change PyDev way of indenting function argument

I'd like to use PEP8 accepted format: # Hanging indents should add a level. foo = long_function_name( var_one, var_two, var_three, var_four) How to configure PyDev so when I open bracket and press Enter it moves caret to next line with…
omikron
  • 2,745
  • 1
  • 25
  • 34
0
votes
2 answers

Best approach to pass parameters to a function?

It's about code readability: I've been dealing with this for a long time and I always wonder what would be the best approach to deal with passing parameters. Lots of times, reading code from other programmers I find lines as…
Didhack
  • 58
  • 8
0
votes
2 answers

Should I put the easy or the hard case first in an if statement

Quite often I have an if statement where I have two cases, one of which requires a one-liner and one of which needs lots of code to be dealt with. From a readability point of view, which should I put first, given that I don't know how likely each…
Bluefire
  • 13,519
  • 24
  • 74
  • 118
0
votes
1 answer

Is there a limit to how large a function can be?

New programmer here! I'm creating my first script on my own, and I have a particular function that is quite large, as in 50 lines. I understand that theoretically a function can be as large as you need it to be, but etiquette-wise, where is a good…
Lentro
  • 45
  • 5
0
votes
1 answer

Is there a better readable way to write this if statement chain?

I have the following code: Creature::cancelWalk() { Player* player = getPlayer(); if (!player) { if (getMonster() && getMonster()->getMaster() && getMonster()->getMaster()->getPlayer()) { player =…
Alexandre Severino
  • 1,563
  • 1
  • 16
  • 38
0
votes
3 answers

Is there any significant benefit to reading string directly from control instead of moving it into a variable?

sqlInsertFrame.Parameters.AddWithValue("@UserName", txtUserName.txt); Given the code above...if I don't have any need to move the textbox data into a string variable, is it best to read the data directly from the control? In terms of performance,…
Kevin
  • 1,940
  • 3
  • 24
  • 38
0
votes
2 answers

Please help me convert this C# 2.0 snippet to Linq

This is not a homework ;) I need to both A) optimize the following code (between a TODO and a ~TODO) and B) convert it to [P]Linq. Better readability is desired. It might make sense to provide answers to A) and B) separately. Thanks! lock…
Hamish Grubijan
  • 10,562
  • 23
  • 99
  • 147
0
votes
3 answers

css styling using custom attributes to make it more readable. good or bad?

I have some css styles with background colors, borders, etc... like this: .bg-red { background-color:red; } .bg-blue { background-color:blue; } /*more background colors*/ .border-red { background-color:red; } .border-blue { …
JoJo
  • 806
  • 1
  • 13
  • 26
0
votes
1 answer

Using `continue` as a break statement

I know a lot of people debate on break vs. if condition: quit == True in while and until loops. I've heard a common opinion of break is that it isn't verbose and it can lead to terrible code structure. Though I was working on a project for CS110,…
Lightfire228
  • 546
  • 1
  • 5
  • 17
0
votes
0 answers

Good practice for local def in a complex method

I am about to write a quite long treatment which I expect to exceed 130 lines. In Java, I would have written a public method and several private methods to split the logic into more readable pieces of code. However, those private methods would not…
Dici
  • 25,226
  • 7
  • 41
  • 82
0
votes
1 answer

How to avoid ragged edged text in web typography?

How do I best avoid ragged edged text in web typography? Is there any common solution apart from using text-align: justify? I'd like to improve the readability of my web site, but words in my mother tongue are rather long (compared to English),…
user1438038
  • 5,821
  • 6
  • 60
  • 94
0
votes
0 answers

c++ parsing a text file using getline()

I am preparing a simple program that is supposed to take a file and then check for instances of certain characters ( spaces, some sentence delimiters and so on ). In the code below, I have the file open. I was able to get delimiters working by…