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.
729
questions
1
vote
0
answers
64
views
golang: pattern for handling message queues? Are functions anti-idiomatic? [closed]
Me and my boss had a discussion today in how to implement services that works with messages coming in from event queues. We call these services processors. One of us argues for using several functions,...
0
votes
1
answer
28
views
Is there any difference between using "content = { }" parameter or directly "{}" in Jetpack Compose?
I was wondering if it is better to use directly "content = {}" parameter instead of "{}" despite I see more often people using "{}".
Is the code cleaner or does the code ...
0
votes
1
answer
41
views
How do i use loop to name or use variables in Kotlin?
I'm trying to create a "pixel" layout and manage movements over there for an exercise, and I would love to know a simple/creative way to name and use all the variables without doing terribly ...
0
votes
0
answers
27
views
Improve Readability of Nested Foreach Loops - Should I Create Separate Methods?
I have a piece of code in my C# project that involves nested foreach loops. While it works as intended, I find it difficult to read and maintain due to its complexity. I'm wondering if it's a good ...
0
votes
2
answers
59
views
How to improve this program's readability?
I'm learning the basic of Python dictionaries and am having an exercise on nesting dictionaries in a list. It basically told me to make 3 dictionaries about 3 people, nest them inside a list, loop ...
-3
votes
2
answers
88
views
Python for loop: array unpacking vs range deconstruction
I'm following a data structures and algorithms course taught in Python at the moment and the instructor always opts to unpack arrays (well, lists) using a range functions (method 2 below) instead of ...
0
votes
2
answers
77
views
How to deal with constant error checking in C?
In C, I am calling many functions having to check if they worked. The code gets ~3x bigger because of it! An example:
char *myStr = malloc(sizeof(char));
if (!myStr)
return NULL;
Is there a more ...
-1
votes
1
answer
230
views
How to make this Python function for finding colourful numbers operate on any number?
A colourful number is one that includes no duplicates in the list of it digits + the products of the subsets of its digits. For example, the products of 263 are [2, 6, 3, 2x6, 6x3, 2x6x3]. These are ...
0
votes
2
answers
298
views
ImportError: cannot import name 'legacy_round' from 'textstat.textstat'
I am trying to import legacy_round from textstat as follows:
from textstat.textstat import textstatistics,legacy_round
But I get following error:
ImportError: cannot import name 'legacy_round' from '...
1
vote
0
answers
14
views
issue in code structure when trying to divide components to logical elements
My team writes a url db.
I am making some restructuring to optimize in it. Since Im also going to be the maintainer of it, I thought of adding readablity refactors. However, I have a situation where ...
1
vote
1
answer
184
views
Are there good naming conventions to get around long variable names, without having to rely on comments for better readability? [closed]
Basically I always try my best to avoid comments whenever possible. I watched many videos from Uncle Bob and regarding the things he wants to express, there are many things I agree to.
He once ...
-2
votes
1
answer
234
views
Initialization with tuple keyword vs parenthesis in python [closed]
This question is about design and readbility, not performance:
Is it more pythonic to initialize tuples with the tuple keyword, or just with parenthesis? Both do the same thing, but explicitly typing ...
1
vote
0
answers
25
views
Cleaner/more performant way to map a point offscreen to the edge of the screen?
so I'm trying to implement a screen waypoint system, like you've probably seen in dozens of different games, where an icon is visible through walls, wherever the target is in the player's viewport. ...
0
votes
1
answer
439
views
When to create separate widget of a component in a very long flutter .dart file
I have this code as a part of a Column having many children making it as long as 400 lines. Is it a good practice to split widgets like these into separate files? What is the recommended number of ...
-3
votes
1
answer
58
views
C# Same methods for different argument type
I have this inteface:
public interface ICommand
{
bool Execute(Vector2 commandPosition);
bool Execute(GameUnit gameUnit);
bool Execute(string shortcut);
}
And a class with these methods ...
0
votes
1
answer
776
views
SQL insert statement - FILL null values for all columns except some
I have an insert statement where I only need to fill 15 columns out of 70 - and all the other columns can remain NULL. I would like to find a way to write this statement in a shorter matter without ...
0
votes
0
answers
14
views
Can a website section / div "sense" the colour or lightness of the background?
Designing websites I often want to use a colour or image as a background. This often involves changing the default colour of the text, or creating a semi-transparent text background to make the text ...
1
vote
2
answers
146
views
Making an enum with stored LinkedHashMap values
I'm somewhat of a beginner to java, although I understand the basics. I believed this was the best implementation for my problem, but obviously I may be wrong. This is a mock example I made, and I'm ...
-1
votes
1
answer
54
views
which of these ways to verify object is better in perspective of readable and maintainable? [closed]
I'm programming Human Resource data sync batch program.
This program reads user and department data from customer company's database and save to our database.
For example, there is class named 'User' ...
0
votes
0
answers
52
views
How to effectively use explicit argument names to clear up "magic numbers" in this polymorphic context
I have this code:
class Base
{
public:
Base(int attributeA, int attributeB, int attributeC) : attributeA_(attributeA),
attributeB_(attributeB), attributeC_(...
0
votes
0
answers
74
views
Readable HTML getting Truncated
I am trying to extract the Readability version of this site - [https://app.termly.io/document/privacy-policy/93a0d7a9-a628-44b5-9748-4f853bed4112][1]
However, I noticed the readable content gets ...
0
votes
1
answer
23
views
This code calculates the total price of a list of items but how can i improve it?
function calculateTotal(items) {
let total = 0;
for (let i = 0; i < items.length; i++) {
if (items[i].type === "food") {
total += items[i].price * 1.1;
} else {
...
0
votes
0
answers
19
views
How to split a large list into multiple smaller lists?
I have an list of 688184 household incomes in df3 also indexed by state, year and serial number and I wanted to have more readable code than the code below. I brute-force manually broke down the lists ...
0
votes
0
answers
172
views
How to make one annotation imply another in Java or Kotlin
I am using Retrofit and Kotlin to build an API client. For accessibility, I will provide examples in Java.
There are a few methods in this API that require a JSON body with only one parameter. I made ...
2
votes
0
answers
55
views
How to solve 'unhashable type error: 'Series' when adding new variable to dataframe that measures readability of FOMC statements
I am looking to calculate the Flesch-Kincaid grade level score of FOMC Statements. When trying to add a new variable for the Flesch-Kincaid score to the dataframe which includes FOMC Statements, I am ...
0
votes
0
answers
95
views
Problem in output of CS50 week 2 Problem set readability
The code is ment to take user input, then compute how many words, letters and sentences are in the input. Then calculate the index.
index = 0.0588 * L - 0.296 * S - 15.8
Where L = average number of ...
0
votes
0
answers
117
views
Mozilla readability - unable to retrieve inner html
We notice using mozilla/readability , we are unable to retrieve innerhtml for some of the websites. Is there anything, in particular, to be done to fetch these details ?
const Readability = ...
0
votes
1
answer
209
views
CS50 PSET2 Readability 2022
Okay! I'm really new at programing, so I don't really know whats going on... my program compiles just fine, but it only says 'Before Grade 1', and I saw with debug50 that float L and float S are not ...
0
votes
1
answer
41
views
What constitutes "one action" in "one line - one action"?
I was going through this Javascript tutorial when I came across a call for “one line – one action”.
alert( 2 * counter++ );
Though technically okay, such notation usually makes code less readable. ...
0
votes
1
answer
97
views
Are there any negative effects to using labels in C to actually label your code for improved readability?
I'm a self taught begginner in C and a few weeks ago I had the idea of using labels to label my code blocks, instead of comments. I'm not using them for flow control (I've never used goto) but to ...
0
votes
1
answer
107
views
Improve code readability of a Python lambda expression with condition
First of all I do not know if these types of questions are appropriate in stackoverflow.
I have the following dict:
file_dict = {"asda_20221003:ada":1, "scdfws_20221104eaf2we":5, &...
0
votes
1
answer
52
views
How to make bs4 code not look ugly as hell
I'm making a scraping project with bs4 and I simply cannot see a way to make it less eye-bleeding. Everything looks like this:
try:
max_tweet_date = max(
[tweet_date_to_datetime(...
-1
votes
1
answer
122
views
How would I make the readability better in Java
I feel like the amount of while loops nested into each other isn't too readable and could be simplified down but I'm not sure how I can simplify it down. Could someone let me know what I would have to ...
0
votes
1
answer
26
views
Is there any tools to do this kind of code formatting automatically
It looks like a formal letter made with MS Word.
I wanna try this kind of format, but doing it manually is a waste of time
Is there any Code Editor/ extension/ something that can do this automatically
...
0
votes
1
answer
575
views
Most pythonic way to import custom helper functions into a main script?
Let's say we have an app, app.py, that does a variety of things. Of course, along the way, there is bound to be "helper" functions that do things such as cleaning data, creating a ...
-2
votes
1
answer
209
views
My code for CS50x Harvard on edX problem set 2 doesn't give back the expected output
I am taking CS50x Harvard on edX, and I'm currently working on problem set 2, readability. I've compiled my code, and it should work to determine the reading level like it's supposed to. However, ...
2
votes
2
answers
96
views
How can I optimize this code for better readability?
I'm not a good programmer, for my bodypart-based collision detection in a game in unity I'm making I've ended up with a switch that looks like this despite my best attempts to simplify and shorten it:
...
-1
votes
3
answers
147
views
How can I clean up these print statements?
So, I'm playing with .csv files learning how to read and present the info. I'm printing the results to the terminal, but as I print more content, I have a wall of print statments that just keeps ...
1
vote
0
answers
38
views
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 ...
0
votes
2
answers
115
views
How to make code more readable and simpler
I have this simple code which i have reduced to as little lines and made as readable as possible. I feel i did a good job but was wandering if it is possible to reduce down further? Any help would be ...
0
votes
0
answers
234
views
'_io.TextIOWrapper' object has no attribute 'replace'
I'm trying to look at the readability scores for a text file using this Python code:
posts = open("/Users/jchavis/Desktop/Data/posts.txt","r")
readability_scores = Textatistic(...
0
votes
0
answers
45
views
Is there an equivalent of the C# dollar ($) operator in Java? [duplicate]
In C# there is the $ operator for strings:
$"Some Text here with {aVariable}";
Is there a similar way of doing that in Java?
The current way I do this is:
"Some Text here with " + ...
0
votes
3
answers
952
views
Is there a way to avoid a nesting of Flutter widgets?
I am going to try Flutter, but all examples on GitHub I've found includes code with a high nesting level of widgets that is bad for readability. For example, this one:
https://github.com/smartherd/...
2
votes
1
answer
78
views
Is there a way to force function parameter to be "unchangeable"?
<?php
// Enter your code here, enjoy!
class Foo {
private $a;
public function getA() {
return $this->a;
}
public function setA($a) {
$this->a = $a;
}
}
...
0
votes
0
answers
58
views
Is it possible in C# to give multiple names to a single variable/property? [duplicate]
Say you have the following code:
interface Foo
{
public int Value { get; set; }
}
class Bar : Foo
{
public int Value { get; set; }
}
Now suppose I'd like to give the Value property a more ...
1
vote
1
answer
65
views
running multiple lines of R code that differ by a single variable each time to improve readability
I am looking to improve the readability of my code by seeing if there is a way to "loop" or "re-run" lines of code that are very similar but differ by a single variable each time.
...
-1
votes
1
answer
117
views
How to name variables and structure code in dynamically typed languages for better readability? [closed]
Debugging old code in dynamically typed languages like Python, Ruby, JavaScript, etc. is often a struggle. For example, below Ruby function extracts only the key:val pairs from the result (hash) if a ...
1
vote
0
answers
168
views
Flutter - Difference in Widget & Stateless Widget & Stateful Widget
Quick one if anyone is aware as I haven't been able to find out.
For widgets I know there are two namely different widget types. One that extends Stateless widget -->
class RoundedButton extends ...
0
votes
1
answer
70
views
Python: Best way to declare more than one keys in a shelf
Context: I'm trying to practice shelves in python and wanted to make the most basic program to try out methods.
I wrote this code:
#creates a shelf, with 3 set keys and 3 input values then prints it
...
1
vote
3
answers
81
views
Are there performance benefits from separating data calculations from data formatting in Kotlin app?
I have a codebase where all my data calculations and data formatting occur within a single function. Are there any performance benefits to separating these out into separate functions or does ...