730 questions
Advice
4
votes
14
replies
237
views
Is there any way to make this more neat?
I currently have a block of code looking like this:
if (StateA)
{
DoSomething();
}
else if (StateB)
{
DoSomething();
DoSomethingElse();
}
I was thinking there must be an elegant way ...
0
votes
0
answers
21
views
Context specification when linking functions in instances in AHK
Good day, I'm trying to improve my OOP competence and trying to create a code to generate a single window(gui) which hold n checkboxes based on the files the code finds in a specific folder. The idea ...
0
votes
2
answers
116
views
Ugly Triple Indirection: Extensible Buffer Management Struct [closed]
I'm currently trying to build a string parser for an AVR based stepper motor controller. The idea is to observe some input string over UART, then breaking apart this string into several sub-buffers ...
1
vote
5
answers
155
views
Find the remaining Enum
I have the Enum A, B, C.
In a method, I am given two different Enum and must return the remaining Enum.
Example: I receive A and C I must return B
The solution that I have is to use if elseif else:
...
-1
votes
1
answer
244
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
2
answers
94
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 ...
1
vote
2
answers
110
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 ...
0
votes
2
answers
589
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
1
answer
318
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 ...
1
vote
0
answers
49
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. ...
-3
votes
1
answer
62
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 ...
1
vote
2
answers
342
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 ...
0
votes
0
answers
60
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_(...
2
votes
0
answers
69
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 ...
1
vote
0
answers
222
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
98
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
122
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, &...
-1
votes
1
answer
286
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
2k
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
2
answers
117
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
vote
0
answers
62
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
0
answers
337
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(...
2
votes
4
answers
2k
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/...
0
votes
0
answers
66
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
votes
1
answer
159
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 ...