instruction
stringlengths
34
36.1k
When encoding a sequence of bits into a string (using an alphabet that is not yet known at compile time and with the goal that the resulting string is as short as possible and that this whole process is reversible), you can use the "divmod approach", see e.g. this post. From my understanding, this appraoch only works ...
I am trying test driven development for the first time (test first development, actually). I wrote down my specifications, then alternated writing tests, then code, writing the code to pass the latest test and not break prior tests. My code is doing input validation on a user-supplied file path: Does the path exist an...
I am the designer of an interface IModel, which will be used by the implementer of a the controller (MVC). The interface contains funcA(). Another programmer needs to implement a specific class for the IModel. I want to direct the implementation of funcA() to use another function, funcB(). This forces some functional...
Sorry for the long somewhat unclear title, couldn't think how to word the problem I'm having. So basically I have a package structure with two reasonable alternatives (as far as I can see) but both involve a repetition on the second level. For example, my top level packages could include tcp and bluetooth and then each...
I adopt a software architecture where I have one single data access in the persistence layer. Indeed, the persistence layer is a mere java application (JAR file) that I consider as an dependency, thanks to Maven's POM. So, when I need to access the database, I just call some DAO classes from some Servlet or such. Since...
I'm now stuck in the server I am programming, simply because I do not seem to find a good and realiable way to handle my "single object" classes, I've attempted the Singleton pattern but it is just plain ugly to have to type everything over and over again. I have this class "TConnectionManager" which basically handles ...
An application that I am working on and trying to optimize does data processing on large files, and so it alternates between being I/O bound with no CPU usage, and CPU bound with no I/O usage. It is block based processing, so this is same scenario happens across hundreds of iterations. The only strategy that I've come ...
Most of financial apps have complex calculations and over time have change in calculation methods. Then you mostly create a new version for your calculator class that extends previous calculator and override some method. You may extend new calculator from old version because you will avoid repeated code and use typeca...
In this MSDN article, the following example code is provided (slightly edited for brevity): public async Task<ActionResult> Details(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Department department = await db.Departments.FindAsync(id); if (dep...
Problem I want to design the class architecture for an agent that interacts with an environment by repeating three steps until the end of an episode: First, the environment provides an observation to the agent. Second, the agent chooses an action in response. Third, the environment rewards the action by a reward. The a...
As part of a work assignment I've long dealt with a giant, dynamic SQL-creating stored procedure that's used for retrieving a bunch of inventory items. This stored procedure accepts a ton of parameters (maybe like 20+) which, in turn, turn on and off the dynamic SQL that's generated. Eventually we exec all this SQL and...
This is more of a design/user experience kind of question, so if it belongs somewhere else please let me know. I have a program that has multiple PictureBoxes: PictureBox1 PictureBox2 . . PictureBox60 Each PictureBox's Tag field is filled in with a String value. When the user clicks on a picture box, the Tag property ...
Can anyone explain why do we need +1 byte for sentinel value? As we know that 1 char = 1 byte so if we declare an array such as char a[50] why I can't store 50 chars instead of 49?
I am trying to figure out when to use the DIC/IoC registry for configuring my software and when to use factories, along with the reasoning behind either approach. I am using StructureMap as my DI container (DIC), which is easy to configure using registries. In the DIC practically all registered objects are static in t...
I'm developing a website (using PHP, JS, and MYSQL) which allow user to upload images. My requirements are as below: User is able to upload 1 or multiple images at a time. Website is able to save the original images and using the original images to create a re-sized version e.g. 500x500 px What I've done I need some...
I am designing a CMS, and would like to start with a simple database schema, with the requirements Two main types of entity,Post and Category For Post, it need to support multilingual and versioning For Category, only multilingual support is needed. For both type, hierarchical relationship support (see the parent fiel...
I started working in a project around 3 months ago and since I joined I saw so many mistakes in the whole design - the architecture is completely dysfunctional and badly implemented and a lot of used concepts like Inversion of Control are implemented in a way which completely goes against any proper conventions. People...
I'm a software developer in a growing SaaS Human Capital Management provider (Agile) and we only use Team Foundation Server (TFS) to keep track of our backlog, stories, acceptance criteria, work order management, etc. Requirements for stories are documented as acceptance criteria in TFS but highly unstructured. It is ...
I'm using the repository pattern as the way to access the DbContext in my C# application, however, I have a report that generates an expensive query (actually several queries) because of relationships (and poorly written code). Then I created a Stored Procedure that returns exactly what the report needs, without any e...
To clear some potential confusion, let me start with the following statements As far as I understand, inheritance is mostly about dynamic dispatch. I understand how virtual pointer table based inheritance works and I assume that this is what 'classical' inheritance refers to. I assume that 'pure' OO-style class-based ...
I am copy/pasting my comment from this article sumarizing a post on reddit: I really don't think "Protocol Orientation" is something new... You've got protocols in Obj-C, you've got Interfaces in Java, Abstract Classes in C++, etc. You can segregate interfaces and avoid inheritance by replacing it with compositi...
I am developing a web framework in PHP, and I want to make it fully extendable. My goal is to make it possible for a developer to change the behavior of any component without having to modify the "core" codebase at all. Developers should be able to encapsulate all of their work in a separate directory. And, I want t...
Our Scrum team has been having incomplete (not accepted) stories at the end of a sprint (usually 3 week sprint durations) that carry over into the next sprint. This has happened in every sprint except one in the team's 30 sprints. We have tried to reduce the number of new story points that we accept in the next sprint ...
I've read a related question Are there any design patterns that are unnecessary in dynamic languages like Python? and remembered this quote on Wikiquote.org The wonderful thing about dynamic typing is it lets you express anything that is computable. And type systems don’t — type systems are typically decidable, and th...
We are creating a project using Aurelia/Typescript. For those who don't know what that is, it's basically a better AngularJS (opinionated). Our project runs perfect, except for the fact that we need to incorporate windows authentication now, which we can get via ASP.NET Core. This is a bit of a problem. Considering tha...
Some examples: CSS image sprites Compiling JS needed on every webpage to one file Implementing lazy-loading for images Consolidating all meta information (username, CDN address, etc) into one request Specifically for AWS S3 browser uploads using signed policy documents: grabbing all the policy documents from the serve...
Suppose I am writing a program in F# for end-users. If there is an unhandled exception, the program will crash. Now suppose that I want application-specific data in the crash report. I can get this by catching all exceptions, logging the relevant data, and then rethrowing the exception. Is this good or bad practice?...
I have an API endpoint written for version and health of tomcat applications. It returns a json response with details. I wanted to know, how can i monitor any change in the json response in real time. I am building a dashboard on top of the endpoints. I will be using django channels consumers to consume events in real ...
I'm making a game with trains. I need to serialize which train is used for each level. So I can simply do: public class Level { Track track; Train train; [...] } public class Train { Wagon[] wagons; } public class Wagon { float length; float weight; } //Example: level = new Level (track, new ...
Before the introduction of the move constructor and move assignment in C++, I had two clear conceptual categories of classes: values for which using a copy was not different from using the original value, entities for which it was different. For values, I provided the copy constructor and assignment operator (and equa...
I am considering how to set precise boundaries of bounded contexts. Considering that a bounded context is a solution space, sometimes it is very difficult to set what exactly is your solution space. Here is an example. I have following bounded contexts Ordering Messaging Content management Warehouse etc. So in a real...
I have an asp.net mvc 5 site. I have a places table / POCO with 3 unique constraints (URL, Email & obviously ID). Users are able to add places - but they may violate URL or Email unique constraints, and I need to tell them why an insert failed. I am tempted to just let the insert fail (by violating the Unique Constrain...
In an ongoing project my team is building a new web application that relies heavily on a rest api. As we decided to try react we naturally came to implement redux and a middleware, as we've read this is the way to go. However, further into the project, we noticed it would be a good approach to bundle all the api relate...
I contribute to an open-source project that heavily uses the ctor-injection design pattern. Recently, there was a discussion about using interception for certain things, including injecting UI commands to a view model, and correctly binding the command to the correct value. As an example, we have a command: public cla...
If I met all requirements on version 1.0 and go on working towards version 2.0, new features would be 1.1, 1.2, 1.3, and so on. What do I version the commits that represent an important fix or a forgotten feature which is required in version 1.0? Even if I didn't version fixes on version 1.0, there would still be two v...
I have a few base, derived classes and need to dump their data to file. The difference is only a field, but I don't know how to reuse code of base class. Sorry if noob question :p Those classes look like this: (C# implement) class Base{ public int id {get;set;} public string field1 {get;set;} } ...
I have two Float32Arrays each one of which is 1.6*10^7 in length(floating point array). Using JS I retrieve them from server and add them element by element. My webpage stops responding and I get the following error message. Is there a way of handling huge arrays on client side without using JS or with JS?
Which class of algorithms would this sort of a problem belong to? If I had to pick up a book on algorithms, which topic should I be looking at to find more problems of this nature and their explanation? Given the current location on of the horse (or whatever the thing is that moves two spaces horizontally and one verti...
Is it possible to move an application (or task) to another core to make it run faster and get all of that cores processing power? The way I understand it is that in an operating system applications share the main CPU and get a shared "slice of time". So if ten applications are running over the course of one second eac...
I am convinced that the amount of routine work in software development is - and should be - relatively small, if not negligible, and that this is the fundamental problem of software estimation. Let me describe how I come to this conclusion and tell me if the argumentation has any serious flaws: All that can be estimat...
I need help with algorithm I'm working on, my problem have 3 main components: Item: an object with 2 fields { Integer reward; Boolean_2D_Array area; } Generator:a module that generates items according to certain logic. Collection: where I keep generated Items For every items that arrives from the Generator I need ...
If you have an image sheet of facets and data to indicate which point on each facet should connect with other points on the other facets, is it possible to position those facets in 3D space based on the connecting points? Essentially turning 2D images into 3D objects. Similar to paper craft folding.
I've been looking at a javascript library for drawing graphs, Dygraph, source on github. It has several enormous classes, such as here and here. Personally, I don't think justifications for large classes are valid, since it goes against principles of OOP, such as the single responsibility rule. In this day and age, ev...
I am trying to learn how lazy evaluation works because I'm going to implement try to implement it in the programming language I'm developing (I know it isn't the best thing to do (to try to implement something you don't even understand) but it's making for a good extensive lesson through the world of functional languag...
I'm doing some code cleanup and I'm looking at my regexes. I have an extremely simple one: (ARA|CHI|FRE|GER|ITA|JPN|RUS|SPA)\s[0-9]{3}-[0-9]{2} It basically validates course identifiers for a specific department (Modern Languages and Literatures) at my university, e.g. FRE 101-01 is valid, CIS 101-01 is not; I cannot ...
The word "Dependency" is used a lot in programming. But I think we might be using it wrong in many ways. I will use "Dependency Injection" in this post as an example. According to the Dictionary.com, the "Dependency" means: the state of being dependent; dependence. something dependent or subordinate; appurtenance. a...
Are there any matching and survivorship nodes in SSIS besides the one offered by Melissa Data? Any implementations in SQL on survivorship would be great as well. An example on my use case is that given that I have some 2 records of referring to the same customer, I want to come up with a golden record that will combine...
I'm a bit confused with TDD+SOLID. 1) I've watched MVA course about test driven development https://mva.microsoft.com/en-US/training-courses/testdriven-development-16458?l=gLxGoEwXC_2306218965 2) I have read various blogs, posts etc. stating that TDD accompanies, if not enforces, SOLID principles OK, let's say I write...
I have an array of unsorted positive real numbers. I need to create a frequency distribution by their ranges. The simplest approach goes like this for num in numbers if (num > 0 and num < 10) a++ elseif (num >= 10 and num < 20) b++ ... else z++ return [a, b, c, ..., z] Is there any faster or more efficient way to...
I am new to OOP. I've read definiton of both terms in many different articles and books, but still can't understand whether there is any relationship between them.
I am creating schedule tasks that run on daily basis monitor system events and send email notification based on some criteria. For example, if user subscription will expire after one month, task scheduler will detect that by comparing dates then send email notification. There are many tasks listen to many events occurr...
Is it a poor idea for readability or maintainability to use functions in conditionals as in the following example? if (move_uploaded_file($file['tmp_name'], $destinationFile)) { // Do work } Versus the more verbose $moveFileSuccessful = move_uploaded_file($file['tmp_name'], $destinationFile); if ($moveFileSuccessf...
I'm working with a model that currently looks like this: class Sign { enum Type { A, B } Color color; String textLine1; String textLine2; Type type; Sign(Type type, Color color, String textLine1, String textLine2) { ... } } A sign of type A has a color and 2 lines of text. A sign of type B has a co...
I'm trying to build a strong AI for a game called Puyo Puyo, in Matlab (I know... but it's the only language I know well). Basically it's like Tetris but you get falling pairs of 2 puyos (blobs) of different (or same) color, among 4 possible colors. You can move them around and place them however you like. Fill the scr...
I'm working with a library (from an online source, not authored in-house) providing an interface as well as an implementation of it: interface FooInterface { // ... } class Foo implements FooInterface { // ... } I'm not satisfied with the default implementation, Foo, so I can always write something like: class M...
In my databases, I tend to get into the habit of having an auto-incrementing integer primary key with the name id for every table I make so that I have a unique lookup for any particular row. Is this considered a bad idea? Are there any drawbacks to doing it this way? Sometimes I'll have multiple indices like id, profi...
I am making a program that primarily deals with heavy data mining and analysis. It is primarily a back-end type algorithm, with no GUI elements or console windows seen as it runs. Occasionally though, it will need to graph something or get very special input from the user. However, I initially didn't want to build the ...
I want to create some clans in my game... And they can have some admins with some privileges... Am I need to create 2 tables one of them for clan info and one of them for clan members ?
I had the impression that "front end" refers to the user interface in most cases, but occasionally people also refer to "the front end of a compiler". So what is the difference between these two terms?
My company manages a lot of web sites, and we are currently working without a VCS. I want to propose a VCS for a few reasons, but I think our requirements may be too unique. We work off of a shared drive that is mapped to windows explorer that has a mirror for each site. When edits are made they get pushed to staging, ...
I'm learning PHP, and I accidentally forgot the parenthesis in Echo 'Example' I'm curious as to why this worked, the only time I've seen this allowed was in SML, where the reason was that "All functions take only one item as a parameter, and that can be a tuple (A grouping of values)" Is it similar to that reason? Or s...
I have the following resources in my Asp.net web API: route: consisting of the following relevant properties arrival_location_id leaving_location_id and location: id name coordinates The thing is, When I create a new route, I create many routes and I want to allow users to create a new locations if they don't alrea...
I'm writing a REST service with Web Api. One of the actions reads an AppSetting value from the web.config during execution. I would assume the web.config is loaded into memory, but during high load, does reading the setting have a noticeable performance impact? What are the best practices for doing this?
Sometimes when you're coding you're on a problem which can be solved with some recursive method. What is for you the best way to detect when the recursion is a good way to solve a problem and how to implement it efficiently? I mean, how do you visualize it? How do you convince yourself that it works?
I am facing tough time deciding on whether to have two different classes in system, one for keeping class invariant and other for (de/)serialization or to just have a single class which does both. The project I'm working on is in Java and for (de/)serialization I am using Jackson mappings. Pros of Keeping 2 classes: M...
While there are/were several languages with dependent types, like Agda, Coq or Epigram, none seemed to gain wider adoption. Despite that dependent types allow very strong type safety, up to writing complete program specifications. Did anyone analyze what are the main blockers for such languages to become more mainstre...
When designing a system that displays information about an entity (but where modification of the data is rare or restricted to few users - such as a user profile), would it make sense to have two separate classes to do this? One for management of a user profile (logging in, changing password, modifying profile content)...
I am writing a "hunting-ground" application in Java. I planned the hierarchy of classes as follows: Animal.java public interface Animal { void age(); void reproduce(); boolean isAlive(); void die(); } Carnivorus.java public abstract class Carnivorus implements Animal { double age; double e...
One of the most basic and widely accepted principles of software development is DRY (don't repeat yourself). It is also clear that most software projects require some kind of management. Now what are the tasks that are easy to manage (estimate, schedule, control)? Right, repetitive tasks, exactly the tasks that should ...
High-level explanation I have an object with some methods: public class Foo { public void Bar() { } public void Baz() { } } These methods cannot be executed unconditionally, there is some validation to be done. I'd also like to expose these conditions to a client (user) in some way. I could do this with a coll...
Is there a preferred practice around initialising variables which are first defined within a branch of code, or is this purely subjective / personal preference? i.e. there are multiple ways this can be done; the most obvious of which are below: #option 1 [string]$path = '' if ($ENV:PROCESSOR_ARCHITECTURE -like '*64') {...
I have an excel like table with a should value and an is value for each day of a month: descrip. | | 01 | 02 | 03 | 04 | _______________________________________ column 1 | should | 60 | 0 | 60 | 0 | | is | 60 | 0 | 60 | 60 | _______________________________________ column 2 | should | 0 | 15 | 0...
The problem is quite simple really. I'm trying to create a site, where the user can add a physical device to a database. Every device has its own unique id, which is stored in the database. However, I want to make sure, that whoever types in the device id actually has access to the device, so that someone can't just ...
I found this same code here: https://stackoverflow.com/a/5854862/257299 struct Base { virtual Base& operator+=(int) = 0; }; struct X : Base { X(int n) : n_(n) { } X& operator+=(int n) { n_ += n; return *this; } int n_; }; struct Y : Base { Y(double n) : n_(n) { } Y& operator+=(int n) { n_ += n; re...
I'm looking for a way to organize database tables when it comes to handling product option pricing retrieval and also storing pricing history for my use case. What I have I have a custom-made product that has various product options and belongs to a product category. I want to be able to query current price for produc...
I have the following circular dependency that I'd like to eliminate. I think I must have a flaw in my design. And I'd much appreciate any feedback on how to fix this. My circular dependency comes from 3 important classes. Worker, WorkingContext, and TaskManager. First, I have 2 Worker classes (Worker, and WorkerGroup)...
I know really good, but dead project (https://github.com/lusis/lua-httpclient), with some pull requests (bug fixes). Repo owner doesn't look at this requests, last commit was at 2014. I want full version, with all bugfixes. What is correct action in this situation? I'm aready have got fork with bugfix.
I have just stepped into the Domain Driven Design paradigm but I have one question: How is an MVVM Model different from a DDD Entity? What are the differences between these two?
The bottom of the Wikipedia "talk" page says that Microdata is dead, and superseded by rdfa and json-ld. What is the difference between the formats (or value), and which one should be used? I'm mostly interested in SEO for Google Shopping, and contact sharing.
I'm working with a client that only loves Wordpress, so I have to create a theme. The idea of my client is to have an interactive background (meaning there's no other content but the background, the menu and the company logo) which creates a water effect, that's already done. Now, he wants the content to be loaded in ...
When following Domain-driven design (DDD), is it correct for a root aggregate to hold a reference to an internal entity that happens to be the root entity on a separate aggregate? I believe this is not correct, mainly because of this rule on the blue book: Nothing outside the AGGREGATE boundary can hold a reference to...
I may look like a total idiot with such a question but nothing came up when I searched it, so I guess why not. Here is my problem: I'm doing the UML work for a C++ game, that will feature animals and races. First, I have one abstract class Entity, and three inherited classes Human, Dog, and Cat. Now let's say I want ...
I would like to know how I should update many-to-many relationships in my API. My app has companies that can have many tools and technologies. The relationship is stored in joining tables companies_technologies and companies_tools. The frontend has a form to edit the company. I would like the users to submit a single f...
Okay so I work on a server application that has multiple communication methods. Including but not limited to WCF, TCP and RESTFUL. These all share information with clients but recently we have been running into issues due to too many clients accessing data. This causes a delay and although we cache as much as we can we...
When you sleep a thread, what is actually going on? I see that sleeping a thread "pauses the current thread for a given period of time". But just how does it work? According to How Thread.sleep() works internally and How does Thread.sleep really work?: the sleep duration will be subject to some system-specific granula...
I am a member of a small team which is part of a larger team of developers working with Git. We (the larger team) have a main branch in a central repository into which we commit our work for the next release (let's call it 1.0). The smaller team has been tasked with developing a feature (upgrading an existing one, actu...
Im writting a web-page in Ruby on Rails , so i can learn the language and framework better. I have a User model which has_many Classifieds models which has_many Photos which accept_attachment :image. So the whole thing works fine , the User creates the Classified , adds details and photos . User model and Classifieds m...
If I have all my business logic in code and make use of Entity Framework, in what situations (if any) would I be better moving some business logic to a stored procedure, instead of keeping it all in code? To be clear, I mean in conjunction with the current setup (business logic in code), not instead of. I have seen a n...
I have WinForms GUI application, which can work in two "states" with different functionality, but these states share GUI controls. I am dividing these states by using enum almost in every method, like: private void picBox_MouseDown(object sender, MouseEventArgs e) { if (picBox.Image == null) ...
Voyager 1 reached interstellar space in August 2012 and is the most distant human-made object in existence. Launched just shortly after its twin spacecraft, Voyager 2, in 1977, Voyager 1 explored the Jovian and Saturnian systems discovering new moons, active volcanoes and a wealth of data about the outer solar system. ...
I'm currently assigned a task, where I have to program a bidirectional synchronisation between 2 ERP-related software, one providing webservices (Visual Studio Web Reference) and the other one providing a REST API. I managed to match the fields of the APIs together, so I could potentially start creating objects in both...
Building a UI editor for Android and basically there are interfaces such as this: interface Item { fun decorate() fun translate(x: Int, y: Int) fun rotate(rotation: Float) fun scale(scale: Float) fun select(value: Boolean) } also has been extended with interfaces like so: interface Removable { ...
I have N strings and M search-replace pairs. Each of the strings contains exactly one of the search pair and the whole string needs to be replaced by the replace pair. Say you have returns,between,paragraphs and turn => foo, tween => bar, rag => baz then your output is foo, bar, baz. N can be a real big number while M ...
As said in the title, which data type should a lexer return/give the parser? When reading the lexical analysis article that Wikipedia has, it stated that: In computer science, lexical analysis is the process of converting a sequence of characters (such as in a computer program or web page) into a sequence of tokens (s...
In scaled Scrum release management, what's the code management strategy if there are unfinished features in the code base? For example, SAFe agile framework recommends all teams complete sprints the same day (they run on the same cadence). Say all the teams are preparing for a release --- they all meet their sprint go...
I'm trying to avoid casting of any type. I have the following simple Bus class that you can use to register your handlers: public interface IDomainEvent {} public class Bus { private static readonly IList<IHandler<IDomainEvent>> Handlers = new List<IHandler<IDomainEvent>>(); public static void Register(IHandl...
I'm strongly considering a web search engine for my next pet project. All the basic principles are clear, but some details are not. Namely, I can't find a neat way to search by exact match, e. g. "The Who". This requirement imposes limitations on how I can modify the source text: I can't use a list of stop words (h...
I've been using various server side languages/frameworks for developing back-end web applications. Every server-side framework that I've been using has the capability for returning views/templates (whole or part of a HTML page) as well as returning JSON responses which will then be interpreted by some front end JS. I ...
Just wanted to hear opinions on this kind of project structure in java for one DDD project: com.some.namespace application services = (app services that talk to repositories and domain model) validators = (validators for DTOs in app service layer) domain events = (domain events) exceptions = (except...
I believe C is a good language to learn the principles behind programming. What do you stand to learn in lower level languages that are "magicked" away from high level ones, such as Ruby?