instruction
stringlengths
34
36.1k
Let's assume I have three classes, as follwing: class A { Array<B> bs; createB() { b = new B(); this.bs.insert(b); return b; } } class B { Array<C> cs; createC() { c = new C(); this.cs.insert(c); return c; } } class C { delete() { ... } } A holds Bs, and B holds Cs. C has a delete method on which for a...
I am peeking through the code of torsocks where as you'll notice, the .travis.yml file instructs Travis CI to test against both clang and gcc. compiler: - clang - gcc I'm still learning and this caught my attention. Why both? Why not just one or the other? Thanks!
For example, in my project, I often found some head of for-loop appears many times, eg: for(let i=0;i<SharedData.students.length;i++){ SharedData.students[i].something=..... } if(isReset){ for(let i=0;i<SharedData.students.length;i++){ SharedData.students[i].reset(); } } . . . which the task that ...
In our applications we traditionally log events locally into the logging files. As our applications are distributed on multiple server instances, searching for particular events are complicated and time consuming. So we decide to introduce GrayLog as centralized logging solution. All logging events from an applications...
We have a website with a lot of functionality, and we now start another one, which should have a lot of common code with the first one. What would be the best approach to avoid code duplication? Possible solutions we consider: put these projects within one parent directory (but in separate git repositories), and just ...
The question is does it make sense to write a unit test which asserts that the current thread is the main thread? Pros/cons? Recently I've seen the unit test which asserts the current thread for the callback of service. I'm not sure, that it's a good idea, I believe it's more kind of integration test. In my opinion, th...
So I have a requirement for something like this: The client shouldn't be aware of how the actual classes are implemented or constructed. The classes implement a common interface So I used Factory class to cater to 1 and an abstract class to implement the second point. Hence I came up with something like this (a simpl...
Usually the domain logic should be contained in the domain entity, rather than being put in specialised external classes called from the entity. This is good to prevent that somebody comes later, changes the class with the domain logic and affects, without knowing it, the domain entity. Example Human { private birt...
Often times, through my framework's importing side of things, I have access to certain data that functions I'm about to use will certainly need themselves. I have "resolvers" that these said functions can use to get the additional data they need but they're very heavy operations and I was thinking: Since I already have...
I had a discussion, if the code for calling information from a database can have a switch to show also deleted entries. Simplyfied the code (C#) look like this: void searchEntry(string searchValue, bool searchDelete = false) Usually, the most part of the code base doesn't want to show up the deleted entries, but if yo...
On designing a cross-platform text editor that optimized for speed - I heard atom.io uses node.js, would it be slow? I heard sublime text uses C++, would it lots of effort to be cross platform and make GUI? I am trying to find out some of the best ways of achieving performance, cross-platform, easiness of making GUI a...
Suppose I have TypeA and TypeB classes, which are totally different, but both hold an list of TypeC objects. Class TypeA { List<TypeC> cs; } Class TypeB { List<TypeC> cs; } Throuth all of it's life cycle, a TypeC instance is belong to a one single TypeA instance and a one single TypeB instance, which cannot be changed...
Our Scrum master wants us to document our feedback for the iteration before our Retrospective. Her argument is that she wants us to have time to document our feedback. Another guy on the thinks that we should be documenting our feedback during the meeting or right before the meeting. I'm a college hire so I'm still lea...
In case we hav functions (f_1,....,f_n) which runs in this order somewhere in the future. I would like to define a relationship between those functions such that if f_i failed due to expection then f_i+1,f_i+2,...f_n shouldn't run also. Also, the user can cancel f_i. If he does, then f_i+1,f_i+2,...f_n shouldn't run al...
Imagine a 'User' microservice that holds all user's related logic, and this microservice holds a database. How could you scale this microservice horizontally and keep consistency ? In fact, if you just add another instance, then if one user is created, updated, or deleted the operation would only be applied in one inst...
We a have test repo outside of the app repo and we can generate data by either having direct SQL queries or through API calls (http requests). We've been entertaining the idea of switching over to using external APIs (http requests). Is there a clear preference as to which approach is better?
I have a string that is used in a few places. string portalLoginPath = $"{Request.Scheme}{Uri.SchemeDelimiter}{Request.Host}/Account/Login"; I was thinking of creating a static class with a string const to store it. public static class StringConsts{ public const string portalPath = $"{Request.Scheme}{Uri.SchemeDelimit...
Assume I have a dumb repository which stores numbers (for sake of this example). It is dumb because it may only create new record, update specified record and list all the existing records - no other logic included. But I want to implement a business logic which will allow me to store new records safely, knowing that I...
I have one table in which there would be millions of records. The requirement is to the records based on the condition and then total on one of the fields. Selectivity would be around approx 50. Should I load 50 records in java and then filter and sum of on the field. Or should I write an aggregate query and get the r...
I just read this SE question about parameter optimisation. I wondered if Python3 bytecode compilation does the same optimisation and this appeared not to be the case: >>> def f(a): return 2*a >>> def g(a): r=2*a; return r >>> import dis >>> dis.dis(f) 1 0 LOAD_CONST 1 (2) 2 LOAD_...
I have a class in my code and I'm not sure if the design I've implemented is correct or if there is a better way to do it. The class I have created have important useful methods that is used by each instance of that class. However, the problem is that the instance itself is never used. The class handles everything that...
I'm developing a multi-teant SaaS application in ASP.NET core mvc and I was wondering what the general approach is to applying tenant logic in a shared database scenario (TenantId for each entity). And more specificly, where this logic should be applied; In the Context, UnitOfWork, Repository or Service? My current arc...
When looking at a new codebase I like to start from a bottom-up approach. Where I comprehend one file and then move up to the next abstraction. But often times I find myself forgetting what the lower-level abstraction is doing. So I'll be at this point where I find myself in an almost endless loop of going back to th...
Let's say we have a generic table like below: id, name, price, quantity 20 product_x 5,00 100 20 product_y 5,00 100 20 product_z 5,00 100 20 product_a 5,00 100 For the name field we more than likely have repea...
In Scala, sometimes class extends a trait to provide some methods to extending class inside. ScalaTest import org.scalatest._ class ExampleSpec extends FlatSpec with Matchers { ... Matchers trait provides useful method like startWith, endWith or include. string should startWith ("Hello") string should endWith ("world...
I'm writing a software application of a few thousand lines of code (in Python), and in order to keep the whole thing together, slowly but certainly the need for unit tests (and later, other types of tests...) has arisen. My problem is how to organize the many testing functions that I've written so far: Suppose I have a...
There is this article that says: A Composition Root is a (preferably) unique location in an application where modules are composed together. Only applications should have Composition Roots. Libraries and frameworks shouldn't. A DI Container should only be referenced from the Composition Root. All other modules s...
I am currently developing the backend for a news application, which fetches news from various aggregators (e.g. Feedly). I thought this qualified as a good use case for the adapter design pattern, so here’s what I did: I created a configuration file that houses all the relevant information about each aggregator, includ...
Once written, a protobuf specification can be compiled using protoc to a variety of implementations in different languages (e.g. python, c++, go). That's great. But to compile that generated code, you need a protobuf development library and, if I am not mistaken, a runtime is required as well. Is there a way to generat...
I have a product which is a combination of mobile apps and webapi . I am working web API. The webapi part created earlier and it build with layered model. Even thought this does not have a business layer (API and Data access), each one created as seperate project in the solution. Now I just optimized the code some leve...
When an android device enters sleep mode it is know that cpu sleeps. That means that, services, threads are paused and everything sleeps. Is that true? In case it is, what happens after the device is awaken? Threads continue from where they left off? E.x if a thread reads from a database and device enters sleep mode(s...
I started reading the book Clean Code by Robert C. Martin and at the start I found this idea of his interesting, "Leave the code cleaner than you found it" adapted from the "Leave the campground cleaner than you found it". Now at my work in our code database I have this getter function in a class that gets a boolean va...
I have a ratings web app where I want to output the average of all the ratings. How I'm currently doing it is recalculating the average every time a new review is posted and storing that in a database table, and every time someone lands on that page, I retrieve the value from that table. Is there a better way of doing ...
This question is not specific to images, but this is the current issue im having so im using this as an example. So basically, I have some kind of a pipeline that some data(in this case, an image), has to go through before It can be used in my app(in this case, a web app). If we split the pipeline into functions it wou...
I have two paths: /students /students/{id}/addresses ...with the following behavior: POST to /students - 201 Created (if successfully created the Student) POST to /students/{id}/addresses - 201 Created (if successfully created the Address under the requested user) Now, imagine a situation where the client POST to /st...
The Scrum guide defines the Sprint Goal as: an objective that will be met within the Sprint through the implementation of the Product Backlog, and it provides guidance to the Development Team on why it is building the Increment. However, I am a bit confused about the proper understanding of what is the Sprint Goa...
I am confused about the two following statements and how do they both influence on which items be included into the Sprint backlog: The Sprint Goal and Sprint plan is produced by the collaborative work of the entire Scrum Team. The Product Owner builds the order of items in the Product backlog in order to best achieve...
When writing tests I usually ignored logging statements, but now I wonder if it was right. The logs are often important tools when diagnosing production issues, moreover there can even be requirements for logs, like "log every interaction with external system, including request and response on highest detail level" or ...
I am tracking the position of characters on a 2D grid (this is a computer game). At every step each character can attempt to move (stationary, up, down, left, or right). There are some rules that govern what moves are allowed. Example: Characters cannot move outside the confines of the grid. Characters cannot pass thr...
When building a standard web Apis in Java world there is two ways I could do nowadays Use SpringMVC (Not Reactive) Use SpringWebFlux (Reactive) There are few benefits of using Reactive that I can think of It uses less memory resources as there is less thread running (maybe better for a container based deployment) It...
In scrum, do you reserve any extra story points for tasks that weren't part of the original estimate, but my come in between the sprint like any technical dependencies?
I have a developer who is developing an ASP.NET Web application for me and I've been publishing it so far on my server, example1.com, so far without any problems. It is managed with a single Git repository on Bitbucket without any hassles so far, when he adds new features, I can easily fetch & pull the changes, and the...
I'm developing an application which has a 3D room. Each room is a 3d model and can contain media boards. each media board contains image(s) as slides or video. I have created following Data Models : class Room { string id; string room3dmodellink; List<Mediaboards> mediaboards; } class Mediaboard{ string id; strin...
The Nexus Guide states that: A Nexus Sprint Backlog is the composite of Product Backlog items from the Sprint Backlogs of the individual Scrum Teams. However, trying to build an analogy between the regular Sprint Backlog and the Nexus Sprint Backlog, I got confused about the following aspects of this artifact: Does...
I am working on a machine learning pipeline where we have to compute certain measures on streaming data. Every day, new raw data enters our pipeline. To update our features, we have to run an ETL that loads the entire raw data and recomputes features. I'm looking for a framework to think about how we can incrementally...
When a user is able to perform an action only once a day, for example getting a free ticket for a competition, there are two possibilities I came across in my experience. 1) 24 Hours Reset If he performs the action on day 1 on 11:45 PM, he can only perform the action again on day 2 on or after 11:45. He won't be able ...
In the Clean Architecture, Uncle Bob defines Entities as enterprise-wide business rules and Interactors (Use Cases) as application-specific business rules. Also, he describes that Interactors are responsible for the "dance of the entities", and in the diagrams the Interactor -> Entity relation is shown as direct, witho...
I'm working on a Java reverse engineering project, where I am analyzing bytecode and trying to identify classes, methods and fields using the ASM framework. After identifying these I transform some classes to implement my custom interfaces with, e.g., getter methods. For identifying classes, I have created an abstract ...
Based on the project structure below i will have some questions Domain Layer 1) MyApp.Domain.Entities (DLL) Product.cs PagedResult.cs Referentes No References 2) MyApp.Domain.Interfaces (DLL) IUnitOfWork.cs IProductRepository.cs Referentes MyApp.Domain.Entities 3) MyApp.Domain.Common.Interfaces (DLL) IClock.cs ICrypt...
I am thinking about using Entity Framework Core in a new project. The project has a many to many relationship. Entity framework Core does not allow shadow state entities as described here: https://github.com/aspnet/EntityFrameworkCore/issues/1368 There are two options for the design: 1) Create a CLR type for the junc...
I need help understanding the following text from section 4.2 on this paper: Implementing Fault-Tolerant Services Using the State Machine Approach: A Tutorial Dependent-Failures Output Optimization. If a client and a state machine replica run on the same processor, then even when Byzantine failures are possible...
I have a case where a bug takes more than an hour to manifest in debug mode (and still 20+ min in release mode). Does one know a debugging strategy which can help to reduce the waiting time until a breakpoint is reached in the area of the code which is suspected to contain the cause? I have tried logging and prompting ...
I like to build a component connector view / UML diagram for the given problem but I realized it's way too slow if you try to do it exactly as it's given in the following text. My question is what could be optimized? Knowing this I would create the entire diagram myself. We have 2 teams playing against each other and ...
I think this question can span multiple languages, but in C# specifically there is a clear distinction between a field (ex: private int a;) and a property (ex: private int b { get; set; }). While there is often good reason to choose one or the other, in many cases they can be used interchangeably and they serve the sam...
The application I'm working on has a need to create a counter representing the number of times each piece of content has been viewed. There are two goals here: Update the counter in real time Minimize load on MySQL Currently what we do, is make a cache key in Redis for each piece of content that contains the view cou...
I'm doing an internship into a small company which is working on part of a systems which runs on a base already written by another company (many company are working on the same project) which is basically a 1:1 translation from an old COBOL system into .NET technology. Since they have not been given enough time, they'r...
If there are n variables each with m possible values. (For integer, m is 2 billion something.) First, map every possible value to an integer from 0 to m-1 in order. And define the mapping functions. index(v): value to integer value(i): integer to value Second, loop the n variables and count how many times every value...
I have a use case where my team owns a web UI to aggregate data from 10+ service teams and present it to the customer in order to collect more information . This data (which is in json format) is very dynamic (changes every other day) and is used for building multiple html form pages where customer inputs information e...
In android there are many different implementations for MVP. Most of them favor to use the Activity or Fragment as the view, a few would make them presenters, and even less, would separate the Activity or Fragment from the MVP, and have the classes related to Model, View, and Presenter reside inside the Activity or Fra...
I need to use DispatchQueue within controller and pass it as dependency. This is what I have tried so far and worked out two solutions. Need to ask what is better and in common use by other developers: protocol DispatchQueuerable: class { func perform(withDelay delay: Double, block: @escaping () -> Void) func p...
I was checking this example of Observer Pattern. https://www.tutorialspoint.com/design_pattern/observer_pattern.htm It seems that there is a circular reference when Observer Pattern is used. import java.util.ArrayList; import java.util.List; public class Subject { private List<Observer> observers = new ArrayList<...
i am having a simple app example here: say i have this piece of code which handles requests from user to get a list of books stored in a database. from .handlers import all_books from flask import jsonify @apps.route('/show/all', methods=['GET']) @jwt_required def show_books(): user_name = get_jwt_identity()['user...
I am referring to Robert C. Martins book "Clean Architecture" on the top of page 318. There he states: In the ports and adapters approach, the OrdersService and Orders interfaces have inbound dependencies from other packages, so they need to be made public. Again, the implementation classes can be made package p...
I am working on a Rails application which employs a classic MVC as its fundamental structure. In that structure the controller is supposed to be responsible for "which view to render when". Now after reading a design pattern book I learned about design patterns and, inspired, started looking for ways to use them to imp...
I've taken on a Visual Studio C# project where my previous colleague used a lot of Extension Methods in static classes over multiple files depending on the uses. In my previous experience I would be more selective when using Extension methods but instead use a public static method in a static class. It got me thinking...
I'm developing this Achievement System and it must have a CRUD, that admins access to create new achievements and it's rules. I need some help with the Achievement CRUD data structure. Rules sample Medal one: must complete 5 any courses with a score of at least 90 Medal two: must complete two specific courses with a sc...
I have Java application. I try to realize multiplayer chat with TCP protocol, but I have an issue. I cannot output all messages I get on client tier (server tier works perfectly), because I give an input to user and create a thread to read messages from TCP client, so <Scanner object>.nextLine(); Is blocking an o...
I have an Android application that communicates with the server using REST. During the flow, the client(Android) usually send 3 separate requests to the server with different data. Some of the data sent during the 1st request are also used during the 3rd request. Of course, we don't want to ask the user to enter the s...
I currently use the Google trends API and I implemented a class to integrate with its services. As you probably know, Google trends tracks statistics which will change over time. So, when I write a test now, after some time, it is very likely that my test will break because the statistics will change. How can I writ...
I want to build a web application in Java on Tomcat server (I am open to change the type of server if needed) The requirement for me is for the user to be able to login and download sensitive data (think bank app and downloading of statement). These should be done through RESTful communication. So obviously security is...
I have asked this question on Stack Overflow and I got a suggestion of posting it here for better suitability. So here is my question : I am new to DevOps, and i have a solution with Umbraco as CMS, Mobile App as front-end for the content added in CMS and .Net MVC web API to connect CMS with the Mobile App. I also hav...
Recently, I tried to deploy a web project to a virtual machine. I used the Ubuntu server as my OS, but while following along some tutorials I came to the fact which was very confusing for the beginner like me. I had to install the Nginx server on top of a server (Ubuntu server). I don't understand why I have to install...
Currently i am handling placing my services by their action type like App Services Storage Payments Providers Gateways IpnHandler But i felt like whenever our payment providers are growing i have to check Gateways / IpnHandler. And i felt like payment gateway should only care about payment and its result. ...
I'm already posting this question on StackOverflow, but thought that asking it in different communities might give me different insight. So here's the repost of the question: Hello, I'm having a financial related service that enable our users to topup their balance in our system, and then disburse the money. They'll be...
I want to make an android app that allows you to write scripts to draw stuff. Like text, buttons, images... using opengl. Now, if i have a function that draws an image like this: drawImage( imageSource, x, y, width, height ); What kind of unit of measurement should i use for x, y, width and height? I could use pixels...
I have a method in API handler which does API validation, performs business logic and then makes a call to db. Is it a good idea to move the business logic to utility class or service class? IMO the business logic should be moved to service as utility class are supposed to have methods which can be shared across appli...
I'm in the planning phases of trying to build a distributed file processing system in Java and I'm looking for feedback and advice: Problem : There are a large number of files continuously posted on an FTP server that we need to grab, process and pass on. Solution Idea: A master node will look for new files on an FTP s...
I have created a rest api. It supports multipart/form-data request type. My API clients used to attach content of files in their system to POST request body. It works fine. But recently there is need for very large input files. I think it will not be a good idead to attach very large file in request itself. How do I ...
I'm trying to figure out a technique to optimize bytecode for the following virtual machine: Bytecode is a flat list of instructions, with execution starting from the first instruction. Stack bytecode: instructions like i++, a+b, method calls f(a, b, c), etc. occur on the top 1, 2, N values on an operand stack, and le...
Im confuesd about the usage of std::move in class constructors. I want to pass a value to a class and check in the constructor if a valid value is passed. If not an exception is thrown. Before i used to pass the value by const reference: #include <string> class Foo { public: Foo(const std::string& value) :...
So i want to understand how DBMS implementation works To give an example : MySQL implements each tables with its own pages, which are 16KB so each table is a file, and is a multiple of 16KB, considering how large is it and therefore how many pages it needs Now i read somewhere that these pages don't get fragmented, so ...
I'm writing a small library to open an xml. If reading top level xml element fails, the library throws an exception. However, if reading one of the minor, lower level xml elemetns fail, I currently throw the exception to stop the constructor, but then catch it and do nothing with it, since the error may not be critical...
My team has developed a new service layer in our application. They created a bunch of services that implement their interfaces (E.g., ICustomerService, IUserService, etc). That's pretty good so far. Here is where things get a bit strange: We have a class called "CoreService", which looks like this: // ICoreService inte...
Onion Architecture talks about separating the UI, Service, and Data Layers. All the samples usually given for this involve a single deployment model of the application. For example in .net most of the samples are Web - MVC app Core/Domain - Simple class library Data - Entity Framework What happens if my application ...
I often encouter the following pattern: A bug is resolved/closed as duplicate of another still open/unfixed bug. I have trouble understanding the reasoning behind this strategy. From my naive point of view, there is at least one major downside: there is no easy way to verify that this is really a duplicate. Normally, ...
I have a time-critical function that needs to be executed multiple times sequentially. void task(state_t *state); It uses a relatively large amount of memory, so I figured that allocating it once at the beginning, and freeing it at the end would speed up the task sequence. state_t *state = alloc_state(); task(state...
Apologies if this isn't the right place for this question, please direct me elsewhere if that is the case :) I was having a discussion with my boss who has experience (but not official education) in software engineering about a member-field in an object that indicates whether the object is active. The objects in questi...
Sometimes, I use the call stack as a data structure. I use local variables as elements on the stack and use the data member of a class to store the top element. When I use this pattern, I feel like I'm doing something a little naughty! Here's an example of the pattern. The pattern ensures that break and continue statem...
Suppose there is a reasonably sized programming task(500 lines of code). Which is better? 1/Code the whole task from start to finish without running the code and debug later. 2/Code some small features, then test and debug, then repeat until the whole task is done. Personally from my experience, sometimes the first app...
I have this two use cases in a user registration process : Case 1 : the user register an account online and the system should send him an email notification in order to confirm that his account has been created and validate his email at the same time. Case 2 : the user account is created with an agent, in an sale off...
I have a module with the class Foo. Foo has three methods: The constructor(__init__()) An error handling method (_error_handler()) The method that actually does something. (run()) Then, I have a bunch of helper methods which are actually called by run(). These methods, at the time of this writing, are declared as "pr...
Because the reaction of @DanCornilescu I understood that my question was not clear. That is why I edited the question heavily. I was brought in on a project where there was only one developer. All development was just done on trunk. But they want to change things: They want to work with different developers from al...
I have a mathematical model with two main "stages" 1. data loading (only a few KB of data) and 2. running a model on the data. I want to implement some tests and checks to ensure the data being fed into the model are valid (correct types, correct values etc.) to ensure the model output is correct. At what stage in the ...
I have been interested in parallel computing lately, and I just wanted to check if there's some sort of standard or workflow for designing a parallel architecture. In particular, I am interested in the answer to the following question: If you need to write a code that you know will be parallelized, would it be best to...
I am currently working on a software library that will be used to develop Class Libraries. These class libraries can be run by our application running on the user's machine The application uses the same dlls that the customer uses to develop their library. The user code expects objects of certain types that are pr...
I am trying to analyze blue green deployment strategy to provide zero downtime upgrades for our customers. We have an enterprise java based monolithic web application that uses Oracle as the data store. There are a few challenges that I would like to get expert inputs With every database object types (procedures, tabl...
There are a number of functions of a kind; returning a boolean, and the name always starts with the "Is" prefix. e.g. IsAlive(), IsDead(), IsKeyPressed(), IsKeyReleased(), etc. How do we categorize these kind of functions? Is there a vocabulary for that?
I'm creating a set of Microservices following Event-Driven Architecture using Event-Carried State Transfer to move state from one service to another. Given the following services; Order service Shipping service The Shipping service will subscribe to OrderStarted, ProductAddedToOrder OrderAccepted events and use those...
I have a class that only holds data, specifically Collections of data, it is called *BezierSplineData: class BezierSplineData { public List<BezierSplineControlPoint> ControlPoints; // ControlPoints that can change the shape of the spline. public List<BezierSplinePoint> Points; // Actual points in the 3D world t...
I am a beginner in Ruby and I am trying to wrap my head around symbols. Would you say that my current understanding, summarized in the following (oversimplified) definition, is true for most purposes? "A symbol is a string constant with its name also being its content." And if this is true, why don't we just use string...