instruction
stringlengths
34
36.1k
I'm really struggling with overheads of context switching. When I need to continue work on some part of the code after a break, it takes up to an hour to recall all the context of the problem I working on and tune up to work. How do you deal with that issue? Maybe you leave some prompts in the code describing context a...
I am writing drivers for different devices to work with my embedded system. Currently I write any new driver manually but for the future I would like to automate this using a settings file. I figure I have 2 options: write a single universal driver that reads the setting file and behaves accordingly; write a code gene...
Context: I have an open source project which uses JNI. While it's possible to build it yourself, I expect most users will use standard Java tools like Maven, Gradle, or SBT to download the JAR, which contains the pre-compiled binary image. This is no problem on Windows, but on Linux it gets complex. I'm wondering how m...
I am working on an ASP.NET Core application that grabs a model from a database via Entity Framework, and will pass a "subset" of that model to our Angular front end. For example: I have a list of Users. On the user-list page, I would like to grab a list of User objects from the API and display them on the page. For eac...
Given the formula to calculate instability... I = (Ce / (Ca + Ce)) with Ce = outgoing dependencies, Ca = incoming dependencies, and I = Instability, ...should I include system dependencies (such as System, System.Data, System.XML, etc.) when counting outgoing dependencies (Ce)? Or, do I just count it as one outgoing d...
I'm a junior developer that is given the ability to help shape my team's processes if I can justify the change, and if it helps the team get work done. This is new for me as my past companies more or less had rigidly defined processes that came from management. My team is fairly small and somewhat new (<3 years old). T...
According to the book, The domain layer should be isolated. In domain entity, you should avoid adding a property represents database PK (usually identity surrogate column called ID). There is no problem in identifying a domain entity because by definition it includes a natural key. If this key is the same as PK, then ...
I have in mind to develop a Ruby on Rails app with two different databases. In the primary SQL db - let's say MySQL, for instance - I'd keep my app items, e.g. user profiling, user-user interactions and, in general, everything that's bound to a model, anything that I already know how is made. Now the best part: I'd lik...
I am wondering how best to slice up a Java Mustache web app which has: Data layer (JPA, Repos, Entities, etc) Service layer getting data from other company web services outside the package Web/Controller layer serving up Mustache template pages Important to note this is all in the same Maven module (I know). What I r...
In short, is instanceof a bad thing? I had a code something like Converted convert(Object o) { if (o instanceof ClassA) { convert((ClassA) o); } if (o instanceof ClassB) { convert((ClassB) o); } throw new IllegalArgumentException(o.class + " not suported"); } I didn't realize it can...
I have data object's let say PersonDto (fields name, surname) and OrganizationDto (field name, type). Then I have some common screen, showing such data, but screen title is something related to type of - Person/Organization. The easiest way how to implement that functionality is to have field/constant in that class. An...
I have been trying to figure out an ACL solution for my application which should manage API endpoint's access rights dynamically. Some said that I have an option of Spring Security ACL. I checked it but lack of documentation frightened me a bit. So that I started to design my own ACL implementation; since I did not sta...
Hopefully not too academic... Let's say I need real and complex numbers in my SW library. Based on is-a (or here) relationship, real number is a complex number, where b in imaginary part of complex number is simply 0. On the other hand, my implementation would be, that child extends parent, so in parent RealNumber I'd ...
I am writing in C#, but this question may apply to other languages as well. public class Test { int a = 10; // I created 'a' here public void M() { int a = 20; // I forgot that I already have 'a' in the class and I initial it again ; // do other stuff with "a"... } } This way isn't ag...
I have a specific problem in git which I havent found an answer to yet. In gitlab I have 3 seperate repos. For my school project the teacher wants me to copy everything into a repo of his and wants to see all my git history. So I would need to fork my 3 repos into his main repo, but I just couldnt figure out an answer...
Assume there is any program that is supposed to be tested and you like to perform an equivalence class analysis on it. Let's say you identified six valid and four invalid equivalence classes. Then, how many test-cases need to be created in each case at least? I'm not sure about that but I think because every equivalenc...
I'm currently building a React Native application and wondering if storing device information such: if my app has granted location permission location service is turned on last known user location in the Redux store can be a good idea. I have different components that needs to know this informations and storing in R...
We're a small team of 3 senior and 1 junior developers and I've been tasked with introducing BDD within our development process. To say there's a lot of confusion about BDD is an understatement and it's appearing within the team after I created some scenarios for user based behaviour. My understanding of BDD is that it...
I am member of the Apache PLC4X (incubating) project. Here we are currently implementing multiple industry PLC protocols. While we initially focussed on creating Java versions of these, we are currently starting to work on also providing C++ and other languages. Instead of manually syncing and maintaining these, we wou...
I'm developing a system, and I've had a question that might help other people. The system would be written in PHP, with a lot of chance of turning a mobile app later, too. Normally, I would create it with a controller that would make the connection to the database, and others responsible for inserts, updates, etc. Cons...
I am trying to modify an opensource project (json serialization one: gson, I want to let it serialize/deserialize objects with circular references, which is not allowed now. ) to do it I have to change an abstract class widely extended. I want to change the behaviour of that class with a strategy object so every child ...
I'm trying to accomplish this scenario : There are 2 types of users, let's say Admin and Worker, and there have different roles. Admin can do a CRUD of questions, and also can create a room where the users can join to play together (this is just a name) but maybe is a good idea to create more attributes inside of it l...
Immutable objects In object-oriented and functional programming, an immutable object (unchangeable[1] object) is an object whose state cannot be modified after it is created Wikipedia (https://en.wikipedia.org/wiki/Immutable_object) Code example in PHP (see question below...) class ImmutablePaymentMethodManager ...
I wrote a small INI file parser as a library which I want to use in a bigger project. Following good practice I decided I should write test cases, too. But I fail to find a good start. The library is extremely small (1 source file for the implementation, 1 header) The library has few public methods. (parse(), get_sect...
Is it possible to scale a low resolution image to a highier resolution upto the point with minimum effect on quality, sharpness and other notable attributes of an image.
I'm reading Clean Code by Robert C. Martin, and the phrase TILT inexplicably appears in some code samples. Example (it's in Java, by the way): ... public String errorMessage() { switch (status) { case ErrorCode.OK: // TILT - Should not get here. return ""; case ErrorCod...
I am trying to improve the architecture of a system where data flows between 3 systems. Every minute, there are thousands of items generated on App 1, which are sent to Midpoint in the following way: App 1 sends items (through REST API) to Midpoint This happens on an "as-and-when" basis: App 1 will keep sending item...
I would like to ask if there is any powerful method we can use to combine the Id's to a single field for faster search and retrieval. My case is like this, I have a table that stores ID's of companies. ID | CompanyName 1 | Company A 2 | Company B 3 | Company C I have another table where there is data that need to b...
I just started looking into programming language design and came across the term intrinsic but could not find any good definition of this anywhere. I hope that someone here can help me with a good definition to broaden my understanding. The description of the word in the Cambridge dictionary says: Intrinsic (adjective)...
I know that @RolesAllowd annotation can be used to provide role-based access control to REST endpoints and I am currently using that with RestEASY. I need to know how it is working behind the scenes. Can anybody please explain to me how Java validates the roles mentioned in the annotation. So far I managed to figure ...
When writing unit tests, I want to reduce the cognitive load of the reader as much as possible. One thing I've noticed that bothers me is that the variable names of the thing that is being tested are often varying quite a bit in my and my teams code. The variable is often named similar to the component in question. As ...
I've been asked to design folder-like structure (in java, but I expect this solution to be language agnostic). There is one root, just like / on linux. Then, it can have almost indefinitely nested folders and files inside. Now, here's the catch: I have to be able, to track some of file details, like size, on every lev...
I'm wondering about Unit Tests. Let say i got a code ( in C#, but language is not important here): public class SOT: ISOT { List<string> _internalCollection = new List<string>(); public string CurrentCollectionName { get; } public void AddItem(string item) { _internalCollection.Add(item); ...
Imagine the application I am building as a normal media playlist (Video / Music). On the client side, I select the files I want to play (Files are located on server), and I send its paths to the server as an array of objects. Converted to JSON the object would look like: { "mediaFiles":[ { "type":"pho...
Are there any algorithms related to the following problem that could be usefull for solving it? I have a convex hull built on some point set. I would like to simplify it (reduce number of points) by still keeping its perimiter (or area) as small as possible. New simplified polygon should not intersect the original hull...
I am reading the following link to learn about system designs of various systems. (This is a paid link, I am attaching all explanations below.) In an attempt to explain the system design of Instagram the above link gives us the following requirements: Users should be able to upload/download/view photos. Users can perf...
As far as we know, the User Stories are the way a requirement is defined in bounded context with acceptance criteria. On the other hand, the Product Backlog enlists all requirements, i.e., new feature, enhancements, and existing production issues. This is not clear, if or if not, the Product Backlog just consists out o...
I was hoping that someone could explain to me in the simplest way possible and with an example, what abstraction is with regards to Oop. I've read articles online and I just don't get it. I'm hoping a simple coding example would help it sink in. I understand it's the concept of hiding complexity from the user and I ...
I am developing a "platform", I have an MVC site that will hold all the main data, as well as our generic API, uses Microsoft authentication to create an account, then our employee MVC will add the data to the database that will allow the user to start consuming our API. I have a custom API for one of our customers, us...
One of the database systems I work with (I'll call it database A) was essentially sharded into 3 schema-identical copies. This was easy to source control, and when a change was made to any of the copies, it would go to all the copies. A few months ago a change was made. A new database was created (not sharded, I'll cal...
I am trying to learn CQRS in my spare time. Say I have a class like this: public class Person { private Guid Id {get; set;} private Guid Name {get; set;} private List<Order> orders; //Methods and constructor go here } I am thinking of a scenario where it would be beneficial to persist the Person class to th...
I'm looking for failures in this "token based login" design, besides the UML "syntax" errors. Theoretically speaking, it will do the trick when implemented on an small project. If true, sorry about my english. Thaks in advance. EDIT: Is 1) this model something useful and clear? 2) Will it work when implemented? 3) Besi...
Lets say we have some configurations stored in a database for how we should acquire some data. One of these fields is an AcquisitionStrategy which denotes how we will acquire the data. I want to add a field that corresponds only to a subset of the rows in this table that have an acquisition strategy of HTTP. Should I ...
I have a data access layer, which currently communicates with a database. public interface IDao<T> // T is my DTO { Write(IEnumerable<T> dtosToPersist) } public class Dao<T> : IDao<T> { private readonly IBulkCopySaver<T> _bulkSaver; private IEnumerable<T> _buffer; public Dao(IBulkCopySaver<T> bulkSave...
I am implementing an asynchronous remote (to aws S3) logging handler (in python, but it doesn't matter) supporting 4 modes: Immediate: the messages get written immediately to S3 - I am trying to avoid this mode By queue size: the messages get stored into a linked queue, and after reaching a certain size (say 500ko),...
While a fundamental concept, I don't understand the statement "every CLASS in Java is a subclass of the class object," which is often quoted in JAVA tutorials usually in the inheritance section. I thought this statement would be true if stated in reverse: every class OBJECT is a subclass of a class." Here is why: in OO...
So at a high level, we have multiple projects/solutions in company and we need to keep them in 1 source control. Since the number of projects is around 50, we are not creating individual repositories for each of them but instead are all in same repository. Our branches reflect the environments which is Dev, QCT, STG, P...
I am implementing Authentication from scratch (php). I reached a point where I have different types of users (admin, author, editor etc.) After dealing with this, I realized I can allow multiple account login at the same time (the login pages/paths are different for each user type). Would it be a good idea to implemen...
I am new to unit testing, but finally getting started. I have been running into a situation where my unit test names apparently grow too long to readable due to the multiple parameters and combinations of them. For example, consider these hypothetical test case names resembling my actual test case names: GetAllEmploye...
I am reading Eric Evan's Domain Driven Design, and I encountered this concept on p108. I am having a hard time grasping the concept, in spite of the explanations mentioned on the pages 107 and 108. Here is an excerpt of the topic from the book: Medium-grained, stateless SERVICES can be easier to reuse in large syst...
why every startup and every big company uses #wordpress ? what is the benefit of using it ? fast management , easy to use , customization instead of creating one with html , css , js and back-end (php) ?
I created a CSV export that works like the code below. There is a LinkedHashMap where the keys are the column title and values are functions where certain properties are read. By reording the lines where entries are added to the map, one also reorders the csv column representation. Column header and data are connected ...
I work on several projects and sometimes they share a common base. How do you work with version control? Here's an example: I've got a boilerplate Wordpress plugin that I reuse. On each new Wordpress plugin project I create code I want to add to my boilerplate plugin. Currently I'm manually extracting libraries & fixe...
Edited: Update is at the bottom There could be a common or best practice for this scenario, but I am unfamiliar with it. However, it could very easily be a matter of subjective opinion on how one wants to implement their classes. Either way I am hopefuly to get some opinion from the spectrum of class designers here. I ...
I was wondering if there is a way to get the values of every case in a switch statement? When you provide a not implemented case, I would like to throw some exception and provide a list of available case values. switch (partName.Trim().ToLower()) { case "engine": //something break; case "door":...
Still trying to wrap my head around microservice architecture since I'm used to a monolithic approach Suppose we try to build a extremely simplified Uber booking system. To simplify things we let's say we have 3 services and a gateway api for the client: Booking, Drivers, Notification and we have the following workflo...
I'm using the MVVM design pattern in my application which is comprised of, A Xamarin.IOs project (View Layer) A Net Standard project (Common Layer) A Xamarin.Android project (in the future) (View Layer) In the Xamarin.IOs project, there's a Delegate class (NotificationCenterDelegate extending UNUserNotificationCenter...
I currently build applications that are fairly monolithic. I have a one or many code bases that compile into one single binary/package and deployed on a cluster of docker containers. All of the data is stored on a single MySQL database, a redis cluster and possibly a NoSQL database for some of the data. In this case, t...
Using a website with Javascript as example. Let's say I have script A which only performs a specific function on page Foo. For example something like sorting elements in a list. Script A is only added to pages that have a list that needs sorted via javascript. In the javascript we access the list with document.querySe...
My parent class has a vector field I want to force child classes to push in that vector as many as items they have. At least one item example: class Options { protected: vector<string> optionItems; public: void printItemsInConsole(){ // prints items on console } } class Main...
I like to create a finite-state machine for the given text below. While solving this, I came accross with several problems I listed at the bottom. (This example is in terms of testing (where you later derive tests of a specification which is in form of a state machine).) Following specification of an elevator is given...
I'm building a personal project, as an introduction to DDD, I'm doing a little bit of analysis and can't get my head around it. My ERD looks as follows: To go over it, as an admin you can setup a restaurant, you can add multiple tables to the restaurant, and you can setup workdays ( like the days the restaurant is op...
It is pretty obvious that any interpreted language CAN also be compiled. For a long time I thought that it was not necessarily the other way around. Then I discovered Ch which is an interpreter that can interpret the whole C language. It also supports parts of C++, Java, Matlab, Fortran and C-shell. This made me draw t...
I'm storing data which logs whether or not a user has logged their attendance for a given day. Some days are unimportant (holiday, weekend), so those are also stored. The two requirements are that: Calculating the number of logs and missed logs can be done quickly, and The structure is scallable for whenever new user...
Which one of the following way is recommended and why? Date d = Date.from(curr); Date d = new Date(curr); Can you also provide some examples behind the reasoning?
I'm studying domain driven design (DDD) and came across terms: Event Driven and Event sourcing. I know it's about publishing event from producer to consumer, and store the log, so my question is: What is the difference between Event Driven and Event sourcing?
We had a interesting debate today over what our REST API should default to doing when validating a request body where unexpected fields are present. I think we ended the conversation in a good place, but it brings up somewhat of a meta point of whether or how to apply Postel's law that'd I'd like to explore further. Ou...
I'm studying Domain driven design (DDD), reading many articles, but never found a simple explanation. Please, help, let's say we have a design: My bunch of question is: What is domain? ( where is domain depicted) on this pic? Where is aggregate on the pic? ( is it many objects or only one?) Is it right that Order is ...
context and background: I prefer OOP for the most part and find it, largely, more intuitive -- this is my bias. When I read that functional language x is better than OOP language y I think to myself: sure, sounds great, if you're computing integrals or performing other mathematical operations. Outside of that domain,...
In the case that a type is specified, it could be on the left (before) or the right (after) of the variable name. For example, C, C# and Java have the type specified before the variable: int num = 5; TypeScript, Rust and Haxe (can) have the type specified after the variable: let num: number = 5; let num: u32 = 5; var ...
I'm using MVVM and I have an app with a UITabBarController, the Main tab of which is a list of publications and the other is a Search screen where they can search for publications. Searching returns a list of publications. Imagine that Publication A is the first item in the list on the Main tab. Now let's say the user ...
I am using ADO.NET to read a bunch of data from the database into in-memory objects. This is my domain model: // Question.cs public class Question { public int ID { get; set; } public string Title { get; set; } public string Description { get; set; } public IEnumerable<Tag> Tags { get; set; } } // Tag...
Long story short, I wanted to use C as a scripting language and in a portable manner so I created a register-based, JITless VM to accomplish this. I've formalized the VM's ISA, script file format, calling conventions, and even created an assembler that assembles the human-readable bytecode to numeric bytecode, now I ne...
I have the following dictionary: { "Drama": 8, "Adventure": 8, "Action": 4, "Comedy": 3, "Thriller": 1 } This dictionary is like a representation of a user's preferences in movies. (in the past he selected like 8 drama movies, 8 adventure ones etc). Then I have another movie with genres: ["Action","Adventure","Fantasy...
I am currently implementing a TCP Proxy Server. The huge problem I have right now is that, based on the clients' TCP data, I am trying to determine whether the client is making an HTTP, FTP or SMTP request. My solution, I am thinking that I have to read the first line of data of the TCP data. For example, an HTTP reque...
Suppose of this question the following: I'm in full control of this project I'm writing a media player Obviously, a media player will allow a user to adjust the volume, so I might have a class that looks like this: public class Audio { private int level; // Constructor and other attributes left out pu...
You've probably been in the same situation: there's a class of objects which have a specific date before* which they should not be considered "active." But how should you represent "active since forever?" PostgreSQL or Python, for example, have very definite but different earliest possible datetime values. Let's say I ...
I have dell edge box that is stored in another location, the edge box is having 4G sim card internet access with dynamic IP address that changes frequently, I usually use ssh putty with the 4G IP address which is IPv6, now if the IP address changes i will not be able to know the updated ip address of the edge box, any ...
I have implemented application using microservices architecture. I take a user story to implement. This involves front end/UI, and two microservices to implement the user story. So I have three components involved. Should one team implement the user story, or should the user story be split among three teams. It is poss...
I'm currently planning an architecture for a system that should consist of multiple microservices. We definitely want to make use of a message broker (probably RabbitMQ). A simplified diagram of my current approach looks like this: As you can see in the diagram I added a Response Queue, which is used by the services t...
I have or am going to have a database with countries and their emissions. Countries in the API have a 3-letter ISO Code. Should I use this for identifying the countries in database, or just a plain numeric id? CREATE TABLE country ( countryid integer PRIMARY KEY NOT NULL, ), CREATE...
In Clean Architecture by Robert C. Martin the dependency rule points strictly from the outermost layer/ring to the innermost. As an example a Dependency Injection Framework should lie on the outermost layer (frameworks) to allow for it to be replaced. However, a DI framework which relies on attributes would clearly bre...
If I have a SQL Server fact table with four dimensions (OrderDate, Customer, Product, Region), my understanding is that it's best to create a non-clustered index per foreign key (dim key column in the fact table). Assuming that is correct, is it optimal to combine OrderDate with each dimension in each of the non-cluste...
a few years ago I wrote a python script for reading CSV, handling the headers, filtering data, renaming stuff via RegEx...bascially to do various ETL stuff. This was done using a exhaustive configuration file that defined all the sources and all the targets. It worked quite fine - but the configuration was everything b...
When implementing interfaces, as a general rule, Impl is evil. Ok, but is it evil in the following case? I've a service that has (and probably will have) only one implementation. In such case, normally I don't need any interface. But, the "contract" must be shared with other modules because the service is exposed using...
I'm reading the book Dependency Injection Principles, Practices, and Patterns and I read about the concept of leaky abstraction which is well described in the book. These days I'm refactoring a C# code base using dependency injection so that async calls are used instead of blocking ones. Doing so I'm considering some i...
Sometime ago in a code-review (C++) I suggested to change the input argument from Path type to Optional<Path>, where the function has specific logic for unset path. It looks for me intuitively better, but the author appealed that Path::empty() (empty path) method should semantically mean the same as unset Optional. My ...
I have a question about versioning when I depend on a third party (TP) project's versioning. Our current process is to release a new version every time TP creates a release with security fixes. The problem is when a TP release contains new funcionally that we want to use in some but not all of the projects we maintain....
Are there any published standards of archive files to hold webassembly (multiple files) with a metadata file that defines the entry point? I'm thinking of something similar to JAR or APK.
Lets say you are coding a function that takes input from an external API MyAPI. That external API MyAPI has a contract that states it will return a string or a number. Is it recommended to guard against things like null, undefined, boolean, etc. even though it's not part of the API of MyAPI? In particular, since you ha...
I've my front end written using HTML/CSS/Javascript. Front end is communicating with the backend(Oracle database) using Java Webservices (Spring boot app). Situation #1: User clicks on the Download button, using Ajax call, I call my Java webservice, java webservice returns the data in JSON format, I display this data i...
I have an object that acts as nothing more complicated than a data store for a collection of items. I do this because it lets me bind the data to a single object, which I can store in the Unity (game engine) editor and assign to a bunch of other objects so they all operate on the same list of data. I'm not really sure...
I have a user table that has 4 rows with id = 1, 2, 3, 4. I delete the row with id = 2 and insert another user and the user will get id = 5. What will happen to the id = 2? Will it be used again or do I rearrange the ids? Rearranging ids doesn't make sense if I have a large amount for every delete operation.
I recently had a discussion with a friend about code maintainability with regards to modifying an iterator inside of the body of a loop (C# syntax): List<int> test = new List<int>(); for (int i = 0; i < 30;) test.AddRange(new int[] { i++, i++, i++ }); The code works fine, and as expected adds 0 - 29 into the list....
My team and I have this Desktop client developed in JavaFX. It basically has a "Remember my password" checkbox. If the user ticks this checkbox, reboots, and reopens the app, the user should be automatically logged in. I'm using a cheap trick just saving a temp file to the temp directory. It's encrypted and it contains...
I'm actually studying about web development. I was just asking why a lot of web apps and chats(Whatsapp, Telegram, Discord, and a lot, a lot more!) are using cache. I mean, after learning cache systems like Redis and Memcached, I was asking how could I use them practically. For example, Redis can cache entire pages for...
From general observation I've come across the standard to be 36. I was looking to incorporate a uuid in my urls but didn't want it that long. Is there a minimum where I can still keep the uuid unique?
I'm designing a relatively simple web application using .net core. I've mostly done desktop development in my career so far, so I'm a bit new to the nuances between desktop and web development. In this application there is a business logic layer and a presentation logic layer which takes the business logic and transfo...
Although I understand privacy concerns, the measure has been imposed by politcians and I want to know what the proper way to put this into place would have been. Right now, each site has to implement GDPR compliance which is kind of redundant with no promise that your wishes are actually respected. Wouldn't it make mor...
While designing a complex system some of my colleges came back with the idea of having two separates APIs, one that will perform the writes into de databases and another one that will only do the reads. I fail to deeply understand why separating those two concerns can be useful for the whole system. It can be useful wh...