instruction
stringlengths
34
19.9k
I'm finding that my code becomes more readable when I make a local reference to this/self, and/or call it something that makes sense in the context. "self" or "this" doesn't really indicate what kind of object we are dealing with, in the same way as "default" or "standard" or "master" is unclear because it's not explic...
My company is working on developing a new product that is similar (but larger in scope) than our existing, primary application. It will incorporate most of the functionality of our current application (except where that functionality isn't currently being used) and eventually supplant it. Our initial thought was to sol...
I want to create a dashboard for my website. I have divided my dashboard into different modules. As I understand it, I will have to make many AJAX calls. The different modules are: total number of page visits changing real-time acceptance rate denial rate, etc... The question I am facing is: how can I minimize my AJ...
I've just recently started familiarising myself with functional programming, mostly via F#, and there's one particular functional idiom that I'm not fully understanding the benefits of. I've seen it described in a few places, but I'll refer to the version in this article. The article describes a shopping cart with seve...
Imagine that I have a game, with Monsters, Missions, Vehicles, and of course their controllers and such, so a Monster class, Mission Controller class, Vehicle Controller class and so on. Suppose that I need the Mission Controller to talk to Monsters. Why? Let's say when Mission A is triggered, all Monsters now turns co...
I always understood that in agile, each sprint is about adding a new functionality to existing application, so that the application can be build incrementally. On the other hand, when you define data model, you need to think of many possible use cases and functionalities upfront, so that data model satisfies wide range...
are there any typeless typesafe languages? By typesafe I mean types are checked at compile time. By typeless I mean types are not declared. I know this is easier than it sounds, maybe even impossible but for example if I had code like this foo = { bar: 123; } In some imaginary language I can possibly know that bar ...
I have programmed a small iterator in Python: class anything(): def __init__(self): self.i=1 def __iter__(self): return self def next(self): if self.i>100: raise StopIteration self.i=self.i+1 return self.i and I would like to use unittest of Python to c...
Back in the old days when I learned to create web pages, the rule of thumb was: Don't resize your images with HTML/CSS, provide the image in its "native" resolution. Otherwise, it will be upscaled or downscaled by the browser and the image will look blurry or ugly. Those were the days when we didn't have high-resolutio...
I make a game and among others I have nations, provinces, tiles and armies. Each army belongs to exactly one tile, each tile belongs to exactly one province, each province to exactly one nation. I want to ask the following questions: Which armies/tiles/provinces belong to a nation? Which armies/tiles belong to a provi...
With immutable models, what would be the best way to batch several changes? For example, let's have a Book that is immutable. I need to change both title and year. I could change one by one, but that would just create one additional object that is not going to be used. Is there any better way for this? I can imagine on...
Whenever I take in data and do something like delete a post, etc. I generally return head :no_content. For example: def destroy @post = Post.find_by(external_id: params[:post_id]) @post.destroy! head :no_content end Is it good practice to use head :no_content over head :ok? Not too sure when to use either.
I don't understand why the running time of the following loop is n+2 ? Also why the running time of the statements inside the loop is n+1 ? Double test(int n){ int sum=0; -> 1 time int i; -> 0 time for(i=0; i<=n;i++) -> n+2 times { scanf("%d",&a); -> n+1 times sum=sum+a; -...
What about if I sell computers with embedded home-made antivirus using ClamAV database as its main database or as optional database? Of course the software isn't open-source/GPL. Is it allowed? Many thanks.
While studying about NFA and DFA in Compiler Design I couldn't get how they converted an regular expression to NFA as shown in NFA.I would like to know why there is an epsilon transition between (8 -> 10) and (9 -> 10). Because I think even if we don't write states 9 and 10 the NFA would be unaffected. Can anyone tell...
Can I get a clear explanation why why can't we instantiate an object of an abstract class. I know abstract is not real. But I want to know more why can't we instantiate an object of an abstract class.
We are using a few jQuery UI elements in our web application, and I need to change their design. For example, the ui-progressbar is way too high and its rounded corners don't fit well with our design. But the style of these jQuery elements is not set in a stylesheet, it appears in <style> tags in the element itself. ...
I'm writing a tic-tac-toe game in C++ and now I found a function to check if a player has a winning board for a connect four game. The function looks like this: bool haswon(int64_t board) { int64_t y = board & (board >> 7); if (y & (y >> 2 * 7)) // check \ diagonal return true; y = board & (board >>...
All, I know there are three types of DTD for HTML 4.01 (strict, transitional, and frameset). And I knew the DTD defines the syntax of markup constructs and the document structure with a list of legal elements and attributes. So why is DTD missing in HTML 5? Isn't it necessary for HTML 5 document? Or no need to specify ...
Suppose I have a series of methods across different classes that all use the same five core variables defined in my main method. I could chain these five variables as method arguments from one method to the next, or I could simply define these five variables as public class variables and reference their path each time ...
At my current job we develop code on a release branch and then do a code review. After all rework is done the final changes are also synced/merged to the 'main branch'. We want to be sure that all changes are synced correctly. What's a good way to review this sync work? Note: the initial versions of files in the releas...
when you make a API, what is a better practice ? http://webapp/api or http://api.webapp/ why ? I started with the API in http://webapp/api and the description of the service in http://webapp. but now, I would like separate the description of the API in differents repositories, for this reason, I'm thinking in chang...
I was curious to find out the advantages of black box pools over white box pools and vice versa. I know blackbox pools are used to model an external participant, whist whitebox pools are used in modelling entities whose process we are interested in. But is there really any advantage of using one over the other or can ...
I am trying to design a simple exception handling strategy for web services middleware using some ideas from here: http://northconcepts.com/blog/2013/01/18/6-tips-to-improve-your-exception-handling/. However I think it is worth it to have two exception classes inheriting from RuntimeException instead of just one. The ...
We are working on a very large codebase. It's basically a web-based operating system, with its own file system and applications. The system's UIs are generated dynamically with Javascript. We've decided to introduce Google Analytics to track various user activities. Our concern is that in order to send data to Google ...
Apologies if this doesn't make sense, English is not my first language. I'm working on an application where workflow is split into 'rules' that are defined on several pages of an Excel spreadsheet, a VB script strips out the descriptions of the states etc and leaves only numbers, then exports this configuration as MySQ...
Sometimes when coding a client-server application, the client needs to make a bulk update. For example: "mark all pending orders as dispatched". To implement these I typically write specific controller methods, which perform the required database operation. It crossed my mind that theoretically this could be done witho...
The linked "duplicate" question is an iffy match at best, because it's asking is pattern X OK (YES/NO) and I'm clearly already in the NO camp, and subsequently asking what is pattern X called what steps can be taken to fix pattern X (neither of which are addressed by the linked question). I recently did a code rev...
For this while loop below. It is clear how the v1,v2,v3 are updated to new data objects based on the equation. But I do not understand how u1,u2,u3 retains the original values of v1,v2,v3.Can someone help clarify? So u1 points to the original data referenced by v1 but not the new reference for v1. def findModInverse(a...
I want to create a Virtual Keyboard that can catch whatever key you 'speak' and send the keystroke to the active application. The Virtual Keyboard part and linking it to Speech Recognition will be done easily but the problem I am suffering is that the Speech Recognition is inefficient! For example I say 'c' and it take...
I am developing an Android App which I have developed for iOS before. The app requires that structured data and files are synced across android devices. In iOS, I was using Core Data and synced to iCloud with the Ensembles framework, which was quite nicely, and I used Ensemble to sync files, too. My requirements are: ...
We're reworking our process with subversion at the moment, and one of the things we're doing is making branches for each release target in our demo environment so that you can test a release that has been delayed independent of code that will be released separately. I am also experimenting with Jenkins in order to auto...
I am having quite a hard time figuring out how to solve this problem. Basically I have a mini social network with notifications and events. I want to add such functionality where 1 day before an event is about to start and 1 hour before the event starts, users participating in the event get notifications that the event...
What is the best practice for exposing different fields for a resource based on user's role/ACL privileges in the system? Let's say I have an endpoint, groups/{:group_id}. My business rules state the following: Non-authenticated users can see only: name and ID fields Authenticated users can see: name, ID, managers, a...
I know that a product owner should write a user story in scrum. A user story is describing a feature for the end user. But who describes what needs to be technically developed and how it needs to be implemented and where is that information stored concerning scrum? That would really interest me! I see a big lack of kn...
<?php if (in_array(exec("pboxsvc pboxlib.bin DeterminarTipoSpool' $idJob"), ['IPP','PSFORM','PBSSFORM','PDF'])): ?> How would you refactor that line to be "eye-candy" and actually note what is going on easily? I often come to the need of splitting lines in conditionals having functions...
I need some help writing some pseudo code for a rideshare system for taxi drivers. The idea behind it is that it would combine real-time incoming taxi journeys and pre-bookings in real-time. The steps I have come up so far are as follows: The system sets a planning horizon of 1 hour (in the picture below its happening...
I understand there is plenty of information on the internet about planning and implementing said solid plan in building a large software application, but I was hoping to get something a little more specific to aid my approach for this specific instance. Some Background: We're a web hosting company that has a team of 3 ...
Short version: A variable is stored in a session variable req.session.userName and also in the json sent with res.render('/', {username: value}). How can I access either of those variables from inside client side javascript?(inside the script tags in the html) MORE INFO: In my express&node webapp, a user has logged in...
Lately I've been coming across several jokes and comics about how apparently awful PHP is. As a complete ignorant of the language, why is this? Is it my own perception or is this the overall general feeling on the programming community?
I have a conceptually simple application: data comes in as small encrypted packets, they decrypted and validated, some are stored in the database, some rules are applied, and a reply might be encrypted and sent. Packets arrive at a rate of high hundreds of thousands per thread per second, so performance is a considerat...
Scenario: I'm looking to protect my software that is written in PHP. The nature of PHP is that it is delivered as plain text and therefore cannot be protected by itself. I don't want to install libs to the server like ZendGuard, IonCube or SourceGuardian. I want that individuals should use the software but should not i...
We use the normal app.config file for the configuration of the application. Although it works for now it has some pretty significant drawbacks: Upgrading an application with a modified app.config is hard. Either it overwrites the existing configuration file or the upgraded app.config isn't installed at all. An error i...
I am looking for best method to create application which are connected to different databases based on client So basically it is a multi tenancy model for an android app (enterprise use) Deploy the same app to different customers but connect to different database for different customer. The things I thought about is ma...
I have modeled my application using multiple 'user' domain objects. Candidate Recruiter Administrator Each entity extends from an AbstractUser implementing UserInterface. interface UserInterface { public function getEmail(); public function setEmail($email); public function getPassword(); public funct...
I'm just starting out on a project to develop a new, fairly substantial web application which has an underlying MSSQL database. We're hiring a team of developers to write the application (in .NET) and I'm building the database (I've actually already started). My initial plan was to write Stored Procedures in my databas...
Suppose there's an object that contains only setters and getters: class Config { public void setName(String name) { this.name = name; } public String getName() { return this.name; } public void setLanguage(String language) { this.language = language; } ...
I am coming from working with ADO.net DataSets and feel fairly comfortable with how they work. Mainly, I usually have a DATA table with a large number of REF tables for lookups. In DataSets it was fairly simple to define a query and some access functions to get a REF table bound to a dataset or a class. I could also cr...
I have a simple upload-servlet and need to report if a file is illegal and has not been added. For some reason i am not allowed to give a html-body back, so i need to use the response-header. Unfortunately the X--response-headers should not be used anymore. So what response-header match my requirements? I daresay Warni...
When I started using Java, I created a custom Event class to mimic C#'s implementation of Events. Since then, I've added some other features, like event listener priorities, and cascading events were priorities are respected. Now that I'm using C# again, I wanted to create an eventhandler class, or at least a class tha...
For a documentary reseach: Architectural Patterns (ex MapReduce), I started by reading the MapReduce: Simplified Data Processing on Large Clusters paper. the authors define MapReduce as "a programming model and an associated implementation for processing and generating large data sets". Can we consider that MapReduce i...
I am creating a HTTP REST API. I have a large collection of key-value pairs, at /base-url. I need to provide the ability to get and set values for a key. My first attempt: GET /base-url/{key} PUT /base-url/{key} The problem is that this requires URL recipes, which as I understand go against the hypermedia principles ...
I think title says it all :) Is there any particular practical reason (I guess it's mostly historic, but I'm unable to find it on my own) why GCC uses AT&T/GAS syntax? Note: I know this is just default and you can switch it Note 2: I personally find "Intel syntax" much more readable, so that's why it surpises me.
I have an application written in C++ that was originally single threaded, but, due to the increasing complexity of this project, I'll need to expand it to at least two or three threads. There are only a total of four variables that will be used between more than one thread threads, making it useless to make everything ...
I am reading some information about the Unit of Work pattern. There is one thing that is not very clear for me: what will happen when you request a couple of records on a thread (1) and another thread (2) removes one of those records an commit the change? Is the removed record on the first thread given a “removed” stat...
So, my problem is in the context of an MVC-style approach. The code here is PHP, but I'm hoping this is a design issue independent of it. abstract class Controller { private $domain; private $view; function __construct() { $this->domain = new Domain; $this->view = new View; } } So I want to create a s...
I'm working on a project I want to keep open source on GitHub, but I have a licensing problem. I have searched for hours, but I haven't found a license which disallows commercial use/sale of the application. This is very important as I plan to sell it.
I am exploring how a Minimax algorithm can be used in a connect four game. I was looking through a program and found this evaluation function. private static int[][] evaluationTable = {{3, 4, 5, 7, 5, 4, 3}, {4, 6, 8, 10, 8, 6, 4}, {5...
Coming from a mainly c# background, I'm used to using the term "interface" for describing an object with no implementation that defines behaviour. In c#, the convention is to prepend interface names with "I", as in IEnumerable, etc. Of course, the concept has different names in different languages. In Swift, the same c...
Within the context of JavaScript/Node.JS; Will using Callback functions improve the maintainability of source code, when there is no need for async programming? For example does the plain code sound semantically more correct and will be easier to maintain/extend, rather than the second one that unnecessarily uses callb...
I learnt that Java did not allow multiple inheritance using abstract classes for simplicity. In java, after a good design of class hierarchy, SubType would not get into trouble of same method prototypes or same name variable, coming from both interface and abstract class as parent types, Because abstract class and int...
I have the following sequence diagram to add a student to a list of students. the implementation could be like List<Student> Students = new List<Student>(); Students.Add(aStudent); I drew the following sequence diagram for it: In this diagram Students is actually the list of students mentioned in the code. I would l...
I've been looking at a couple of the MVC tutorials on the ASP.NET website and and have noticed numerous of them make use of Entity Framework (especially the Identity provider stuff). Maybe my experience is a bit too "old-school", but I believe a website should never directly talk to a database (even if you wrap it in r...
The entire idea of simulated annealing is to avoid getting stuck in local optimums, which is why sometimes, a worse solution is accepted. However, simulated annealing will automatically accept a superior solution to the current one. Thus if you are in a local optimum, then simulated annealing will get you out of it fo...
First of all, sorry if this post is too long. I'll start with the… Short version: Is it generally advisable or a good idea to design an interface property as asynchronous simply because we cannot be sure whether each and every implementation can guarantee that it's evaluation will be cheap? That is, can it be a good id...
I'm not an expert programmer so this may be why, but I've come to notice that whenever I create complex code (like a Chess game I recently made), I am able to write the correct code to get the program working, although I find that later on- or even a few seconds after!- I often have to pause, and think, how does this w...
I recently found the game that was my first encounter with a computer, a DOS game running in text mode. It was released in 1984 and is available on abandonware sites, but I've started to wonder if I may make a modern version of it (hopefully being able to release it as open source). In the game, there's a copyright not...
This is specific to JS in the browser for a traditional multi-page site (i.e. not a single-page app). For single-page apps, the advantages are pretty clear: the main view page is going to be long-lived, and it will load any number of sub-views which may all have different JS dependencies. Loading all your JS up front i...
I've obviously heard a lot about the Micro-Services Architecture and think it makes a lot of sense (especially with the success stories of Netflix). I'd like to implement a small Grails application in Micro-Services (although the framework doesn't matter too much). My question is about the "Security" or "Users" Micro ...
I am relatively new to Scrum and I am not clear on the boundaries of a product owner. The product owner that I am currently working with seems to behave more like a manager than someone who gives requirements to developers. When talking to me or other members of the team without the team lead present, he behaves differ...
I have recently joined a development project and was suddenly given the job of lead developer. My primary responsibility is to break up the programming part of the project into tasks, give these tasks to the other developers, and then make sure that the pieces work together. The problem though is I haven't a clue how t...
This is a question I was asked at a job interview, and I can't figure out the answer they were looking for, so I'm hoping someone here might have some ideas. The goal is to write a function that is guaranteed to never return the same value twice. Assume that this function will be accessed by multiple machines concurren...
Would it be possible to implement exception mechanism in pure ANSI C similar to the one used in popular OOP languages (with familiar try-catch-finally clauses)? If yes then how? I'm especially interested how would anyone jump from function to the catch block bypassing all remaining code in try block?
I am trying to design a restaurant ordering system in UML, which should also include the stock system. One of the classes is a Dish (i.e. a dish on the menu), and another is an Ingredient. My initial idea was to place an aggregation of Ingredients within Dish, but I've also read that a many to many relationship is more...
I am working on a project right now that is having me calculate monthly interest on a bank account. The way the interest is supposed to be calculated is as follows: Use the daily average to calculate interest. The daily average balance of an account is calculated by the taking the average of the end of the day balance ...
To give some background, i have a WCF SOAP service in .NET that needs to return pdf files. This service will be used by multiple application, many times in a day. The size of the files returned varies from 10KB to 10MB. Also, there is no shared location where the file can be kept and the path can be returned. It can be...
We're in the process of switching from SVN to git, and I've noticed that we're seeing a lot of these commit messages in git: Merge branch 'development' of [Url to Origin]. These are coming in where other developers are pulling down changes from remote, into their local repo, before they push their changes back into rem...
Given an undirected, unweighted graph coded as a 2d array, how can I find the number of different connected components? Example There is the following 2d array (I'm not putting any brackets to make it more readable): 1 1 3 1 1 2 2 2 1 3 3 2 4 4 1 4 Since each discrete number can create a component with the same numbe...
(I am currently using groovy but it should apply to most OO languages so I also put the langauge-agnostic tag) I try to program in a function style which also includes method chaining and avoiding variables. Therefore I often find myself writing code with the with method in groovy that every object has. It works likes ...
I have a question based on SmallTalk and C++. In one of the programming languages books, there is a question like: "Does an object in Smalltalk require its own private stack? What about in C++?" Could you please explain those questions above if you know the answers? Thanks.
I've heard in a number of places now that people expect languages to use, or at least have, a self-hosting compiler in order to deserve respect. I'm curious as to why this is. A compiler seems like a very significant piece of software to write, and I imagine not all languages are well-suited to creating them. Wouldn't ...
although I'm programming in C++ for some time now, I'm always faced with design decisions (probably due to the language's flexibility). One such problem is deciding if a method should be part of the class or not. As an example, oftentimes, I have a Simulation class similar to the following, class Simulation{ public: ...
I've seen this before but haven't found concrete reasons. When you add Entities to your EF model, EF auto generates classes for these entities. In terms of DataAccess, why is it preferred to not use these Auto Generated Classes, and instead use your own Data Models for Data Access. Ex. EFAutoGeneratedClass = //que...
I'm trying to grasp what's the idea behind TDD and how a team is supposed to work with it. I have the following test case with NUnit + Moq (just writing by memory, it is not assured the example compiles but it should be explanatory): [Test] public void WhenUserLogsCorrectlyIsRedirectedToLoginCorrectView() { Mock<IU...
Note: if you feel that I should include code, please tell me. I am solving a problem of finding shortest path between nodes. I am given the vertices between nodes, however they are one sided (ie you can go from A to B, but not from B to A). The twist of the challenge, is that the paths (vertices) taken must be even num...
Is there a name for this pattern? I've written this kind of thing a few times in JavaScript and recently found myself writing it in C#. Thing is, I expect this has already been implemented in a library somewhere I didn't know what to look for. In pseudo code it's something like this: if (null != referenceToPreviousRequ...
So I have an array of distinct pairs of positive integers. That is, my array looks something like this (for instance): { (1,5) , (6,4), (5,3), (2,3), (2,4) } And my task is, for a given pair (a,b) find (if it exists) the pair (c,d) which has c > a and d > b and, in addition, is the "minimal" such pair (that is, c is mi...
Disclaimer: I came to Programmers.SE to ask this question because I understand this is the place to ask this type of question, and not necessarily stackoverflow. If I am wrong, please close the question and direct me to a place where I may be able to discuss it. I have noticed that people have been saying (in the year ...
My source XML does NOT contain the root declaration i.e. <?xml version="1.0" encoding="utf-8" ?> And when I run the file command on it, I get: ASCII text, with very long lines, with CRLF line terminators Can I confidently use US-ASCII or UTF-8 interchangeably when reading the XML ?
I want to write an application that creates scheduled events at specific times. When the delay elapses the event notifies the application. The scheduled events must not be stored in the application's memory because if the application shuts down all scheduled events will be lost - I do not want to write a custom persist...
As far as I can tell, the basic operations (add, delete, search) on a B+ Tree would function the same if minimum occupancy was 1, or 1/3, or any other function on node size. All the sources available give the minimum occupancy as 50%. Why 50%?
I'm working on a project where one part is to save data of different people. A typical person might have the following structure: Email: Multiple values possible City: Multiple values possible Contact no.: Multiple values possible ... As you can see, the point here is the possibility of multiple values for different f...
Consider an e-commerce site, where Alice and Bob are both editing the product listings. Alice is improving descriptions, while Bob is updating prices. They start editing the Acme Wonder Widget at the same time. Bob finishes first and saves the product with the new price. Alice takes a bit longer to update the descripti...
I don't know if to have domain models with properties that not always are set, it's a some kind of code smell or design error. I put an example: I have an app that lets read internet magazines using Rss. For domain models, I use cases of use. Briefly I have: There is a magazines library. You can consult the profile o...
I have recently read this excellent article on the microservice architecture: http://www.infoq.com/articles/microservices-intro It states that when you load a web page on Amazon, then 100+ microservices cooperate to serve that page. That article describes that all communication between microservices can only go through...
I frequently have this problem but didn't find it as an established programming pattern. I have some Class C whose equality is determined by some key k and I want to prevent time-consuming initialisation of additional equal objects. This is my implementation but the synchronized get method prevents parallel instantiati...
We are trying to continually improve our source code base and a question came up recently which throws open a new area to improvement. Where best to put URLs that are needed in JavaScript? Do we put the URLs in the JavaScript files themselves? function onButtonClick() { $.ajax({url:"/my/url/directly/in/t...
The testing team (the so-called QA team in some organizations) insists that the development team should share their (the development team's) test cases with them. Their arguments are that the development test cases are the starting point for the QA testing. As a development team member, I don’t understand the request. ...
I have a Java web application, running in a cluster of Tomcat application servers and a shared SQL/JDBC database. Data from the database is cached in memory in each instance of the web app. My web application needs to update the database periodically with weather report data from a source outside of my web application ...
I am looking to make a mobile application (iOS and Android app) that will interact with a website. The app will need to log in with a provided username and password and also get some information from the website. I have no access to the website other than that of any other user. The idea is to simplify, automate and m...