7,738 questions
Best practices
1
vote
5
replies
78
views
Is passing the same value to a function twice bad practice?
this program prints a pyramid (its from a cs50 problem set). I call the function recursively by decrementing n, but i also wanted to keep track of its initial value in all the loops after the first ...
Best practices
3
votes
3
replies
69
views
How to avoid messy if statements when using many feature flags in Angular?
I’m part of a team of 10 developers, and recently our product team requires us to use feature flags for almost every new change.
The idea is that they can always “roll back” to the previous behavior ...
Best practices
1
vote
4
replies
147
views
How to declare an array of structure to keep track for the end?
I'm trying to have an array of structure.
The sprite_s struct:
typedef struct sprites_s {
bool *initialized;
sfSprite *duck;
} sprites_t;
Can I, with memset, fill the array with data so I can ...
Best practices
1
vote
2
replies
80
views
Guideline for method ordering
What's the best practice, preferably backed by a publicly available guideline issued by a tech company or a standards organization, when it comes to the order of method declarations in a Java source ...
-3
votes
1
answer
89
views
Usage of tap({ error }) vs. catchError for side effects [closed]
In Angular/RxJS, when should you use tap({ error }) and when catchError for side effects? How do you best separate the two logically or combine them?
For example, does resetting the UI to its previous ...
0
votes
0
answers
37
views
Can't enable code editing in WebStorm with Vue cli
I'm new in Vue, and I'm trying to enable code style inside a <script> block in WebStorm, and in the settings everything is correct, but the style still doesn't work inside the <script> tag....
-6
votes
1
answer
154
views
Is it acceptable practice to alias nested templates like std::vector<std::vector<T>> for readability in a team environment? [closed]
I'm aware that C++11 introduced alias templates (which is well-explained in this thread) that makes it simple to reduce verbosity. For example:
#include <vector>
template <typename T>
...
2
votes
0
answers
59
views
ESLint rule to enforce newline indentation style for multi-line assignments/expressions?
I'm trying to enforce this indentation style in TypeScript:
const response: Asana.Response<Asana.Tag[]> =
await tagsApi.getTagsForWorkspace(process.env.ASANA_WORKSPACE_GID!, opts);
...
1
vote
0
answers
26
views
How to disallow newlines before or after comments with ESLint?
The @stylistic/lines-around-comment rule allows me to require new lines before or after comments, but I can't seem to find a way to disallow them. I thought the @stylistic/padding-line-between-...
2
votes
2
answers
180
views
how to change code style format on flutter
I am developing with Flutter using Android Studio. When I try to format the code using the Cmd + Opt + L keys, it ends up like #1 below.
Is there a good way to make it look like #2?
//#1
@override
...
-1
votes
1
answer
49
views
Indentation Rule in SonarLint for Typescript
I am new to sonarLint rules, I am trying to findout the rule for indentation and variable naming in typescript rules.But couldn't find it.
I was able to find naming rules for classes and functions but ...
0
votes
1
answer
123
views
Wrap long C++ function heads with clang-format
I just started to use clang-format and I could set up quite a lot of things, but I am stuck with my general handling of long function headers. This is how I usually create them:
void ...
4
votes
2
answers
190
views
How to make all our code comply to coding conventions/coding styles?
I'm trying to set up SonarQube to have our coding conventions/rules in it. I'm looking for ideas on how to do this best. We're using C# as our dev language and Visual Studio as our IDE.
We have dozens ...
0
votes
1
answer
231
views
Switch case: Return from impossible default case
What to do if I use a switch case in a function, and the default case should not happen, yet I must return something?
I tried to program some cellular automaton, where there are two possible cell ...
0
votes
2
answers
104
views
Avoid ifdef in my project for multiple hardware
I have a project written in C on STM32 platform. My project source code will be available for multiple hardware. I use CMakeLists
For example I have 2 header for the moment hardware1.h and hardware2....
-6
votes
3
answers
81
views
Scope Variable inside Python's Try, Except block
At first, i wrote my simple code as below:
while True:
try:
x = int(input("what's x? "))
except ValueError:
print(f"x is not an integer!")
else:
...
0
votes
1
answer
59
views
How to manage multiple uses of a model in an application?
I'm currently implementing an application and have for example a Customer model that's used in several different parts of the application. Each part only uses a subset of the properties from the ...
-1
votes
1
answer
147
views
I want to add retry logic and. refactor the code in the python socket connect code
I have the below Python code which checks whether the ssh host is up or not:
`for hostname ,ipaddr in host_dict.items():
if tcp_conn.tcp_port_is_open(ipaddr, constants.TCP_PORT, ...
1
vote
1
answer
53
views
Can I create a default object in the constructor of a class in the dependency injection pattern?
I'm starting to develop a rest API in the MVC pattern using NodeJS and Typescript.
In my model layer I created entities, services and repositories.
My controller layer is decoupled from the framework ...
-1
votes
1
answer
127
views
Best practice regarding code in constructor for initializing in C#? [closed]
I am learning C# and learning about classes, and I have a question regarding best practices in class initialization and constructors.
For instance, I was doing a practice exercise from Player's Guide ...
-2
votes
1
answer
49
views
Which of these is the best structure of a if-statement in a BlocListener for a SignIn? [closed]
I'm designing an application that uses Flutter Bloc and i'm not sure which of the two approaches is better in terms of structure. One is shorter in terms of lines of code, while the other is more ...
0
votes
2
answers
83
views
How to reuse switch block labels without goto?
How to implement the following code without goto and unnecessary code complexity?
namespace Test
{
static class Program
{
bool keyA = false;
bool keyB = false;
// ...
...
0
votes
1
answer
65
views
What is the recommended way to store application-wide values like the path of its AppData folder?
I'm working on a C# application and need to store application-wide values in a MVVM project, such as the path to its AppData folder. What is the recommended approach to achieve this? I'm very new to C#...
1
vote
1
answer
45
views
How to create custom mixed data types shortcut
I have a number of functions in my code whose data type of their input arguments are basic data types. Mostly string|int|float and sometimes null|string|int|float .
public function example(string|int|...
-2
votes
1
answer
57
views
error: request for member 'write' in 'sg90', which is of non-class type 'int' sg90.write(180); [closed]
I was trying something for my first project working with Arduino about an automatic trash that open when a hand get close to her. While I was coding, I got an error.
Here is the code:
#include <...
1
vote
0
answers
62
views
Using Repository pattern to fetch data from different places and build list of objects
My spring boot project is structured so that i have modules contract (that handles incoming requests) and impl (that deals with the logic). Contract has a facade that passes the request to a facade in ...
-2
votes
1
answer
31
views
JavaScript function to validate an email address using regular expressions, ensuring it follows the standard format [duplicate]
implementing a JavaScript function to validate email addresses using regular expressions. The function needs to check whether the provided email address follows the standard format.
typically try ...
0
votes
0
answers
78
views
Suppress "this.field" code style warning only in constructors
Is there any way to suppress Visual Studio's this.Field code style warning only in constructors (without individually annotating each and every constructor in my code, I mean) and keep it everywhere ...
0
votes
1
answer
39
views
Need help on how to get my bigger image shown above the thumbnail images after radio botton checked on the thumbnail images without use javascript?
Here is the code i have. when I click on the image1, the same image1 will shown in the bigger container, however i could only place the bigger image container below the thumbnails images i have as the ...
-1
votes
1
answer
209
views
What is the 'correct' approach to clean code UI in Delphi Pascal? [closed]
I'm quite new to Delphi Pascal, and i'm not sure if this Question suits SO, but i don't really know where to ask this else.
My issue is, that i try to develop a Delphi Pascal application, that has an ...
-1
votes
3
answers
107
views
How do I reduce repetitive error handling in java [closed]
So I have a code snippet similar to this. I feel like the if statements should be in a common function. I am not sure how to handle that because school and student should be passed to this function ...
1
vote
1
answer
43
views
Is there a solution to a react installation error?
I tried running react-create-app (app_name) but ended up having a problem. I also tried cleaning the cache, --force, same issue. I tried deleting the node module file I previously had and ...
0
votes
2
answers
235
views
Pixela does not let me create graph (HTTP Error: 400) - user does not exist or the token is wrong
I get an error message (HTTP Error) 400 when trying to create a graph.
The user has been successfully generated, as can be seen from the below message:
import requests
USERNAME = "...
1
vote
0
answers
95
views
How can align if statement in cpp with clang?
I would like to align the following lines
if (_a) { return; }
if (__b) { return; }
if (____c) { return; }
with clang-format.
Desired Result:
if (_a) { return; }
if (__b) { return; }
if (____c) ...
0
votes
1
answer
104
views
Why Feature Envy sample code in the clean code book is a code smell?
I am reading clean code and in the 17 section it is said that when a class is more interested in the fields and functions of another class it means that feature envy. then the following sample exist ...
0
votes
1
answer
361
views
is it okay to change the value of parameter inside of method in Dart?
In Dart, it is allowed that change the value of parameter in method like this
void changeValue(int num) {
num = 10;
}
I know that above code isn't occur Error, but num = 10; can't change actual ...
0
votes
1
answer
29
views
NextJS import location styling?
I have already a project which has a file that is importing following function
import theme from 'src/configs/theme'
But when i created new nextjs project and created same folder structure and ...
-2
votes
2
answers
59
views
INNER JOIN ON LEFT JOIN. What best way solve problem? [closed]
If you need inner join on a left join what variant better for performance and coding-style?
"Cross" joins
SELECT
demo.id AS demoId,
demo2.ID AS demo2Id,
demo3.ID AS demo3Id
FROM demo
LEFT ...
-3
votes
1
answer
42
views
How to access webtable data in selenium?
enter image description here
Exception in thread "main" java.lang.AssertionError: expected [true] but found [false]
I tried to automate the web table code by using valid Xpath, stream, and ...
-1
votes
1
answer
890
views
Suspect code indent for conditional statements
currently I am working on C project and i faced the following error -
8-print_base16.c:11: WARNING: suspect code indent for conditional statements (8, 15)
related with Betty coding style.
This issue ...
0
votes
1
answer
130
views
How to make clang-format not add new line before opening brace of a function with requires clause?
When I auto-format with Clang-format, it is always inserting a newline before brace when requires clause is there.
This
constexpr auto size() const noexcept
requires(!Unique) {
return stdr::...
0
votes
0
answers
144
views
Checkstyle with Maven plugin has not expected failed checks
I have my_checkstyle.xml file. I assume it is based on Sun's checkstyle.
It is located in separated module that is built together with other common modules for the project. I try to useit for the ...
1
vote
1
answer
141
views
How to mitigate spelling mistakes in Python properties?
I've read quite a bit about Python properties and I understand their benefits, as well as them being generally more Pythonic than getters/setters. However, I haven't found any mention of their usage ...
2
votes
1
answer
171
views
How to change input float name color on ionic?
I want to change the color of the float name for the input.
i set --border-color: #222428; and this change the color of borders only, i need to change color of the word password and email on hover, ...
0
votes
1
answer
64
views
how i can give some specific amount of spacing on console after printing a string
lets just say that lenght of string is 10 than put 5 spaces on console after string , but if lenght of string is 5 than put 10 spaces on console some buid in function for this purpose in c++
lets say
...
0
votes
2
answers
158
views
Which code is better? Efficiency vs code readability [closed]
I solved a problem using different approaches. I was wondering which approach is better.
I believe in terms of time complexity, the first approach is more efficient, but the code is long and looks ...
0
votes
1
answer
45
views
I couldn't get data from class
I've a class for store scripts in data folder like this
import 'package:keydata_zipcikti/models/script_model.dart';
const scripts = [
Script('create network folder bash script')
|
|
|
];
and ...
0
votes
1
answer
163
views
Extracting embedded-hal pin definitions into a separate file
I would like to make my project's pin layout configurable and extract all pin number definitions into a separate module.
I can't erase all pins because I still want to take advantage of embedded-hal's ...
0
votes
1
answer
384
views
Generating Access Token through OAuth2 Returns Null in Flutter/Dart
My app is in Flutter/Dart. I am trying to generate an access token through OAuth2 with Azure credentials. Once I login with my credentials, it successfully authorizes, but it doesn't redirect ...
0
votes
2
answers
175
views
Butterfly pattern output
public class butterflypattern {
public static void Pattern(int n){
for(int i=1; i<=n; i++){
for(int j=1; j<=i; j++){
System.out.print("* ");...