Questions tagged [patterns-and-practices]

Design patterns (repeatable solutions to commonly occurring problems) and best practices in software engineering

Filter by
Sorted by
Tagged with
0
votes
1answer
69 views

How to reconcile CD with major architectural changes?

(This question is inspired by the SO blog entry Fulfilling the promise of CI/CD and this old question of mine: Why is it wrong to comment out code and then gradually remove it to keep track of what I'...
0
votes
1answer
64 views

Should I use SCSS mixins as shortcuts for default CSS syntax?

This question is mainly about readability and understanding of the code. Im am also in the process of creating a SCSS framework like Compass and Bourbon. I struggle to write SCSS because I like to see ...
23
votes
5answers
7k views

Where did usage of OS signals go?

From what books I read on linux system programming, it seems like signals were the primary way to communicate events between processes. They were the gateway into many interesting functionalities, ...
-1
votes
1answer
155 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 ...
12
votes
2answers
3k views

Code duplication vs. abstraction

I've inherited some research code where there's already a fair amount of code duplication: on several occasions, the original author duplicated a file and changed minor things to calculate a variation ...
2
votes
2answers
206 views

Understanding passwordless sign up for mobile apps

How does phone number based authentication work, and what are its best practices? I've noticed there are apps with streamlined sign-up/log-in processes where only a phone number is required, simply ...
2
votes
4answers
396 views

Confused about inheritance and correct usage. Should I avoid using members in base class?

I am using C++ , but as far as I understand most OO principles are cross language. In most of the articles that I have read and liked about inheritance the advice are about : not to use it for the ...
0
votes
1answer
142 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
4answers
109 views

Should I public method and test it instead of testing a caller

I have a method called GetValueA() and GetValueB() which return string that in formatted public string GetValueA(){ string a = service1.GetA(); return Format(a); } public string ...
5
votes
1answer
311 views

Methods with "With" prefix?

I started working on a project and I saw some methods with this With prefix and I'm wondering if this refers to a known pattern. Does anyone know of this naming pattern?
0
votes
2answers
88 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) ...
0
votes
3answers
103 views

Strategy & Architectural Decision: Customer data migration between two companies

Asked this originally here, and didn't receive any answer so far, hence posting here too. Let's say company A acquired company B in a certain region. This means, A and B were competitors in that ...
0
votes
0answers
32 views

How to best process unreliable conditional data on the frontend?

For the past couple of weeks, I was working on creating a simple visual display of some data as bullet points. I already have a solution for the title but I wanted to post this question, to hopefully ...
1
vote
4answers
209 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 ...
6
votes
4answers
507 views

Is there a standard name (or examples) for the "sandwich" pattern?

I've noticed a certain idea recur in different contexts, but before I start calling it "the sandwich pattern", it would be useful to know (in the spirit of other "Is there a name for ...
0
votes
3answers
151 views

Sysadmin password storing

I'm quite unexperienced in the sysadmin area. Now I'm facing the responsability of managing two (remote) servers. I'm working in an informal organization. So I have passwords for the OS's users, ...
2
votes
2answers
102 views

What pattern for translation is better, naming the key by screen/context or by text?

I'm in a dilema where I'm translation a full mobile app where the translations are going to be a key value pair but I'm not sure how to name the key. Should I name the keys describing what the text is,...
0
votes
0answers
68 views

Can someone suggest what pattern I used mistakenly and is it correct in this situation. Any alternative?

