Questions tagged [coding-style]
**DO NOT USE! This tag refers to an entirely opinionated subject and is therefore no longer on-topic.** Questions that follow coding style and conventions.
7,756
questions
0
votes
0
answers
6
views
How can you make SSH read the password from keyvault variable for sudo reboot, which it doesn't do by default?
We have a requirement for rebooting the linux server via a python code via an airflow dag and I tried to do achieve it using sudo reboot command, by first connecting to the server as a root userad ...
3
votes
1
answer
37
views
Recommended way to write a condition with multiple ifs
I am trying to do alert the user if any 2 of the 4 counter variables is non-zero.
What is the best way to code this without a long if else condition like this?
# Description: report violation if any ...
0
votes
0
answers
20
views
Wanted to add Events and Notification to JS, HTML, CSS, Calendar
I was working on making a calendar and wanted a way to add events to each date and a notification ahead of the date if possible. I would be greatly appreciative for any insight. I have got an HTML, ...
2
votes
0
answers
30
views
Is it clean code to use if($variable) when $variable is type hinted in php?
In php I always check a variable for the exact type, like if ($myVariable instanceof MyClass).
I check at least if its null, if its not an object if ($myVariable === null).
If I really just need to ...
0
votes
0
answers
49
views
C coding style question - using global variable vs static variable & wrapping function
there is a global variable which indicates whether booting is done. I am using vim with cscope, so whenever I try to find assignment or definition of this variable, it shows all symbols.
So, I want to ...
0
votes
0
answers
18
views
How to add content to a specific category of navigation menu using html in blogger
I'm new to blogger. I don't even know about coding. Some days ago, I created a blogger using default blogger theme. I have created a custom navigation menu by watching tutorials.
I want to know about ...
0
votes
0
answers
9
views
why does slicing operation prints string twice instead of once in python 3.10 [closed]
as per this answer, https://stackoverflow.com/a/29237560/19406548
a = [1,2,3,4,5,6]
print(a)
a[2:2] = ['C']
output : [1,2,'C', 'C', 3, 4, 5, 6]
why here C is coming twice..?
because [2:2] means that ...
1
vote
0
answers
21
views
I am writing the code for "String to integer" from leetcode and getting below error or runtime error. Please help me how to solve this error
class Solution:
def myAtoi(self, s: str) -> int:
n=len(s)
ans=''
INT_MIN = -(2**31)
INT_MAX = (2**31)-1
sign=False
if (ord(s[0])>=65 and ord(s[...
-2
votes
0
answers
36
views
Which one is more optimized- string concatenation or a dedicated class
I am solving a graph problem. One node is not identified by a number but by multiple attributes- attr1, attr2, attr3 (all being strings)
Right now I am concatenating attr1, attr2, attr3 and performing ...
0
votes
0
answers
14
views
How to change/remove the name of app on the Mac's Application Menu bar?
Does anyone know how to tweak the name of each app on Mac's top menu bar?
I just want to make it disappear time or change its name to something else sometimes, but have no idea how to tweak it.
I have ...
0
votes
2
answers
26
views
Error: Method 'toDouble' cannot be called on 'int?' while creating an app on Flutter
Hi I am having an error while creating an app on Flutter
Error: Method 'toDouble' cannot be called on 'int?' because it is potentially null.
Try calling using ?. instead.
...
0
votes
0
answers
60
views
What is the best naming convention for constant variables? [closed]
I usually use the UPPERCASE naming convention for const variables, but I sometimes forget and am very inconsistent with it. I know a lot of people use the UPPERCASE convention, but what are the limits ...
0
votes
0
answers
12
views
Using setPostSimFcn to process the outputs of a simulation each time?
My model 'notch' is a microgrid model.
and I have three phase currents [i1,i2, i3] measured and sent to the workspace.
It is to produce a signal signature for the three currents which is [x].
then ...
0
votes
2
answers
20
views
I tried this javascript code of simple if else block Error:-Declaration or statement expected
constant bill = 275;
let tip = 0;
let total = 0;
if (bill > 50 && bill < 300);
{
tip = 0.15 * bill;
console.log("tip", tip, "bill", bill)
}
else if (bill < 50 || ...
-1
votes
1
answer
25
views
How can I make these JS code more elegant? [closed]
I have encounter a coding problem. I try to insert some style elements to HTML, and when these style loaded, console log "done"
var genStyle = () => {
const instance = {}
setTimeout(()...
-1
votes
0
answers
14
views
(Tweepy) Sending an Exiting Tweet to Someone via Direct Message
I am trying to send an existing Tweet -- i.e., a Tweet someone else has already posted -- to another user via DM using TWEEPY.
Is that possible? And if so, what method do I use?
0
votes
1
answer
43
views
What is the correct code organazing according to Clean Code and Refactoring with Inline method?
I have such a method
private async Task<List<ApiModel>> GetCollectionAsync(HttpClient httpClient,int categoryId, int pageNumber, string sessionId)
{
var response = await ...
-1
votes
1
answer
35
views
How can i customize date picker in flutter like that
I have a project and designer demanding the date picker like that anyone help how to customize it like that
0
votes
1
answer
23
views
Best Practice? Making conditional statement strict or following logical flow?
So I'm new to coding and I'm going through the Python 100 Days of Code challenge on Udemy and was on the task of creating a leap year calculator. The following is my code vs the instructors code. My ...
0
votes
2
answers
24
views
Calculating median of a sorted array using Quicksort, Quickselect method and Selection Sort Python [closed]
I solved that using Quickselect algorithm. Now i want to implement this using Quicksort and Selection sort algorithm.
-1
votes
1
answer
38
views
What are some common degenerate cases for structures or functions in computer science?
I can think of only a few for example the zero length list or set. The zero length string. How about empty matrices or tensors? How about parallelograms with all zero degree angles? How about a ...
0
votes
1
answer
24
views
REST API naming for short entity version
For instance,
I have a team entity and API to retrieve teams will be like this:
GET \teams
To retrieve a single team
GET \teams\{team_id}
and so on...
What name will be good if I need to return a ...
0
votes
0
answers
34
views
Is there any way to set rule for removing trailing comma using PHP-CS-Fixer?
I'm using PHP-CS-Fixer to set up linting in project. There is a rule trailing_comma_in_multiline. It lets you to check whether all multiple-lines arrays have trailing commas.
Is it possible to reverse ...
0
votes
1
answer
13
views
Is it possible to have optional property in ebean ORM
When using Ebean, let's say, I have the ORM class as follows:
@Entity
public class Student {
@id
private UUID id;
String age;
}
Assuming that the age is a nullable column in the ...
-1
votes
0
answers
27
views
Code style: Use method to initialize class in Java
I have an interface IWorld and a class Caller which calls methods from the interface, say method1(T something), method2() being called with some variable T. My goal is that Caller does not know ...
1
vote
1
answer
22
views
Conditionally display data in HTML with conditions
I want to print properties of an object like Nord, Est, Ouest... as elements in HTML like label: value which label is the name of direction and value its real value if exist!
But sometimes some ...
1
vote
0
answers
28
views
How can I enable auto formatting in CLion?
I installed CLion a day ago and I want to format the code automatically after I type semicolon like in Visual Studio (I am coding in C++). I tried the code style menu but it works only if I format it ...
0
votes
0
answers
38
views
Parsing elasticsearch response
TL;DR
Please suggest some strategy which would not alter state of variable being passed to nested method calls.
Longer version:
I'm writing a code to parse elasticsearch nested aggregation response ...
-1
votes
0
answers
35
views
What is the cleanest option out of these three for finding the max [SOMETHING] in a loop?
Consider the following possibilities. Suppose you know the collection has at least one item.
// option 1: using an index syntax instead of the preferred iterator/range-based-loop
Obj max = ...
0
votes
2
answers
45
views
Where to put Laravel validation that is not related to column
For example, I have an HTTP request that handles some entity creation (let it be Role)
And validation looks like this:
class CreateRole extends FormRequest
{
public function rules()
{
...
0
votes
2
answers
33
views
Clean up code with multiple toggle states in reactjs
I have a couple of buttons with antd library and want to add the loading state for each. I create multiple states to control those loadings
const [loading, setLoading] = useState(true);
const [...
0
votes
1
answer
30
views
Javafx: Reduce events of checkable Listbox
I have a generic Javafx Listbox with checkable items (up to 20 items).
When I (de-)select an item, a property change is released to update other parts of the program.
It works all fine so far.
But I ...
0
votes
1
answer
29
views
Python game timing
I'm trying to make a game in which I've got a bomb object that a has self detonate attribute called time.
when this time reaches 0 the bomb 'explodes' and disappears from the screen and then generates ...
-1
votes
1
answer
27
views
Where should I declare variables if the function is called so many types
I have an IRQ handler, it's called each time the user press a key on his keyboard, hence this function might be called so many time in a short range. Right now, inside the handler I declare two ...
0
votes
0
answers
29
views
Is there a way to enforce variable declarations in Python through coding style?
I'm using PyCharms to work on Python projects. I find that writing functions is easier when we declare the type of the function parameters or the type of the new variables declared explicitly. It also ...
-1
votes
1
answer
31
views
Avoid repetitive null checking for arguments in functions calling functions
Context:
getProfilesFromResponse is a utility function used by websocketMessageHandler to parse the profiles from a websocket message.
What's a better and clean design?
Should getProfilesFromResponse ...
-1
votes
1
answer
52
views
Clean way to write this if
Hi I'm writing python function and when I try to test it with pylint it shows: R0912: Too many branches (20/12) (too-many-branches). How should I write this code below cleaner?
rows = len(board)
cols =...
0
votes
2
answers
53
views
Is there a short elegant way to write variable providing with exception?
So, I want to write these kind of things for my code, but there's too much code for one variable. How can I use modern Java for solving this problem shorter or cleaner? Moving it in the separate ...
-1
votes
2
answers
33
views
Scala Test: how to assert lenghty exception message securly and clean without hardcoding?
I have the following code, which is used to (sha) hash columns in a spark dataframe:
import org.apache.spark.sql.DataFrame
import org.apache.spark.sql.functions.{sha2,lit, col}
object hashing {
def ...
0
votes
1
answer
43
views
How to make this code cleaner? react native
I am building a stack navigator and want to make it cleaner I Tried many times but I couldn't
here is my code,
export default function Navigation() {
const {isSignedIn} = useSelector(state => ...
-1
votes
1
answer
35
views
Argument convention in PyTorch
I am new to PyTorch and while going through the examples, I noticed that sometimes functions have a different convention when accepting arguments. For example transforms.Compose receives a list as its ...
-1
votes
1
answer
47
views
Use identifier in PHP and how does it affect the logic
Use identifier is used when we want to send some outer environment variables inside closures so I have a scenario.
$invoiceList = UserInvoice::where('user_id', $this->user->id)
->...
0
votes
0
answers
24
views
How to make clang-format to apply both Align and BlockIndent in AlignAfterOpenBracket?
There're Align and BlockIndent in AlignAfterOpenBracket with BlockIndent I can do this
// what I want(only with BlockIndent)
socket.async_write_some(
asio::buffer(_data, length),
[this, self](...
-2
votes
1
answer
43
views
Structuring go interfaces with subpackages [closed]
I am developing my first real go application and am trying to wrap my hand around my codefiles should be structured.
The main part of my code is going to be a number of types which all implement a ...
-2
votes
2
answers
46
views
Which type of function fits more [closed]
Say, I need to sort some scores from classOne, classTwo, and classThree. Each class has their own file, named as stated previously. I need to print them on the screen, as following:
Class One:
John 23
...
0
votes
1
answer
52
views
How to write this in an eaiser way?
How could I write this in an eaiser way?
product_pairs =
[[(1, 2), (1, 3), (1, 6), (1, 8), (1, 9), (2, 3), (2, 6), (2, 8), (2, 9), (3, 6), (3,
8), (3, 9), (6, 8), (6, 9), (8, 9)],
[(0, 5), (0, ...
0
votes
1
answer
62
views
What is the purpose of <asp:templatefield>?
It seems like there is HeaderTemplate and ItemTemplate and EditItemTemplate within the TemplateField at the code which I am examining.
What else can exists with <asp:TemplateField> apart from ...
-2
votes
2
answers
101
views
Is it more "correct" to disable a function with a special value or a second parameter? [closed]
Say I have some function that I may or may not want to execute during a particular run of the code, and this function also takes some argument that is passed in as a parameter at runtime. Is there ...
-3
votes
3
answers
60
views
Java coding style to be more concise
How can I compact these code in Java without creating other objects?
myObjectNumberOne.setTitle("title");
myObjectNumberOne.setBody("body");
myObjectNumberOne.setAutostart(true);
...
-1
votes
1
answer
40
views
Finding out what the block element <hb> is used for?
In the book I'm using to study HTML it says and I quote "<h1>,<h2>,<hb>,<p>, and <blockquote>, are all block elements. But what is the block element <hb>? I ...