instruction stringlengths 34 36.1k |
|---|
In python the following code works perfectly fine.
class Table:
pass
table = Table()
table.fruits = ["apple", "orange"]
But as soon as we check it out with some kind of linter, errors will start showing. Pylint will complain about attribute defined outside __init__ method, Mypy will claim we're trying to access ... |
I have seen the term "common interface" used a lot while reading books about OOP.
For example, the book The Essence of Object-Oriented Programming with Java and UML says the following:
Abstract classes usually define a common interface for subclasses by
specifying methods that all subclasses must override and define
... |
Once upon a time we did this
/**
* Function that does lots of things
* @param {boolean} state
* @param {number} max
* @param {string} set
* @param {number} timeout
* @param {boolean} bail
* @param {string} name
* @param {function} cb
*/
function doLotsOfThings(state, max, set, timeout, bail, name, cb){
}
The... |
In our project, we have DEV, STG and PRD environments that are configured to mirror each other (especially STG and PRD). We have unit tests that we run on DEV and, if they pass, are moved to STG when we have code changes. A similar process is used to move code from STG to PRD.
A lot of these tests involve DB operations... |
A) I know that threads of a process share logical address space . Therefore they share data by default.
B) But if two threads of different processes want to share data ...then there are two options available ...message passing and shared memory
Are the synchronization methods (locks etc.) used for both types of communi... |
I'm trying to create web app(flask or django-rest) that would scrape some data and save it to JSON so that it can be viewed in the frontend (VueJS).
I'm wondering if it is better to save the scraped data as JSON file in the database directly (noSQL?) and then create another api endpoint so that the frontend gets the JS... |
What is a good way to test whether particular file, having a timestamp in the name is created?
def writeFileOnDisk(fileName: Sting, outpuPath: String ): Unit = {
val saveFileNamePth = outputPath + fileName + "_" + currentTimestamp
// write the file on the disk
}
The method basically writes file ... |
I am building a blog system, the blog can have its comment. And like to provide the upvote/downvote feature for both the blog and comment. Since the vote count number of blog/comment should be persisted, i choose to use MySQL to act as the data store.
It seems that i have two choice, the first one is, use a general tab... |
I'm turning a VB6 application into a VB.NET (using a migration tool). This software relies on a custom DLL which handles logging. This DLL logs to flat files and optionnaly in a GUI component.
Also this application will become a Windows service. Since I'll have to rewrite parts of the code, I wonder what benefits I wou... |
Problem
I have designed an evaluation tool (in python) and need some help to make it more user friendly. The tool requires ~100 (nested) parameters, which it gets from a yaml file and stores internally as dictionaries (e.g. one dictionary for data loading, another for preprocessing, ...). However, it is really difficul... |
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 is the best practice or pattern to follow when a class must behave slightly differently in a given context?
I am asking... |
Since my previous question was closed (https://stackoverflow.com/q/62354455/1173166), I thought this would be a better place to ask the question.
Original:
JavaScript we designed specifically for browsers. It wasn't pulled off the shelf. So what were the reasons behind making it a scripting language rather than a comp... |
At this point i would exclude the inheritance....
So the question is about more like extend into a seperate class or into the class which should be extended, both play in the composition-league.
So Possibility 1:
class A
{
//some behaviour + state
}
class B
{
final A extend;
//some injections or self-crea... |
I commonly use a boolean condition/variable when it's something too big or complicated and takes too much space by itself inside ifs - basically to avoid repeatability and thus improve readability. E.g. has_three_repeated_digits = len(some_number) == 4 and len(set(some_number[1:]) and set(some_number[:-1])) != 1 and ..... |
For a clean architecture where there is presentation layer (Javascript), web api layer, application/domain layer, infrastructure layer (EF Core ORM). Let's say it is an ATM system and the use case/function is Deposit. Imagine is a a web version although it doesn't make sense.
After authenticated, user enter the input d... |
My project uses Microsoft SQL Server Express 2019 as data-engine and potentially will be migrated to other data-engine.
The database used in the vb.net Desktop application.
Tables usually contain an optional field "Note".
By design of the app can be used "record has no note" or "record has a zero-length note".
In VB se... |
I want to make a service that is supposed to upload Photos in S3 and make them available using a link.
I have few design plans for my service.
PLAN 1:
Upload photo to my REST API which will update details like id, size, type, etc in a db table and upload file in S3 before updating in db. The db table will have s3 link ... |
I've been trying my hand at building apps with Flutter and Dart. I noticed in my apps that if someone decompiled my app they could access a whole lot of things I didn't want them to access.
For example, if I am calling my database to set the users 'active' status to False when they cancel their plan they could just com... |
Let's take Shopify. They consider a shopping cart abandoned right after a customer has entered their email at the 1st step of checkout. I think it's wrong because a customer might need at least 5-10 minutes more to complete a purchase. Even if he doesn't complete it now, he might come back to browse products, then we m... |
What is the best way to implement a app store in a SaaS application? For example, say you have an ERP application and you want to allow external accounting systems to integrate into your application.
I was personally thinking about a combination of webhooks (to send the latest info to the external app) and allowed the ... |
I know my question sounds a bit weird so I will try to explain my issue with examples.
In my application, I have two types of business objects : Shops and Customers for example.
Both of them can be associated with multiple Tags, with the exact same properties : let's say Id and Name.
So a customer "John" can be tagged ... |
I'd like to know some best practices on how to build rest API for a backend which shall communicate with a mobile app by anonymous users.
This is the scenario with details:
I'm building a demo library app that shows details about books, those details are returned in a JSON format when the app fetches the URL
www.mylibr... |
My job requires me to know how to work with Ruby, Python, Bash, Puppet, Golang, MySQL and occasionally Scala and PHP. Yes I really do have projects including most of these and there are weeks where I have 3-4 tickets from projects which cause daily work with 4 different languages.
Yes, I can do it in an acceptable fash... |
I am creating a web app with JS and PHP where users can edit a file similar to a text editor such as notepad. I've decided to use a database to store these files. One of the primary functions of a text editor is the file history (Undo and Redo).
I would like to store this on the server and not just on the client. This ... |
I keep reading about "well defined interfaces", as here, here or here, specially when talking about microservices.
What's an example of the opposite, an interface that is not well-defined?
|
A few months ago I found a presentation with slides about the benefits of migrating to the cloud. I think that the presentation was maybe quite old but I think that it started with arguing that physical on-prem datacenters often have a lot of overcapacity and only 2 % CPU is used in that example.
The presentation also ... |
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 wrappers, or add in a testing framework like PowerMock? I've heard it's bad practice to use powermock, but it seems unrea... |
(I’m trying to phrase this question to be as specific as it can get, but since I’m mostly interested in high-level design it might be a bit still too vague. Let me know if I need to edit it or specify it any further!)
I have recently made a customised pattern for data sharing in Swift, and I’m looking for ways to valid... |
So this is an example endpoint to fetch one user by its username
[HttpGet("{username}")]
public async Task<ActionResult<object>> GetUser([FromRoute] string username)
{
// ...
}
Regardless of the value of username the database will either find and return a user or null. But you know that a username has validation c... |
I've encountered several scenarios that require me to mock certain helper methods because they call outside resources. As a result, I'm forced to convert all my helper methods from private into public. Is this a code smell/bad practice?
|
Say I have a domain entity User:
class User {
constructor (username, email, password) {
this.username = username
this.email = email
this.password = password
}
}
Now, all users need a way to validate their username and email
There are two ways I can think of doing so:
Inside the domain entity (domain/e... |
I'm just curious, I'd like to understand how compiled code works from the moment I run an executable file. Some time ago I had found a very well written article which helped, using a hex editor, to read a binary file and, for example, find out the references to external function in external static libs. But I cannot fi... |
I know that user stories and use cases are written by a customer not the development team alone. And I know that on each iteration the development team picks a number of requested use cases and delivers them by the end of the sprint.
First question is: Should the requirements analysis and design phase on each iteration... |
TLDR: Does using DB objects as my AggregateRoot lead to bloated God objects. In comparison to the issues I see in using separate DbObjects and DDD objects.
I'm trying to bring together my understanding of DDD and Clean Architecture, with CQRS via MediatR handlers. All make sense when I read about them separately, then... |
I'm working on an app where we need to use different authentication flows depending on how the user is accessing the app. I want to make sure that there is only one instance of the authentication service at a given time (singleton).
There aren't that many auth services types and I don't expect there to be more than 3-4... |
If I have a IRepository that Create,Update,Delete and Get an entity from the database and I do a fake for it with a public List inside it.
If I am testing a command that is using it:
is a bad practice asserting to the list inside that Fake?
If not, how this way of testing is called?
Is this an integration or unit test... |
How do I achieve two things at the same time writing Java Spring Application:
Clean Architecture
JPA goodies (@Transactional, Optimistic Locking, dirty checking, etc.)
I like the idea of database/ORM framework being an unimportant detail that can be easily replaced, but I'm not sure how to effectively implement it.
L... |
I am developing a library for an embedded system with very little storage in C++. I would like to declare an array for a specific use in one function, however I am unsure if I should declare this in the function as a static array (which would be ideal for my use case), or if I should declare it as a private member in a... |
Display devices have their own PPI.Do these devices respect the DPI information of image file? If not, then what is use of"DPI" of image file?
example:
Image file- height: 1200 px width: 900 px DPI:300
Monitor- PPi:100.
What would be size of image when displayed?
Thank you!!
|
Background:
I have a JSON object (named JSONConditionObject) which looks like the following,
{
"condition1":"value1",
"condition2":"value2,value3 ..."
//more fields below very likely to be added/changed
//also the nature of values for a condition (String/List) might change as well
//For eg, it can b... |
I have a big backlog of tasks gathered during last years. And new tasks are added occasionally. All tasks have the same priority and tasks never expire over time.
I was thinking of the reasonable way to have them done
Do the newest task first.
I see the flaw of this approach, that the oldest tasks may never get chance... |
That is quite specific circumstances I've come across, and I somewhat struggle to find proper way how to approach this.
I'm given a class written in swift-language, which has a control property, like this (I generalized some names to avoid reference to actual product):
class FooViewController: UIViewController {
..... |
Reading the Google C# style guide I came across this:
Generators vs containers
Use your best judgement, bearing in mind:
Generator code is often less readable than filling in a container.
Generator code can be more performant if the results are going to be
processed lazily, e.g. when not all the results are needed. Ge... |
I have a simple app which has the following architecture:
front-end
api/
back-end
server.py
api/
utils/
The app is already using http based server which is started/configured in the server.py. However, now I would also like to use websockets for some new functionalities, while my old http -based code will ... |
I am looking for a way to design a system that can provide a linear and incremental counting for invoice number accros a scalable system.
At this time, I have four pools of two servers (two pool for europe and two pool for america -> total eight servers ). This system handle sports subscriptions and can generate invoic... |
Given a minimum spanning tree in an unweighted graph of (10 .. 500) vertices and (vertice_count .. 1000) edges. Each vertex can have
up to 6 edges.
Given K agents/bots/processes/etc.., all starting from the root of the spanning tree.
What would be the best way to distribute the "work" to explore the graph (eg. visit al... |
The following code works and is clear, but it's also verbose. I suspect that there's a way to make it more terse, so that it could be skimmed quickly and it'd be more obvious what's happening.
// The functions return either `false`, or a valid URL.
$redirect = site_redirects( $domain, $_SERVER['REQUEST_URI'] );
if ( !... |
I am writing a function that I would not like to get called given a certain context and am wondering how best to convey that to possible users of the function. Assume, for exemplification, I am writing a function process_payment that must not get called in an environment that demands certain security standards on the p... |
Why will it take that long to transition all Mac software to ARM according to Apple? I thought all they would need to do is to recompile the source code of their apps and rewrite SIMD code from intel intrinsics to ARM NEON intrinsics. What am I missing that makes this work take this long?
I apologize if this is not the... |
I am coaching a client who is reorganizing their Program and could use some advice.
Background: The client works for a large corporation with many different programs that all take their own approach to Agile or do not use it. Over the past two years, I have coached the Program towards the adoption of the methodology an... |
In general, should I use variable length arrays or malloc? In my specific case I am processing files of very short to very large sizes. Also if I compile on version MacOS 10.15, and then run on 10.13, it seems VLA's won't work. Malloc is more likely to work. What should I use?
|
We have a legacy order system and a new order system that are both currently active. The legacy order system takes 'offline' orders still, the new order system handles 'online' orders but uses the legacy order system for operations, so the legacy system has both offline and online orders. Eventually, the new system wil... |
It seems like the consensus is to learn by doing when it comes to programming, well that seems like the advice given to most beginners.
How will beginners learn to write efficient code when they dive head first?
|
I'm designing an application in a micro-service architecture and I have
some questions regarding error codes.
Found some information about it (1,2) - but more focused on the responsibility
of the error code management.
Suppose I have 2 micro-services and an API Gateway.
At current design - each micro-service is definin... |
We are decomposing a monolithic legacy system into microservices. As we do so, we can't completely remove reliance on some of the data in the legacy system that's required for each microservice.
Should each microservice integrate directly with the legacy database to read and write data under its domain or should we hav... |
I have used this design pattern in several entity-component designs. Now I want to introduce it to my team:
It concerns a type-of relationship, where the instance structure and the type structure are mirrored using a naming convention:
Vehicle -- typeof --> VehicleType
Vehicle and VehicleType can then be specialized ... |
When I'm designing a system for a program, I often make misjudgements that will prevent the design from either working, being maintainable, easy to use or all the above. This means I will usually have to iterate several times, refactoring my code until I achieve this.
Recently, I've been trying to think about this as I... |
I noticed this pattern in my programs: I'm building a system, like the one I'm building for my local hackerspace right now. It's using database as its "brain" - a scraper as a separate service fetches building rental advertisements and a chat bot announces them on a task-related group chat. Both synchronize using the ... |
I'm working on a relatively large system, that is about online transportation reservation. The system is decomposed into some services, that are interacting via REST interface with each other and the UI.
I have a service, called BillingService, that is responsible for establishing, payment and finalization of bills. E... |
We have two microservices A and B that are developed inhouse.
A provides an API that B consumes.
Let's assume that B has some specific integration tests that ensure that B is compatible with A.
We want these test to be run whenever the developer team from A commits a change.
Currently each team has a separate Jenkins a... |
This question is based on this separate question on stack overflow.
I have a very low-level structure meant to compactly save presets on flash memory. For simplicity I am going to use stored_record as a substitute, obviously the actual type has a /lot/ more fields.
struct stored_record
{
int16_t foo;
};
Now I also... |
A customer has reported a bug that neither them nor us have been able to reproduce. This is the only report of this bug happening so far.
We've spent a lot of time trying to replicate the issue (followed the customers' exact path, with their same browser, and even set the server and local machine clock to replicate the... |
I’m trying to create a web application with a forum and user profile along with other functions. However I’m thinking about how I might implement an ID for each user. The best way I’ve seen other applications do it so far is like Discords, which is something I’d like to emulate in my own app.
Here is a link to Discords... |
I'm in dire need of some help.
My background is from python, js and ruby, with using frameworks to provide good structure.
A potential client has an internal app which does quite a bit of stuff. This means there are multiple functions, and a lot of code. The project is written in php, which I don't have much knowledge ... |
note: This is of couse about software-architecture/design-principles, but as no architecture is completely detached from its language, please note that the language i am using is C++.
I am using an API, with a debug-layer that lets you give names to API-specific objects, so that readable debug-output is generated from ... |
For my project I need to use same algorithm for both web and Android application.
I thought about handling the algorithm server side but I feel this would put too much unnecessary load on the server so I would prefer it to be handled client side.
What approach would be recommended for this situation to avoid both load ... |
The table
Let's say we are running a webapplication for the Superhero Association. In there, there is a table of 1 000 000 super villains which need to be watched. Everytime a super hero gathers new information about villains he updates the table.
The table itself is paginated, sortable and filterable.
Example
The user... |
I need to send a series of floats over a TCP socket.
Firstly, is it safe to assume that most platforms (e.g off the shelf Windows PC/Laptop) and architectures represent floats in the same way (i.e IEEE 754)?
If so, I was thinking of doing something like this:
float a = 29.054;
int* b = reinterpret_cast<int*>(&a);
//St... |
I have been working on designing an API that lets client create a product (think of product as something like website domain, something that comes into existence when client makes order for it to the service). Correspondingly with every purchase results in creation of the order object. Which means creation of two resou... |
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 or is it considered as misusing the default methods?
@Repository
public interface OrderRepository extends JpaRepository... |
I manage one middle sized website that uses Flask and PostgresSQL on the backend and some JS with Angular and Jinja2 templates on the fronted.
Now we're going to create a second website that will be similar to the first one, most of the models and tables could be shared amont the 2, just simply put, both are used for s... |
Suppose I have a REST application running on a remote server which connects to a mysql database. Now let's say the password of the db has to be changed. What are the right methods and practices that has to be followed to avoid failure of requests.
One solution is to create a new user with same level of permissions as o... |
When building an application or program using the concepts of reactive programming, how does this work for nested reactive properties?
I have an example using Swift, ReactiveKit, and Bond, however the concepts apply to any reactive programming setup.
class User {
var firstName: Observable<String>
init(firstNam... |
I always think about this scenario where we need to perform a task conditionally and the task requires calling another microservice. What I am not able to understand is which microservice's responsibility is to evaluate the condition?
Let us take an example:
There is a dedicated inventory microservice. The system has c... |
In C++ and Java and many other OOP languages, in order to send a message to an object, you have to use the object.function() syntax, for example:
myCar.start(); // send the start() message to the myCar object
But why was this syntax chosen to send a message? why for example wasn't the function(object) syntax chosen... |
I'm having a series of data as documents in a document db (CouchDB)
Sample of a document looks like below
{
_id: xxx
_rev: xxx
data: xxx
position: 1
}
These documents displays in a web front-end in a vertically scrollable list and any item can be dragged and dropped to change position.
The position key is always u... |
I have to create a class named Phone, which can be any phone like Android, iOS and Windows. Again in Android, I will have various types of phones. For me challenge is, I have to maintain more than 100 properties of each phone.
Some features are common in all the three phones, some are common between only Android and iO... |
Say I have a service that is producing events of the format
type: SEND_MESSAGE,
to: 'bob@foo.com',
And I have another service, that is saying, "for the next four hours, I want to consume all SEND_MESSAGE events that are directed to the people in this array: ["bob@foo.com", "jim@jam.com", joe@jog.com"]".
So ok, this ... |
My app is being deployed on various platforms, among which GNU/Linux, iOS and Android. I am contemplating the branching model of the central C++ code git repo, upon which all platform-dependent code depends.
Would it be a good idea to keep it simple by:
keeping master sacred == not only compilable, but also HEAD has p... |
I go to several sites that offer their data in XML, JSON, CSV formats. As shown here,
https://www.space.org/basicspacedata/query/class/boxscore/format/csv, I choose the format. Question is how is the data stored on whatever database they use? Certainly they don't store the same data in different formats? Are the fo... |
I'm making my 1st official project. It's written in Python, is open-sources, and I'd like people to be able to freely and easily fork and modify the code. The project name is "shelf" and the main script/executable is shelf.py.
I'm trying to make everything modular. The main script shelf.py should be the only thing the ... |
We have the current software pattern below.
Sql Server Db --> Repository --> Domain Layer---> Dto Layer
The Dto layer filters sensitive data, and brings only required domain data to client API users.
A repository pulls All the data from Sql Server database. One thing I don't understand with Repository is, it may get ... |
I am working on a hobby project of mine where I want to make an application to doing my personal finances. Just for learning. I am trying to adhere and implement best practices and patterns to learn and to evaluate how they work in real life.
So for this project I work in Kotlin and decide to follow the Clean Architect... |
I have asked this question in stackOverflow, but I guess that maybe softwareEngineering is more appropriate. (here is the question in stackOverflow)
I have frames sized with a fixed size of 7 values (t_i, i in {1..7}). Each value is stored on 2 bytes (the max value is then = 2^(16) -1 = 65 535) and is divided by a reso... |
According to Why is Global State so Evil?, as I understand, global state is bad and I should use dependency injection instead. That means, for example, a mobile app that use bundles of app level data as follow:
public class UserData{
private static UserData userData=new UserData();
public UserData getInstance()... |
In my current maintenance project, there is REST API resource URL like this:
/sites/<site id or site code>/buildings/<building id or building code>
In this endpoint URL, there are two parameters,
<site id or site code>
<building id or building code>
As the name indicates, these two parameters are ambiguous, say the v... |
I'm developing a REST API using Nodejs along with MySQL as the database.Is it okay to keep open the MySQL database connection open through out the Application or open and close connection query-wise ? Is there a best practice or a standard methodology for handling situations like this.
|
Firstly i am aware that different hardware architectures handle floats differently, so I can't guarantee the same result on different machines even with the same inputs.
But in my case i do not have a compounding issue where the differences add up over time (like you might experience with physics engines), so i can for... |
I have read that we can think of an OOP object as a "small program" that send messages to other "small programs" (objects), but I am not sure if this is a good analogy.
One reason that make me think that this is a flawed analogy is that with real programs, I can send a message to a program telling it to do a task, and ... |
I'm writing a microservice (in .netcore) that will handle some requests using WebAPI, but also it needs to react to some external events. I see 2 possibilities how to solve it (on a very high level):
Have a lambda that is triggered by SQS message, and put event(s) handling logic in that lambda function.
Have a backgr... |
Is there a term or some short wording to refer to an expression in the "first" line of the control flow statement?
func() {
if (a == b) {
var = 1 + 1
return True
} else {
var = 5 + 5
return False
}
}
if ((a == b)
&& (c == d)) {
...
}
In the first example, the term/wording should "match" a == ... |
I am planning to implement a cryptographic library for several languages and looking for best practices. I have looked at several threads, especially this, this, and this one, which answer my questions partly only.
I am interested in a couple of languages (among others, C, Haskell, Python) and have read how to package... |
Use case interactors in the Clean Architecture consists of the application specific business rules.
Interactors uses the Data Access Interface to fetch the required data from the data access layer.
Basically I see two approaches to test these interactors.
Using test doubles rather than the actual data access layer
Us... |
I am trying to create an Entity/Relationship Chen Diagram for a new APP. Scope is simple enough.
I will have multiples types of users login through the same Login Form.
What I decided to do... Is create a parent Table call Credentials that will contain only the Username/Email & Password.
Users, Subcontractors, Clients... |
(Purely for learning purposes)
Say the DB contains 1 billion rows with 200 bytes per row = 200 GB of data.
The traffic at peak is 1000 requests/s, with each request asking for one DB row.
What cache size would I begin with to ease off the load on the DB? I realize that this is determined best empirically and can be tun... |
I am planning to design a programming language. One challenge I face with is whether it is a good idea to have const as a variable qualifier instead of a type qualifier.
For example in C++:
const int x = 5;
means that x is of type const int.
While in my language, H++, the variable x is a const and its type is int.
Thi... |
Still getting to grips with EDA. Suppose in your system you have an Order Service, which first needs to check if the customer's account has enough credit from the Account Service. There are multiple ways of doing this:
You could achieve this purely with Events over a bus:
Order Service (marks order as pending) --> Or... |
Assume a resource URL in the context of REST API:
/sites/<site id or site code>/buildings/<building id or building code>
The value of the two path parameters, <site id or site code> and <building id or building code>, can be either id or code as the name indicates. Implicitly it means:
for instance, there is a building... |
Note: I'm asking about the strategy behind unit / integration / end-to-end tests, not about classifying tests as one or the other.
More so in the past than present, it was expensive to write and run end-to-end tests for every possible scenario. Now though, for example with the increased use of test fixtures / emulators... |
When I'm writing code in the form of IO Monad, I wonder what's real value of it.For example I have a function as def something(in: In): IO[Out]; my function is a pure function that **returns an impure recepie(just another function) which could be composed with other receipes, and finally triggered.
Is postponing the si... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.