Client_1 uses --> IService_1 and thus Service1_impl public interface IService_1 { void DoTask_1(); } public class Service1_impl : IService_1 { private readonly IDepService_1_v1 ...
1
vote
1answer
101 views

Who should log output, the ThingDoer or the code which calls ThingDoer.DoThing()? [duplicate]

Here's a common question I ask myself: If I have a ThingDoer class and it has a method DoThing(), and I want to log a message stating "Doing a thing", should I put this logging code in the ...
4
votes
2answers
117 views

How should my application treat database collisions that are handled safely?

My applications uses error reporting to track exceptions. My application uses SQL transactions to make sure that operations are completed completely or not at all. My application is multi-threaded. ...
1
vote
1answer
45 views

Deisgn Pattern: How to map UI requests to Controllers to Services?

I'm learning about writing WebApi design patterns. I am trying to create a simple CRUD web app with ReactJS UI and C# .NET CORE webapi with sql backend. Articles show that specific Repositories are a ...
4
votes
2answers
101 views

Separation of data retrieval and processing in loops?

Often I need to get some data and process it in some way. For example getting a list of customers from an API and assemble some summary data on them. As an example, getting : api_result = api.request(...
2
votes
1answer
94 views

Reusing aggregate root key across bounded contexts?

As the question states, is this bad practice? I have a User aggregate root in the bounded context of Identity for authenticating the user. In this bounded contexts I have fields for the User related ...
0
votes
2answers
44 views

Logic in data provider vs test body

Lets say we have a class Cat: class Cat{ public eat(String food){ if (food.contains("cat")){ burp(); } } private burp(){ System.out.println(&...
1
vote
1answer
175 views

Communication mechanism among windows or pages WPF

I work with C# and WPF and not using MVVM approach. One of the important part of applications is communication among Windows Pages and UserControls. In MVVM they do it behind the scenes and let you ...
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 ...
37
votes
8answers
9k 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 ...
1
vote
4answers
221 views

Pattern / solution for Boolean decision making chains

I need a solution for decision making chain. There are number of criteria that may return true, false or be inconclusive. A non-functional code (Java) would look like this: Boolean res = ...
4
votes
2answers
278 views

Is there a term similar to "upsert", but for the "find or create" case? [closed]

I'm wondering if there is a commonly used term similar to "upsert" or "merge" but for the case of "find or create". Ideally with a single word, something shorter that &...
-2
votes
1answer
107 views

Patterns for multi tenant systems [closed]

Ok so first I want to describe the anti-pattern anti-practice. Company creates system for customer number 1. Then customer number 2 comes along they fork the codebase customize it. (Say for variations ...
0
votes
2answers
1k views

Unit testing private methods

preface: I know this topic has been asked about a lot on here in the past. Hopefully I will make it clear that I've read a fair amount of the questions/answers on the topic, and other literature, too. ...
1
vote
2answers
124 views

Adjective for function types on wether the values are received or sent

I don't know how to phrase this better, but I remember reading an article about type theory, that categorized the values being received by a function and the values being sent back from the functions. ...
1
vote
1answer
123 views

Writing a SQL recordset as a HTML Table - a bad practice?

I'm maintaining an intranet using ASP Classic. Some of pages looks like one or more HTML tables used for administration tasks. Those tables are obtained by SQL requests. Server side, they are kind of &...
0
votes
1answer
93 views

Should a payment success or error page expire?

When payment is made, it either succeeds or fails for whatever reason. In this case, though not important, the payment is made on a third party payment website, like Paypal, and a callback url is ...
1
vote
5answers
517 views

Is this an anti pattern or misusing the interface default method?

Instead of checking the null and throwing exception each time we call findByOrderNumber method, I came up with this pattern by taking advantage of a default method, are there any patterns misused here ...
1
vote
1answer
77 views

Object oriented service best practice when changing a methods behavior for given context?

I expect this is a common problem and/or pattern question for beginners to OOP. Somehow I find myself wondering again and wasn't able to find a decent answer. So at the risk of creating a dupe... What ...
-2
votes
1answer
118 views

Seeking a Pattern [closed]

First off, I totally understand that an interface cannot contain a static method because what would the method act on - that is clear. Suppose I want an interface to mandate a method that is ...
1
vote
2answers
564 views

Best way for resource (entity) relations loading in a REST API

We have a problem of load time in our REST API, which is the result of having Fat DTO (nested DTO s) & the N+1 problem (which is off my question), means that we are loading too much data in one ...
5
votes
2answers
427 views

Is it a bad practice for a unit test to "trust" the other?

Assume I have the following two functions: function storeObject(object) { // Connect to database // Prepare query // Execute query } function retrieveObjectWith(id) { // Connect to ...
8
votes
3answers
707 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
1answer
39 views

Microservices of different resource type

I am building a system composed of a few micro-services over AWS. I encountered the need of a certain MS to do the same logical work but of a big range of work load. for example, the same logical work ...
2
votes
2answers
446 views

Does it make sense to use meaningless named constants?

For example, does it make sense to refactor the following code: a = a * 2; as: const int INT_TWO = 2; // ... a = a * INT_TWO; My question hinges on the fact that the new constant conveys no ...
2
votes
1answer
148 views

What is the name of the throw-an-exception on invalid inputs pattern?

In some .NET libraries, there's a pattern of two alternative ways to call a function. int i = x.GetValue(k); /* Might throw. */ if (x.TryGetValue(k, out int i) { /*...*/ } else { /* ... */ } I ...
28
votes
9answers
8k views

In software design, should an application remain agnostic regarding its usage with real world data / mock data?

Let me try to summarize a bit more with a simple example: You're building a large application, a user portal for example, with feeds, news, account management, and a whole range of difference ...
0
votes
2answers
174 views

How to write the following snippet in more cleaner way?

When the caller gives me a call, I need to evaluate n number of criteria which currently I'm doing like if (a & b & c & d & e) Day by day the conditions are growing and it'...
0
votes
2answers
117 views

Refactor the method which has the sequence of the similarly looking blocks of code to (or towards) the design pattern(s)

I need some help to understand if the code below could be refactored to something less straightforward, less repetitive and more towards any appropriate pattern. What I feel uncomfortable with in ...
1
vote
0answers
70 views

Composing objects: how can I enforce an interface upon each component?

My goal was to be able to create an object which is composed by other objects without having to know beforehand what these objects were, then do checks to see if they actually exist, then add them to ...
1
vote
2answers
445 views

How to avoid magic strings when doing Translations

I have worked in companies that to achieve translations based on the user's localization they use a file to store those translations. However, when they try to access a translation on that file they ...
9
votes
2answers
402 views

Jumpy Code with Descriptive Function Names

I'm currently building out some functionality on a page. When writing JS I've been making a set of smaller functions like FindCarouselLocations(elem), GetImagesFromLibrary(url), and BuildCarousels(...
-1
votes
1answer
455 views

Function returning dynamic value [closed]

Imagine you have a chain of functions calls, in which each function is taking the previous function's output as input for the next calculation in the chain. Make an assumption that you are leading ...

1
2 3 4 5
7