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.

Filter by
Sorted by
Tagged with
0
votes
0answers
47 views

Naming conventions for C# classes that hold helper or utility methods [duplicate]

I am writing some classes for experimentation framework. I named one of the classes as "ExperimentHelper". The code reviewer said names like ExperimentHelper and ExperimentUtil are not good ...
8
votes
5answers
2k 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 ...
5
votes
2answers
299 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 ...
8
votes
4answers
464 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
4answers
335 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 = ...; ...
-1
votes
1answer
153 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 ...
4
votes
2answers
200 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
1answer
63 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
3answers
137 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
4answers
265 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
2answers
224 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
1answer
274 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
2answers
94 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 ...
0
votes
1answer
139 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 ...
0
votes
1answer
72 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
2answers
86 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
4answers
207 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
2answers
34 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
2answers
226 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 ...
0
votes
0answers
47 views

best way to write to console in c#

i am using xamarin to build an android app. what is best way to write to console? I think you need 3 main things. 1st is visual indicator (so its for eyes to find it) 2nd is error location 3rd is ...
0
votes
0answers
21 views

Python flask app creating log files from pods

I have a flask app which reads logs from my kubernetes based on the environment product name and product type. I m creating the log files dynamically when a request arrives. If i choose a static ...
-2
votes
1answer
75 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
1answer
127 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
2answers
113 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 ...
1
vote
4answers
284 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
3answers
233 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
1answer
46 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
1answer
146 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
4answers
136 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
1answer
47 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
3answers
381 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 ...
3
votes
3answers
234 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 ...
7
votes
1answer
1k 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
0answers
42 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 ...
1
vote
3answers
456 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 ...
-4
votes
1answer
50 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 ...
23
votes
10answers
6k 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. ...
4
votes
12answers
920 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 ...
1
vote
3answers
319 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
2answers
159 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 ...
18
votes
8answers
11k 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
1answer
155 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
2answers
125 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 ...
-3
votes
1answer
129 views

Is it good practice to use try/catch like Python in Java?

I mainly use Python and just started learning Java. For now, I've tried using try/catch for basic file read/write as follows public String[] readFile(String fileName){ try{ // read file } ...
-1
votes
1answer
59 views

Angular: send form or object?

My question is about clean code or best practice. I have a big formGroup and in my opinion its more difficult to map the form to an object than to send the form to the backend. best regards
1
vote
2answers
221 views

Can a build system be used effectively as a unit test runner?

The way of running automated tests (specifically, a large number of small, «atomic» unit and regression checks) that I am used to is to maintain a monolithic executable built on top of a test ...
0
votes
3answers
111 views

When using a DSL to structure my application, should I favor coupling the code with the DSL, or trying to have majority of my code independent of it?

We're currently using the Apache Camel Java DSL to structure our application, but I guess this question can mostly apply to any DSL in general. Now, amongst our developers, we are divided on two polar ...
3
votes
2answers
3k views

Best practice for Python main function definition and program start/exit

What is best practice to define a main function and entry point for a script/module that may be used started as main, but not always? Here's how I've been doing it in the past, similar to realpython: ...
-2
votes
1answer
50 views

How do you enforce API contracts across mutliple stacks?

For systems that are built on top of diverse tech stacks, including both static and dynamic types languages, what is in practice some ways to have the API contracts published and enforced? Some wiki ...
-3
votes
1answer
121 views

What is meant by service? [closed]

We know there are services in windows but I am reading a book by Ed Snider and he uses the term “service” whenever his program requires a certain feature/functionality. Like he creates a navigation ...

1
2 3 4 5
31