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

How can I make this more readable and cleaner?

I am wondering what I can do to make this more readable and clean. By readable, I mean easier to read for other developers. I don't really want to have the same code twice. I am thinking that I could make some method or methods to make it shorter,…
Thomas Nappo
  • 241
  • 4
  • 13
2
votes
6 answers

C++ Nested If Statement Readability

I have reasonably complicated logic for if statements. I am currently using: if(numerical_evaluation) { if ((!boolOne && boolTwo) || !boolThree){ //do stuff } } where boolOne, boolTwo, and boolThree are logical operations (perhaps…
enderland
  • 13,825
  • 17
  • 98
  • 152
2
votes
3 answers

Do macros make the code more readable?

I had a debate about macros and their readability. I think that in some cases using macros can make the code shorter, more comprehensible and less tiring to read. For example: #include #define EXIT_ON_FAILURE(s) if(s != 0) {std::cout <<…
White Zebra
  • 309
  • 1
  • 5
  • 15
1
vote
1 answer

format dictionary for with new lines and tabs when converting to string?

Is there a simple way to format a string of a dictionary? I have a dictionary that I want to save into a file, to do this I am passing it to the file as a string using str(dictionary). This means that the dictionary looks like this in the file, just…
1
vote
3 answers

clojure-more readable way to write this function?

I have written this function to convert a vector of maps into string. There is a second map called field-name-to-columns which contains a mapping between the field-name and the actual name of columns in my database. My goal is to get a string like…
Razz
  • 15
  • 4
1
vote
2 answers

Why would you declare a std::string using it's constructor?

Most people when declaring strings in C++, or most other languages, do it like so: std::string example = "example"; However I've seen some code samples where it is done like this: std::string example("example"); To me it seems like it needlessly…
1
vote
0 answers

How can I improve the readability of my Swift data formatting function?

I have the following function in Swift and am looking to improve the readability: Adding the variables to the Array below all of the let variables seems kind of funky to me and I was thinking maybe it would be good to declare an empty array above,…
Dylon Jaynes
  • 166
  • 11
1
vote
1 answer

Is there a readable built-in generalization of the `zip` method with automatic "unpacking" of tuples?

Given two lists a=[(1,11), (2,22), (3,33)] and b=[111, 222, 333] I would like to know if there is a syntactically easy-to-read solution to iterate over triples of values as follows: for x,y,z in WANTED(a, b): print(x, y, z) # should iterate…
flonk
  • 3,726
  • 3
  • 24
  • 37
1
vote
1 answer

Apache Thrift Struct for better readability

I just started working with thrift and created following thrift interface. map> getInformationByIds(1: set Ids) As you can see, the return type is a map of maps. I want to know wether I can improve the…
Isuru Herath
  • 298
  • 6
  • 20
1
vote
5 answers

Improving readability

I need to find minimal date(year , month , day, hours , minutes , seconds), my code is working, but it look's terrible and it's very long. What can I do to avoid this ladder to make my code readable? ( I want to use only stdio.h ) #include…
user17221096
1
vote
1 answer

Type hints for all the classes defined in a module

Let's say I have a module CustomClasses.py, which contains 10 classes. I have a method let's say process() which can take an object of any of the classes of the CustomClasses module. Method: def process(custom_class_instance): some code... Now,…
1
vote
1 answer

How to decide on the amount of test cases for smaller than functionality?

I have some function that does one thing for 5 cases that conveniently have the values 1 to 5 and something else for the other cases. The possible values come from an API that currently has ~100 values but is constantly growing. I want to unit-test…
1
vote
0 answers

How to create a generator that brings specific, unrelated lazily evaluated expressions

Discovered this after discovering the all( ) function in Python doesn't shortcircuit as I expect because the expressions inside the list you send are not lazily evaluated. So: all([ previous_task is not None, self.task_type ==…
1
vote
3 answers

convert array into array of subarrays

I'm looking convert an array into an array of subArrays. An example would be: let arr = [1, 2, 3, 4, 5, 6, 7, 8] arr = [[1, 2], [3, 4], [5, 6], [7, 8]] Now if the length of this array is not divisible by 2 let arr = [1, 2, 3, 4, 5, 6, 7] arr = [[1,…
Jack.c
  • 1,035
  • 1
  • 11
  • 14
1
vote
1 answer

Grabbing data with relations. 1 big query or afew small queries

Suppose I have a table structure like I want to grab all user metas is it better to do a big query joining all tables in the image ... SELECT [columns ...] FROM usermetasections LEFT JOIN usermetakeys ON ... LEFT JOIN usermetas ON ... LEFT JOIN…
JM at Work
  • 2,417
  • 7
  • 33
  • 46