Questions tagged [conventions]
A generic tag covering any accepted method of doing things, which could include naming, spacing, coding, commenting, etc.
1,149
questions
0
votes
1
answer
77
views
Use case for np.log2 vs math.log2
Sometimes, authors use np.log2 instead of math.log2. For example, in this PyTorch code:
num_pools = int(np.log2(spatial))
(where spatial is a Python number)
Because math.log2 is a built-in an ...
0
votes
1
answer
83
views
Use branch prediction with no else statement
I am currently implementing selectionsort. Using the code below and the driver file to test it below. I am currently trying to do micro optimizations to see what speeds it up.
public static void ...
1
vote
2
answers
65
views
Is there a convention in the order of registers used to store values for calculations when using assembly language x86-64?
I know this question was submitted many times, but I couldn't find any clear answer yet, so I'm sorry, but I still have the doubt.
When programming in assembly language, for personal issues, not ...
1
vote
1
answer
47
views
Better practice for double or more line breaks in Rust? [closed]
I want double like breaks like below:
[ your title there ]
some kind of content...
In rust, there're two macros to print to stdin, one with like break and one with no like break.
And some possible ...
1
vote
1
answer
68
views
What is the point of using >| when redirecting to /dev/null?
I'm looking at a Bash file from the GitHub docs. Here's an excerpt:
agent_load_env () { test -f "$env" && . "$env" >| /dev/null ; }
agent_start () {
(umask 077; ssh-...
0
votes
2
answers
144
views
do { } while(0) alternative in macro definition or any other possible options [duplicate]
I have encountered a way of making a multiline macro function definition in C/C++ compilation, that does not meet any clear code conventions (and possibly creates performance drawbacks?). Is it the ...
3
votes
2
answers
90
views
Is Using double variable type instead of float a bad habit [closed]
I have to code C for my college exams and I have practice of declaring double variables instead of float variables. Is it a bad habit? Can they deduct marks for it? (we never exceed the float limit)
I ...
0
votes
0
answers
26
views
HTML sourcemap convention
Per the Source Map spec §6.2:
There are two suggested ways to link source maps to the output. The first requires a server support to add a HTTP header and the second requires an annotation in the ...
0
votes
1
answer
56
views
Best practice: where should user prompt messages reside in Java classes - main or method class? [closed]
I'm creating a Java class with methods, setters, and getters. I have a createTrain method that prompts the user with a message like 'Create how many trains?' in the form of a string. Should this text ...
3
votes
1
answer
124
views
Ways to represent float infinity in C++
I want to express floating-point infinity in C++ for my program.
I came across two ways to achieve this: using INFINITY and std::numeric_limits<float>::infinity().
Both options seem to work, but ...
0
votes
1
answer
26
views
GET for complex payload scenarios?
Our team is designing a RESTful API that strictly follows REST conventions. We are currently facing a challenging problem for which we have not yet found a solution. As you can see, the
...
0
votes
1
answer
100
views
Is it safe in general to use spaces between specific thickness values (e.g. Margin or Padding) in XAML elements?
Recently one of my colleagues started using spaces instead of commas as separators for specific values in Thickness fields like Margin and Padding:
<Label Margin="0 1 2 3"/>
While ...
0
votes
0
answers
23
views
Data sharing across subdomains
I am developing a react app. The idea is to host different components of the app individually under the same domain (but different subdomains). How would this affect the efficiency of the application ...
0
votes
0
answers
6
views
Is it bad practice to raise errors when input doesn't match the requirements?
Is the following syntax acceptable, or should the raising of the error be replaced by adding the if-clause in the else statement?
Example of raising the error:
def ask_birth_year():
while True:
...
0
votes
1
answer
406
views
In sveltekit, what's the convention for splitting client side code between route files?
Both +page.js/ts and the <script><script/> tags within +page.svelte files are for processing client side code.
What's the typical convention for choosing between these 2 files?
0
votes
1
answer
24
views
Is there a convention for how to shape deeply nested ElasticSearch queries?
Very specifically, I am trying to generate an arbitrarily deeply nested ElasticSearch/OpenSearch query, and I was curious if there was 1) a convention for and 2) any performance ramifications for how ...
-2
votes
1
answer
401
views
How to specify CSS media query breakpoints? [duplicate]
What is the right method to use CSS media queries?
Should I specify a breakpoint for each device size or write the queries according to when my website's shape starts to get bad? What is the ...
-2
votes
3
answers
139
views
How to identify a C-style string in C?
In C, a function may ask for or give a C-style string, or not. Or return it.
How to distinguish a C-style string from a non—C-style string? Is there an idiomatic common way to do this?
Maybe you could ...
0
votes
1
answer
548
views
Is there any importance for indentation when breaking a line (using backslash or parenthesis) in python?
Is there any importance for indentation when breaking a line (using backslash or parentheses) in python? How about the style recommendation, which one is recommended? I tried to ask bing chat/chatGPT ...
0
votes
0
answers
39
views
Typescript definition file - for a function, return actual property types, or custom property type itself?
I'm trying to write a TypeScript type definitions file for an external JS library, MusicKit JS. I'm fairly new to TS (and especially declaring type definitions in TS). The MusicKit docs are, at times, ...
0
votes
1
answer
106
views
Is there a convention if GNU-like CLI should consider stdin or file passed as arg to come first?
I'm designing a CLI that should accept input in two ways:
From stdin: cat in_stdin.csv | csv2parquet -o out.parquet
From one or multiple files passed as explicit argument csv2parquet in1.csv in2.csv -...
0
votes
2
answers
175
views
Variable with same name as keyword
Is there a good way to create a variable, function, class, etc. with the same name as a keyword?
What I usually see (and follow myself) is using slightly different names. For example, using clazz or ...
1
vote
1
answer
256
views
What is the best practise for mybatis mapper xml files?
I'm a bit confused about mybatis mapper xml files.
Is it better to have each class in a separate mapper file like below:
<mappers>
<mapper resource="org/mybatis/builder/AuthorMapper....
0
votes
1
answer
583
views
Why is it recommended to use multiple files when making a C++ project?
I'm Learning C++ and coming from GML which is pretty similar in syntax. But what I don't understand is why it's recommended to break up a project into multiple files and multiple types of files.
From ...
0
votes
0
answers
167
views
REST API support and naming for POSTing data as json or file upload
I have a REST API controller supporting the following:
IActionResult PostRows([FromBody] Rows[] body)
POST /api/v1/rows
with a JSON body, e.g. [{ id: 1}, { id: 2}]
I also just added a REST API ...
0
votes
0
answers
16
views
Should I initialize my JComponents when declared or initialize them inside the constructor? [duplicate]
So I've two pseudocodes:
class A
{
JFrame sampleFrame = new JFrame();
JPanel samplePanel = new JPanel();
JButton sampleButton = new JButton("Click");
//...
A()
{
// Other ...
0
votes
0
answers
257
views
Can the usage of the UI Document (form the UI Toolkit) without a camera be considered a good practice in Unity?
I'm need a low resolution (pixelated) view for my game and am using a render texture, so the camera isn't rendering anything to the screen/game view. To bring the downscaled view to the player I'm ...
0
votes
0
answers
13
views
Is there a reason why configuration files options are commented instead of set to false in many systems?
I was wondering why it seems to be a convention to comment options in configuration files instead of setting them to false.
In most cases, instead of having an option like that :
#This an option to ...
1
vote
1
answer
41
views
Is serial considered a keyword or a numeric type?
Here it is mentioned that, "the data types smallserial, serial and bigserial are not true types, but merely a notational convenience for creating unique identifier columns." Everywhere in ...
0
votes
0
answers
16
views
Have we any best practice for standardising key naming across platforms and/or frameworks?
Have we any best practice for standardising key naming across platforms and/or frameworks?
Expecting advice from peoples experience
-1
votes
1
answer
70
views
Industry standards a self taught android developer should learn | Android studio, kotlin
I'm a self-taught android developer, I want to work as an android developer but I have some imposter syndrome. I think there should be coding conventions we should follow when we code, like:
Follow ...
3
votes
2
answers
368
views
Should you decorate dataclass subclasses if not making additional fields
If you don't add any more fields to your subclass is there a need to add the @dataclass decorator to it and would it do anything?
If there is no difference, which is the usual convention?
from ...
-1
votes
1
answer
79
views
is there a distinction between single prefixed underscore and double prefixed underscore in the C++ STL implementation?
I am asking this question for readability reasons not for implementation.
I haven't found any article explaining any distinction between single prefixed underscore and double prefixed underscore or ...
0
votes
0
answers
113
views
What's the point of unwrapping a single value from an array?
I've seen in a few apis where when an array value is expected, then when it's only one value the library/framework will unwrap it from its array and just send the single value.
What is the point of ...
1
vote
0
answers
54
views
Tests name convention best practices
Does anyone knows some good references to guide me in order to give automated tests, the best possible names? I know the rules but want good references to support some of the names that I used. Thanks ...
-2
votes
1
answer
133
views
Should comparison be implemented under `compare` or `operator ==` when both are needed?
In making a class, the compare method and the operator== overload should have identical functionality. Therefore, only one implementation is needed, and I'm trying to figure out if there's any reason ...
0
votes
1
answer
87
views
Python class, methods and conventions [duplicate]
Suppose Im creating a class named Bar:
class Bar:
def __init__(self, foo):
self.foo = foo
Once I create an object of Bar, How should I get the value of the foo variable?
Should I just ...
1
vote
0
answers
156
views
How to handle logging and imports when running a python module as the main script?
I have a python library/package that contains modules with functions & classes I usually import inside of my application's main script. However, these modules each contain their own 'main()' ...
0
votes
1
answer
179
views
How should I organize my update/draw logic when using requestAnimationFrame?
The JavaScript code for my HTML5 game has the following structure:
// <body onload="load()">
function load() {} // Load all images then call init()
function init() {} // Get all images ...
0
votes
1
answer
30
views
Why do maximum line lengths sometimes end with 9?
In some conventions, PEP-8 for example, I see maximum line widths recommended to be set to values ending with 9, such as 79, 99, 119. Why not rounded to 10, like 80, 100, 120?
I feel like it's an off-...
-2
votes
1
answer
49
views
Function naming convention when with qualifiers: adj+verb, verb+adv or adv+verb? [closed]
For example, for names comprehensiveInspect, inspectComprehensively, and comprehensivelyInspect, which to choose?
'inspectComprehensively' obeys syntax, but I have never seen a function name ending ...
0
votes
1
answer
83
views
C#: convention for synchronous method implementing an async interface
I have an interface that needs to be asynchronous. Most of the implementers of that interface will be asynchronous methods.
interface IValidator {
Task<bool> ValidateAsync();
}
However, one ...
-1
votes
1
answer
138
views
Using Python's `unittest` module to compose tests of functions in a separate file
I have an issue with getting my unit tests to resolve calls to the S.U.T.'s functions. The S.U.T. is defined in a separate file, but in the same project. I've considerable Python experience, but I've ...
0
votes
1
answer
111
views
Why do most PyQt tutorials create classes from widgets?
TLDR why do people create classes (Window for example) when its only going to be used once?
Some examples:
RealPython, the first code block
PythonBasics, first code block
PythonPyQt, first code block
...
0
votes
1
answer
187
views
How to reproduce ASP.NET Core 6 conventions (post configure route)
Documentation contains something unclear and unbind to finally result description about conventions https://learn.microsoft.com/en-us/aspnet/core/razor-pages/razor-pages-conventions?view=aspnetcore-6....
1
vote
1
answer
168
views
Is there a convention for JSON serialization of Python objects?
Is there a convention for JSON-serializing (and deserializing) Python objects to identify the object type? I've gone through this example solution below (which I find quite decent with slight ...
7
votes
1
answer
3k
views
What should be the right "commit type" from conventional commit? [closed]
I created a commit with the purpose to unhide a feature, the code change is to only uncomment some lines of code and show the feature, so now the feature will be displayed to the user.
Should this ...
1
vote
0
answers
196
views
Slug - How to deal with Unicode or non-Ascii character
So I am learning Slug convention, but so far they mostly deal with English character, like "Hello world" would be converted to "hello-world", but there are very little information ...
2
votes
0
answers
225
views
Synchronous and Asynchronous code confusing definitions
I might have misunderstood or be missing something but I have to clear this issue:
Asynchronous code means code that gets executed with multiple operations at the same time, without blocking.
...
1
vote
1
answer
878
views
Using import statements for packages and modules only, not for individual classes or functions
The google python style guide mentions at 2.2 that Use import statements for packages and modules only, not for individual classes or functions..
Why is importing functions or classes bad practice? ...