instruction
stringlengths
34
36.1k
I've run into this same problem over and over again and I haven't found a solution that I really felt was optimal. Say in an app, you have an ordered list and you let the user change that order by drag and drop or something. You want the changes in the order to persist. How do you model that? How should I design a rest...
I'm currently creating a project that utilized a lot of forward declarations and such so I've come across an issue where my #includes seem to be extremely redundant. Example: config.h #include <Windows.h> #include <vector> config.cpp #include "config.h" #include "resolve.h" #include <Windows.h> #include <vector> //fu...
Our company is using an external API that is actually in beta state. This means it's not stable at all yet, and it changes its requests/responses every week or so. I'd like to write test to ensure my code is working. Unit tests are already done for my own code. But the API itself isn't tested, because it would violate...
I'm doing an research-project where I'm researching the options to handle changes in an event-driven microservice architecture. So, let's say we got an application where we got four different services. Each of these services has an own database to store local data. In this setup, the four services communicate with each...
I need some guidance with a problem that requires validating XML against a very large XSD file. I am making use of the CSTA XML API (without SOAP). The XSD's for the messages seems to be a very intricate set of files, including each other. All XSD's are "consolidated" into a large file csta.xsd (http://www.ecma-interna...
I have studied computer science and am now working in a company as a single developer on a pretty agile Java-project for almost a year. The project will soon be successfully (at least I hope so!) finished. The core functionality ... is functioning and even some other stuff that was not in the start-requirements. I eve...
There are a few functions in php that throw errors when they fail, such as ftp_login. If I have this code. try { $result = ftp_login($conn_id, $ftp_user_name, 'incorrectPassword'); if (!$result) { throw new Exception('Could not login.'); } } catch (Exception $e) { echo $e->getMessage() . ' - ' ....
I'm working on an update process which inserts items into a sorted list, and processes those items' indices in the sorted list. To help me with this, I created a sorted list with an "insert" method which returns the index of the new element in the list. For example, given a list of [1, 3, 5], then insert(4) will chang...
I have a problem with my Software design. I want to generate UI controls from XML messages over the network. The XML messages contain simple information about a component and its properties for example: <? version="1.0" encoding="utf-8" ?> <components> <component name="Car"> <property name="length" type="do...
I understand in JavaScript the this and arguments "variables" are automatically made available inside functions. Is there a formal name for these kinds of variables that are automatically made available and don't need to be sent as parameters? Is "variables" even the correct term for them? Since this and arguments ca...
I am a .NET developer. I see ASP.NET MVC framework now started providing a self-hosting feature. It makes a lot of sense (to me). A self-hosted application feels complete with no external dependency. The question I have in my mind is now why would anyone NOT want to self-host ? I mean, Are there any advantages that IIS...
I'm attempting to collect the user's input and execute a search using an API. At this point, I can use the API (ebay search) by typing keywords into the html document- but I want the user to be able to type the keywords for searching. I created a simple modal with a form containing text input and a submit button. I ga...
I have a small function which parses my command line arguments. It also tests for required options and throws on any errors. The function currently takes argc and argv and returns a structure which is formed in this way: struct options { std::string arg1; std::uint16_t arg2; std::any<std::string> not_required; };...
This question is very similar to this one, but the answer doesn't match my needs. It's focused on a specific UML tool (Papyrus) whereas my question is more general about UML. I would like to represent a nested action in an activity diagram, but I don't know what is the common way to do it. The idea is that there is an ...
I have a bit of a storm in a teacup at work, and I'm trying to figure out if I'm in the right, in the wrong or maybe a little bit of both. It all started out innocently enough; a developer from another team was commenting during a code review of my team's code. We're a [relatively] new team and we tend to write our cod...
I have a top10 table (like top 10 restaurants say). Each top 10 row can have up to 10 top10items associated. Models public class Top10 { public Guid Id { get; set; } [Required(ErrorMessage="Title Required")] public string Title { get; set; } } public class Top10Item { public Guid Id { get; set; } ...
I've recently started developing a project in Node.js. Of course, right now the packages I'm using are pretty up-to-date as I'm starting afresh and using the latest version, but there's a pretty high version turnover rate for most Node.js packages and often certain features will be deprecated or dropped, and of course...
I'm starting with Zend Framework 3 and I saw an example on the tutorial that goes like this: public function addAction() { $form = new AlbumForm(); $form->get('submit')->setValue('Add'); $request = $this->getRequest(); if (! $request->isPost()) { // <-------------- HERE!!!! return ['form...
In a typical web application, dates are retrieved from the database layer strongly typed (e.g. in c# as a System.DateTime as opposed System.String). When a date needs to be expressed as a string (e.g. displayed on a page), the conversion from DateTime to string is done in the presentation tier. Why is this? Why is...
In higher-level languages such as Java or Python, we don't usually need to implement our own data structures since the languages provide their own libraries for them. So, for example, how would we start writing a data structure for a set with test-driven development in mind? How would you create the tests first?
I am studying data structures and I have hit a bit of a road block. The top is Big oh notation and it is simply confusing. While I can find the upper bound for the simplest of loops, when it comes to the more complicated stuff, I get a bit lost. I have got this Java stack array program that I am using as practice and w...
Say there's a package, foo. Foo is being developed primarily in Python, up until version 1.13.2. At that point in time, the primary developer decides that Go is much better suited to the task. He creates a new branch and codes up a package in Go that has the same functionality or even some improvements to 1.13.2 of the...
Current situation We are implementing (and now maintaining) an online shopping web application in a microservice architecture. One of the requirements is that the business must be able to apply rules on what our customers add to their cart, in order to customize their experience and the eventual order. Quite obviously,...
Working with the Success Factors OData API and encountering issues whenever the schema is modified. For example this morning my code broke because a new column was added to provide new functionality. My code obviously wasn't using the new column but an exception was raised because it encountered an unexpected column. H...
For instance, array.map accepts a callback that returns a value. const newArray = oldArray.map(item => doSomethingTo(item)); Promises also accept callbacks that return a value. const requestPromise = $.ajax(...).then(res => doSomethingTo(res)); But the way I see most event emitters, they seem non-functional by design...
When writing some functions, I found a const keyword in parameters like this: void MyClass::myFunction(const MyObject& obj,const string& s1,const string& s2,const string& s3){ } often causes splitting a line into 2 lines in IDE or vim, so I want to remove all const keywords in parameters: void MyClass::myFunction(MyOb...
For example, I have a react.js component named Question which need the props title,id,content. <div id="main-section"> <div id="question"></div> </div> ReactDOM.render( <Question id="xxxx" title="xxx" content="xxx"/>, document.getElementById('question') ); I come up with two methods: design an restful ...
I'm planning on using a message queue for communication between a game engine and game server. This should allow me to write both without direct dependencies on each other. The example that I'll use in this question is a DisconnectMessage. A server can send a DisconnectMessage to the engine if, for example, the client ...
We do have several Components in our product which are Component A Component B Component C Dependencies are (if unmet the system fails): A <-> B B <-> C We are currently creating a build pipeline and finally the Software for each component gets packaged into a single firmware image: A -> Output A B -> Output B C -> O...
I am tasked with redesigning an existing catalog processor and the requirement goes as below Requirement I have 5 to 10 vendors(each vendor can have multiple stores) who would provide me with 'XML' file per store. Basically, 1 products xml file per Store, and multiple Store files per Vendor. Max file size can be 500 M...
This is the Project Euler question #5. The statement is pretty much finding the least common multiple of the first n natural numbers. So for example, the least common multiple of 1, 2 .. 10 is 2520. I admit I was just trying random stuff and I didn't expect the following to work (written in Python): factors = int(inpu...
I'm trying to simulate an elevator, as always I started very simple by taking only a single order at a time, then added memory to the elevator in the form of queues so that floors are traveled in the order in which they were pressed, which obviously isn't the best approach. So at the moment I'm using a very simple and ...
I've recently gotten into functional programming. I asked a question earlier over here "'Remembering' values in functional programming" and learned a lot of things I hadn't even realized I wanted to learn yet. It was very useful. It did leave me with a few new unanswered questions. The primary of which is, when should ...
I have built an (web) API with a couple of endpoints, which in turn have a lot of CRUD-operations. The code itself conforms to the SOLID principles. Now I have a consumer for that API which states that if they use my API it will break the SOLID principles on their end because my API provides more functionality than the...
At work, we are having 'arguments' about naming styles / conventions. Imagine having a service called UserSettingsService. This has 2 methods, one to get the user settings and one to save. Would you name the method to include what it does exactly, like .getUserSettings(), or just get()? One argument is that the Use...
communication waste is the time spent in communication between team members in the following cases: delivering features which are not needed by the customer delivering partial features (analysis, design, or testing is done, but the feature is canceled before it is completed and delivered) Any other type of communi...
I have a profile resource. Profiles can have a parent and an arbitrary number of child profiles. What's the best way to model this in a RESTful scenario? I thought of a number of different solutions, each with pros and cons: /profiles/:profile_id/children + it's clear that we are querying the profile resource - the la...
Generally speaking in a MVC framework we have the Controllers that do things like making sense of a request, preparing the parameters and starting an action in the business logic through some kind of "entry point". The business logic is where the real application is described and it's usually defined in terms of servic...
I'm creating an RPG game where a player has a set of skills, each of which he can level up to improve its effect. Here are two example skills: health: increase player's maximum health regeneration: slowly regenerate player's lost health back Skills have many similar attributes, like name, description, maximum_level, ...
Often, command line parameters are documented using a vaguely EBNF-ish notation such as the following: The output of dir /? on Windows: DIR [drive:][path][filename] [/A[[:]attributes]] [/B] [/C] [/D] [/L] [/N] [/O[[:]sortorder]] [/P] [/Q] [/R] [/S] [/T[[:]timefield]] [/W] [/X] [/4] The output of netsh /? on Windows...
I am trying to modify the DOM via javascript. I've been suggested to use jQuery like this var options = $("<div>") .append( $("<ul>").append( $("<li>") .text("Resolution: ") .append( $("<select>") ...
I'm in the process of analysis for a browser-based game I'm making, and I have question about programming the economy system. I'll use a simplified system to ask my question. Each user as GameState object, holding everything there is to know about his game. The structures, each level, the army and whatnot. More importa...
I have looked all over and can't find clear answers to the following: If I write code in PHP or Python that uses GPL MySQL connectors for PHP or Python - which license applies to my code? That of PHP or Python, or GPL? Can I run my PHP or Python code on a server and offer commercial services without the GPL? Can I bun...
As a side project with my coworkers -- we are oil and gas geologists -- we have been creating an interactive map-based learning tool for other geologists. We are having trouble building the database, and here is what we're doing: Using ESRI ArcGIS software to create map polygons from literature. Exporting them as CSV ...
In standard C, you have a few options for declaring a function that accepts a pointer to a chunk of data: void style_1(int * arr); void style_2(int arr[]); void style_3(int arr[10]); void style_4(int size, int arr[size]); void style_5(int arr[static 10]); void style_6(int size, int arr[static size]); The thing is...
I'm wondering if there is a good way of explicitly declaring (not necessarily enforcing) ownership transfer of resources in Java. My problem is basically this: There are resources that need to be cleaned up (think AutoClosable) that are dependency-injected into an instance by its creator. I want to communicate to the c...
Opinions on reliability/viability of doing something like this to workaround IEEE oddities in addition and subtraction etc...? I want to avoid BigDecimal,Formatters,etc... GC overhead exploring this idea. int fivePlaces = 100000; Assert.assertEquals(1.13269, add(1.13270, -0.00001, fivePlaces), 0); private double add(d...
I have implemented some simple messaging system IMS for my own use inside the application, that allows sending and recieving message for objects. I have a singleton object IMSContext that has a method transfer which is used to pass messages by every object IMSContext.instance.transfer(message) Also that IMSContext sto...
I am using Typescript in Webstorm with Angular 2 and I am frequently getting warnings that a given method can be static. Yes, these specific methods do not depend on the state of the object they are a part of, but there will not be a time when it is used and the object is not instantiated. Should I still make those met...
I recently started moving a monolithic application to microservices architecture using docker containers. The general idea of the app is: scraping data -> format the data -> save the data to MySQL -> serve data via REST API. I want to split each of the steps into a separate service. I think I have two choices, what ...
For example: we don't put python compilation files (.pyc's) into the repo, probably because python generates them automatically. In a java house, do they commit the .jars to their repos? Traditionally, I believe, C source went into the repo with headers, link libraries? or whatever it took to do a compile, but never o...
Consider the following code: package main import "fmt" type Vertex struct { X, Y int } var ( i = 10 p = &i v = Vertex{1,2} q = &v ) func main() { fmt.Println(p) // Outputs the memory location of the pointer fmt.Println(q) // Outputs the string &{1 2} } Why isn't the memory location of p...
I am going to write a very simple VM and bytecode compiler. Is it typical for a bytecode compiler to read the syntax and attempt to create the bytecode directly or is there an intermediate stage to make the process easier to understand? If I do compiler -> bytecode - it should be a less tedious process, but maybe more ...
There is a single network-shared folder of files that is to be processed by threads running on several servers. Once a thread starts processing a certain file, I don't want any other thread to process it. What are some techniques to ensure that only one thread processes a certain file? Keep in mind that the threads ...
It is well known that Singletons are anti-patters for several reasons: tight coupling singletons are pathological liars no testability inheritance is not available you cannot program to interfaces, you program to implementations But there is the code: class ISingleton { protected: ISingleton() {} public: vir...
I have a project in visual studio that contain more than 10 header and source files. I start to realize I did not assign return error codes for each header correctly (i.e I found out that there are multiple error codes with the same value in different headers with different names, some error values even match state va...
I am very new to elastic search and i need to know it is even useful to store data? because i was curious to try my hands on how elastic search works and i used postman>run elastic search then added some data in postman and then could able to do POST operation on the data so i need to know without any database also ho...
In Clean Code, it is written that "the ideal number of arguments for a function is zero". The reasons why are explained and make sense. What I'm after is techniques to refactor methods with 4 or more arguments to solve this issue. One way is to extract the arguments into a new class, but that would surely lead to an ex...
I've created an application that can create and update documents. A document is a relational database (it's a SQLite database). I'm planning to update the structure of the database (add fields, add relations, add tables) The database stores the database_version in itself. I plan to embed update SQL scripts into the sof...
I'm trying to get a Java programming project set up in a way that it can be built completely offline just from the files in version control, on any machine, with no prerequisites to install. (Sole exception: the JDK) I don't know much of Maven, but I'm learning Gradle currently. For the build I'm using Gradle with the ...
I apologize in advance if the question is not directly involved in programming but I could not find a forum of programmers who deal with general questions. I am developing a cross-organization application. For a person that has no programming knowledge at all, the final product looks fairly simple - a desktop applicati...
I can't understand how the following structure elements are being initialized. MSG m = {4, 1, 0};. MSG has two elements: one is of type int and other one is an array of type short that's already been initialized. Which elements of m are assigned the values 4, 1 and 0? Here is the listing of the code taken from the bo...
I'm currently writing a web application for our small company which was originally just planned to organize appointments more efficiently by displaying our customer structure and automatically plan tours which originally just meant that our staff needs access to it. However, since we then have our structure built we co...
If I am loading a model with Model::find($id) and the id is not found it returns null. This is fine except if I try to chain things. Model::find($id)->loadAttributes(); Load attributes is going to fail because it's not a method of null. The simple solution break it into two lines and check if it's null before calling l...
I have n number of one-dimensional arrays similar to: [0,0,0,0,0,1,1,1,0,0,1,1,...] 0's and 1's indicating occupation. And k number of smaller arrays similar to: [2,2,2], [2,2], [2], [2,2,2,2] with varying sizes. What I want to do is to see where and how I can fit the smaller (second) arrays to bigger arrays followi...
I've got my answer to this in the comment of the one I checked. Which Algorithm Approach Should I Take to Generate Lambda Expressions in Java? but I don't exactly know where to look in terms of generating lambda expressions with Parsing in Reverse. I'm not exactly allowed to use programs like ANTLR. The tutorials and ...
I have some information about a user I need to store and access in an ASP.NET MVC 5 application. Here are some of the things that I will need to store/access: Theme choice If they want to show panel bar navigation If they want to show menu bar navigation If they want to hide unauthorized links etc. I am trying to fig...
I am writing a program that controls some hardware via a serial port. The program will run various function based on user input. I need a way to queue these tasks and execute them synchronously on the same thread. I also need to be able to cancel them and track their status. So I was thinking I could use tasks and cha...
I've done a lot of research on this, but I'm still quite confused. I'm currently working on an Arduino-compatible software project. The project is open source, so I want others to make use of it as well, but I don't want them to create derivative works with closed-source licenses. I would like them to acknowledge any c...
Which of these is the ideal way to check if a value exists without caring exactly what its value is? if let _ = flags[.showField] { showField() } if flags[.showField] != nil { showField() } In the first case, it seems more Swift-y to use if let _ = and futureproofs it (I can imagine a future where Apple says you must...
I don't have much experience in caching among web applications, but I am trying to educate myself in the field and try out various techniques and approaches in ASP.NET MVC. The majority of tutorials and articles I see online are mentioning output cache ([OutputCache(VaryByParam="...")]), various donut caching methods e...
Today I had an interesting discussion with a colleague. I am a defensive programmer. I believe that the rule "a class must ensure that its objects have a valid state when interacted with from outside the class" must always be adhered to. The reason for this rule is that the class does not know who its users are and tha...
What is the historic reasoning behind having both prefix increment(++i) and postfix increment( i++) in the C language? (this question and this other stack overflow question aren't as complete as the answers here.) Two obvious ones always come up: One is often clearer than the other: For instance: i=0; while (i++ ...
I have been looking for a term to deal with a seemingly common pattern where a string consists of numbers separated by a . to n levels deep. A prime example is Semantic Versioning numbers which are comprised of three numbers wherein 1.0.0 > 0.1.0. A project I am working on uses this pattern for identifiers for an n-lev...
Basically: I am creating an enterprise web application. I would like to do extensive logging of both client and server activity, with all logs ultimately stored on the server. I have found many articles describing one specific strategy or tool for this, but nothing comparing the options. I know there is no single be...
I am self-learning Michael L. Scott's Programming Language Pragmatics. The following quote explains how deep binding and shallow binding are different in the presence of static scoping: program binding_example(input, output); procedure A(I : integer; procedure P); procedure B; begin writeln(I); e...
I am posting this here instead of on Stack Overflow because this is more conceptual. I am primarily thinking of this a Linux context, but this can be extended to other operating systems. When I didn't know what I know now about operating systems, I figured that iOS applications signature checked by other programs. I wa...
From https://en.wikipedia.org/wiki/Name_binding name binding is the association of entities (data and/or code) with identifiers.[1] An identifier bound to an object is said to reference that object. Binding is intimately connected with scoping, as scope determines which names bind to which objects – at which locations...
I'm working on a software using VB.Net which retrieves string packets through a TCP socket. The problem is it receives hundreds of packets per second. For each incoming packet the software should connect to the database (right now it's Access DB) and do one of the following: Query one row of the database and use some ...
As per the classical SDLC phases of planning, defining, designing, building, testing, deployment and maintenance what could be quite unique in the scenario of modern or contemporary apps. By modern apps i mean all modern apps that are being used on mobiles/smartphones and tablets and also those that are used in drones,...
My string is of type"abacsdsdvvsg" or"a a a a a a a" And I use String[] stringArray = s.split(""); or String[] stringArray = s.split(" "); I'm wondering what would be the complexity(in O(string length)) for above splitting? PS: I know how to calculate O(...) if code is given. Here I don't know the algorithm of split fu...
I'm really struggling to come up with a design pattern for an Alerter I'm building. Here's a contrived example of what I'm trying to do: A person wants to get an alert by weather type (rain, snow, sun, etc.). A person also has a choice of alert method (email, sms, slack channel, hipchat room, etc.) I need to: have a cl...
Situation We are currently developing a large web application (Web API 2) - several entities and thus require several endpoints for each. But suddenly, they changed to "one endpoint fits all" approach, something like: /api/data?entity=entity_name Then the usual controller for GET, POST, PUT, DELETE. We have something ...
I read some articles about developers who takes rabbitmq and produce from PHP messages to write to mysql. they do this to make the page speedup and not wait for mysql to return an answer. So in my case, since I want to write to mysql every page request in my site, and yet PHP does not have thread pooling, this I assum...
I'm just starting out using programming using the MVC design pattern, and I would like to know if I understood it correctly and where I should put certain things. So I understood that I should put all my files in one out of three folders, (or just separate the code): Model - Database models. Controllers - logic that de...
I have 500.000 files with the combined size of 350GB. So an average file has 0.7MB size. Each file has metadata: 1 to 100 keywords and optionally a short description. I need to filter the files and find the keywords of the search expression in the keywords of the files and in the descriptions. Note that some of the fil...
I have an array of elements, each with a start time and an end time. These form a timeline, some of which overlap, and others that do not (and have a gap between groups of overlapping elements). I written some code that removes the gaps between the non-overlapping elements (red lines as per the image below) however it ...
I am developing a REST API for a user management service (being used by other micro services). My model contains the types User and Server among others. Server to User relation is many-to-one (each user has a non-null foreign key to the server table).The Server type has a field named address. I have to implement a REST...
The terms debugging and antibugging seem to be widely used for referring to tools, measures and design patterns to get rid of bugs. After reading Peter Norvig's Paradigms of Artificial Intelligence Programming: Case Studies in Common LISP I was not sure about the difference between those terms: It is a good idea to in...
I have the following JavaScript code: function tokensOnSameLine(node1, node2) { return node1.line == node2.line; } What would the preferred name for this function be? I've considered the following: isTokensOnSameLine - sounds awkward but it matches the is convention for predicates. areTokensOnSameLine - sounds ...
In Java there are primitive types for byte, short, int and long and the same thing for float and double. Why is it necessary to have a person set how many bytes should be used for a primitive value? Couldn't the size just be determined dynamically depending on how big the number passed in was? There are 2 reasons I can...
May be it seems an open question (or non-constructive according to stackoverflow standards) .... but I am asking if there's something rigid according to Software process standards addressing this topic ? If there are one or more "Hard to find bugs" that need complex scenarios, extensive testing, very big or special dat...
I'm trying to read up on implementation details of Swift, and one thing I can't nail down are its "witness tables". It looks like they're a separate vtable pointer used for structs. But why would you need that? Structs are copied by value, so you already know at compile-time what type they are. So wouldn't you just har...
I came across the term identity mapping in some papers about neural networks but am not sure what it is supposed to mean in that context. I'm guessing it means to map a sort of input to an output? I came across this term in the papers Deep Residual Learning for Image Recognition (2015) and Identity Mappings in Deep Res...
Does this question still apply: Why are native ES6 promises slower and more memory-intensive than bluebird?? In regards to the latest versions of Node.js and EC7?
I'm going to write a simple password manager, which is going to store my accounts encrypted. Here is description of the classes , LoginManager - This class will be responsible for authenticating the user, since the data on the harddrive will be encrypted, it will succeed only if the data is succesfully decrypted, the f...
Lets say I want to setup a roles table that has a polymorphic relationship to resource. I understand that that I could directly setup a foreign key - by adding for example a roles.forum_id column. But why is (AFAIK) creating a compound foreign key where one column holds the key and another the table to reference not p...
I am working on a Java / Spring web application. The application issues licenses on demand. Each license has an expiry date. Licenses can be renewed by the admin. I want to send an email notification or perform some operation 90, 45, 30, x, y, z no. of days before the license expiry. The email notification to be sent e...
I have a global position keeper of screen items so items don't need store their own positions. class Screen_Position_Keeper: # functions to add stuff def get_px_row( self, item ): try: return self.item_to_row[ item ] except KeyError: raise KeyError( 'You never registere...
I'm reading the Design patterns book by the Gang of 4. Does a singleton use encapsulation? To me it would seem like yes, but i'm not 100% sure. Maybe I don't have a good understanding of encapsulation.