Questions tagged [code-readability]

Code-Readability is how easy it is to understand a piece of code. Whether it be reading someones code, or writing your own.

Code-Readability is how easy it is to understand a piece of code. Whether it be reading someones code, or writing your own. This includes Coding Conventions, positioning of white space, declaration of variables and among other coding practices.

337 questions
2
votes
3 answers

What should be the name of the arguments in Array.reduce?

As a matter of best practices in terms of code readability, Which of the following naming convention should be used while naming arguments of the callback in Array.reduce? const studentAges= [15,16,14,15,14,20] Generic const sum =…
2
votes
2 answers

IF statements - How to reduce / simplify the amount of source code

I'm in trouble trying to reduce this section of code of my function: checkData(day, month, year, area) { if(area == "year" && year == this.year) return true; if(area == "month" && month == this.div && year == this.year) …
user10026373
2
votes
3 answers

better way to check if variable has enum value in C

my question is related to appearance of the code and how is it doing in terms of performance. let's say i have an enum: typedef enum { THIS_IS_A_VALUE1 = 65, THIS_IS_A_VALUE2 = 10, THIS_IS_A_VALUE3 = 45, THIS_IS_A_VALUE4 = 5, …
someone
  • 101
  • 2
  • 12
2
votes
2 answers

Java 8: How to elegantly remove redundant outer objects on base of inner object ID and date in Java 8?

There is ObjectOuter which contains another object called ObjectInner which is having an ID. We need to remove Redundant ObjectOuter having duplicate ObjectInner Ids. (We have another DateFinish object in picture) public static List
fatherazrael
  • 5,511
  • 16
  • 71
  • 155
2
votes
4 answers

avoid a lot of if-else checks

I am working on a moderately large C file where I need to do processing for 3 different exclusive conditions. (if condition 1 is present do this, if 2 is present do something else and likewise). So, at many places in that file, I need to do if/else…
hari
  • 9,439
  • 27
  • 76
  • 110
2
votes
5 answers

Neatest/most idiomatic way to rewrite this If in C#

I have this if-else statement which does what I want. What it's doing is pretty straightforward as you should be able to tell. if (width != null && height != null) { if (top != null && left != null) { ret.type =…
2
votes
2 answers

Best design pattern for structured sequential handling

Doing maintenance on a project I came across code, which I find unnecessary hard to read and I wish to refactor, to improve readability. The functionality is a long chain of actions that need to be performed sequentially. The next action should only…
2
votes
12 answers

C#: Extension methods and the Not operator Best Practice

I have an array of strings and I wish to find out if that array does not contain a certain string. I can use the not operator (!) in conjunction with the Contains method like so: if (!stringArray.Contains(searchString)) { //do something } The…
Chris Dunaway
  • 10,974
  • 4
  • 36
  • 48
2
votes
6 answers

Better way to set default values?

Can we make the following Ruby code shorter, and at the same time more readable? height = do_some_calc height = 128 if height == 0
mlzboy
  • 14,343
  • 23
  • 76
  • 97
2
votes
1 answer

Lazy with DryIoc, am I doing it right?

I need to be able to use DryIoc to create Lazy objects. Because I'm working with a legacy application which use a God object and relies on a heavy Dictionary of complexe KeyPair, I'd like to replace each value with a…
Serge Intern
  • 2,669
  • 3
  • 22
  • 39
2
votes
2 answers

Method call overhead

What's the overhead of calling a method in .NET which returns immediately (because a condition which is the first code inside is not met)? I'd argue that no matter how real-time your application is, that overhead is negligible and that in any case…
Román
  • 1,943
  • 2
  • 18
  • 28
2
votes
1 answer

Dictionary items to variables

Is it possible to make simple variables from dictionaries? Something like: dct = {'key1': val1, 'key2': val2} should be turned to the variables key1 and key2, so that print key1 val1 print key2 val2 Why it may be important? In my case because of…
jake77
  • 1,892
  • 2
  • 15
  • 22
2
votes
1 answer

Atom IDE : Vertical code folding lines to improve code readability

I have searched on this for quite some time and am unable to find an answer after which I've turned to you folks. I am working with the Atom IDE and my query is very simple - I would like to have to vertical faint lines which run from beginning of…
Aakash
  • 21,375
  • 7
  • 100
  • 81
2
votes
2 answers

How to use constant powers of 2 readable in c++?

I need several integer constants with 2^n and 2^n - 1 in my GNU c++ code. What is a good practise to keep the code readable? The code uses decimal values at the moment 4294967296 and 65536 which is hard to debug in future. 2^12 is not implemented…
Jonas Stein
  • 6,826
  • 7
  • 40
  • 72
2
votes
1 answer

print multiple lines in shell - improving readability in provisioning a Vagrantfile

I use printf to setup my Nginx settings, and it works fine, but it's awkward to read and alter; is there a better way to improve readability? config.vm.provision "shell", inline: <<-SHELL sudo rm /etc/nginx/sites-enabled/default sudo…
Mike Thrussell
  • 4,175
  • 8
  • 43
  • 59