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
1
vote
0answers
30 views

What is right way of using event aggregator/message bus

Recently I had conversation with colleague, who proposed that whole app could be driven through event aggregator (or message bus). I think this is really good pattern if someone wants to decouple ...
0
votes
1answer
40 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
104 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
50 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
170 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
91 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 ...
0
votes
1answer
79 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: ...
-1
votes
1answer
41 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
75 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 ...
0
votes
1answer
152 views

What is the most common stateless way for authentication in microservices?

I'm trying to get into Microservices by creating a project, so far I've stumbled upon authentication mechanisms, in a monolithic architecture, the client (web app) would send a request with the user ...
-1
votes
2answers
152 views

How to tell if a group of items is stacked horizontally or vertically based only on their positions?

How do you tell if a group of items is stacked horizontally or vertically given only the items x and y positions? Vertical Group: item 1 item 2 item 3 Horizontal Group: • item 1 • item 2 • item 3 ...
0
votes
0answers
54 views

What best practices/principles could help me improve my routine call placement?

I'm trying to change my module's outline since I feel I'm blocking some reuse possibilities, but I don't know how to justify it under the lens of good practices/design principles. Keep in mind this is ...
0
votes
4answers
161 views

Prevent developer errors / debugging help

How much should I factor in potential future developer error when writing code? This works better with a few examples: switch(something) case 1: return good; case 2: return fine; case 3: return ...
1
vote
1answer
157 views

Which statements can be considered as exit points?

There are many discussions related to whether it is better to have only one or multiple exit points per function, but it is not clear to me which statements can be considered as exit points: only ...
37
votes
8answers
8k views

Is it ok copying code from one application to another, both belonging to the same repository, to keep them independent?

