instruction stringlengths 34 36.1k |
|---|
I would like to find out if I understand single responsibility principle correctly.
The function below is suppose to return user ID store in database by using the SAM account name pass into it.
Look at the commented codes below, is it true about the single responsibility of a function/method?
Do this function violate s... |
In a recent MVVM mobile app project I wrote a set of API classes and Database classes where there was a clear flow of logic between both api and db code. To enforce the way api and db interacted I created an additional abstraction/proxy layer.
For instance the login process was to call this new layer Login function tha... |
I am in a confusion where I cannot decide whether a rule is validation rule or Business rule. I have simple POJO with JSR 303 bean validation rules.
public class VehicleDto {
@NotNull(message = "Vehicle ID is not given.")
@Size(min = 3, max = 20, message = "Vehicle ID length is out of range of 3 to 20.")
@... |
My main experience working with multithread environment was using Scala, so if I had an object that was concurrently updated by multiple threads I always used Akka. Now working in Java environment I don't want to bring all Akka dependencies and futures complications for a simple case where I have a concurrently updated... |
I would like to know the efficient way one person from my team could completely understand an unknown git repository from scratch (i.e. i don't provide them any detail) ?
Take the situation depicted herebelow
How could a person from my team quickly and efficiently know the complete structure of the repository ?
How c... |
I'm specifically asking about Django here, but I'd appreciate any insight.
I'm currently writing up a basic social network. My plan is to allow users to make different kinds of posts (ie text posts, image posts, and video posts) and then allow them to access others' posts chronologically on their feed. The feed needs t... |
I'm in trouble, my team (3 devs including myself) works with mobile and backend development and we are dealing with some problems trying to order this process. Let me try to explain my situation, our team has two main problems:
No testers (dev tests their own code)
Lots of interruptions along the sprints, to do anothe... |
In my company we made almost every system in micro-service architecture. I working on the backend system, we have many api that working separately from each others. Today We're come up with the question that which component should have the responsible to give front end the data their required.
Let's say we have
Custom... |
I'm working in a project (with Python, SQL, Javascript) where the devlopers before me have started saving sets into database fields.
Example
Here the field "audience" can have sets as content. Is this really a good and working idea? I'm wondering because I was taught to never save lists into a field in a database and... |
The AngularJS commit message format is a set of rules for how to your commit message should look. It has been adopted by AngularJS and other projects. According to these rules, a commit must be labeled in its subject with one of the following commit types:
feat: A new feature
fix: A bug fix
docs: Documentation only ... |
Lately I've been playing with writing my own programming language, following the excellent Crafting Interpreters book but I've hit something of a snag.
I'd like to extend the parser to accept variable declarations in the form of: var x,y,z and to allow for unpacking like [x,y,z]=[1,2,3] (noting that jlox doesn't, as ye... |
I write lots of code that involves three basic steps.
Get data from somewhere.
Transform that data.
Put that data somewhere.
I typically end up using three types of classes - inspired by their respective design patterns.
Factories - to build an object from some resource.
Mediators - to use the factory, perform the t... |
I have an interface that has ~30 methods and has two different implementations.
I am trying to create another implementation which will have some custom logic and at times it will call one of those existing implementations depending on some conditions.
The issue is that I only want this behavior for a subset of methods... |
From Type Compatibility - Introduction:
Structural typing is a way of relating types based solely on their
members. This is in contrast with nominal typing. Consider the
following code:
interface Named {
name: string;
}
class Person {
name: string;
}
let p: Named;
// OK, because of structural typing
p = ... |
The application requires that admin user can provide same actions like real user. It is normal situation when in application changes IIdentity so that when we click to button "Login like some user" result is as if this user logins via default login page, but in this IIdentity we have property IsAdminLoginLikeSomeUser w... |
Suppose you have an event and you wish to add members to that event. Would you design that as event/:event-id/members/ ? or just make it '/members' where you specify the event id in the POST body ?
Dealing with nested entities. For example. An Event has a Mini Event and You wish to add members to that Mini Event. So a... |
I started working in a stock broker that hired me and more two developers to build a piece of software to help them.
I am the newest member of the development team. My friend, another developer in the team, asked me to create a software engineering model to apply in the project, because the way they are doing now is n... |
While writing personal projects as well as well in the job, I often struggle to proceed on the current task because either I get stuck on what I was thinking or didn't thought about all the corner cases that may arise in the future. I was thinking what if before coding anything I do some brain storming and write a seri... |
Say I have an aggregate root called Customer. In this example, the customer has a collection of invoices.
Is it ever "acceptable" for the Application Service layer to create an instance of the Invoice class? The invoice class is not the aggregate root.
I realise it is not "acceptable" for a none aggregate root from a... |
Going through CS OOP classes a couple years ago, the examples they always used for OO class examples were the standard car/tire/engine and shape examples.
I sat down with the book 'Agile Principles, Patterns, and Practices in C#' and the Coffee Maker example attempted to change my view of OO class design. The book sai... |
Background: I'm working on a new project at work that will run in AWS. We're trying to use a modern microservice architecture and take advantage of cloud technology, but we don't have much experience with that yet. Due to some library restrictions, we need to run at least some of the services in Python, which my organi... |
I've always used public methods and recently been advised by one of my friends to always avoid defining methods as public, as far as possible, though I have worked in any commercial company I have never "really" understood the concept of why public methods are not "safe to use at times".
I have worked a lot with c# an... |
I have a DSP (Digital Signal Processor) with a very well defined application, (this explication will be simplified)
The DSP uses TDM (Time Division Multiplexer) frames to receive audio information, the audio information is processed (simple IIR (Infinite Impulse Response) filter) and then outputted thru TDM, mainly the... |
I have a Console project reads inputs from CSV file and tries to save them to database.
For that, I created a class Person that maps a CSV row.
The CSV file has two columns Name and Age. Person class is like.
class Person
{
public string Name;
public int Age;
}
So the list of all populated objects is List<Pers... |
Can you in "plain English" explain why we need Single Responsibility Principle?
Especially that it moves the what I call "bloat" into other places. See below for more info. By bloat I mean in my specific case, I have multiple responsiblities in a Controller that exhibit themselves as functions/methods. By applying... |
I'm currently coordinating the development of a software for a certain scientific computational task. The developers are all working on the project on a voluntary basis. Our goal is to publish the software as free software once it is done. The whole project is being developed in an academic establishment, where I'm the... |
I am currently reviewing memory partitions and I have a problem that is really confusing me. Suppose you have 5 memory partitions: 100K, 500K, 200K, 300K, and 600K.
Also suppose you have 4 processes that need to be allocated memory. (212K, 417K, 112K, and 426K)
Using the First Fit algorithm and processing the alloca... |
What are the differences between these? I would assume UI would be the overarching interface for a specific application composed of multiple windows. A window would then be composed of either 1 or possible multiple views. A view would then be a portion of the Window that a view could draw on? Am I thinking about th... |
What is the best way to store/expose locations?
Things to consider:
I want to expose only locations from a specific area to user
I want to be able to let user pick more or less direct locations (ex. suburb or city)
It has to be future proof, let's say the area of available locations will expand
Are there more things ... |
As a CS student, I've learned a decent number of programming languages over the years, most of which have had some concept of a "nullable" or "optional" type. Note that I'm not talking about null pointers or references, or weakly-typed languages like JavaScript where anything can be null. Examples of what I'm talking a... |
I am doing C++ programming in Ubuntu and really care about the efficiency of my code. The computer that I work with has 32 GB of RAM and the compilation is done with the C++11 option. I noticed that for a very large dynamically allocated array such as my_array_1 in the following code, accessing elements occur significa... |
In my C++ project, I have two classes, Particle and Contact. In the Particle class, I have a member variable std::vector<Contact> contacts which contains all contacts of a Particle object, and corresponding member functions getContacts() and addContact(Contact cont). Thus, in "Particle.h", I include "Contact.h".
In the... |
I'm in the process of refactoring legacy code. Unfortunately it is a WebForms application with very tight coupling and smelly code. Currently access to database is inside models which looks something like this:
var fooModel = new FooModel();
fooModel.Select(sqlConnection); // Accesses db and populates model's data.
I ... |
Currently we are developing our microservices by running them all locally using docker. We are now limited by the resources of our local machine and we are trying to find a solution to scale our development environment.
We want to keep quick feedback and our current debugging tools/IDE locally.
Based on this article we... |
When I use the Exception provided by the SPL the options are limited. So it's hard to pick which exception would be best suited to handle File exceptions.
I know the best scenario is to write my own Exception (FileException or something), but I was wondering if the SPL could provide of some use here.
I'm currently thin... |
I have a new requirement that for a given User how many vehicles he can drives. At present this information needs to be shown as a list of vehicles. There can be different types of vehicles, for example:
User A
Cars
SUV 1
Toyota RED
Bikes
Fav Yellow
Rocker blue
And so on...
The users are normally family members h... |
Like it happens to many, our C++ project grew larger and larger, and it finally hit the point where maintainability starts to be a concern, mostly due to build times: even by using ccache, every change requires anywhere from 30 seconds to 5 minutes to rebuild and test (actually it seems that "linking" is the time-consu... |
Say I have two classes: Customer and Invoice. The database tables look like this:
CREATE TABLE Customer (ID int, name varchar(30), primary key (ID))
CREATE TABLE Invoice (ID int, date datetime, foreign key (CustomerID) references Customer(ID), primary key (ID))
I am trying to decide whether this relationship would be... |
I'm giving a presentation tomorrow on Software Process and Machine Learning. My primary goal with the process slides are to get across that most of it is really reliant on project management and personal time management techniques. I mention things related to process cycles (waterfall, prototype, spiral, etc.) and I fo... |
Say I want to create a C# implementation of an API for some 3rd party service, and I want to have an option to get the json posts and responses out somehow, what would be an elegant way of doing that?
Example of a method:
public class MyApiImplementation{
public PaymentRespose CreatePayment(decimal amount, string o... |
Do Special Case or Null Object design patterns still provide value when application behavior, not just object behavior has to change?
I was tasked with revisiting an old application and refactoring its code to better log/handle errors.
This application is a .NET MVC API written in C# that handles readonly data. Since i... |
I want to know which are the rules so i can figure out what code files should be put in the "core" directory (and sub-directories), because i didn't get it yet.
I was thinking if it's about code that the user doesn't interact with directly, like database management ones, for example... Is that it?
Thanks in advance. ... |
A quick search on the role of compiler brings up the following:
A compiler is a special program that processes statements written in a
particular programming language and turns them into machine language
or "code" that a computer's processor uses.
However, I also read that every language needs to have a target ru... |
I have always been taught that one of the most important things to do at the beginning of the developments of a software is the Requirement gathering. I have also been taught that requirements always (most of the time) change dramatically between the beginning and the end of the project, either because the client wasn'... |
Basically this question is of the variety "Can I check that we're not about to do something dumb?"
We're setting up a new system that needs to guarantee delivery of emails.
We have an existing system that processes financial transactions and we want to decouple that from sending receipts (which it is currently handling... |
An example is switching the main view according to the selected item in a hamburger menu. Also sometimes it is just a small part of the GUI that changes according to the application state or according to user interaction with other parts of the GUI.
In WebForms days we used to create a tab control and hide the tab butt... |
This week I want to start a greater app project that is expected to handle much data. The app will provide an interactive forum, a media library that allows streaming and a task module with push notifications.
The forum data and the videos should host on a server and be provided through a service, securely.
Since I'm ... |
I'm currently writing a neural network implementation in c++ and a curios question occurred to me:
I want my NN to be "generic", therefore i want to be able to define custom transfer and error functions. My first instinct is to create an interface (abstract class) and pass derived objects as argument (basically funct... |
I'm programming in Java and have the following problem:
I would like to do collision detection. For that, I need different types of BoundingBoxes. For the sake of example, let's say that I have entities that have a circular collision box and entities that have a rectangular bounding box. So I need two classes, Bounding... |
(This is probably a dupe, but if so I haven't seen it yet, although it may be Best practice for encapsulating a parameter that requires multiple interfaces to be implemented, but that question doesn't answer my situation)
Normally I don't care that c# only has single inheritance, but I have run into something where I t... |
In the article: Why POCO, there is this sentence:
Maciej Sobczak puts it well: “I just don’t like when somebody gives me half of the language and tells me that it’s for my own protection”.
I don't understand what he means, even though C# is owned by Microsoft & Java is owned by Oracle, it doesn't mean they hold half ... |
I had an interesting discussion today with another developer about how to approach a class with a method that accepts a string and outputs string.
Imagine something like the following which is completely made up for the purpose of example
public string GetStringPart(string input)
{
//Some input validation which is... |
I have written a webscraper in Python that grabs data from ~10 different websites (they have confirmed that this is ok). Most of the websites are a little bit different, but the general idea of getting data from each is the same:
Load the site's URL
Press anywhere from 0 to 3 buttons (depending on the site).
Enter a s... |
I am wondering if this is a good idea in the first place.
Basically I want to create a template upon which to build numerous sites. The idea is I can update the "core" of the website without having to change much, if at all, any application specific code.
This way, if there is a flaw in the core of one web server I can... |
I am working on understanding DDD and want to see if this idea is sound, if it is common practice, and if there are any pitfalls or unforeseen complications.
I want to effectively have one "entity" with a globally unique primary key. I want to use event sourcing. I would like have different AR classes represent this "e... |
Premise: I'm asked to develop a system that will trace sensitive data. The data are gathered by an intermediate operator (let's call him IO) on an office terminal. The final user (EU) will show up to the office, identify itself via an ID document, the operator will acquire the information and send it to the system.
On ... |
I am writing an iOS application in XCode. The data loaded for the multitudes of viewcontrollers is generally loaded from the DB upon the viewDidLoad() or viewDidAppear() for that particular VC, or it it is passed from one VC to another upon IBAction button clicks.
I am wondering if there is a better/more efficient way ... |
Imagine a psedo-code class like this which does name comparisons:
public class NameComparer
{
public bool DoNamesMatch(Name name1, Name name2)
{
if(WholeNameMatch(name1, name2))
{
return true;
}
return ProcessorIntensiveFuzzyMatcher(name1.Forename, name2.Forename)
... |
Recently, I've been talking with a friend about the code I've written. The code looked something like:
import json
def save_data(destination, data):
with open(destination, 'w') as out:
json.dump(data,out, ensure_ascii=False)
# Code...
save_data(path,data)
Similar for loading the file.
My friend argued that it... |
I've got a class member function that generates a large list and puts it into a private member variable so it can be accessed through a getter. The generation of this list is a rather intensive process (in my testing it's just under a second, but with larger datasets I expect it to take much longer), involving lots of ... |
I am looking at updating some of my companies existing code to allow unit tests to be implemented. To be able to do this, all repositories are being interfaced to allow DI. However, the existing code has a habit of creating 1 repository class per table in the database, meaning that one section of business logic may n... |
I'm working on a free software GUI application and we are considering what non-essential files to include in the end-user package
Here are my thoughts of possible files we may want to include:
License file,
Readme
List of contributors
Are there any other non-essential (non-essential for starting the software) files t... |
In my current organisation, we have several different build environments (like toolset etc.) which are needed for compiling the code of different modules within the same product. I found this a big mess where every engineer, in order to build their codebase, first has to go through the mundane task of setting up their ... |
I have a C++ serial code which simulates a physics algorithm. The C++ code is serially optimised. What is the standard procedure and documentation that is followed while parallelising the code or for GPU acceleration? I am accelerating the code on Nvdia Tesla K40 & Intel Knights Landing cluster.
|
Two months ago I joined a development team for implementing new features over a software that evolved over 10 years. The current state is that there is very few documentation and in order to develop a new feature, there is only the architect who completely understand everything, so the developers need to implement what... |
Suppose that a user has multiple items. Each item would have complex configuration - multiple tables with relationships.
Each configuration table would have an id and a item_id which is a FK to items table.
My question is given that we have a relational database and we export all tables to a text format (csv,json, etc... |
Disclaimer:
The post is Spring and Hibernate specific but any generic advice would be helpful too.
I recently started on a project which contains following technology stack Hibernate, Spring MVC and Angular2.
After reading a bunch of blogs and tutorials I found clean architecture has a good set of guidelines and I lear... |
In my C++ project, I have three classes, Particle, Contact, and Network. The Network class will have N particles (std::vector<Particle> particles) and Nc contacts (std::vector<Contact> contacts). Particle objects will each have a number of contacts, represented by Contact objects, and contacts are shared by pairs of pa... |
I'm having trouble defining the boundaries of my bounded context(s). I have the following, simplified/incomplete, versions of the classes in my domain. All of these classes are unique so they are Entities and I think they should be AR's as well, though I'm less sure about that last point. A Customer, User and Carrier a... |
Where exactly in the 3-tier-architecture is the access to the business layer (e.g. REST API) located? I would say that the API must be between the presentation and business layer, but I have never seen that someone has defined it that way.
Presentation -> API -> Business Layer -> Data Layer
Would that be a reasonable a... |
I have a search function on my site that needs to search through ~2000 items (this table never changes, it will always have the same number of items) stored in MySQL. All it needs to do is search by name or 'LIKE' the name and return the id. I have thought of two approaches to this:
Query database using ajax on keyup(... |
I have an application 'A' that was over engineered using Amazon SWF to do jobs asynchronously. We are re-writing it to app 'B' to keep it simple and do the same jobs synchronously without using SWF. The actual code that does the job was kept clean and separate. Application 'A' will eventually be decommissioned - say li... |
I have a client side android app which needs to send an encrypted string to a server implemented in PHP. For this I have chosen an asymmetric algorithm (RSA).
Should I:
Save a public key in client side and use this for encryption and then
send the private key and encrypted string to the backend
or:
Get the public ke... |
For context, this project is a personal budget program I am working on while I try to learn to use MVC patterns effectively.
There is a SessionController that passes user commands to a MonthController. Each controller has a Parser that maps commands to controller methods.
Currently, the controller has a Month object as... |
I am new to the Xamarin technology, and I am working on an Asp.NET Core Web application which basically delivers micro-services which will be consumed by a Xamarin.Forms application.
So my Web API will offer quite a few operations, and each of them would use their own model class to represent their response and their p... |
I use this pattern quite often in JavaScript. Here is an example:
const comments = [
{ text: 'Hello', id: 1 },
{ text: 'World', id: 4 },
];
const byId = id => element => element.id === id;
const comment = comments.find(byId(1));
Sometimes, this pattern can make our code readable and modular. What is this pattern... |
I'm not sure if this is the correct form to be posting this on Stack Exchange. If not I apologize in advance and hope someone can point me in the right direction of where to post.
I have a AWS Load Balancer with multiple EC2 instances all handling my web traffic. I'm wanting to add iOS Push Notification support. I curr... |
I have read the replies from those post(Why are interfaces useful?) and (Why use an interface when the class can directly implement the functions?), which is the similar question as my this post. But I still cannot understand it why we use interface since we need to implement the method in our derived class?
I can unde... |
I am currently using NodeJS & Express to load webpages which contain element content that is rendered via a query to MongoDB.
A GET request will create Button elements, binding the MongoDB _id to each button.
I am designing a Point of Sale system. Each button is an item with an associated price on the Database server... |
My company develops embedded systems and they have a project where they are developing a new platform which will be used to do demos for potential clients. They are introducing a new technological concept and they want to have it as base for new products, so they can reuse most of the blocks of code generated and have ... |
In GNU/Linux the recommended installation directory for internal binaries of a given package is /usr/lib or /usr/libexec. However, I can't find any recommendation for internal (non-binary) executable scripts. Should they also go in the mentioned directories? Wouldn't /usr/share make more sense since they are architectu... |
I'm working on some code where the structure looks like:
Class A {
Client client;
B b;
void process(request) {
data = fetchData(client, data);
b.process(data);
}
}
class B {
C c;
void process(data) {
data2 = someProcessing(data);
c.process(data2);
}
}
class C {
D d;
SqsClient sqs;
... |
As a 3rd-party, I'm writing a program to interface with a webservice. The problem I've run into is that some classes end up being as commonly used as ints/strings (e.g. User), so I need to be careful with which responsibilities I give each class to prevent mega objects which depend on every other mega object.
The best ... |
I've come up with some ideas for the database design, but I don't know if any of them would be practical in production:
posts and a separate post_edits table with a copy of all previous revisions. To get a single post, it's completely transparent as if the post_edits table isn't there. Nothing wrong with this, but it ... |
A recent endeavor of mine requires asking users how related two concepts are. Example: Kiwi and Fruit. Identical? Fairly Similar? Rather different? Unrelated?
It occurs to me that for certain combinations of terms (such as Strawberries and Tasty) people may have varying opinions. This, in effect, poses problems ... |
I've been using a functional approach in my programming of late. I know that mutability and state changes are big no nos within the paradigm. I now find myself working with databases and other data structures where state must be changed. I've been trying to learn about monads and other means of interacting with state, ... |
I've been aware of SOLID for many years now and I've always though about "OLID" was a good set of design principles to follow... problem is I've always found difficulties with the "S", I've always thought of it as a very ambiguous principle and believe me, I've read about this principle from many different places/books... |
struct co_ordinate {
double x;
double y;
};
// -----> DESIGN 1
class Land {
public:
Land(std::vector<co_ordinate> co) shape_before_plotting(co) {}
// actions
// creates stage 2
// populates shape_after_plotting_outside_boundary
void do_plotting... |
In most web application which deals with a database, one has to enter the DB creds in a settings or config file, like DATABASES variable in settings.py in Django. What is the general practice to secure the creds such that only a selected few in the team knows the creds and even they are not able to connect to the DB wi... |
I have completed a project. But errors unexpectedly occurs anytime when the user inputs data in it. Yesterday my program was performing very well.
But today when the client tested the project it had some unexpected errors.
Is it a normal thing to have such unexpected errors?
Or Is there a way or a technique to verify t... |
I have a thread that goes in a loop doing something like this
void thread()
{
pthread_mutex_lock(mutex);
for ( ; ; )
{
/** code **/
{
pthread_mutex_unlock(mutex);
/** do_something **/
pthread_mutex_lock(mutex);
}
if (exit)
return;
}
}
where exit will be updated in a di... |
Introductory piece of code:
class BaseClass
{
protected Foo MyFoo { get; }
}
class ChildClass : BaseClass
{
void SomeMethod()
{
MyFoo.DoStuff();
//Here, I have no idea that MyFoo is not defined in this class,
//but rather in the base class.
}
}
The problem/debate is that you ha... |
I'm doing the exercise 10.1, page 476 from the book Java: How To Program, Early Objects by Paul and Harvey Deitel (10th Edition).
Modify the MyLine, MyOval and MyRectangle classes of GUI to create the class hierarchy as shown in picture below. Classes of the MyShape hierarchy should be “smart” shape classes that know... |
We have a logging protocol that defines how output of logging libraries should look like, e.g.:
each line should be a JSON
each line should not exceed 1MB
There are multiple implementation of this logging protocol, i.e, logging libraries written in different languages (Java, Python, etc.). I would like to create on... |
I have doubts on approaching doing this.
I have a Train class and a Wagon class. There are three types of wagon: FirstClass, TouristClass and DiningCar. Each of these types has the same properties and methods, the only difference between them is their multiplicity with the Train class.
Each train class has one and only... |
I'm working on a new style of database migration system that is coming along nicely. There is one last aspect of it that I want to finish, which is to enable MySQL linting. For background, this is a little different than standard migration systems that come with e.g. laravel, django, etc... Rather than specifying ac... |
I'm trying to port code from entity framework 6 (EF6) to entity framework core 2.0 (EF-Core) and have ran into a dead end.
In my EF6 code, I have a base class called Record which defines the base properties and methods of all Record types. This base class provides common functionality and properties for all different t... |
Which method is better to store the data in a database and why?
Here is a restaurant example. I'm using a SQL database and JSON to communicate with the database.
Imagine each row is a column in a database
Mostly without objects
Resturant ID -string
Resturant name - string
Resturant picture - hyperlink
Resturant des... |
I've been searching for weeks for an answer to this question, which seems as though it would be common across pretty much all applications and therefore a problem right at the forefront of CQS.
CQS dictates that a function should either:
Change state and return void (command), or
Change nothing and return a result (qu... |
I have a table UserItems {ID, UserID, ItemID}
Items must be in RAM (not in db table).
What is better for this? As enum with attributes or as dictionary of items?:
enum Items
{
[InternalParam("x432", 34)]
Red = 1,
[InternalParam("x431", 12)]
Green = 2,
[InternalParam("x438", 54)]
White = 3
}
OR
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.