instruction
stringlengths
34
36.1k
(For more backstory/explanation, see my previous question.) I'm a middle school student working on a very, very informal project; my problem statement is as follows: There is no way for theoreticians, researchers, and students in the field of quantum computing to simulate and test complex, large quantum circuits in an...
I have quite a few years of programming experience pre-university and have been working full time as a mobile dev at a small company for about 3 months now, so am quite far ahead of almost everyone in my courses at university. We will have a group software project consisting of 4-5 2nd years (including myself), one or ...
In JavaScript, you can have a loosely typed language. So doing the following is acceptable: var iterator = new TokenIterator(this.session, cursor.row, cursor.column); var matchType; var found = false; var depth = {}; var i = cursor.column - token.start; var bracketType; var brackets = { ")": "(", "(": "(", ...
I've been assigned to create a development policy for our project which is a test case management web application using Spring MVC and Java. For instance, I think I would have to create the coding guidelines to be followed by the new joinees in the team. Also including the project architecture so that whenever a new jo...
I have a list of IReader that I read at the beginning of my program. Later on I need ReaderFactory to get appropriate IReader based on Extensions it can use. The problem is the factory needs to know about available readers. So I have two options: Make static ReaderFactory with method static Get(string extension) and s...
I am having a very difficult time because my colleague seems to exhibit Premature/Unnecessary optimization efforts Premature deduplication with questionable abstractions For example, we use a modified VIPER architecture. He introduced a base class for the Router component (using generics) as part of implementing the f...
Most often I need to call a service method from a controller, and based on the outcome, if there's an error show an appropriate error message depending on the error (or some other action, showing message is just an example), otherwise proceed. A very simple way I am using is returning an Outcome object from such method...
We have a legacy C++/CLI solution that generates primary executable, but is being expanded out to generate libraries as well as including relevant unit testing. Since we have a number of classes in both the library and executable that implement a common interface, what is the correct way to organize the solution for it...
In a NoSQL database (MongoDB), I need to store a list of creditcards for a user and to keep track of which one is active. I came across 3 patterns: #1 Keep the active property in the Creditcard schema User | _id: String | creditcards: [Creditcard] | ... Creditcard | _id: String | active: Boolean | ... #2 Keep the ref...
I got this idea from this question on stackoverflow.com The following pattern is common: final x = 10;//whatever constant value for(int i = 0; i < Math.floor(Math.sqrt(x)) + 1; i++) { //...do something } The point I'm trying to make is the conditional statement is something complicated and doesn't change. Is it bett...
In a Microsoft ecosystem (i.e. WebForms/MVC/WebAPI VisualStudio projects) why should I rely on an external task runner for JavaScript files like Grunt if I already have MSBuild at my disposal as the default building/task running system? When I first saw grunt in action I wondered why it was even being used, as it seeme...
In conventional web application there is single action per one button click from user. So clicking on submit form, send email or change status, delete user etc all this does single action per page load then shows status message. I am creating new application and trying to decide the likelihood of ever needing multiple...
Replace each symbol (letter) with a number so that the equations hold across all 3 equations. Solution should be able to solve the general case of any 3 equations. Can assume 2 terms summed to an answer. A recursive solution would be a bonus. pot + pan = bib dog + cat = pig boy + girl = baby I saw this in the book ...
I have to give my one of the biggest interviews next week and I am working hard for that. I have also enrolled myself for some mock interviews for that. So, coming to the problem last day I had this mock interview and I was asked this question: Search an element in a sorted and rotated array at first I was clueless but...
I've been implementing a network protocol, and I require packets to have unique identifiers. So far, I've just been generating random 32-bit integers, and assuming that it is astronomically unlikely that there will be a collision during the lifespan of a program/connection. Is this generally considered an acceptable pr...
I have released many open source software under Apache 2.0, now I'm providing a SaaS using that software. Basically, I need to prevent people just taking my software and just rebrand it to provide it in SaaS, being in direct competition with my own SaaS. AFAIK Apache 2.0 makes that possible, even the rebranding (changi...
I have a software component that is a part of a bigger software product. The software component lives in its namespace Component. Also the component has an interface (some part of it is below) that other components use: class IComponent { ... virtual void AddClient(unsigned int id, Component::Client client) = 0...
The question is only relevant for typed programming languages, dynamic solutions aren't satisfying. Let's assume that the language is C++. Example architecture: - DisplayObject (base class) -- Container (derived from DisplayObject) -- Sprite (derived from DisplayObject) So I have a game engine in my hands and it only ...
How to handle a next kind of situation in general: I've defined two aggregate root types AR1 and AR2. The AR2 holds value-based identity of the AR1. I have to keep eventual consistency between those aggregates so if some command changes the state of the AR1, I have to change states of every AR2-objects, which hold the ...
I'm programming a small web scraper in python which I want to speed up by parallelizing things. The scraper is crawling URLs whereby a single URL can represent an 'item' or an 'index'. An index in this case is a list of URLs of other items and indexes. The parsing for an item URL differs from the parsing of an index UR...
picoTCP (an open source embedded TCP/IP stack) has always had a development focus (both in picoTCP itself and with picoTCP) on linux & gcc systems. The final target is usually an embedded micro (ARM based). For this reason we put quite some logic into the makefile to keep modularity high. We're also using compile flags...
We are in the process of developing white label apps for iOS and Android app. I was thinking about the test strategy for handling white label apps with minimum resources. My company is targeting for at least 50 customers for the first year. Is there a way to handle white-label app with limited resources(testers)? For ...
I'm in the process of developing an ASP.NET Core WebAPI that uses EntityFramework to access the datastore. One of the things we need to support is sorting and filtering. I'm assuming that the HTTP query-string will be populated with the various criteria for the filtering and sorting. But I'd like to see some actual re...
I'm actually a programmer on a few languages, but I realized I really didn't know much how the computer works on a deeper level. So I thought a good idea to discover and learn how does it work was to create a basic programming language. I come here to ask you if this is a good idea or if there's a better way or learnin...
At work I was assigned a task to investigate on the severe slowness of an application I am not familiar with. Simple requests were taking several minutes to resolve. Here's how it was before (simplifying): There is a facade method to get a subset of information about orders, with the customers There is a CustomerDAO,...
I wrote a utils library (5 KLOC) that a lot of my projects use. I've also written a very small project (150 LOC) that needs just 1 or 2 of the classes in the utils library. I really don't want to add such a large dependency for such a small use, but the other options...moving/copying the classes or having a utils2 libr...
Introduction I am working on a Java EE Web Application that is a basic CRUD app. It is built with Servlet and JSP technologies, without any Frameworks. I am doing it to make my hands dirty in plain Java EE things. Project structure Here are directories/packages of the project: entity - entity classes which are simple...
I know I should encrypt the password whenever I save passwords for security. But I don't know how should I encrypt password that when I save for autologin. If the password was just for checking user, I can encrypt passwords with one-way encryption like pbkdf2. But the password should be protected, and I should access ...
My department is about to make some new hires. They are likely to be a) junior or b) more experienced that myself. This year I have helped some C engineers transition to C# and observed some interesting code structure being written. I wish to learn more about why they are doing it, if I should encourage 'my way' and wh...
I'm working on a web application that stores identifiers, such as usernames and email addresses in a "normalized" form and a "non-normalized" forms, for a variety of reasons. For example, an username 'John_Smith' would be normalized to 'johnsmith'. However, some of the user interfaces need to work with the normalized r...
Over the course of the past few days, I've been trying many different methods for correctly calculating jump targets in bytecode, but none have been practical or reliable. Furthermore, the methods I've tried did not allow nested if-statements and/or elif statements, which are important features of any language. I am wa...
The following commentator writes: Microservices shift your organizational dysfunction from a compile time problem to a run time problem. This commentator expands on the issue saying: Feature not bug. Run time problem => prod issues => stronger, faster feedback about dysfunction to those responsible Now I get that w...
I'm working on an automation project in C# and it has 2 wrappers: DesktopAutomation and BrowsersAutomation. The first has a dependency on UIAutomation.dlls (access to the MS desktop elements) and the latter on Selenium. Their role is understood I hope ;) Now, There are user actions on the browsers that require a depend...
I have that self-hosted RESTful messaging service with authorization, SSL and more good stuff that goes with it. Now, I would like to consume that service, so I need an UI. Usually (for cross-platforms sake) I tend to develop ASP.NET MVC web application, but this time I'm not sure how to proceed. However, I have some i...
I know GA questions are often almost impossible to answer exactly, but I'm looking for some general advice (although specific advice would be great too!). I've just written my second GA, which tries to find a phrase (say "i like bananas"), which it does by generating binary strings of 5 times the length of the target s...
I'm working on an Agile program and we are debating on how to deal with what we call "stabilization sprints". We have to build our team and decide on several key items but it seems there aren't really a well defined guideline to help us decide about them (or we can't find them) so I was hoping to pick your brain on thi...
I'm creating an HTML5 game using javascript and have got some problems during the first instantiation of the objects of the scene. Scenario Self-written 2d game engine that supports multiple types of objects. 'Glossary' An object is a scene-related entity, and is always an extension of a model, which is abstrac...
I teach software engineering at undergraduate level and I have a question to UML practitioners. Most software engineering textbooks take a serious effort in covering UML diagrams. But on the other hand, I heard from many graduates that UML does not seem to be used in the trenches anymore. What UML diagrams are still ...
I want to understand how EF track ID when the primary key is identity. (DB first) For example class User { int Id; //auto generated via SQL identity, also the primary key of the table Users. string Name; } //adding a new user- User user = new User () {Name="TestUser"};//Id will be 0; DB.Users.Add(user); DB.Sa...
I've always thought that a "common library" was a good idea. By that I mean a library that contains the common functionality that is often needed by a few different applications. It results in less code duplication/redundancy. I recently read an article (can't find now) that said this is actually a bad idea and went as...
I like working in languages with static types, because I like using types as a tool for designing an API before I start coding it. I also like TDD, because it helps me concentrate on working in small steps to ensure I get consistent results. But when I combine the two approaches, I often have this problem: I design the...
I have a piece of code parsing a text file line by line. I have to goals: Testing the syntax of the text and extracting information of it. It is quite likely that syntax errors occur so I want to provice helpful information about where and what. To give an idea of the problem, I have a text file like the following (sim...
I am in the process of creating my own concatenative language, heavily based on Forth. I am having a little trouble understanding how the compiling words CREATE and DOES> work, and how they are implemented (How the state of Forth's run time environment changes exactly when they are executed). I have read the following ...
Occasionally, the most logical name for something (e.g. a variable) is a reserved keyword in the language or environment of choice. When there is no equally appropriate synonym, how does one name it? I imagine there are best practice heuristics for this problem. These could be provided by the creators or governors of p...
This is more of a theoretical question which I hope is okay!? I want to code my own drag and drop jQuery plugin, but i'm wondering the best way to go about structuring my code and actually doing it. Note: This MAY be opinion orientated as well but I don't mind, I just need suggestions on a good way to go about this an...
I'm working on a website project for a software engineering course. This site will be using a database to store data, currently through JDBC and MySQL. Now the first thing I would want to do, is use the bridge pattern in order to decouple JCBC/MySQL from the implementation of the website, so that if in the future we de...
I'm trying to design a N-Tier Solution for my existing WebAPI project. I have a WebAPI project where, as of now, all the business logic are written in the controllers and the data validation are done by annotations. This is now leading to duplicate code across controllers when I'm trying to implement same logic. So I t...
Let's say I want to program a parallelized web crawler which has a shared FIFO queue (multi consumer/multi producer). The queue only contains URLs. How do I detect the end of the queue? A worker process is always consumer and producer at the same time because it takes an URL from the queue, crawls it and adds any found...
I'm not really sure if that is right "stack" to ask that question, well two questions actually. What's the potential use for capped collections? (besides logging) Capped collections cannot be sharded, but they can be replicated. In case of network partition and after rejoin, how is capped collection synchronized/merge...
What is the best way to find the duplicates in a list of a list of integers (no matter what position thay are in)? I don't necessary need code just the best way to go about this problem. eg: List<List<int>> TestData = new List<List<int>> { new List<int> { 1, 2, 3 }, new List<int> { 2, 1, 3 }, new List<i...
problem: Making a video-game has the following challenges on variable storage: send player states every 50-200ms, so store position/ rotation as efficiently as possible. store large blocks of data for each player regarding their cooldowns, abilities, and loadout all variables have to revolve around the connection id a...
I'm looking at the upcoming Visual Studio 2017. Under the section titled Boosted Productivity there is an image of Visual Studio being used to replace all occurrences of var with the explicit type. The code apparently has several problems that Visual Studio has identified as 'needs fixing'. I wanted to double-check my...
I'm exploring composite pattern to write a file system, one of my requirements is to create a unique root element in this case a directory, similar to Linux System ('/'), I have seen many examples of creating this in the client like this: class CompositeDemo { public static StringBuffer g_indent = new StringBuffer(...
I'am little confused about how business logic should be implemented using web services. For example, think about an education management application. There are simply students, teachers and courses. Now, the server side of the application may provide getStudents operation via a WSDL interface. This operation returns li...
It may not be clear so I'll develop the idea: The point is to develop a web interface to write down notes (and anything you like), and track its evolution. My question is then: how can I store such information such that I can also keep track of modification history? On the relational database world it would ideally loo...
The application will continuously (approximately every second) collect the location of users and store them. This data is structured. In a relational database, it would be stored as: | user | timestamp | latitude | longitude | However, there is too much data. There will be 60 × 60 × 24 = 86,400 records per user, daily....
I'm not sure if I am in the right place to ask this question. Please tell me if I'm not. I have the following problem: I have a production process, where a product first has to be produced, it is then stored, and packed afterwards. Hence, it can be seen as that the product has to go through two machines in series. How...
We are moving to Self-Hosted TFS and I am having a difficult time with setting things up properly. What we want to do is: 1) Have some user accounts be testers on Project 1 and thus they can create and manage work items, but not have access to the code on the project. We got this done by setting those user accounts up...
This question is about refactoring existing database design. My data flow is User generates some data for product lines A, B, C Data is saved into the database once Data is later retrieved multiple times Current design has 3 tables: data_a, data_b, data_c, where each table shares some columns that are identical (in ...
I have a client who insisted that we keep our new development separate from the main branches for the entirety of 2016. They had 3-4 other teams working on the application in various capacities. Numerous large changes have been made (switching how dependency injection is done, cleaning up code with ReSharper, etc). ...
I still remember good old days of repositories. But repositories used to grow ugly with time. Then CQRS got mainstream. They were nice, they were a breath of fresh air. But recently I've been asking myself again and again why don't I keep the logic right in a Controller's Action method (especially in Web Api where acti...
Let's say I have a users resource, with two properties: name and email as specified by a users JSON Schema document, which right now looks like this: { "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "additionalProperties": false, "properties": { "name": { "type": "string" ...
My company employs people who add and edit records in a PostgreSQL database using a web interface. These updates then need to be compiled into a mobile app (Android, iOS) via SQLite and released as a new version every few months. We haven't quite gotten around to 'hot patching' the SQLite database; that is to say, down...
After picking up some Swift skills with Java as my strongest language, one feature of Swift that I really like is the ability to add extensions to a class. In Java, a pattern I see very often is Utils or Helper classes, in which you add your methods to simplify something you're trying to accomplish. This might be a s...
For example, to keep a CPU on in Android, I can use code like this: PowerManager powerManager = (PowerManager)getSystemService(POWER_SERVICE); WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "abc"); wakeLock.acquire(); but I think the local variables powerManager and wakeLock can be elimin...
I'm using Java Eclipse EMF to model my Composite Pattern. What would be the right UML representation to model aa new class (Root) which implements a unique root directory. This is the original Composite pattern. This is my representation: Target representation would be: root |___ dir1 |___ dir2 |___ dir3 | ...
How is software architecture decided in a scrum/agile project environment, if everyone is focused on just one small piece of the problem how is over all system design decided upon. There doesn't seem to be a role where one person take ownership over the technical execution of the project so you could possibly end up i...
I'm looking for some assistance and ideas for developing an algorithm for choosing random soccer teams based on the skill levels of the participating players. What I have so far is a list of particpating players with arbitrary skill levels between 1 and 100. e.g. PlayerA: 30, PlayerB: 45, PlayerC: 50, PlayerD: 55, Play...
I have a Google App Engine app which is used by a small amount of users of a certain niche website. The app's only function is to get data about the user from that website's API, use that data to produce a CSS file, and deliver that CSS to the user. There are a few apps (made by others) like mine for this website; mine...
I am currently designing a system to support our employee staffing process. I collect weekly preferences from employees, and feed that into a system for staffing. Availabilities can be defined as absolute dates (e.g. Employee John is available on 01/01/2017 from 14:00 to 16:00). Or by recurrence, where one can define a...
This is something I see all over Cocoa: func someAction(_ sender: Any) which is called like: someAction(someObject) This can be very confusing to me. The infamous example is in NSView subclasses: print("Hello, World!") Despite this being standard Swift syntax for printing to the console, in an NSView, this will open...
I have an application which works with pure JDBC. I have a dilemma where should transaction handling go, in Service or DAO layer. I have found that in most cases it should be implemented in Service layer since DAO must be as simple as possible and exists solely to provide a connection to the Database. I like this appro...
I am currently working with a system which has been upgraded piecemeal from an original Visual FoxPro solution, to a system that now has the following parts: Local FoxPro installation (this is a Point Of Sale system, so designed to be used on touchscreens in stores / salons) Local windows service which syncs data from...
I have an intern and he writes code fast. However, I have difficulty making him understand the importance of writing classes and follow the OOP paradigm. We recently had a discussion that went like something this: "Instead of having this long function that extracts data from two different queries and then combine the d...
Let's suppose we have a nullable variable. int? myVar = null; If we wish to use it's value, there are at least two options: Explicit casting DoSomething((int)myVar); Calling Nullable<T>'s .Value property DoSomething(myVar.Value); I've noticed that when the conversion fails, in both cases the same exception is thrown...
Let's say I have a reverse proxy set up getting traffic at http://gluten-free-snacks.example.com. It serves different URLs by sub-directories, not sub-domains, for a better web UX. Its default behavior is to route all requests to a WordPress site which I handed over to the marketing team which they will definitely use ...
Android developers probably are familiar with Ceja's Clean Architecture, where use cases are classes that implement the Command Pattern. Shvets defines the pattern intents as follows: Encapsulate a request as an object, thereby letting you parametrize clients with different requests, queue or log requests, and support...
When we call the same function on a list of things, we call that "map". What do we call it when we call a list of functions on the same data? I don't mean pipe - not feeding the output of each function in turn into the next function - but simply iterating over a list of functions, passing each the same input?
Suppose you set up a Redis cluster with one master and two slaves. Two clients are connected to each of the slaves. Both clients make conflicting changes at the same time: What happens if these changes are replicated to Master at around the same time? Are they just applied to Master in the order they are received, ...
I need to send messages from a Windows Service to a Azure Service Fabric Stateful service. The network connection is not very reliable, and there must not be lost data. I was hoping I could use NServiceBus with a store & forward pattern to send the messages. Is my thinking fundamentally flawed?
According to this clean-code guide you should encapsulate conditionals: function shouldShowSpinner() { return fsm.state === 'fetching' && isEmpty(listNode); } if (shouldShowSpinner()) { // ... } Why not just write: const shouldShowSpinner = fsm.state === 'fetching' && isEmpty(listNode) if (shouldShowSpinner) { ...
I am developing a website where client needs that any notification should reach as soon as it is created. so i am using setinterval function of jquery and using ajax requests to get the notifications. the time interval I set is 2 seconds. and its not the only ajax request which is going this way. there are following a...
For the first I would like to mention that I'm newbie in real-time systems programming That's why I'm not sure if my questions are correct. Sorry for that But I need some help Question in short: How to implement hard real-time software to be sure it meets hard deadlines? It is necessary to use some QNX features? Or it...
A little bit of confusion over here. I am trying to reproduce Git's behavior regarding pagers and editors (as I think Git developers already done good (maybe the best) design choices in this scope). While trying to break it down I found that Git uses the pager/editor set to the environment variable $PAGER/$EDITOR. Howe...
Is it a best practice to initialize class dependencies in a constructor or should a class be initialized in the method where it is used. Let's say we have the following situation, and PriceCalcService is used only in a couple of methods. Order also takes other parameters, and sets its state. public class ShippingServic...
I'm trying to rewrite some code I wrote time ago using some C++ good practices. To achieve such a goal I'm using as reference Effective C++ (1) and google coding convention (2). According to (2) a function should be declared inline if it is 10 lines or less, according to (1) furthermore the compiler could ignore the in...
Let's suppose I have a backend with API-only Rails. There is also a Javascript single-page application (Aurelia, but could be something else) talking to this API. Should I keep these together, in the same Git repository, integrating Rails with Aurelia to some extent, maybe with the Rails asset pipeline building/bundlin...
A recent bug fix required me to go over code written by other team members, where I found this (it's C#): return (decimal)CostIn > 0 && CostOut > 0 ? (((decimal)CostOut - (decimal)CostIn) / (decimal)CostOut) * 100 : 0; Now, allowing there's a good reason for all those casts, this still seems very difficult to follow. ...
I have been spending quite a lot of time trying to decide if I should use apache** or nginx. I am very biased towards nginx due to the simple configuration, better scalability and it just feels more secure overall. However, AJAX is a must have on my list of requirements, so if nginx prohibits the implementation of AJAX...
I think I've got the hang of writing a GA when you know the number of genes in a chromosome. For example, if you're searching for a string, and you know the length, you can just generate your initial population of random strings, then breed and mutate until you (hopefully) converge on a solution. Similarly, in the trav...
I'm designing a configurable api and I've seen a few ways to accept options from the caller. One is using an options object like so: var options = new MyApiConfigurationOptions { Option1 = true, Option2 = false }; var api1 = MyApiFactory.Create(options); Another is using a configuration function: var api2 = ...
Say I'm writing a GA to solve the travelling salesman problem. I don't know in advance what the shortest path is, so how does my GA know when to stop? If I wait until the best fitness doesn't reduce for a few generations, how do I know I'm not temporarily stuck in a local minimum, which some mutation in the next genera...
I am working on a very basic driving simulation. I am trying to decide the relationship between the following objects: Freeway, Vehicle, Driver, ProximitySensors. My real-world analysis suggests the following relationships: A. Freeway has a vehicle: because a freeway can have multiple cars and a car can only have one f...
Say that I have a C++ class with some fields with static storage duration, call it class A. Is there some way to use inheritance to "inject" these static fields into classes which derive from class A? That is to say, if class B and class C derive from A, B and C will have the same static fields as the base class A, sha...
I wrote abstract base for some turn-based games (like chess or tic-tac-toe) and wrote game based on this base. And I stuck with choosing how to design class hierarchy. Here is two variants for wich I came up: And here is second screenshot (it is too long to post here as image) In first variant all classes in different...
I am designing a SaaS application where thousands of users will be using this application. This application will do lots of data crunching and analytics. I am considering creating a main database which will hold all user credentials and configurations, then I will create individual databases for each customer for stori...
I have few async REST services which are not dependent on each other. That is while "awaiting" a response from Service1, I can call Service2, Service3 and so on. For example, refer below code: var service1Response = await HttpService1Async(); var service2Response = await HttpService2Async(); // Use service1Response ...
We all may have seen applications like JIRA, or many CRM or other applications that allow its users to define their own custom fields to an entity, and do a variety of stuff with it, like making them mandatory, validate their values and so on. I want to do just that in the Product we are creating. Let's assume our pro...
I'm a newer developer who has worked on some personal projects as well as non-profit/charity projects. However, I seem to be the most "senior" developer in my circle, meaning, most guys come to me for help and when I need some help, they can't help me. As I don't have a full-time programming job, I'm sort of lost in te...
NULL is the billion-dollar mistake but there is nothing in the type system of C++ to prevent it. However, C++ already has const-correctness so implementing NULL-correctness seems trivial: introduce a keyword, __nonnull, as a specifier in the same class as const, which can only be placed after the * in a declaration. A...