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 ...
5 votes
2 answers
115 views
How to simplify template member function definition?
I have a class that looks like this template<class T, class THash, class TEqual, class TCompare> class GraphT { public: typedef NodeT<T, THash, TEqual, TCompare> NodeInt; typedef ...
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 ...
-2 votes
1 answer
80 views
Naming of file while saving with extension
How can I save a file with the name as: oldname+"_new"+extension in an elegant way? I currently do: ext = os.path.splitext(file)[1] output_file = (root+'/'+ os.path.splitext(file)[0]+"...
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) { ...
-1 votes
1 answer
78 views
How do I debug the issues in my code so that my subfunction can also print?
This is a code of my function, I had to breakdown the main function into subfunctions. When I tested the main function it worked but not when I tried to print the output of subfunction. I tried to ...
0 votes
2 answers
133 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) { // ...
0 votes
0 answers
61 views
Angular & RxJS - Seeking suggestions on the best practices & code refactor
I created a mini app which shows the Continent & the Country selections. just to practice RxJS concepts. (You can checkout to ng-conf/learn-rxjs-01 branch on https://stackblitz.com/edit/stackblitz-...
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 ...
-2 votes
1 answer
160 views
indentation to make software control flow apparent. What do you think about it? [closed]
How many times have you encountered a function with a return statement deep within the code? Or failed to notice a break or a continue in a loop? While I have not been blindsided by return recently, I ...
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
4 answers
133 views
What are the implications for the compiler of using a for loop with ternary statements as conditions?
Instead of having two different loops that have identical printf statements, you can make a for loop that uses a boolean and ternaries to switch it forward or backward. Why is this bad form? Because ...
-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' ...
1 vote
1 answer
101 views
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 ...
-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 ...