Questions tagged [programming-practices]
Programming Practices are the commonly or not so commonly used practices in development of software. These can include things like Agile Development, Kanban, Coding shortcuts, etc.
1,595 questions
-4
votes
3
answers
219
views
is it bad practise to go back to your last backup when you encounter an unneccessary bug? [closed]
I find when I am programming and I fix a bug in one area of the codebase, sometimes something slightly related or maybe unrelated breaks, and as a result I usually copy and paste the fix to a ...
-1
votes
1
answer
220
views
Reducing Server Calls or Improving Server Response Times?
In the company I am working for, we have been told to keep server requests to a minimum. There are probably reasons for this specific to the company, but it made me wonder.
Let's say I am building a ...
2
votes
2
answers
602
views
Design of a modular application
I'm developing an application (Java) in a modular architecture. I have two approaches in mind and I'm not sure which one will be "better code" in case of maintenance and conventions.
I have ...
2
votes
3
answers
1k
views
How to keep track of Indices
I've discovered my biggest issue with practicing interview questions and writing software more generally is keeping track of indices in python, maybe partly because my first two languages were the 1-...
0
votes
3
answers
148
views
Should we test private data (static objects in this case) to make sure it maintains its structure?
I had a discussion at work about whether to unit test a private static object we're using as data for a public component.
const data = {
45: { name: 'John' },
2: { name: 'Patricia' },
27: { name: '...
1
vote
1
answer
461
views
Common methods of generating code with code
I wish to develop an application that can generate code based on an user input.
Long story short: a user gives a formal description of a Resource (can be viewed as a REST resource) and based on this ...
6
votes
2
answers
3k
views
Is it good practise to rely on the insertion order of python dicts?
Since python 3.7, it is guaranteed that dictionaries maintain insertion order. The linked stackoverflow Q&A states
This simply means that you can depend on it.
Is it good practise to depend on ...
-2
votes
2
answers
4k
views
Best practices around writing testable extension methods
I’m currently working in C# and I’d like to write and extension method against a type. There is a small amount of repeated logic between classes surrounding JSON deserialization, using the ...
-1
votes
3
answers
729
views
Improving APIs that call 3rd party APIs [closed]
So I'm designing the backend of a platform that often calls other 3rd party APIs.
The issues I've noticed were latency issues (sometimes the calls were fast, others a bit slow >15s) and I'm ...
15
votes
5
answers
6k
views
Are there any problems with using continue or break?
My Software Engineering teacher just said: "Avoid using continue and break, always make it work without using these". Is there a problem with these instructions? I would say he didn't say ...
13
votes
6
answers
6k
views
Is it bad practice create "alias" variables to not use globals or arguments with long names in a method?
Is it OK to create a variable which only purpose is to increase readability?
Example:
public class Example
{
private final HowLongCanARepositoryNameReallyBeRepository ...
6
votes
2
answers
2k
views
Why would you use 'new' and 'delete' for something that will be referenced through a vector?
I'm going through some code from this article about ECS-systems in game programming and trying to understand it, and something I'm seeing a lot is using heap memory in places where it seems like ...
9
votes
4
answers
665
views
How to document alternative code I considered but didn't go with due to performance?
I write code in R, and often find myself attempting to optimize the code for better performance. In a given script that tackles a specific problem, I test different code alternatives and compare them ...
3
votes
4
answers
815
views
Is it a bad practice to have an interface method to tell whether it can handle an object?
interface Resolver {
boolean canResolve(SomeInput input);
SomeOutput resolve(SomeInput input);
}
public static void main(String[] args) {
List<Resolver> resolvers = ...;
...
0
votes
1
answer
753
views
Source of "... against the interface, not the implementation"
For a paper I am writing, I need to find the origin of the following two phrases:
Code against the interface, not the implementation
and
Test the interface, not the implementation
(Note: the ...
9
votes
2
answers
1k
views
Should function names describe their parameter types?
If you wish to perform the same action using different parameters, you can either make differently named functions:
public Apple findAppleById(long id){
return repo.findById(id);
}
public Apple ...
1
vote
1
answer
155
views
What is the best approach to use a common variable in multiple method in a request in laravel [closed]
I have a $c variable that is calculated at the beginning of the request. After calculating this several nested methods use it as a part of their job. Is it better that I pass down the $c variable to ...
2
votes
3
answers
211
views
How to deal with interpreter dependencies
Consumer software often has interpreter dependencies. How should a situation where the required interpreter is not by default installed on the targeted system be handled for consumer software, soft ...
4
votes
4
answers
1k
views
API Design: Sending errors in the response
Suppose I have a products API:
/products
GET: List of products
POST: Creates a product
/products/12345
GET: Get a specific product
PUT: Updates a specific product
So is this a good idea for the ...
1
vote
2
answers
3k
views
One API or Two APIs one for internal use and the other for external use
I follow the Layered architecture Like this:
But with two differences:
I use Blazor Assembly for UI Layer.
I have API layer(REST) In between the presentation layer and the service layer.
My ...
2
votes
1
answer
485
views
How to balance 'efficient' vs 'clean' code? [closed]
I have been coding in python for a little over a year, and I have learned a lot and developed quite a few applications, in the process.
I do not program for my profession, I simply program ...
1
vote
2
answers
561
views
Is using KDoc/Javadoc comments inside of a function considered bad practice?
I often find it helpful to use KDoc/Javadoc comments inside of a class or function instead of normal comments. IntelliJ colorizes them more obviously by default and, more importantly, allows ...
1
vote
1
answer
904
views
Is it bad practice to run different versions of code in different environments? (i.e. test, prod)
As an example, let's say you have the following pseudocode:
if test environment: # meaning you don't have the typical service account prod perms
sudo as service account + do operation
else: # in ...
1
vote
3
answers
319
views
What do you call a routine that contains a smaller routine?
Just a question about general terminology. A subroutine as I understand it is basically a packaged subset of instructions that a routine runs to obtain a specific result that it needs for a larger ...
0
votes
2
answers
121
views
Calling general-purpose methods from the code that clearly needs only specific behavior
Here are a couple of examples in Python:
clearly_even = 2 * get_integer()
print(solve_for_any_integer(clearly_even))
def solve_for_any_integer(x):
while x % 2 == 1:
x = make_even_from_odd(x)
...
1
vote
4
answers
244
views
When should a method depend on a data source and NOT have it declared as a parameter?
I was assigned a code review to one of my colleagues.
I posed the following, which I wanted to share here in order to hear whether I am right or wrong.
Consider the following code snippet:
public void ...
1
vote
2
answers
125
views
Using public nested types to self contain complex POCOs for serialization
So a lot of the web says not to use public nested types unless you need the member visibility semantics (including this msdn article, even though that article hasn't been touched since 2008).
For the ...
2
votes
2
answers
2k
views
If Entities, in the Clean Architecture, are enterprise wide rules how different applications consume them?
In this post, Uncle Bob writes:
Entities encapsulate Enterprise wide business rules. An entity can be an object with methods, or it can be a set of data structures and functions. It doesn’t matter so ...
-2
votes
1
answer
147
views
Does it make sense to have a return type for a method doing batch operations [closed]
My application syncs data between 2 different services. Data flow looks something like this:
Target <-- My Service <-- Source
I have a method that starts this batch operation:
// we have ...
1
vote
1
answer
180
views
Best practices when combining development environments
I'm working on a Swift-project (an iOS-app) where a webview is used to show an HTML-document. This document is manipulated by some JS, which is compiled and minified from TypeScript. There's also SASS ...
3
votes
2
answers
242
views
Checking the user in almost all use cases
I have a web application that has Users that belong to Companies. A User can only belong to 1 Company at a time and they can manage their own company information. I'm using java spring and I'm ...
3
votes
4
answers
7k
views
Is it good practice to put comment headers into each file?
I have an Unity project with countless of C# script files and I'm working on it solely.
Although nobody else is working on it, I'm aware that some form of code documentation is crucial for my future ...
4
votes
3
answers
1k
views
Passing object or using the field
I would like to know what is a more appropriate way to code in Java. Is it generally better to pass entire objects in the method's parameters or just using the fields from the class?
Using the field:
...
-1
votes
1
answer
80
views
Unit testing a chain of network requests - how many tests?
I have some fairly complex code, that is a chain of API calls. The result of one call is the input of the next.
class PaymentService {
func pay(userId: String) async {
let paymentSource = ...
-1
votes
1
answer
264
views
How to avoid cyclic dependency in UI application
I'm developing an UI application where I ran into an issue with a cyclic dependency. Here is the simplified code, to explain the problem.
#include <list>
class UiStyle;
UiStyle* CreateStyle();
...
1
vote
4
answers
196
views
How to design a program that would definitely use microservices in production, but which I want to demo on a virtual machine for my portfolio?
So I am an independent software developer and I'm building up my portfolio in the hopes of helping with job applications. I have a broad design for a web based "app" (not really like a phone ...
0
votes
1
answer
122
views
where to put conditional in chain of operations
I have two types of input data which will go through a number of steps for processing. The processing differs only in one of those steps, e.g.:
TypeX: A() -> B() -> Cx() -> D()
TypeY: A() -&...
3
votes
3
answers
696
views
What is the technical terminology for the practice of checking for null and edge cases in programming?
I took a PHP test for NASA recently and thought I should have done better. I believe the issue is something I used to know about, but need a refresher in. I can't remember what it is called though. It ...
4
votes
3
answers
2k
views
When doing multiple operations on a variable, is it considered bad practice to reuse the same variable name?
A commonly repeated best practice is to not reuse local variables. However, when doing multiple small operations on the same variable, I struggle both with coming up with good names for all the ...
11
votes
1
answer
5k
views
Is it bad practice to require the same module in multiple files in Javascript?
Let’s say I have three files, all of which import a fairly large module. But I’ve divided them because they have different functions. Now each of the JavaScript files needs an initial statement like
...
1
vote
0
answers
69
views
How to implement timing-mechanism for fantasy draft process utilizing ASP.NET Core 3.1 SignalR
I have developed a Fantasy Draft system utilizing ASP.NET Core SignalR, along with Azure's SignalR service (for backplane/scaling stuff).
Last year I utilized a poor-mans' javascript version that just ...
2
votes
3
answers
2k
views
Best practices for maintainable Graphviz / PlantUML code
I've been using Graphviz a little and just found out about PlantUML which is quite similar.
I make diagrams but later the processes or systems depicted by the diagrams might change so I need to make ...
-3
votes
1
answer
560
views
Import chains in Python
If my foo.py is merely foo_var = 1 and bar.py is merely import foo, I know I can write baz.py that says from bar import foo_var, but should I? (Or should I instead do from foo import foo_var?)
Is ...
24
votes
10
answers
7k
views
What does the crash early concept mean?
While I am reading The Pragmatic Programmer e2, I came across Tip 38: Crash Early. Basically, the author, at least to my understanding, advises to avoid catching exceptions and let the program crash. ...
9
votes
12
answers
5k
views
Why do or should programmers save data in text based formats like JSON or XML instead of binary?
I see a lot of reasons to use binary over text-based formats.
With binary, I find it a lot easier. I can use fread(data, sizeof(struct DataStruct), 1, fileptr) to read, or fwrite to write data. I ...
2
votes
4
answers
986
views
C++ - Is it bad practice to use compiler specific functions?
My requirement is simple, I want to be able to count the number of bits in a number. With a little bit of research, I found that MSVC has __popcnt, GCC has __builtin_popcount and so on.
At this stage,...
3
votes
2
answers
230
views
Is it good practice to have applications remove old AppData files when they're no longer needed?
I have a Desktop application that was saving some data to %AppData%\MyApp\old.txt (roughly 1KB).
I have decided to rename the file that I write to to new.txt.
If I push out this change, customer ...
20
votes
8
answers
23k
views
Is an empty 'while' loop bad practice?
Consider the following:
public boolean maybeUpdateTime() {
if (this.timeReference.isAfter(lastInterval.getBeginning()) {
this.timeReference = lastInterval.getEnd();
lastInterval = ...
4
votes
1
answer
580
views
What is the right way of using event aggregator/message bus?
Recently I had a conversation with a colleague, who proposed that a whole app could rely on an event aggregator (or message bus).
I think this is a really good pattern if someone wants to decouple ...
1
vote
2
answers
384
views
How to avoid duplication with Data Sources
I just started reading The Pragmatic Programmer e2. I came a cross the topic of avoiding Duplication with Data Sources, which I did not fully understand. The pragraph reads as follows:
Many Data ...