123 questions
-3
votes
0
answers
107
views
How can I restructure my code to avoid having a loop where each iteration depends on multiple if-else branches? [closed]
I have this code for my school assignment:
void doAction(int &counter, int &position, int action){
if (action == 3) {
position = (position + 1) % numOfValues;
} else {
counter = (...
3
votes
2
answers
108
views
What kinds of optimisations can produce a const parameter?
I always wondered if it is a good practice to have always prefer const parameters when I can ? On one side you tell the compiler that this variable won't be mutated inside the function's scope so it ...
1
vote
0
answers
317
views
Spotless and java-code-format don't apply No Wildcard Import
The java code format suggest that star/wildcard imports are not tolerated.
Without the help of the IDE, neither the java-code-format nor spotless can enforce this.
Is there any success case out there?
...
0
votes
0
answers
17
views
Does a named standard exist for comment annotations?
I have encountered, and used, several different forms of comment annotations. Eg.
// TODO: Also trigger this task
// FIXME: in this very specific circumstance this should handle this way instead
// ...
1
vote
0
answers
442
views
Cppcheck suppress unusedFunction for user library calls?
I have a c library that I am passing through Cppcheck and am getting a lot of unusedFunction warnings for public calls that the user makes.
The Cppcheck wiki is quite unhelpful with their checks ...
0
votes
1
answer
108
views
PhpStorm Catch sentence with multiple exception classes PSR-12 code style
I am using PhpStorm 2023.3.4.
I set the code standards for my project to PSR12. This means 4 space indentation, no tab char.
I have a PSR-12 compliant chunk of code like this:
<?php
class MyClass {
...
-1
votes
1
answer
304
views
Code standards check before commit in PyCharm [duplicate]
I would like to have some analysis done on Python code before I commit, to gently “enforce” the standards.
I would like to have a check such as:
no print in new code
No methods longer than 50 lines
...
2
votes
0
answers
158
views
Is it Pythonic to import an external symbol imported into another module?
Please guide me on the pythonic way for a minor code-standards question. Searching SO re imports gets me many discussions comparing import foo vs from foo import bar which is not my concern here. ...
1
vote
0
answers
46
views
Structure Policy for Django / Python Libraries
Question Summary
Hi Folks,
This is a kind of opinion question, I've built a Django library for my company and I keep swithering and changing my mind on how to structure it.
Possible strategies I've ...
1
vote
1
answer
317
views
Not operator or Strict comparison on false?
What's the best practice for writing if-statement on boolean value?
function foo(boolean $bar)
{
if ($bar === false) // ...
// or
if (!$bar) // ...
}
With a Not operator it's more compact,...
0
votes
1
answer
201
views
How to wrap long lines of Apache Camel Java DSL code
In my project we are using Apache Camel via Java DSL
This is how a typical route looks:
from("direct:MyPizzaRestaurant")
.routeId("PizzaRoute")
.log(...
1
vote
1
answer
961
views
Exceptions to control execution flow in managed .NET code - a good practice or not?
Here is a very simple functionality example, to make the discussion easy. Suppose, I am logging some abstract objects' content in a flat log. If an object's json representation contains property ...
3
votes
1
answer
1k
views
Code Standard - is it better to have a getter/setter even though they are never used?
The IDE has suggested to add a getter/setter to a private field.
It is never used, and reaching the field is only from within the class.
what is the preferred coding style? keeping the never used ...
0
votes
1
answer
145
views
How we can achieve writing reusable and modular code
How we can achieve writing reusable and modular code in an Enterprise code. What are the basics to get started
-1
votes
2
answers
58
views
Are there penalties for just using the new keyword instead of creating a class variable before calling the class method?
Example
(1)
var classVar = new class();
classVar.Method();
(2)
new class().Method();
I like the second way, less wordy.
Is there a performance difference?
Is it considered bad coding practice?