340 questions
0
votes
1
answer
75
views
Is it possible to reuse property code to get rid of annoying property copy/paste boilerplate in a dataclass?
This is going to be a bit hard to explain, but I'll try nevertheless:
So, I'm a novice trying to turn a Kahoot Generator I made into a library to share on GitHub. After thinking about how I wanted the ...
0
votes
0
answers
44
views
Can't use BinaryFormat functions modified using BinaryFormat.ByteOrder to feed a field length to other BinaryFormat functions
Context
Writing a Power Query function to read binary data from a binary stream where some fields are preceded by their length as a 32-bit Little Endian Integer.
A systematic error occurs when using ...
1
vote
1
answer
110
views
Is conditional awaiting misleading?
Consider the following two code snippets (assumed to be inside an async function that returns void / we don't care about the return value):
Long version (without await):
if (condition) {
...
0
votes
2
answers
132
views
throw exception and then catch vs duplicate error handling
I have a code logic as below:
// Option 1
try {
String result = x.getResult();
if (result == null) {
// some handling
logger.error("xxx");
}
} catch (Throwable t) {
// ...
1
vote
1
answer
1k
views
Visual Studio Format getter and setter on one line
I just scaffolded a project using Template Studio WinUI v5.3 and when I press Ctrl K D to format document, the getter and setter is placed on new lines.
current.cs
public class MyClass
{
public ...
0
votes
0
answers
85
views
Do compiler optimize memory usage of temporary variables used for better code readability?
Edit: Changed bools to const bool, Added argument to anotherValueTest. May have oversimplified it before.
I am using a MSP430 and the integrated Compiler from the IAR Workbench. Link to workbench
...
-1
votes
1
answer
64
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' ...
-2
votes
3
answers
143
views
Explain this if-else condition in Python
Code
def addition(num):
if num:
return num + addition(num - 1)
else:
return 0
res = addition(10)
print(res)
Explanation
I know what the function is doing:
it is a recursive ...
-1
votes
1
answer
51
views
Simulating C/C++ empty defines in Java
I know Java does not have pre-processor, but I struggle to find a way to do this.
I am looking to create macros to improve code readibility, to specify which of the functions or parameters are for ...
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
217
views
Am I using dynamic arrays correctly?
New programmer here. I need to write a program using dynamic arrays to simulate an election. The program should first ask for a number of candidates, then take the candidate names and the number of ...
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
213
views
Why using Macros in class for magic number readiblity is not right in class C++
I used Macros at top of class to tell what is 1 and 45.00 instead of just writing magic numbers.
Question is why using Macros in following class (see the default constructor) is not a good idea? Why ...
1
vote
2
answers
3k
views
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::...
0
votes
2
answers
200
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 ...
2
votes
1
answer
508
views
How can I access elements of cv::Vec4f by readable name?
I'm using the cv::HoughCircles() function from OpenCV to detect circles in an image. The function takes an output parameter of type cv::OutputArray to provide the results. Based on the example code I ...
0
votes
1
answer
1k
views
The Cyclomatic Complexity of this method is 13 which is greater than 10 authorized
Please help reduce the cyclomatic complexity of this method. I don't really understand how this can be done, I need all the conditions in this method and obviously there are no duplicates.
private ...
0
votes
1
answer
256
views
go structure filling: pointer receiver vs returned values
Looking for a reference to a good reading or sharing an experience of what is better from the code readability/maintenance/best-practice perspective.
There are two options on how to assign values to ...
2
votes
2
answers
207
views
Defining the values of a field in a database in the Laravel code to make the code more readable
Currently, I am writing a laravel application with a part for sending messages between the staff at the company and the clients.
So, I have a field named "status" in the database. In this ...
0
votes
2
answers
121
views
Improving code with reflection and generics
With the following code, how could I improve its readability using reflection and generics?
It's a lot of repeated code, but I'm new to these concepts.
"dl" is an interface but I'm not sure ...
0
votes
1
answer
56
views
Python panda datastructure
I had a datastructure as a numpy array. Python accessing a data structure
Instead, I see I can get it as a panda dataframe. To write readable code, I'd like to address the data in the values column (...
0
votes
4
answers
109
views
How could I reuse this JS code for other questions in my own online quiz? Objects? Frameworks?
How to go about reusing my js code without just copying it and changing the names of variables? I want to add more questions but reuse the same code? This is a simple web test/quiz.
CURRENT CODE ...
0
votes
1
answer
39
views
Is there any way for grouping cases in MySQL CASE statements?
Is there any short form for writing MySQL CASE statements as in PHP switch? For example, if i have:
SELECT
CASE Type
WHEN 1 THEN "A"
WHEN 5 THEN "B"
...
-1
votes
4
answers
2k
views
How to line wrap a long boolean expression with parentheses in java
How to wrap this expression in java for more readability with the constraint that the sub expression (shouldSendSomething(x) && loooongFunctionName1(x) && looooongFunctionName2(x)) ...
0
votes
0
answers
116
views
Is there a programming language that is close to english and read purely left to right?
Is there a programming language that is purely written left to right?
Example (close to Python syntax):
Normal Python: a: int = 2 + 3
Left to Right Python: 2 + 3 = a: int
The assignment should be ...