Given a repository which contains two different applications A and B (e.g. bootloader and RTOS), is it ok to copy source code from A to B in order to avoid dependencies (include's, adding A source ...
4
votes
8answers
399 views

How to scale code reviews

My boss say we should find a way to scale code reviews at our company. As it is right now, we have about 16 software developers spread across 4 different teams/squads, but soon the company will close ...
0
votes
3answers
142 views

Use the type returned by a function as information

Over time I become used to use the type of the returned value of a function as a piece of additional information. For example: A function that is supposed to return or an array if the arguments are ...
-1
votes
3answers
99 views

Difference between update a property and fire an event

It seems to me that update a property is always an 'event' and that all you can do with an event handler can be done in the property let/set routine. And, in my limited experience, I never needed to ...
-3
votes
2answers
160 views

Guards: Isn't it true the we can replace them if “if” - “else if” - “else” without any significant drawbacks? [closed]

There are a lot of examples over Internet that show why you should use guards. For example: public double getPayAmount() { if (isDead){ return deadAmount(); } if (isSeparated){ return ...
1
vote
1answer
76 views

Is it a good practice to have XML document with no-namespace elements in the middle

I have an XML looking like this: <?xml version="1.0" encoding="utf-8"?> <n0:OrderConfirmation xmlns:n0="http://company.org/interface/MVSI" xmlns:ord="...
0
votes
1answer
89 views

Efficient way to find Xor of pairs with given target X in a range 0 to K

I came across a problem: given an array (can be huge 10^8) and an integer, K, find the count of pairs in the array whose Xor equal to each value in the range 0 to K. eg: Arr = 1 2 3 K = 2 since K=...
1
vote
1answer
107 views

counting identifiers and operators as code size metric

I'm looking for a code metric for monitor and track over time the size of several projects and their components. Also, I would like to use it for: evaluate size reduction after refactoring compare ...
-2
votes
1answer
54 views

What is the term for generalised code to handle cross system functionalities

I work in a codebase which handles two countries' energy market functionalities as- payment, energy consumption, billing statements, addresses etc. For this I need to make sure that when I am writing ...
-3
votes
1answer
347 views

What naming convention should I use for a JSON RPC client API designed for multiple languages?

This is the documentation with the original RPC client API specification. The naming convention in the specification is camel case. Naming conventions might differ in subtle ways for different ...
3
votes
1answer
51 views

How to test channel pipelines in Go

I use the "channel pipeline" pattern quite a lot in Go, which looks something like this: // getSomeNums spits out ints onto a channel. Temperatures, pressures, doesn't matter func ...
46
votes
6answers
8k views

Why is 2FA usually done after the correct password has been provided?

If all accounts have 2FA for a given product, is there any reason why the 2FA box couldn't be on the primary login screen? Is it bad practice to request 2FA code along with username and password on ...
17
votes
9answers
2k views

To what extent should you program by “sketching”?

In Hackers and Painters, Paul Graham talks about how he "sketches" as he programs: For example, I was taught in college that one ought to figure out a program completely on paper before ...
0
votes
1answer
121 views

Using for_each instead of iterators to avoid iterator invalidation

I am writing a simple custom (special purpose) container and would like to allow for iteration over each element, however, avoid using iterators due to the problem of iterator invalidation. Instead of ...
7
votes
5answers
774 views

Why are people coding “C-style C++”?

In discussions about whether to cast the result of malloc or not when coding C, one common argument is that if you cast the result then you can compile your C code with a C++ compiler. Why would one ...
2
votes
2answers
139 views

Better way than repeatedly passing the same parameters?

I have some methods in my code that essentially hide/show some Views, like showTitleHideBody(), showBodyHideTitle(), etc. They just change their Views' (tvTitle, tvBody) visibility. Initially those ...
-5
votes
1answer
44 views

Should code be refactored to be more unit testable or should a framework like PowerMock be used?

Assume there's some code that's already in production that needs some unit testing. Generally speaking, would you want to refactor this code that's already in production by adding things like adding ...
-4
votes
4answers
404 views

Why are magic numbers bad practice?

Why are magic NUMBERS considered bad practice? For example: memcpy(ResourcesDir+GameDirLen, "/Resources", 11); What is wrong with the 11? Why are magical numbers so bad? Please, my question ...
2
votes
2answers
204 views

Time complexity for a small code

I'm trying to find the time complexity for the following code. N= number of elements in array D= a constant: D>1 V= a constant: V>1000 counter=1; //the maximum value of the counter is N/D. ...
-1
votes
2answers
104 views

MVC who knows about whom?

In the Model-View-Controller pattern, I do understand the role of each component. The Model represents our application's domain model. The View presents this information and the controller ...
3
votes
1answer
107 views

What is the expected performance of While loops using `array.pop()` assignment vs other methods

Recently I was asked to refactor some code that leverages JavaScript's array.reduce() method because other developers felt the code hard to read. While doing this I decided to play around with some ...
-4
votes
1answer
53 views

Question about the tutorial purgatory in coding path

Dear all the programmers and overflow friend, First, I want to say thank you to stack overflow users for helping me finish 20% of my PhD project since last year (using python to draw some technical ...
1
vote
3answers
124 views

Good etiquette for 2 optional arguments that can't both be used

I'll demonstrate with an example of the normal distribution in Python. def norm_pdf(x, mu=0, v=1, p=1): """Returns un-normalized probability density of normal distribution at x. mu: mean v: ...
8
votes
3answers
669 views

Is it bad practice to add “false or” or “true and” to conditionals?

Is it bad practice to add false or ... or true and ... for the sake of promoting code genericness and/or ease of use? As in: SELECT * FROM table WHERE TRUE AND IsEnabled AND SomeField = some_value ...
-4
votes
2answers
116 views

How to exploit efficiency of C? [closed]

I want to write a program that performs heavy computations and I want it to be as fast as possible, so I choose C to be the language. Nevertheless, I was told that in spite of its simplicity and high ...
-1
votes
2answers
176 views

Explaining why a code's modifier should also be its committer [closed]

The context of this question is the early stage of introducing a VCS into an academic setting consisting of non-SW-engineers, largely unaware of modern best practices related to coding as a team. At ...
0
votes
2answers
78 views

How sensible is it to build a website/app etc. using an external api?

Wanting to expand my programming horizons I recently started building a website. I have started to build up my website and it is heavily focused around an external api. The reason for using this api ...
1
vote
1answer
60 views

Using Builtin Method vs Manual Implementation

I work in a DevOps role and mainly write glue code and OS-level automation. I've rarely needed to deviate from existing language implementations or "reinvent the wheel" in the small programs I've ...
-3
votes
1answer
175 views

What are the best practices for writing a long, multi-step process? [closed]

When writing a long process, i.e. one filled with many steps of business logic, what are the best practices for organising it? There are a few different options here that I can see: Just write a long ...
-4
votes
3answers
105 views

What can an assertion test that running the actual code cannot?

I'm currently learning Jest, Enzyme, Detox and testing in general, but I'm still trying to grasp the benefit of testing. From what I understand, testing is about creating hypothetical situations. Let'...
9
votes
3answers
485 views

Is porting code from different language plagiarism?

Is porting code from one programming language to another considered as plagiarism?
0
votes
2answers
161 views

Should I use a class with only static members to encapsulate my program?

So I'm writing a network simulator in C++ as part of a university project. Right now, I have a class structure that looks something like: //includes type aliases #include "GlobalTypes.h" //main body ...
3
votes
5answers
413 views

Always better to wait?

I've been wondering if this concept has a name and a consolidated theory behind. If you need to build software, but you don't need it right now, it's always better to wait because the technology ...
2
votes
2answers
188 views

The usage of getter notation inside the context of the class

Consider the following JavaScript code: class MyClass { #myPrivateField; constructor() { #myPrivateField = new AnotherClass(); this.theGetter.method1(); // or: this.#myPrivateField....
-3
votes
1answer
90 views

Choosing the correct “opensource” license for codes [closed]

In programming terms, what defines Open Source? I am building a platform that I want to be open, to be used by other programmers in the context of running their own apps on it at the same time for ...
2
votes
1answer
110 views

Is it a good software engineering practice to store libraries as attributes of objects?

Suppose I initialize a library, say, in python object - #filename: file_A import file_ class A(): def __init__(self): self.pd = file_.pd self.np = file_.np And suppose the ...

1
2 3 4 5
30