instruction
stringlengths
34
36.1k
It is generally understood in software engineering that global state is bad. However, OpenGL has been designed very much embracing the concept of global state. many of the things you modify will affect everything in your program (active shading program, uniforms, active buffer, glDepthTest...) Because of this, I ended ...
I'm trying to make an abstract board game. In the game, a player can choose to make multiple actions within one turn such as placing, moving, or rotating a piece. I'm not sure if whether or not my implementation is bad. I was told by my professor that using instanceof and if statements like this is a sign of code smell...
for example, sometimes I need to define a hardcoded string with some variable parts, I often have trouble to choose the style: style 1 : reuse every characters when possible showMessage(num){ let strArr=['Mon','Tues','Wednes','Thurs','Fri','Satur','Sun']; alert('Today is '+strArr[num]+'day'); } style 2: Keep the v...
For example, I have multiple projects which shares some common libraries: ProjectA CommonLib1 CommonLib2 ProjectB CommonLib1 CommonLib2 At the moment, they are all in one big repository: ProjectA ProjectB CommonLib1 CommonLib2 However, I think it is better to have one repository for ProjectA and ProjectB. But...
I have a situation on the front end where a user clicks on “Download” button and the query behind the scenes is going to take over a day. I have a Spring boot web app running as far as web services are concerned. What I want: When the download button is clicked on the front end, I would like to put this process in som...
When I think of software configuration, I think of a file that is read by runtime - said file would contain things like the port a server might use, whether to use encryption, and paths of various resources. When I first came across "Software Configuration Management", I thought it meant the management of configuration...
I'm trying to implement authentication and session management for a microservice. In order to do the process RESTfully, I understand that I'll need to use some kind of token-based authentication to avoid tracking client session data on the server. The following quote from this answer on the Information Security Stack E...
I am evaluating an open source CMS called Piranha (http://piranhacms.org/) for use in one of my projects. I found the following code interesting and a bit confusing, at least to me. Can some help me understand why the class is inheriting from a base of same type? public abstract class BasePage<T> : Page<T> where T : Ba...
Trying to figure out which structure is cleaner between using a specialized function or using parameters to accomplish the same thing (see code example below). Essentially, I can reduce the number of abstract methods in my interface by adding parameters (as in the BufferParameter case). If the methods themselves got to...
Our previous developer set his name in the license of our open source project. Thats how license header looks: Copyright (c) 2018 (his name), Stichting (our company name) <(his email)> Can we change that to our company name?
I'm writing a project for school - Tinder-like app. I thought of implementing database entirely in RDBMS (PostgreSQL). But now I think it's a good opportunity to get to know NoSQL systems a bit. I'm closest to using Redis (seems fast and friendly), but I'm also thinking about: MongoDB (very popular) ElasticSearch (see...
I recently joined a company where I was tasked with building a system for one of their clients. The work I've done is so far working well, but the most senior developer on the team who's been with the company for many years is having trouble understanding my code. He says it's hard to follow. I tried conducting a train...
Let assume that we have a system in which the users can chat with each other and we are working on the backend. We can name the service which fetches the chats in one of the following ways: ChatsService UserChatsService If we use the second version, is it a bad practice or it is ok in your opinion ? The idea is that s...
I am working on a little framework where I have this directory tree: project/ |--- ... (directories unrelated to the question) |--- public/ | |--- index.php .htaccess The .htaccess sends every request to project/public/index.php but I have to add specific rules for assets (stylesheets, js, images, ...). Searching ...
I'm designing a database that holds the information for users of three diferentes apps that share the access to the data trough an API. For every user i'm storing credentials, profile and roles. What I'm looking forward to have should accomplish the following requirement: Some users need to have access to more than one...
This might be a bit of a wide question. I have a couple of classes in Java that take input a String which is a mathematical expression and evaluates it. I want to implement a desktop GUI for this. The user inputs the equation in a textfield and a couple of rectangles should be displayed under the textfield if the equa...
I Have a REST API endpoint where the caller can supply some optional filters for the results. GET api/inventory For example, an object member of a GET request may look like the following { "books" : [ { "id" : 1, "description": "this is book 1" } ] , "pencils" : [ { ...
for example, suppose I need to play different sounds according to "grade": file list: fairSound.mp3 goodSound.mp3 excellentSound.mp3 code: showResult(grade){ if(grade==0 || grade==1){ SoundUtility.play(fairSound); }else if(grade==2 || grade==3){ SoundUtility.play(goodSound); }else if(grade==4){ Sound...
I would like to be able to implement immutable data in C++. In short, given a C++ object in which I would like to modify a member variable, instead of modifying that member in place I would like to get a new copy the object with the member being modified. To address this, I wrote a small template class to represent the...
My boss asked me to develop for him a price quotes desktop software (he doesn't want a website), he wants to give the price list and the users of this software would write the prices according to the boss prices, all the bosses prices would be stored on local DB. I thought about the following idea: to develop two deskt...
I work with a feature branch model where the branches get merged into master when they are ready. Before a larger test (specific to my field of work, involving a lot of heavy hardware), several feature branches (individually tested using simulations) are merged into one "test" branch. Before the actual test, the "test...
Let's say I'm requesting a list of IDs for which I'd like to receive relevant DB entities (e.g., my-restaurant-api.com?restaurants=1,2,3). In this example, let's say ID 3 has been deleted and should not be returned. Should the API response: return a 404 return a 200 and include the entities that exist return a 404 and...
I practice TDD and refactor aggressively. Recently some colleagues have complained that the resulting pull requests are difficult to review, or would require a lot of regression testing. When I refactor, I'm disciplined about using safe, behavior preserving refactorings, mostly around changing names and extracting meth...
As you know, epics consist of user stories. The user stories are short descriptions which specify the requests of the user. They can be perfect instance of the questions listed below: Who, What, why One of the customers told me that he wants a main page for anonymous users of that application, and this page must provid...
I just started leaning about algorithm design and I am now having trouble identifying the additional space used in an algorithm. For dynamic program, as far as the examples I've learnt, such as knapsack problem, interval scheduling, sequence alignment, we all explicitly create a data structure to store results of sub-p...
This may be an obvious question but I really don't understand this so if someone can help me that'd be great. Basically, I am in the middle of developing an e-commerce app for my database management class and I downloaded a free trial of the web design app Sketch. After playing around with it for a bit (having no clue...
I have a requirement to create a console application that will read in data from a file. This data will be used to create new users in a database and assign them roles. The input file will specify usernames to be used and the roles to which these new users will be assigned (7 potential different roles where it is possi...
I have a simple concept like in the image below. Basically there is an Item which can be 1 of 3 types and a character that can be 1 out of 2 types. All generalizations are disjoint. What I'm trying to do is to somehow depict with UML notation that a Character can at any given time carry only one item but Monk can carr...
I am a bit confused by the nesting that occurs in Media types (also known as their former name 'MIME types'): The top level types are called application, text, image video, audio, message, model and a couple of others. However, it is not clear to me why certain subtypes are nested under one of these, while other subtyp...
Lets say I want to store songs in my database. Instead of having just one Song table, I have ten tables. The Song table also has a foreign key to the Artist table. When an artist is added to the database, we check exactly how many songs are there in each of the Song tables, and we assign the table with the smallest num...
Not using UncheckedIOException, NullPointerException possible public void callerMethod() { Object result = ioMethod(); // call instance method of result } public Object ioMethod() { try { // IO Stuff return new Object(); } catch (IOException e) { e.printStackTrace(); }...
While reading on the design for autosuggest implementation on large scale systems (like google), I'm able to understand the usage of trie and how top "n" terms are stored at each node to quickly retrieve the list. However, I'm not able to get my head around the logic of efficient way of "sharding" the trie in a distrib...
I am facing trouble in creating a unique, customer facing Booking Id. It's a simple thing to do at backend where we can create a UUID and maintain uniqueness. But the UUID looks ugly from a Frontend Customer perspective. I wouldn't want to keep quoting or using this 36 character string everywhere. I do understand to ac...
Here i am basically looking for performance improvement. I need to match names in a SWIFT message (Let's say MT 103) against sanctions lists (sanctions lists by UN, by OFAC, some custom lists) and below is what i have developed Since there are various lists and total number of names are more than 50 thousand so i loa...
I have a website for admin and a mobile app for normal user. Both of them share a same database which is now on the cloud(The website for admin is already deployed with the database on the server). The way I use to connect to our local database for our mobile app is through PHP scripts which contains the necessary para...
Background: I am working on a service where the domain logic exists as a library, and then the actual executable is built on a web framework as a wrapper around the domain logic library. There is no guarantee two customers run the same version of this service. Task: I was asked to create a way to print the schema for r...
In Elements of Reusable Object Oriented software by Erich Gamma and friends, the intent for Abstract Factory Pattern says: Provide an interface for creating families of related or dependent objects without specifying their concrete classes. Can anyone explain in clearer terms what does author mean by related or depen...
I am trying to start with a geo search project that will find all landmarks in the 10 km/miles (not important for this story) of a particular landmark. So for example, lets say I have a database of a 1,000,000 landmarks. In order to find all landmarks in 10 miles range of a landmark with certain coordinates, I would ha...
We are currently in the process of building a service (a REST API) which is called on by our primary application. The primary application contains a users/permissions/roles set up which is used to verify if the user is able to complete tasks on the application. The user-roles relationship is one-to-many. The third part...
Can someone explain to me why one is necessarily better than the other? int M() { int y; LocalFunction(); return y; void LocalFunction() => y = 0; } Versus int M() { return LocalFunction(); } int LocalFunction() { return 0; } I'm not getting the point of using the lambda expression vs just m...
I have part of the system that looks like this: Basically, the client decides which API call to invoke on the server based on the flag that is previously provided. It knows in advance which type of response to expect as well. So the code would look something like this: if (flagOn) { Response1 = ApiCall1(); Proce...
I have an application say x which uses another Java library(say Y) as a JAR file . So y basically needs to download a file and load it into memory before any of it's methods are called at runtime by X. How do I make sure that files are downloaded and loaded before any of the methods of y are called ? Also, Y is being u...
I'm developing or maintaining a free software project Foo which uses CMake for a build system, as well as source control (e.g. Mercurial or Git), with the repository being available online. Now, this project depends on another project, Bar - say, it uses include files that this other project provides. Bar exists indepe...
Why is the method in Global.asax called Application_Start() and not ApplicationStart()? According to MSDN method names should be in Pascal case.
Let's say i've got the following absurd viewmodel in a MVC application. public class Absurd { public string WelcomeMessage {get; set;} public string PlainTextAdminPassword {get; set;} } And this is the entirety of my view <div>@Model.WelcomeMessage</div> Let's assume that both my WelcomeMessage and PlainTextAdmin...
My project structure (Spring / maven): src / main / resources / application.yml src / test / resources / application.yml This is working well (when I launch test, it takes the test application.yml). But often, I see posts where the application.yml is postfix to take the active profile: i.e.: application-test.yml for t...
My web application at the moment accepts REST requests and handled via some controllers, which calls corresponding services to perform the logic. Now I want to add in some security logic before calling the services. This includes checking if a service can be accessed ALSO amend the request body if necessary. I am havin...
I'm a web developer of a small, local SaaS web application. It currently has about a half-dozen clients. As I continue to design the application, it's become increasingly harder for me to convince myself to commit any time to the project, which has happened in the beginning phase. Having grown attached to the project a...
I am struggling with some web application which is quite big and messy. There are several Domains that land on the server. domains can have a "channel" and every channel should use different templates for customized look and feel. The decision which channel to use takes place in different parts of the code and is chaot...
There's this sample repository, which showcases different Android testing practices. One of the apps is android-testing/unit/BasicSample, which is very simple and, among other things, checks the email field and for that purpose adds a listener like this: mEmailText.addTextChangedListener(mEmailValidator); https://gith...
So I started a month ago at relatively small company (12 people in the building) as a junior developer without professional experience apart from my own (7 years) and no degree. We're building a JEE app that's been going on for 15 years, and for the next version it was decided we would rebuild the frontend, removing fr...
Just read this article: https://microservices.io/patterns/data/database-per-service.html We are designing 2 microservices - both have tables in a shared db. What I'm wondering is if I build an API that provides access to these sets of tables... where should this (HTTP REST) API be installed? on a separate application...
Logically how can I prevent a client from making changes to a domain model entity if a service is not used? For example: Let's say I have an Account class that contains Transactions to compute a balance. A service is used to coordinate the interaction of these entities. However, I only want a client to be able to use s...
I'm having trouble finding resources for this implementation I'm trying to figure out. I want to save nodes in a binary search tree (self balancing) containing an ID and value struct Score { int id; int score; }; If I want to delete (id=2, score=7), how can I delete this node without deleting id=6 or id=5? ...
I am loading a large amount of data (2,000 files with about 30,000 rows, 30 columns) for use in a Django application. The files are based on 40 different templates. The column names are consistent within the templates but not between templates. We've manually mapped the columns to canonical names for the fields we are ...
I am trying to figure out how to translate the onion architecture into an ASP.NET Core WebAPI solution, this is what I ended up with: Let's say I have an application that takes a file path / uri into input whether via a Console application or a WebAPI application, read each line and if some business rules are met chang...
Admittedly it's probably mostly in traditional BASICs (which require line numbers) that I've seen this. Take these examples (cribbed from Wikipedia): 10 PRINT "Hello, World!" 20 END and 10 INPUT "What is your name: "; U$ 20 PRINT "Hello "; U$ 30 INPUT "How many stars do you want: "; N 40 S$ = "" 50 FOR I = 1 TO N 60 ...
In my program, I have a long-running function from which I would like to interact with the user for various reasons: Giving status updates ("Downloading file /foo/bar.png") Displaying warnings ("File upload failed; will retry later") Asking for input ("Please enter your google drive password") The problem is, of cour...
This is really a question about "best" or "practical" practices, and would be interested if anyone else has had a similar need as myself, and how they handled it. I have a REST(ish) API that we have developed to "bolt onto" the front of an existing legacy system. I use this "REST" API to enable both third party, and ou...
I recently learned about Flyweight Pattern from this link. It is written there: It’s very important that the flyweight objects are immutable: any operation on the state must be performed by the factory. I did not understand this well. Any opinion will be appreciated.
Say you have a HomepageController that' suppose to show all the blogs, users, gallery, and some members-only info (for logged-in users) Normally, it looks like this: <?php class HomepageController { public function index() { $blogService = new BlogService(); $data['blogs'] = $blogService...
I am willing to refactor some code that acts like a controller class executing work embedded in other classes. On one side it looks good as the controller is generic and what changes has been well encapsulated, but on the other side the solution implies lots of downcastings. I have proposed a generics based refactorin...
There exist lots of discussions on variable naming. However, I would like to address a specific aspect. I am a data scientist and deal with dozens of features/variables/columns — however you may call them. My work benefits from names that: contain information about the variable's ontological background; this means tha...
When writing a lexer/parser, why/when would an advised developer chose to define the tokens' types through an enumeration field/type hierarchy? The closest question I've found here so far was Lexing: One token per operator, or one universal operator token? by Jeroen Bollen, but it seems to be more about the ideal dee...
The Spotify model has become a popular example for the right way of doing development. If a product has a single, main, code repository, like most products have, how do you make squads autonomous and independent? There is common code that different squads will work on during the same period and if a squad adds a bug, d...
In one of the projects I work for, we have just added karma to run unit tests. When reviewing the MR of a coworker, I noticed the karma.conf.js (the configuration file) has 120 lines, which seems to be a lot for me. While reading each configuration, I noticed many of those configurations are the already default values....
I'm implementing an API with pagination which has max_results that can be specified by the client. The server will have a hardcoded limit, for example 100 results per page. In the situation when the client specify max_results >100 which is more expected behaviour and why do you think so: return just 100 raise an erro...
My question comes from using the agile template in Azure DevOps though its more of a general question about dealing with bug work items. When a bug work item has been investigated and the issue has been identified, prior to any tasks being created to resolve the bug, where/how is this usually documented? Looking at th...
As a Ruby/Rails person, I often deal with method delegation. It's often convenient to delegate a method to a composed object or a constant. Ruby even has a def_delegator helper method to easily build delegators and Rails' ActiveSupport improves the builtin's interface with delegate. Yet when I looked at Python, I found...
Suppose I have a kind of UML activity diagram with 1-n forks and joins. The assignment of the individual nodes relative to each other is defined by an XML relationship table via UUIDs where each sourceand target attribute's UUID represents such an individual node. The following, highlighted example should clarify this:...
Say there is a single database table containing information about two different types of animals: land animals and sea animals. I want to create two lists of animals, one list for each type of animal. Is it better practice to query all animals from the database, iterate over the returned list of animals, and place them...
I am modeling our existing database in transition to a graph database. Currently here is how I can interpret the database a graph relationships group -have-> groups group -have-> participants participant -is-> user user -has-> profile user -has-> user-accounts user-account -composed of-> social-logins user-account -com...
I've been thinking a lot lately about safe code. Thread-safe. Memory-safe. Not-going-to-explode-in-your-face-with-a-segfault safe. But for the sake of clarity in the question, let's use Rust's safety model as our going definition. Often, ensuring safety is a bit of a how-big-is-the-net problem, because, as proven by Ru...
If I display user_id that represents each unique user in the db as an atrribute in an HTML element, is that good practice? Because I need the reference to the user if I want to perform an action on that particular user such as adding him to be my friend. Example in HTML: <div data-user-id='12' onclick=addFriend(12)> ...
On my e-store I wish to allow customers to buy store credit, which could later be used to purchase items from the store. The vision is that the customer would send some actual money to my account via e.g. PayPal/Credit Card/Whatever and that amount would then appear on their profile. E.g. if a customer carries out a cr...
Very beginner. Need to compute route from A to B for a robot. i would like to know how to store area map and compute the route. I can compute shortest path etc using algorithms e.g. dijkstra. What format of maps are used for efficiency. Edit: 0. Unable to find anything useful using search 1. could not find a relevant...
I am currently working on a game engine for work and have hit a wall on my idea. I have multiple objects (called prefabs) that have very common properties such as Position, Rotation, and Scale. There are more, but let's just focus on those for this particular issue. The idea was to create a base class called RenderObje...
I am quite new to DDD, but I am currently working on a system which has a payroll element to it. I have a requirement to send payslips to an external system when they are created. Currently the payslip process is all in the existing legacy code, but I was thinking that it might be a good chance to move some code into a...
My situation is this: I am contributing to a Symfony/PHP project. I had to completely reskin one page in the application. The controller logic is almost totally unchanged. I only had to change the template file (named index.html.twig). But the changes are completely different. If I make a pull request with these change...
I have a series of classes that represent widgets in a layout system. The base class for all of these concrete widget types is Widget. If I have a Button and a Text Box, these both derive from Widget. The layout is structured as a tree. Each widget can have only 1 parent and zero or more children, which are also of typ...
My understanding is that separate data store per service is a best practice in microservices architecture. This Nginx article mentions that, but it goes on to advocate a Master Data Management system for ensuring consistency of data across disparate data stores. How can both coexist peacefully? It seems to me that e...
I'm trying to learn the best practices for code design and reuse in C++ so I am going through the well known GoF Design Patterns Elements of Reusable Object-Oriented Software. I noticed that nearly all design patterns use dynamically allocated objects. To prevent memory leaks, I'm leaning towards using shared_ptr for a...
I am seeing bad practices occurring in our version control where my colleagues are creating their own versioning system with stored procedures so that they can compare results before/after changes and we end up with multiple stored procedures in the database with slightly different names e.g. StoredProcedureV1, StoredP...
Is it good/bad practice to add more constructors just for test purposes (to mock the DOCs used in my SUT) like this : public class A { private B b = new B(); private C c = new C(); public A(){ } /*** * used for test puproses * @param a * @param b */ A(A a, B b) { //...
I'm working on a service which has a lots of dependencies. The way how I call them is I'm wrapping each service client around an Adapter. Like this (I'm using Java): public abstract class AdapterBase<Request, Response> { protected abstract String adapterMetadata(); protected abstract Response makeActualCall(Re...
So, first let me explain my current setup. I have an unmanaged ethernet switch which is connected to my intel nuc (server A) and an external had drive. Server A is running: Ubuntu Docker Gitlab container (I push my code to this, it builds an image adds it to docker and then replaces the old version) My website is ge...
The language is PHP. I have several functions that relate to each other (and sometimes use each other) that I've decided to couple under the same class. Here are my reasonings, do keep in mind that I'm limited by what I don't yet know in terms of how my code will be used: These functions have no clear need for a class...
Our react web application is broken down to multiple components. Some of these components are part of the same git mono repo and some live in a different repo. Now, to implement a bug fix we have to update the changes in one repo, release a version of the package, update the tree of dependencies, release other interme...
I am working on a project on both iOS/Android/macOS/Linux (Windows is optional, and surely no website version). There are a lot of related webpage-like data and the team decided to store the data in a specific markdown format (not the ordinary *.md format) to meet the requirements in the specific domain being dealt wit...
so I am in a position where I doubt my solution to the following problem: - we are developing a wpf desktop application with c# and have a decent plugin system. This increases the libraries we have in the system (multiple git repositories, multiple libraries). The libraries are then packaged to our local nuget server....
I'm working on a project at the moment and I'm using this project to try and apply DDD. However, there are parts of my implementation that I just can't get my head around or don't feel right. I'll try to describe how I currently have my application setup; In my domain layer, I have my aggregates, value objects and a se...
I looked multiple places for some advice on how to solve this before asking this question, but I couldn't find something similar to this. So I have the following scenario in Java Spring Integration Let's say I have some super class type class Foo { private String error; public Foo(error) { this.error = ...
Context At my company, we have a major Python package which is written in Python 2. We are now planning to migrate it to Python 3 (we don't care about keeping it Python 2 compatible). I am a junior developer and my coworkers are senior people, who don't have a strong computer science background. Issue During the planni...
Suppose that: you invent a new coordinates system and you create a class to represent it you have two products which need to deal with this coordinates system but which, apart from that, are completely independent Then, how do you share this class among both products? I think this question can receive a generic answ...
Rather than writing a monolithic code, I've been taught to find the parts of code which can be reused (in the same code or in others) and create a function based on them, which should perform "one and only one" task. Is there a term for this programming style? Modularization? It's definitely not functional programming,...
Within an organization, suppose you have an internal tool used by different teams and for different use cases. This package offers APIs in different languages. One could say that having multiple APIs enables more people to use the tool, as they don't have to learn a new language and can use their favorite one. On the ...
I'm doing code review on a change my co-worker made to our Java application, and I've found something I'm not very familiar with - a nested class. From reviewing the code, it seems like the nested class is being used as if it were a normal class - and asking my co-worker about it, the reason for putting it in as a ne...
I have a library, which sends and receives a set of binary messages and parses them. So far I’ve used inheritance for my design, i.e. class BaseMsg { // init msg from rx'd binary stream virtual bool fromBinary(std::vector<char> b) = 0; // write msg content to binary stream to tx virtual std::vector<cha...
May I be so bold as to ask (from an amateurish point of view), what is the general strategy for dealing with potentially ever expanding domain models? By way of example, I have Staff, and in the beginning they could just have have a department (although sadly, in reality, it had to be a List<Department> because it's n...
In React, when rendering a mapping from elements of a list/array/iterable to React elements, we're required to attach a locally-unique key to each element. Generally this is so that if an element changes or is removed, React only needs to rerender that specific element rather than the whole list. This key is required...