instruction
stringlengths
34
36.1k
We are discussing proposal to split a big C++ program into multiple separate executables that would communicated using shared memory. The shared data structures are large, so we do not want to use loopback network or any other approach that would just copy them. The arguments for splitting are that every part can be de...
We have recently moved to Java 8. Now, I see applications flooded with Optional objects. Before Java 8 (Style 1) Employee employee = employeeServive.getEmployee(); if(employee!=null){ System.out.println(employee.getId()); } After Java 8 (Style 2) Optional<Employee> employeeOptional = Optional.ofNullable(employeeS...
I was just wondering this while programming in python. If I have a function foo which take a collection (list or tuple, perhaps set etc.) and manipulates on its elements somehow, e.g. filter, trim, increases, etc. should such function return the same type? For instance, if it accepts any collection and filter things ou...
About the app: This is an android app. The app has two components/ two different users, scorers who score the game and fans who view commentary of the game. Scoring User : A scorer watches a live baseball game and puts the score after each pitch/event of the game. These events are pushed to the server and also stored...
As our devs are writing internal applications, often times we need to share code. There are various ways to do this, but it usually comes down to creating a nuget package on a shared server or hosting a web api internally. We don't have a definitive way to decide between the 2 and currently have a mixture of both. Any ...
On my current project it is a common practice to generate Hibernate Entities from database tables using NetBeans functionality. I'm normally used to first write the Entity-class and define the mapping in an XML-file or with annotations. Is it considered bad practice to generate the entity classes through NetBeans (or a...
I have a question around which is preferred and seen as more right approach. Out company's messaging solution of choice is Kafka. We have a task to build a service that would provide events in cloud environment via HTTP(no port opening, widely used - easy to get clients onboarded). Events originate from company's own d...
I've read several papers, articles, and section 4.1.4, chapter 4 of Compilers: Principles, Techniques, and Tools (2nd Edition) (a.k.a "The Dragon Book") which all discuss the topic of syntactical compiler error recovery. However, after experimenting with several modern compilers, I've seen that they also recover from s...
For my personal project I need to store 2D shapes in a Postgres database. For example Circle, Pentagon, Rectangle and so on. At first I've done it like so: all shapes are inherited from an abstract class called Shapes, which has some methods that I need each object to perform on itself, for example (I'm using java wit...
Is it OK to have a class something like this public class Weapon { private string name; private int might; // etc... private Weapon(String name, int might) { this.name = name; this.might = might; } public static final Weapon Alondite = new Weapon("Alondite", 16); // 100++ w...
I'm trying to figure out what my API route and HTTP method should be for supporting a dual list box (e.g. http://geodan.github.io/duallistbox/sample-100.html) Say, I have a collection, GET /employees which looks like: [ {'id': 1, 'name': 'Foo', 'selected': true}, {'id': 2, 'name': 'Bar', 'selected': false} ] where...
I suppose I have the following use case: I want a synchronous service if possible (in case of machine crash I want to finish it in background, by some other node) I want to save something in my database and publish an event to an event stream like kafka or kinesis (which means 2 transactions db + evt stream) I am sta...
There are endless resources on creating CRUD for REST resources but I can't find much on doing the same for Messaging. Given two services A and B where A receives incoming requests that initiates the creation of the resource R. When A receives the request it does some processing and creates R and then wants to store R ...
Occasionally I see major, relatively new, open source C projects targeting very old C standards, typically C89. An example is systemd. These projects have intelligent people at the helm so they probably have a good rationale behind this decision that I don't know about. That benefit of the doubt aside, it almost seems ...
I have the following entities in my database (it's simplified): Student (id) StudentCourse (id, student_id, course_id) Course (id) Lesson (id) LessonCourse (id, lesson_id, course_id) StudentCourseLesson (id, student_id, course_id, lesson_id, completed) So: Student can sign up for a course (StudentCourse entity is be...
I have requirement like user can booked space (office, room, meeting room etc) for a rent for particular time period. But requirement is like user required to booked space every month 5th date, or they need that meeting room in every week Friday. I have no idea from where to start for store data. How to design class or...
When I'm writing an computer-vision program (using OpenCV and Python) I need to print/show a lot of intermediate results in form of images (using cv2.imshow(..)) for debugging purposes to find out what is happening. After finishing the program I have no idea what to do with this "debugging code". Because this code is u...
I am trying to encourage working practices that are more agile. I am trying to understand the difference between a Use Case and a User Story. I have read a lot of articles and questions like What's the difference between "use case", "User Story" and "Usage Scenario"? and Is it reasonable to assume a 1:1 relationship b...
I'm building an Mvc application with microservices that retrieve information from the database. I have a question related the microservices. I want an entity from database with some property in a page of the application. So I've build the method of the service that retrieve the information. In another page, i want the ...
To use Strategy Pattern in Objective-C, I think it is mainly by selector. To omit if...else, use Objective-C runtime, convert string matching to choose selector (Strategy). Am my understanding right? Here is demo: Strategy Pattern in ResponderChain Communication Pattern. create a Router to use ResponderChain Communic...
I am trying to create a web UI for image processing, with some operations similar to what a site like fotor.com offers. However, I have problems to achieve a similar performance. For example, lets say I uploaded an image on fotor.com of around 3+ MB and performed a basic operation of setting the image brightness to "fu...
I am a freelance developer. I have multiple clients, each client has multiple projects, and each project has multiple distinct pieces of software. I recently migrated all my source control from my old subversion service to a business github account. My question is, what is a workable strategy for organizing clients, p...
Can anyone point me to patterns for, or material on decentralised federated system design / federated data/service architectures? To give some more background on the problem I'm looking to solve, here's the full context. I've had an idea floating around for a while to create a "reverse address book". i.e. Rather th...
When to use else in conditions? 1) a) long int multiplyNumbers(int n) { if (n >= 1) { return n*multiplyNumbers(n-1); } else { return 1; } } or b) long int multiplyNumbers(int n) { if (n >= 1) { return n*multiplyNumbers(n-1); } return 1; } 2) a) int max(int num1, int n...
E_d is an environment where one can develop, build and test a .NET web application. E_p is the production environment, where only running the application is possible. That is, build is not possible. Repo_src is the source code repository. Now I would like to implement a poor man's application update mechanism (for bina...
My office uses Git and SourceTree for our version control. This came about because when I joined there was zero version control and SourceTree was the only system I had ever used. I am not an expert by any means, but I am the most experienced out of my coworkers so I am the de facto expert responsible for teaching ever...
I'm creating a game (well, a plugin) where each player has a list of skills, each of which has an unique type object, each of which has a list of actions that need to be ran when a player executes his skills. I drew a diagram to show my classes: https://i.stack.imgur.com/NOdDF.jpg And here's a quick mockup in pseudo-py...
I'm asking this question coming from a background of no experience in web development, so please be patient as I attempt to explain what I'm doing (if I use the wrong terminologies or if this has already been asked. Tried searching, but I don't exactly know how to concisely ask this question). I have a server I've dev...
I have built simple auth for REST servers in academic projects. I always used the headers to pass the credentials. This is probably just because every tutorial I've ever seen did it this way. Initially, I'd have header fields for user and password, but I eventually switched to basic auth. Anyway, whatever it was, I alw...
Imagine I have an abstract class Node which has several methods and attributes. (Join a network, send a message, broadcast ...). I want to be able to add/remove functionality to/from that Node class (Routing functionality, mining functionality, ...) I was thinking about using a Decorator pattern since that let's me cha...
I am learning a lot about this principle (also thanks to two answers I received here) and would like to elaborate on another point that somebody mentioned. 1) Is the following a violation of LSP? class Base { public virtual void UpdateUI() { //documented: immediately redraws UI completely } } class Co...
I'm trying to understand DDD and one of the key concepts in DDD are the Domain Objects. As i understand they're supposed to 'hide' the internal state and allow modification of it by only by using methods (behaviors?) and only in a way that keeps the (internal) state always valid. Would it be an over simplification to ...
I want to calculate the runtime of the following function T(n) = (1+2+3+4+5+...+n)/n At first this doesnt seemed hard to me because it can be solved easily by transforming the formula T(n) = (n(n-1)/2)/n = (n^2-n)/n = n-1 which leads into O(n). By thinking about this function i struggled. I am not sure if I am allowed ...
I looked trough some of my older code and found that I was using the using namespace directive. From what I read in a lot of google results, it seems that it is never a good idea to use this. Is there actually a valid use case for this construct or was this just a misguided attempt to make peoples lifes easier, that fa...
Suppose I'd like to implement the templating pattern, but the only real differences between the subclasses are their choices of some invariant dependencies. Is there a drawback to preferring this style: public abstract class AbstractClass { private final DependencyA dependencyA; private final DependencyB depend...
This project will serve many duplicate requests with location-specific answers. I.e. 10,000 people in New York will all get the same server response (a list of businesses in New York), but one person in Atlanta will get completely different data (businesses in Atlanta). Planned architecture: 1. In memory cache which...
In the comments to an answer of another question, I proposed the following Java code as a better way of writing a more procedural-style variant of the same operation: employeeService.getEmployee() .map(Employee::getId) .ifPresent‌​(System.out::println‌​); (where getEmployee() returns an Optional<Employee>) An...
I'm writing an app which tracks device location and based on some factors (user gets an assignment), it needs to change the location tracking settings (for example, frequency). I have an issue with how to design this. // I left out methods to start\stop tracking interface ILocationTracker { event EventHandler Locat...
I am learning Python and when I learned that we can build Custom classes for exception, I got into a confusion of Why ? for example1 : class MyException(Exception): def __init__(self, error): self.error = error def __str__(self): # DO THE WORK TO BE DONE FOR THE EXCEPTION prin...
Let's say we wanted a typeful, pure functional programming language, like Haskell or Idris, that is aimed at systems programming without garbage collection and has no runtime (or at least not more than the C and Rust "runtimes"). Something that can run, more or less, on bare metal. What are some of the options for stat...
How should be represents process of versioning in developer team? Suppose that we have CI system, and we want start versioning our software. If we speak about semver, then major and minor version must changes manually, right? What to do with path version? I think also manually, but not sure. Build number may got from ...
Using a static site generator has the advantage of themes, blog and hosting (via Netlify). How can this be combined with a login form, show a user is logged in and dynamic pages (flask backend), while still keeping the same styling and being perceived as a single app?
I have open source C# .NET project at GitHub with Appveyor CI + code coverage. There are configurations like Release and Debug. There's also platforms like x86, x64 and Any CPU. This results to following: Configuration | Platform | Tests --------------+----------+-------- Release | x86 | 100/100 Release ...
I'm just starting out with Qt and I really want to try and keep my application as separated from Qt as possible in case I decide to use a different toolset later, but at the same time don't want to make any decisions that will really cripple my application right from the beginning. When writing a Qt Application is it c...
I have the opinion that each method in a service should only do one small step of a larger task, delegate a result to the successive step/method and terminate. No matter if this next method lives in the same service or not, it is always triggered via inter-service routing (message queue, service discovery + REST call, ...
I have been asked to develop a multitenant application where, Company/Users can log in, a user can belong to a company, but I has been asked specifically that they don't want to be inviting users to their company manually because they think it's a lot of work, but they also want to avoid exposing other companies when a...
So I'm working on a project and I'm running into conceptual problems in creating my user interface. It's for a DirectX11 multi-monitor game I'm writing. I've got a prototype working, with entity menus popping up and more entities inside those menus. All is well and good, except it's a coding fuster-cluck. I'm doing ...
Unit testing requires writing tests first then code, on the other hand in F# (and most of the functional languages) some codes are extremely short as follows: let f = getNames >> Observable.flatmap ObservableJson.jsonArrayToObservableObjects<string> or : let jsonArrayToObservableObjects<'t> = JsonConvert.Deseriali...
I have a piece of code where I iterate a map until a certain condition is true and then later on use that condition to do some more stuff. Example: Map<BigInteger, List<String>> map = handler.getMap(); if(map != null && !map.isEmpty()) { for (Map.Entry<BigInteger, List<String>> entry : map.entrySet()) { ...
I am a layman without any programming-like education but I spent the better part of my free time to get into programming bots for some games in first AutoIt and then C++. I was introduced to programming in a very procedural style only using free functions. A couple of weeks ago, my focus shifted from actually making th...
Please see the question here: https://stackoverflow.com/questions/2352654/should-domain-entities-be-exposed-as-interfaces-or-as-plain-objects The general consensus is that Domain Models should not contain interfaces. Now see here: https://github.com/jbogard/presentations/blob/master/WickedDomainModels/After/Model/Memb...
I am trying to implement a preemptive scheduler in C, but I have some understanding problems: When the scheduler is called by an interrupt, a context switch may occur. The context switch can only be programmed in assembler. In my C program a task is a function. If the scheduler is called by an interrupt and a context s...
Given an array A[N] of N booleans, return a, b such that a >= 0, b > 0 and A[a] = true A[a+b] = true A[a+2b] = true or -1 if they don't exist. The best algorithm I could find was brute forcing the entire search space, O(n^2) and I wanted to know if there's a better algorithm.
It's very common see a generic's DAO implementation like this: public List<E> getResultList(String namedQuery, Map<String, Object> parameters) { Query query = entityManager.createNamedQuery(namedQuery); parameters.entrySet().forEach(e -> query.setParameter(e.getKey(), e.getValue())); return query.getResultL...
Using SQLite in a WPF application that schedules events for people. The application will be used by 2-4 users concurrently. I'm wondering how to ensure each user has the most current database information. What I came up with is: Start a separate thread responsible for checking for database updates. Use time interval...
Say I have a namespace as follows: CompanyName.TechnologyName[.Feature][.Design] Like this: https://github.com/vkhorikov/DddInAction/tree/master/DddInPractice.Logic/Atms .Design is the AggregateRoot (e.g. BuyingAggregate). This namespace contains all of my Entities and Value Objects. Say I also introduce a Domain Ser...
I have the following scenario: We want to create nuget packages on VSTS We want the packages to be available for an external party (preferably no login, tokens...?) For our developers we want to have the symbols for that package coming from VSTS The Debug packages should have the output + pdb files. (no source) If I...
When parsing user input, it is generally recommended to not to throw and catch exceptions but rather to use validation methods. In the .NET BCL, this would be the difference between, for example, int.Parse (throws an exception on invalid data) and int.TryParse (returns false on invalid data). I am designing my own Foo....
Sorry if title is not clear, suggestions on better title are welcome. For the purpose of [self-]education I am writing a toy scripting language that would compile to bytecode and be executed on a toy VM. This is not going to be a turing-complete language, and it would only contain simple flow control structures such as...
In DDD, is it okay if creation of one AR forces creation of another AR? Take for example: class User { // User related functins } class Schedule { // Schedule related functions } class Scheduler { private ScheduleRepository repo; // injected public void Schedule(User user, Event event) { Schedule sche...
In my company, We are planning to build more than one web application on a single Database. The proposed design of each of these apps are - ASP.NET MVC as Presentation layer, Restful API as service Layer(also works as domain/business Layer) and Entity framework (EF) as data access layer. But Many of my colleagues a...
Let's say there is an extensible system in place, which uses an algorithm that requires that the elements it operates on are unique. The signature to call this algorithm looks like this: function algorithm([Collection of Elements]) Now there are multiple modules that use this algorithm, which call the algorithm like th...
Reading a Node Stream I want to be able to receive a stream of text, and trigger the continuation of my stream. The following code solves my purposes but I recently read that we are using Subject too much when we may not need to. I'll use this code to read files from disk or from S3. Is it possible to replace my subje...
Background I've been thinking about documenting design patterns in our code by setting up interfaces for the common design patterns so that when people read my code it would be clear that I am using a design pattern. I would do this by create a project, in our solution, called Design Patterns, so it was clear it was me...
In C# we have Extension methods. Extension methods enable you to add methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type. An extension method is a special kind of static method, but they are called as if they were instance methods on the extended ...
I've found out that there are 5 use case levels: Level 0 Cloud Level 1 Kite Level 2 Sea Level 3 Fish Level 4 Clam Cloud level lists only high level users goals such as "Manage files". Kite level mentions the actor and some more specific cases. For what I've understood, Sea level use cases should document the foll...
I have a current project which consist out of two independently developed projects: Spring REST as back end Angular as front end I do have a Jenkins instance available for building my projects and I'd would like to "marry" both of the projects in a CD job to a single deployable file (.jar) Is this a job of jenkins, t...
The question is pretty straightforward, I'll try to explain why I want some explanations. (All of this is my 1½-year junior Java developer opinion, which may be more than incomplete. Which is why I am asking the question there). It increases the coupling between classes, as some classes need other classes, and so on. ...
I have a LogFormatter class which looks like below @Sl4j class LogFormatter { public static String format(String taskType, String taskId, String message) { return String.format("TaskType: %s, TaskId: %s, Message: %s", taskType, taskId, message); } Mostly there are 4 type...
I'm building a website that lets a user pay for a service that automatically does some video encoding for them. Encoding takes several minutes. A naive solution would run each encoding job immediately. this could lead to several instances running and cause all of them to finish very slowly. the processing would probabl...
I'm asking this question for a colleague since he doesn't have enough reputation to post images in a question During our normal development we found a deficit in our REST Api. We display entities in our UI like this. Whereby the buttons at the top are so called actions. In the Image you can see buttons which act as ac...
With all the talk of Microservices with Domain Driven Design, I have been looking at two architectures, the Database-Centric Architecture and the Domain-Centric Architecture (Not to be confused with Domain Driven Design). Now in the Database-Centric Architecture, the database is the focal object we depend on. Without i...
I have read plenty of questions on here about overriding .equals and .hashcode for testing purposes only. My Domain classes have implemented .equals and .hashcode. Should I be 1) Duplicating these classes in my test project or 2) Using the Domain Class .equals in my test project The only justification I can see for ...
I'm working on a file-synchronization client that currently produces a stream of changes to the underlying filesystem. That is a stream of create/update/move/delete events is produced for each synchronization "target". Each event includes a sequence-ID, which provides information about the ordering of events, and then...
Is the M (model) in MVVM equal to business logic + data? Or is it just supposed to be data/state for the view? Background: In a project we use "model" as a name for an object that holds presentation data. I expect that to be wrong. In my opinion a class/structure that just holds presentation data or state should called...
I was talking with a friend another day about OOP in small projects. In the most of projects that me and him worked the SOA was the rule. Per example, imagine a Order in a SOA application. The scenario of this application could be: A lot of services (UpdateOrderService, CreateOrderService, etc) calling each other. The...
We had a debate on our team about how clean the Master branch should be. The application is written and maintained by two people, me (a developer) and a GUI/UX designer. The GUI/UX designer does a lot of prototyping (or "sandbox"-type experimentation) to test or fix various layout issues in JS & CSS. This preliminary o...
Assume that you have the following 3 entities: Manual Version Document 1 Manual has multiple versions and 1 version has multiple Documents. I want to build a Web API that allows customers to insert their manuals, versions and documents, but what is the best practice? Do I accept the posted data object in a nested XML...
In a company of about ~100 developers, and ~2 pen-testers, a product is being developed. There's a good amount of diverse code coming in via github PR requests every day. The goal is to review as much new code as possible before it gets merged. On the one end of the extreme, it'd be something like 'review every PR a...
Please see the code below: public virtual bool Equals(Entity other) { return Equals((Object)other); } public override bool Equals(object obj) { var compareTo = obj as Entity; if (ReferenceEquals(compareTo, null)) return false; if (...
I think one of the biggest pain points in working with microservices is making sure that the APIs are well-documented and APIs do not change their behavior without affecting downstream applications. This problem becomes amplified when you have many services that are interdependent on each other. Perhaps at that point y...
I was reading on this page about setting a flag in a loop and using it later. Most of the answers agreed that it's a code smell. One of the answers suggested refactoring the code by putting the loop into a method and the boolean and break become a return instead. The second answer suggests that using the break means yo...
The implementation is MVC. The View is isolated to the browser layer. The Model is isolated to the persistence layer. The Controller is split with: UI controls in the browser mostly so input is syntacticly correct, authentication and authorization controls are in the listener layer (Tomcat and remote LDAP), and data...
Say I have a function that returns a weighted selection from a set of resources, according to a desired distribution. For argument's sake let that resource be string colors. const distribution = { red: .1666, // We want 1/6th of colors in the world to be 'red' yellow: .3333, // ... 1/3 to be 'yellow' blue: ...
When it comes to tests, I can think of two options: Put both test and application in one image. Include only application code in the image. Create a test-specific container that builds after the main image and adds some layers to it (test code, dependencies etc). With the first option, I can test the container and s...
For example, I have simple C program that only have main function that just returns 0. What registers should loader (Linux exec loader, I guess) install before start a program? I didn't find information about this except stack pointer register.
Looking at a range of cross-platform languages, libraries and GUI toolkits, I often notice a conspicuous absence of support for asynchronous file I/O. This seems like too much of a common factor to be a coincidental oversight in all of them. However I don't know enough about individual OSs or these languages'/libraries...
Here we have TV class and DVD class as example: class TV { public: TV(); virtual ~TV(); void on() const; void off() const; }; class DVDPlayer { public: DVDPlayer(); ~DVDPlayer(); void SetCD() const; void StartPlay() const; void Eject() const; void PowerOff() const; }; We crea...
We have a micro-service that has a Domain Model and have an analytical service for the domain which has its own Query Model. The domain model and the query model are stored in separate persistencies. Currently our Query Model uses a sub-set of the attributes from the Domain model. However going forward we have require...
Working on an application that uses DynamoDB for data storage, which is new-ish for me. There are two tables, both use a simple guid for their key. I need to divide data per client. Someone can sign up for their organisation, which means I need to separate data between clients. I was thinking of using a range key for c...
I have quite some experience with TDD in Java and Kotlin and currently try to learn testing with Javascript. I am not sure if this is really a question about weak vs. strong typing or about general design. I always was under the impression that mocking/stubbing code you don't own is a bad idea. In Kotlin I would cr...
I have used RabbitMQ but I haven't used Apache Kafka. Is it a similar problem that these products solve, or is there no connection?
I've the following endpoint: a/{id}/b and want to create a b with sending POST request to it. If a with given {id} is not found should I response with 404 NOT_FOUND or maybe with 409 CONFLICT? It is to handle plain a/{id}, the trick is that here a subresource is used.
Let's say we have following SQL table structure Entities (5-15k) Keywords (15-20k) EntityKeywords ExcludedKeywords (keywords which should be excluded from common matching) We need to find related entities, which are entities which have most common keywords ordered descending. Now obviously, querying this on each load...
This scenario seems pretty ordinary, and yet, strangely, messaging systems (like Google Cloud PubSub and Task Queues and ActiveMQ) do not seem to support it -- they assume that topics/queues are long-lived. A frontend webapp server sends a request to a backend server. The backend server replies to this request wit...
The goal of the RegEx is to match exactly 6 characters, but in addition it should match empty strings or white space (e.g: ^$|\s|^(\w){6}$). Is it good practice check for empty string/white space in a RegEx expression, or to perform this check in the higher level code, such as String.IsNullOrWhiteSpace? There seems to ...
As a C++ developer I'm quite used to C++ header files, and find it beneficial to have some kind of forced "documentation" inside the code. I usually have a bad time when I have to read some C# code because of that: I don't have that sort of mental map of the class I'm working with. Let's assume that as a software engin...
How thick should a viewmodel be? For example, should my viewmodel or model handle the actual filtering? For example, let's say I have a Roster object holding a collection of Users which are assigned a type (i.e. full-time, part-time, etc.). Instead of having one large viewmodel to handle the filtering of full-time ...
I'm new to forking and open source and I'm porting a Rust library into Swift but I wasn't sure if I needed to fork the original repo and then replace it with my new files or just upload my own repo and mention in the README that it's a Swift port of an existing library
I am not working yet, just studying and recently dealing with SOLID principles. I have read quite a lot about open closed principle but unfortunately most of the books and articles share the same examples. I do not understand the following: if the class should not be changed after it has been