instruction
stringlengths
34
36.1k
I'm working on a codebase with very little testing. The code is 90% an ETL pipeline with functions like def sort_data(df: pd.DataFrame, column: str = 'date') -> pd.DataFrame: return df.sort_values(by=column).reset_index(drop=True) or def validate_no_duplicate_index(df: pd.DataFrame) -> pd.DataFrame: assert df.in...
I have read many articles online but each one of them fail to give even a basic example on how an Object Oriented Database is stored and represented. For example each of the articles say that they are not tables, but are objects and then provide an ER Diagram with arrows pointing between them, for example, wikipedia. R...
What we often see is that software companies create an internal API which is then consumed by their own user interface. And we were trying to find the benefits of those, other than it's easy/easier to switch to another technology for user interface. Mostly these API's are custom made for that specific UI and isn't gene...
When writing tests for TDD is it good (or bad) practice to write multiple test for the same requirement ? If it's good how many times should it be repeated? If it's bad is it it the QA engineers work to do so? E.g. Testing a calculator that adds 2 numbers. # import stuff here def test_Cal(self): self.assertEqual(...
We've got a few CSV file templates with different set of headers. In each CSV template there's at least one unique header and each template is meant for a different entity in the system. Right now, when the user wants to upload a CSV file, the user choses which type of a CSV it is from a dropdown, so that on the backen...
I had a discussion with a colleague of mine today regarding versioning of a REST Api. We currently have an API with support for versinong by providing the correct version in the URL. So for instance: https://ourapi.com/api/v1/something (where v1 would be version 1) Now we want to make a few contract changes to one of o...
I have a method that accepts one or more optional arguments and I'd like to log them, following the best practice of lazy interpolation of log values: def frobnicate(a: str, b: int, c: typing.Optional[float] = None): # note: c = None actually means absence of data, it's not a placeholder for a default value myl...
Note: I'm new to using paid APIs (like Stripe, GPT-3, Twilio, ...). When you are using a paid 3rd-party API, you are essentially betting on them keeping reasonable prices in the future, right? So in case you'd want to switch the API provider, potentially the work to switch could be huge if their endpoint design is diff...
Say we have a data grid of car models in our application. In the data grid, many fields were displayed, such as the brand, the model name and the year of production. However there are many more fields of these car model entities stored in the repository (database). In another place of the application, there is a drop-d...
we have a private nuget repo setup available for all department developers, each developers can contribute and deploy their own reusable library which gets uploaded for the entire dev team to use after few reviews. We have a standard policy that all Libraries should be developed .Net6. Issue here is, the developers use...
The application I am working on is written in TypeScript and I need to manipulate DateTime. I always avoid doing date/time calculations manually, because they have a lot of edge-cases. The Date class in JavaScript is, let's say, a funny implementation in my opinion. I would much prefer to use the immutable dates in the...
I have a requirement from a bank where they need to store data in a tamper proof way but at the same time they need to purge it after 7 years. The current process is they receive a letter and file it. After 7 years they shred it. The first part of the requirement can be achieved via a blockchain or an immutable databas...
I have a technical application that interacts with different hardware components: measurement devices, sensors, custom hardware. These use dedicated interfaces like USB, serial ports, TCP/IP communication and others. Most of these devices' implementations wrap a request/response pattern: Send something to the device an...
I'm developing an application (Java & JavaFX) that writes/reads data (a file). The problem is I don't want to restrict user to run only one instance (of my app) at a time, as I really can't think of reliable way of doing that so it works on both Windows and Linuxes (e.g. server), heard of sockets and files - both are d...
It recently came to my attention that its best practice to avoid database calls in constructors. I feel like this means you end up repeating unnecessary code, thus the code is less DRY? For example, this approach means the list of available courses is available in the Semester object and the db call exists once. public...
Let's say I have a single resource of employee that belongs to user: { "id": 1, "name": "John Doe", "userId: 1 } When making a GET request to /employees/1, I'm using a JWT which contains the userId. Any user can fetch this record regardless of their userId (as long as they're authenticated), however, I want to i...
I have a web applications (angular) which is connected to backend using websockets. The role of web app is to display data from multiple sources (which are updated constantly by some Scala Spark apps) in dashboards; because the backend is deployed on multiple instances (3x centOs), the frontend will send the request to...
I need to add extra data to a list endpoint. Basically it is the list I want to return and an extra data. Like below { "results": [...], "extra_data": { "field": "value" } } Is it okay to return this result from list endpoint or a detail endpoint?
We have a robust set of micro-services available. For simplicity, let us call the services S1 S2 S3 S4 S5 For simplicity, think of the flow to be this. S1 -> performs step1 (start step) S2 -> performs step2 S2 -> performs step3 S3 -> performs step4 S4 -> performs step5 S5 -> performs step6 (final step) Now, for track...
I'm reading Clean Code In Chapter 6, Objects and data structure First talk about Data Abstraction: Hiding implementation is not just a matter of putting a layer of functions between the variables. Hiding implementation is about abstractions! A class does not simply push its variables out through getters and setters. R...
A colleague of mine did this UML component diagram to represent both the required/provided interfaces and the internal structure of the subsystems that compose the system we're working on: (The subsystems are called "User Management", "Votes Management", "Post Management", etc...) This diagram is for a System Design D...
I am currently exploring adding unit tests to my Django REST Framework project. I totally understand adding unit tests for other components of the app like models. However, I'm stuck at testing views. I understand using Client is for adding integration testing while using APIRequestFactory is for adding unit tests. I'm...
For my project, I am required to complete a software requirement and systems requirement for a program I am developing which needs to be fairly detailed. However I am struggling to differentiate between the two on what kind of information is contained in each section. My program is related to artificial intelligence i...
I am being challenged (or confused) by this problem: I have a List<CustomObject> in which each element has around 20 fields/attributes. In this list I might have sort of duplicate items. Four particular fields may be different, if the others match I would regard them to be equal enough and I want to merge them into a s...
Problem I need to build a profit/loss graph for a mobile app. The api from which I can get the historical price data only allows me to retrieve 1 item at a time. If the user has 500 items that would create an api failure since I can only make 50 req./min. What is the best way to calculate this? Let's say the user buys:...
I am working on a Django based project that is version controlled with SVN. My main objective is porting it from Python2.7 to Python3.9. Whilst I port the project, my team brought some updates, now I want to get these updates and port them to Python3.9 as well. Our issue here is, how will we manage 2.7 and 3.9 codes in...
Lets say we have DTO class with 15 properties. Usually DTOs like these are mapped from other objects. But sometimes some DTOs may use values from multiple objects. In these cases, should we “Map” or “Create” an object? In our project we currently have these scenarios handled by constructors, in some places by static Cr...
Is there any performance detriment to assigning variables vs using them inline. I'm guessing this WOULD be worse if a method was returning primitive and I was 'boxing' it (e.g. method returning int, and me storing to Integer). What about something like the below? String foo = buildFoo(); String bar = buildBar(foo); ret...
Assume an application architecture with three layers (presentation, domain, data access - though presentation is irrelevant to this question) that follows dependency inversion: The domain layer specifies domain models and repository interfaces The data access layer has a reference to the domain layer, implements repos...
I've recently joined a startup that has, in my opinion, a strange (and inefficient) way to access their database. Their implementation consists of multiple REST APIs that are exposed to multiple clients, these APIs, according to them, were made with a micro-services architecture in mind, that's ok. My problem is with t...
I am having a problem currently where product managers are raising improvements as bugs. Also, they expect us testers to catch them early. Our company doesn't have any requirement document and as QA we collect the information by brainstorming and talking to product managers. Recently the QA had a meeting with the manag...
Very recently a discussion came up regarding the usage of different buildspec.yaml files, one for branch builds and the other for deployment builds and I was wondering, since after some research I wasn't able to find the best practices on this topic from AWS, what is the approach I should follow when it comes to this t...
My team is communicating proposals for the interaction of several processes as a flowchart. I've been drafting a codebase architecture we can use as a starting point. There are two ways intended behaviour can change, each of which poses maintainability issues: What each edge does. Edges are in general bidirectional, a...
I've come in to a project where it's a best practice for an Init method for all tests in a class to contain mocked happy path functionality. This should allow most methods to pass without exceptions. I'm guessing the benefit is removal of code duplication and that other test methods not directly related to this code ex...
In trying to separate interface from implementation, I ran into a circular dependency problem. There is a best practice in the world of Java: consume interfaces instead of concrete classes. That is, instead of declaring variables of type ArrayList<int>, use the type List<int> instead. That way the migration from Array...
I would like to add integration testing/automated acceptance testing for a mobile app calling a registration API from the backend. I will register a sample user on the test feature then delete the user on tearDown. Something like this: test('registration test'){ RegistrationRobot registrationRobot = RegistrationRobo...
We want to create an API to communicate witha device we currently sell. The API should be available for several platforms like C / C++ / .NET / Python and available for Windows and Linux. The idea is to have on single source of truth. A C API and the others are just wrappers around that C API. However as i am not the g...
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 basic web application with a standard Nginx/Apache server, would it be better in general to write server requests that tr...
I'm newbie in Java and I have question. Pass a value to a class via a constructor or a method? public class HelloWorld{ public static void main(String []args){ TextModifyFirstVersion textmodifyFirstVersion = new TextModifyFirstVersion("test"); textmodifyFirstVersion.modify(); TextM...
We have two applications, each of them separated with its own backend and frontend. The first application is the user-facing one. They register on the site and as soon as they want to execute a critical action they should be redirected to the frontend of the second application that will ask for the users personal data....
In our team we have a recurrent problem that we are not able to solve. As long as the team grows, we tend to accumulated PRs at the end of the sprint / release and these become a bottleneck to advance in our daily tasks, and at the same time, at the end of the sprint we have to let our work to review PRs. Our goal is t...
So I came upon this time complexity result and I was confused about it, it said that : O(nlogn) + O(logn) =O(log(n+1)) Why is that the case? Shouldn't the result be O(nlogn)?
I've had this idea because I've recently had to upgrade a large enterprise project (due to security vulnerabilities) that was completed and not touched for years before I joined, and both the backend (Spring) and frontend (Angular) were so out of date that I'm not sure it's possible to upgrade it since there was no doc...
I have been looking at different solutions for large scale chatting solutions. I feel as if I understand 90 % of it but am turning to this forum to tie the knot. I imagine running a bunch of message servers behind a load balancer, keeping long lived connections to the client (wss or xmpp). The amount of servers can sca...
https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/422 The HyperText Transfer Protocol (HTTP) 422 Unprocessable Entity response status code indicates that the server understands the content type of the request entity, and the syntax of the request entity is correct, but it was unable to process the contained ins...
I have a few basic questions on how to implement an API for a basic e-commerce system. The relevant entities are Customer, Puffle, and Review. Each Puffle can have zero or more Reviews. Each Review is authored by a Customer. Currently, I have the following relevant endpoints: /catalog which returns all Puffles with th...
I will explain with an hypothetical example. Suppose that my domain is Cars. Everyone around the software, talks about cars. Car is the aggregate root of aggregate roots. For example, CAR table has 150+ columns in database (irrelevant for this question, but for you to imagine). So, there is class in the system called C...
There are many posts about the benefits of static code analysis tools. However, in which scenarios would you recommend NOT using (or significantly limit) them? For example, do you also run them on tests? I use mypy and pylint and usually find them very helpful. However, in a few cases I spent more time working around t...
Let's say I have a system to which I can upload documents via an API. There are three services: the UploadService - responsible for providing a HTTP endpoint the StorageService - responsible for storing uploaded documents the FileCabinet - responsible for managing a file cabinet (e.g. categories, hierarchy, etc.) I'm...
Can an effective code review be performed without first understanding the intent behind the code?
How does the 2 differ in terms of actual usage? In DDD, we use a repository to get Aggregate Roots and persist them. We forget about the implementations and focus on the domain and so it doesn't matter where we are taking the data from. That being said, why does ACL exists? Usual examples of ACL is when getting data fr...
I have a single *.h file. This file contains a single (more to come) function declaration. Now the implementation of that file is very complex. the corresponding *.cpp contains several function definitions that are used by that publicly visible function. I would like to keep the "main" *.cpp file of that function as cl...
I'm curious if there are any obvious pitfalls to the following: I have a database table that, because it is storing many objects of various subclasses, I'm using a JSON field to hold the non-overlapping properties. (i.e., the common properties like id, creation_date, parent_id, type are all separate "normal" fields, an...
I have this list of Notes: public static List<Note> _notes = new List<Note> { new Note { Id = new Guid("00000000-0000-0000-0000-000000000001"), CategoryId = "1", OwnerId = new Guid("00000000-0000-0000-0000-000000000001"), Title = "First Note", Description = "First Note Description" }, new Note { Id = new Guid("...
if The ISA acts as an interface between the hardware and the software why we have firmware? What exactly is firmware and how it works.
I'm just wrapping my head around the topic and building a simple neural network from scratch as I go. I'm trying out different data types to hold weights, values and biases as well as different activation functions and back propagation techniques. While I have some success with treating the input/output layers as binar...
This is Arduino code, but since it uses C syntax, and it's not Arduino-specific, I thought I'd ask here. I have a few values defined so: #define PID_RPM 0x0C Typically it's used as a hex number. But in one spot, I need to print the last 2 chars ("0C") as literal 2 ASCII chars "0C". Right now I do it with a switch and ...
class Foo { abstract doStuff() {} } class Bar extends Foo { doStuff() { ... } } class Baz extends Foo { doStuff() { ... } } From a functional perspective doStuff does exactly the same thing, however if it should be done to bar or baz then the implementation is completely different. I try to separate data...
I was researching about best practices for standardised JSON response formats for APIs, according to various sources available online general consensus looks something like this: //Successful request: { "success": true, "data": { /* requested data */ }, "message": null } //For failed request: { "success...
I have two tables, parent and child. Parents can "have" multiple children—in our case they are related through a third table, parent_child_mapping rather than the child storing its parent id directly. (Legacy reasons.) We now need a paginated list of parents, sortable by the count of children per parent. Is this an app...
We use microservices and spring boot in our saas (multi tenant) projects. We will proceed through the schema per tenant. We manage the error messages we show to the users through a database. We are thinking of writing these messages to Redis. These error messages may be common messages used by different microservices. ...
I'm building a site using a CMS that already holds user information such as userId, Username, Firstname, Lastname. I want to build a system that holds additional user information such as the user's Title, Date of birth etc… Should I: Create a new table to hold the additional fields? This would prevent needing duplicat...
I'm having a dilemma regarding whether or not to use Doxygen's \@file (a.k.a. \file) command. On the one hand, it's somewhat useful for you to use @file, and IIANM, Doxygen relies on its presence somewhat when producing documentation. On the other hand: It is redundant information - Doxygen can know what the filename ...
Say I use GUIDs as keys. Considering the chance of a duplicate GUID being generated being what they are, is code like this considered a code smell? Guid newID = GenerateGuid(); while (dictionary.HasKey(newID)) newID = GenerateGuid(); dictionary.Add(newID, value);
I am trying to read up on System Design, and several articles talk about how a Primary Key for the input data, which is a string, can be passed into a Hash function and we get a number. This can eventually be used in consistent hashing, or other hashing techniques. I get the idea of the hash function, where if you pass...
Our CI process goes as this cycle (I think it is quite normal), unit test => build docker image => run function test against the image => if test fails remove the failed docker image, figure out the reason and build a new docker image. But checking the test result and removing the failed images has become a labor-inten...
I read multiple times that when a member function only uses API of class it is member of, then it should be made free standing and put in to same namespace, for example, bad practice: namespace A { class Foo { public: void printA() const { std::cout << a << std::endl;} ...
My Python project comprises data handlers, models and can be run with different modes. Throughout my code I use statements like if mode=='mode1': # or if isinstance(model, Model1): To adapt the flow of training scripts and plotting scripts. I believe I am already making use of the strategy pattern by having different ...
I am writing an Azure Pipeline framework in YAML which will be used on multiple projects, each with its own environment variables. I am now wondering whether the best option is to define these variables in variable groups or to use YAML templates. The Requirements The requirements are as follows Values should not blee...
I have an import that needs to grab data from a REST service and import into an web store. It's basically an ETL type of service, but because the REST service can be slow and I don't want to call it for every entity in the loop, I'm finding myself having to pass in a lot of parameters into the methods needed for import...
Our project consists of a cluster of microservices (let's say 20, mainly JS & PHP) that are communicating among themselves and exchanging data (via MQ) among themselves. Also, clusters have API available to other teams. So microservices process either our requests or API requests. A while ago our team agreed to have ou...
We have a on-premise web application with frontend (Node/Express) and backend (Python/Flask), which, like every other web application I've ever worked on, provided HTTPS by using a proxy web server (in this case, Nginx) to handle the secure connection and port forwarding to the actual frontend and backend servers, whic...
(In the context of reading about the systemd D-bus implementation called sdbus (full sdbus API here)): What does "OOM-safe" mean? From this blog post, by Lennart Poettering, the author of systemd and sdbus: The new sd-bus API of systemd (emphasis added): Of the two libdbus is the much older one, as it was written at t...
In a project that my team is working on, we have type aliases for primitive types. The reason, I got from my team, for this is to have consistency across the codebase. For example: type FruitName = string; const fruits: FruitName[] = ['apple', 'banana'] Now, because of this, if I use alias in a function argument, and...
I'm working on an app that needs to be localised for two different countries, let's call them Atlantis and Buranda. As well as translating the site into the relevant languages and displaying dates, numbers, etc. in localised formats, the Atlantis region needs a feature to work in a particular way but the Buranda region...
My company has a workflow that involves ingesting huge amounts of raw data from external sources into SqlServer and then interpreting and weaving that data into our own application tables. This weaving process consists of many thousands of lines of TSQL code in stored procedures, which call other stored procedures, all...
Although I do find some (apparently old) posts on the topic on the web, I could not find one here at SE. Thought of raising this here to see if what I read is accurate/is all there is to it. So basically, in trying to structure and document my application, one of the prominent architecture principles used is Singletons...
I'm looking for an algorithm for placing tiles of different sizes within a complex area (all 2D) as randomly but efficiently as possible. I know the different dimensions of the tiles provided and the quantity of each. What I need to do is to place these tiles within an irregular area, such that: Tiles are placed so th...
Is it a valid code review criticism to have someone manually arrange the order of keys in a dictionary or map they created for a feature, by numerical or alphabetical order when it doesn't improve functionality? I can understand the argument of it could potentially improve readability but is this a valid criticism/revi...
I think it will help to give a little context, not only about the DB architecture but the actual product. I am building a business where we will be selling pallets of liquidated merchandise. Think a wooden pallet with 10-100 items (every item will have a scannable UPC) on it. Each of these items needs to be listed o...
We currently have Reporter and Assignee fields for Jira stories. For example, let's say we move from the 'Code review' column to the 'Ready for testing' column. Should the tester then come in, delete the original coder's name from the story, and put his name as the assignee? I'm used to Azure Devops where if a tester c...
I'm developing a full-stack Rest application following a narrative description of a working context. There is a class Job with two subclasses Job_A and Job_B. Job_A produces Report_A while Job_B produces Report_B. I guess there is an abstract superclass Report even if it is not stated explicitly. Each report must be ex...
At our job we are having a heated discussion with the DevOps team on how to architect and modularize our microservices. We come from a 2-coupled-monoliths approach, so we are trying to avoid common pitfalls. Our CI/CD is done with GitHub Actions, and we use Kubernets to deploy our applications. We started a microservic...
We have a function that processes the user request if it is not None, how best to style it? I did not find a better choice in PEP8 Style 1 def user_handler(user): if db.getUser(user) is not None: """ Here we have a big body of function """ return {'message': 'Successful handled'} else: ...
I'm trying to learn about the different types of database architectures and how their differences influence which one or combination of should be used in software system. I understand that OLTPs typically consist of row-oriented DBs due to their faster write speed and OLAPs typically consist of column-oriented DBs as c...
I am studying system design for distributed systems and in this page (https://github.com/donnemartin/system-design-primer), one of the following advantages was mentioned for federation for databases was: Smaller databases result in more data that can fit in memory, which in turn results in more cache hits due to impro...
I had to create an ASMX web service for my company. Even though ASMX is old, I tired to do everything according to modern standards. So I have a UI layer (web service layer), business layer (service layer) and a data layer (for talking to the database). However, I cannot get DI to work ,and I don't think it's worth th...
When processing data sets in batches I usually can think of the following three implementations. Which one do you consider better than the other and why? Notes: The implementation is in C# but the question is about the algorithm. The GetBatchedData works with a fixed batch size The Process method can take an empty bat...
I am having difficulty understanding how denormalization results in more storage necessary. For example, let's say that in a normalized relation, there's Table 1 and Table 2. In order to join Table 1 and Table 2, I need another table Table 3 that maps Table 1's primary key to Table 2's primary key. In a denormalized re...
If I have a graph which consists of nodes like this: class Graph { public: ... int32_t width(); int32_t height(); const Node * getNode(int32_t height, int32_t width); private: std::vector<std::vector<Node>> data; } where each node is a struct with multiple member variab...
I'm learning how to write unit tests on a project I'm doing with my friends. One thing we tried was to mock the return values of function calls if the functions are declared in a different "layer". For example, if I have a function in the routes/ directory that calls another function in the services/ directory, my un...
My question is regarding using private type in F#. Consider the case we have some application and we have some library. One may consider using units within the library, and making them private behind this "layer". App needs to use a specific unit to use library functions. [<Measure>] type private year [<Measure>] type...
I am writing extensively in a typed language in the last couple of months and wondering what a proper pattern for this behaviour is: When I create a new database entry (whatever this is) I am receiving parameters via an API Once the entry is created, it also has an id attached to it So for each item, I have a type Ne...
Say we have a software system with a web server serving writes to a Master DB. This Master DB is then replicated to several read-only DB replicas. From my understanding, the process of asynchronous replication is fairly straightforward. The user posts a write request to the web server. Once this request is processed b...
I have been searching extensively about the difference between synchronous and asynchronous patterns and how this relates to event driven architecture. On its face it is quite obvious, I simply equated asynchronous with Event Driven. But then I came across this quote: All asynchronous systems are event driven, but not...
I'm wrestling with a design choice question here. I've got a class that needs a couple of semaphores. Semaphores are non-movable objects. Objects of this class however need to go into a vector (there's one per thread for this process). I'm pretty sure the Right Thing™ to do here is put the semaphores in some kind of ma...
I have a task to develop a website that allows storing of data resources from other APIs and users can analyse and visualize this data. This data is sensitive and data leakage should be minimal. I implemented data isolation through user row-level multi-tenancy [acts_as_tenant][1]. I could not implement Schema-level mul...
I'm about to create a service providing a simple CRUD Json REST-API. The main requirement is that documents stored/received always conform to a schema provided as JSON schema. So here's the thing: Usually, I'd create DTO classes, map them to internal data classes and make sure that data written to the DB is always vali...
The Collection interface in Java has, among others, these methods: boolean add(E e) boolean addAll(Collection<? extends E> c) boolean remove(Object o) boolean removeAll(Collection<?> c) default boolean removeIf(Predicate<? super E> filter) boolean retainAll(Collection<?> c) Common for these is what they return: true ...
Everytime I write a header I end up doing something like this: #ifndef D723E2D5_1943_4166_87CC_73F5C9C47544 #define D723E2D5_1943_4166_87CC_73F5C9C47544 #include "RandomIntegers.hpp" ... #include "IRenderer.hpp" namespace Pathfinding::Core { class ApplicationBuilder; } namespace Pathfinding::Datastructures { struct No...