instruction
stringlengths
34
19.9k
I have a few optimization algorithms (for finding function minimum) and I'd like to check how good they are. Suppose I build test cases and compare the actual results to theoretical ones. What measures should I use to estimate if the function minimum was actually found? I thought about: mean number of function evaluat...
MSDN says that to properly clean up an object which contains managed and un-managed resources, you need to implement the 'Dispose Pattern'. Given that the class implements the IDisposable interface, and overrides the Object.Finalize() method (has a destructor), is there any reason why the compiler shouldn't automatica...
When an API's data structure does not fit well with an angular app, I am trying to determine the best-practice in my specific design and implementation for converting it to a usable structure. I was doing this on an 'as needed' basis within the app controllers/directives, which quickly lead to spaghetti code. Now I'm t...
I'm working on an application that plays music. During playback, often things need to happen on separate threads because they need to happen simultaneously. For example, the notes of a chord need to be heard together, so each one is assigned its own thread to be played in. (Edit to clarify: calling note.play() freezes ...
I've been using MongoDb (mainly with Meteor) and for me, it has been a great way to mock up prototypes and proof of concepts quickly. I'm just wondering, after building the initial product, if your product is likely to grow and change, is it a good idea to stick with mongoDb? Cause it seems like with MongoDb, you need ...
I have an industrial equipment which is controlled by a software. The software connects to it using sockets, and keeps the connection all the time alive, while from time to time sending commands to the equipment. Now, this equipment is represented by a class which encapsulates the sending and receiving of data. Next, I...
There are different stages of compilation Such as Preprocessing stage Syntax analysis Semantic analysis Intermediate Code generation Machine Code generation Optimization Linking My question here is in which stage of compilation "typedef" is resolved.
This is a rather conceptual question, but I was hoping I could get some good advice on this. A lot of the programming I do is with (NumPy) arrays; I often have to match items in two or more arrays that are of different sizes and the first thing I go to is a for-loop or even worse, a nested for-loop. I want to avoid for...
Is there any issue with creating a new controller within the ascx view pages. I don't want to create a model, are there any issues with doing it this way. Normally, the controllers control variables within the model, and the model is the middle point between them, but I am creating a new instance of a controller class ...
I have written a single page application that uses rest services to retrieve JSON objects. The JSON objects being returned are C# objects serialized using the Newtonsoft.JSON library. The returned JSON object contains $ref pointers to specific $id objects within the same JSON object (The question here shows an exampl...
I believe in the user experience of always having a confirm pop-up for deletions. However (though we're very used to it), a separate small pop-up window is not ideal and for users on different browsing devices, using different input devices, they can be a nightmare. So I was thinking of changing all my 'confirm delete?...
this is a conceptual question, but if i initialize a variable in c# as public will it be able to be used in the class as I want a variable "player1" and a variable "player2" where either could be one of the two (or more) Player Computer Here is what i would like to know how I would do: public class Game { ...
Consider the following (Microsoft-sanctioned) code: <% using (Html.Form<HomeController>(action=>action.Index())) { %> <input type="text" id="search" /> <input type="button" value="Submit" /> <% } %> The using statement has but one purpose here: to add a </form> tag to the end of the generated HTML. This fee...
This is a badly titled question...maybe a moderator can make it better. Nearly two decades ago, I took a computer graphics class as an undergraduate. We got to do whatever we wanted for a final project as long as it demonstrated what we learned about CG. So, I read a book (I can't think of the name at all) that descri...
For a web application I'm working on right now it's very important that automated e-mails arrive at the recipient. I've set up the mail server on the VPS that the application is going to run on. I've taken all the regular precautions to make sure that the e-mails it sends are not going to be filtered out: SPF, DKIM, e-...
Take the following basic structured code for example: class Player { public QuestLog QuestLog { get; set; } } Let us consider that "QuestLog" has the ability to fire off some events when things are added or removed from it. Normally, I would subscribe directly to the QuestLog, such as doing something like: player.Q...
I'm writing a soft real-time application in C#. Certain tasks, like responding to hardware requests coming in from a network, needs to be finished within a certain amount of milliseconds; however it is not 100% mission-critical to do so (i.e. we can tolerate it being on time most of the time, and the 1% is undesirable ...
I am writing two classes in C#: A Matrix class that represents a general Matrix with n-by-m dimensions A SquareMatrix class that inherits from Matrix and has the constraint of being n-by-n The reason I designed it this way is because square matrices support additional specific operations like calculating the determi...
I am attempting to learn object oriented programming by designing a simple web application related to the Catholic liturgical calendar. I have very little formalized training in programming, but I have been able to more-or-less successfully learn basic programming concepts and the purposes/syntax of a couple languages....
I'm currently in the class modeling phase of my project. Real life Scenario: Let's say I have a Project that is composed of Main Components and each Main Component is composed of Sub Components and each of Sub Components use multiple Materials. I created a class based on the entities: public class Project { public ...
If using Python on a Linux machine, which of the following would be faster? Why? Creating a file at the very beginning of the program, writing very large amounts of data (text), closing it, then splitting the large file up into many smaller files at the very end of the program. Throughout the program's span, many smal...
In almost all circumstances, primary keys are not a part of your business domain. Sure, you may have some important user-facing objects with unique indices (UserName for users or OrderNumber for orders) but in most cases, there is no business need to overtly identify domain objects by a single value or set of values, t...
I heard that twitter practices "dogfooding," meaning that they use their own API for the website. However, I don't really understand how that's true. When I use Firebug, I see that all the AJAX calls are made to some URL like: https://twitter.com/{username}/{whatever else} Rather than: https://api.twitter.com/1.1/stat...
Consider the following class: class Person: def __init__(self, name, age): self.name = name self.age = age My coworkers tend to define it like this: class Person: name = None age = None def __init__(self, name, age): self.name = name self.age = age The main reason for ...
Lately I've been working on a small personal project which is basically an Entity Component System framework with autoupdated Systems. While I have a pretty good idea on the way the framework should work, because of lack of experience I am having trouble with actually keeping everything decoupled. Some details on the f...
TL;DR What error generating and handling strategies do you use in Multithreaded code intended for use by others and why do you use them? If applicable, state what programming paradigm it's useful for. I'm more interested in imperative, concurrent environments but any in general will be useful. I'm writing a little con...
I have an ElasticSearch search engine and an internal web application. Prior to applying the security model, search results were very fast. The security model restricts some users from accessing certain pages. We have 7 "types" of pages. Our process is currently this: Search engine queries all records For each type...
I'm currently writing an e-learing web-application. I'm sorry if this is information overkill but I think it's better to describe it in detail so you get the idea. I have made thought on every point and would just like to know if my approach is ok or totally off the mark for this is the first time I handle that much da...
I have a COBOL CICS process running on a mainframe legacy system. The process does over 2K DMLs in a highly concurrent DB environment. After each CRUD operation, the result is used to make further computations followed by CRUD operations again. This entire process runs under a transaction block such that any failure be...
I'm working through a problem in Programming Pearls -- specifically, the implementation of a program which sorts a file containing, at most, 10,000,000 integers (Column 1, Problem 3). Since the book doesn't specify how the data should be stored in the file, I'm considering storing the integers as raw bytes (there are s...
I am rather inexperience in Java, and I'm having a problem in forming a subclass of a class I have created. The class I have made, called Vector2D, contains methods, such as add(Vector2D addend), that takes a Vector2D object as an argument, and returns a Vector2D object. This method in particular is designed to add two...
I'm currently using substitution method to solve recurrences. The problem I'm having is dealing with T(n) that have either ceilings or floors. For example in the following example see example here. They end up using the guess: T(n) ≧ c(n+2) lg(n+2) My first guess was T(n) ≧ n lg(n), which turns out to not work but my ...
I'm currently reading Robert Martin's Clean Code. I think it's great, and when writing OO code I'm taking his lessons to heart. In particular, I think his advice to use small functions with meaningful names makes my code flow much more smoothly. It's best summed up by this quote: [W]e want to be able to read the progr...
I'm working at my first software internship, and it's great so far. One problem I'm having, however, is getting clear requirements from my co-worker (we'll call him Person A) who assigns projects. Normally, I get requirements from a co-worker/manager, design/code/test my changes, and eventually commit them for integrat...
I have a background on .NET development, recently I was asked to code back-end service for a mobile app. I had experiences on MVC, and now I'm trying to understand more on Restful Web API. My questions are: Is Restful API as back-end service one of the best (or suitable) choice for mobile app? What is the common soluti...
Recently I came across the following in one of our projects. In one of our MVC views they are passing model data to an Angular controller through ngInit directive. In xxx.cshtml: <div ng-controller="AssessmentController" ng-init="Init('@Model.Status','@Model.ARN','@Model.AssessmentID','@Model.AssessorID',@Model.Co...
Some background: in order to learn GUI programming and drawing in Windows I'm starting to create my own GUI toolkit in Windows (so this is a didactic exercise, please don't suggest "use Qt" or "use MFC"). I would like to draw the entire window area from memory DCs in double buffering (thus also handling mouse and keybo...
I'm programming an application for an embedded device. We are using an RTOS that supports multi threading. The device is supposed to mimic an older project that was programmed in plain C (without threads). The original project uses a stack and START / END functions at the beginning and end of each function that can be...
In my app, many appointments can be booked for activities. Each activity has many price packages with a price and a quantity. On showing the cart, I need to work out what combination of packages to use to get the user the best prices and allow all the appointments to be accounted for. There is not always a quantity...
I am currently developing a continuous backup software. The key feature of the software is instant backup meaning that each time a file is created, modified, renamed or deleted the change is immediately reflected on the backup repository. In order to achieve this we designed the system so that once the client applicati...
Basically, let's suppose an application that manage some user's meetings. I have a filtering zone on a page that aims to specify the category of items I need to specifically return. Supposing two kind of filters: Retrieving my actual meetings (meetings currently occurring or planned in the near ...
My question is that is the P part of the LAMP really necessary? I will have the database and I can connect to it via the appache http so why will I need php/python in the server side (if it is a really simple set up) also from a seperation of concern it might be more robust at least thertically to leave the P out of ...
After reading some questions about the probability of UUID collisions it seems like collisions although unlikely, are still possible and a conflict solution is still needed. Therefore I am wondering about the background of choosing UUIDs for CouchDB Is the "unlikely collision" a responsibility of the developer? Was it...
Sometimes compilers inline function calls. That means that they move the code of the called function into the calling function. This makes things slightly faster because there's no need to push and pop stuff on and off the call stack. So my question is, why don't compilers inline everything? I assume it would make the ...
I have a unit I'm testing which generates a file name and saves something there. I will need to pull the file out of that location to test it was stored right. I know how the file name is generated, however, hardcoding the logic for file name generation throughout my tests feels like a 'Magic Number' to me. Is there...
Was there a language change that required it or some practical reason why Bison was no longer appropriate or optimal? I saw on wikipedia that they switched, referring to the GCC 3.4 and GCC 4.1 release notes. These release notes state: A hand-written recursive-descent C++ parser has replaced the YACC-derived C++ par...
The question title speaks for itself. I'm specifically thinking in terms of a Node.js server. Additionally, this question is assuming that you don't need eval(). Also, if this is not possible, why not?
I've read a lot about RESTful, but I have always had a hard time figuring out how I'd use it with a very long query string. This is an in-house project, and it won't always have a simple /someAction or someController/12/14/my-article-I-want-indexed. I'm not worried about SEO because the application is not on the Inter...
How would the following solution be implemented? Would you need to put this code in each library assembly or just in the main assembly that is determining whether it is safe to call the library assembly based on whether or not it originates from a given intranet Web site? Also, who should call the CheckSite method - ...
Is the following method considered to be doing one thing only? I'm wondering about that since it takes an optional argument. public function findErrors($name = null) { if ($name) { return isset($this->errors[$name]) ? $this->errors[$name] : []; } return $this->errors ?: []; } If not, would it be b...
It is a language agnostic question, e.g. I have a unit test like # Unit test User user = User.create('john'); assertEquals("User name is john", "john", user.getName()); # Web test start from here goTo("/user/john"); assertTitleEquals("john"); Do you think it is an anti-pattern? Although I can write a full selenium t...
When I create an instance of a class the system allocates memory for all instance variables of the class. Some languages may call them fields or properties. But what about the code of the class methods? Are those duplicated too or do I have the code only once in memory? I know all instances got their own values - even ...
I want a background worker to continue running and occasionally update the user interface. My first idea was to use a BackgroundWorker and in its completed event just fire it up again. Is using a BackgroundWorker in this fashion acceptable? Or are there potential issues from using the completed event to trigger the w...
I have a project for a PIC16F1454 that needs some custom linking. Basically, I've separated my code into two parts that can be downloaded separately in the field and thus update (almost) all of the flash memory, including the bootloader. As part of the plan to avoid bricking itself, I have this structure: Lower, pro...
There are 2 arguments for having shared libraries: It helps reduce disk space. When a shared library is updated, all the binaries depending on it get the update. There is mainly one drawback for shared libraries: They (can) introduce dependency hell. On desktop computers, the 1st advantage doesn't really hold anym...
I'm writing a commercial package that uses R (GPL) for its computation. The GPL FAQ clearly states that GPLed programming language interpreters do not impose licensing restrictions on the "program" (text file with R code). So far, so good. Part of the package is compiled using Rcpp, which also uses the GPL. The next pa...
I'm a beginning coder and I've been working on a WPF app for several months now and struggled to implement anything in MVVM due to time constraits to learn so I coded my program the only way to knew how: with code behind, tight coupling, and a whole bunch of spaghetti code. My program has grown into 20,000+ lines of m...
I've been thinking about language design lately, and reading over some of the new things in Haskell (always a nice source of inspiration). I'm struck by the many odd uses of the left <- and right -> arrow operators. I guess the many different usages comes from prior art in math and other languages regarding arrow synt...
I hope that programmers is the correct stack exchange for this, as it is quite a concept based question. I'm working on a data structure in C++ that is a represents data in 3D space. The x-y plane is large (say 0 - 10 000) while the z-axis has a very small range (0 - 10). All the data is located on integer (x,y,z) poin...
If software can be built to recognize faces and match those faces to names, then how is that CAPTCHA works? Recognizing letters seems a lot easier than matching faces.
Let's take this simple c++ program as an example: #include <vector> class A { void fun() { a = this + 1; } A* a; }; main() { std::vector<A> vec; vec.resize(100); } Forgetting for the moment that this is a pointer to some instantiation of A, this question is about the variable this itself, and where its conten...
I am working on a robot that has some AI built in. However, the mandated robot controller does not have the power to do the work onboard. This means that I need to use a co-processor. I am writing all of my AI in C++. This will also be a TCP server. I have an idea for the protocol. The C++ server receives commands and ...
My application needs to perform an operation once every 10 minutes, but that operation is triggered many times more frequently. Occasionally it is triggered three or four times a second in different processes, and that's the main thing I want to avoid. It's Django, and at first I used the django.core.cache feature, but...
I find it really odd that the initCause method of Java's Throwable class can only be called once, or even not at all (if the constructor accepting a Throwable was used). This makes exception chaining not as easy as I think it should be. private Throwable cause = this; public Throwable(String message, Throwable cause) ...
We've got several sites. Some are HTML/Angular, some are built on a CMS, some are built on other code. What we'd like to do is have a consistent header experience for each site. I'm trying to figure out the best way to do this. I've got a couple of options - Have it served on one site - then put it in an iFrame on eac...
I am designing and implementing a programming language, and I am using LLVM for native code generation. Among others, performance is a key feature of the language, and as such, I am looking to implementing link-time optimization. On the official LLVM site, I've read that LLVM features powerful intermodular optimizatio...
How does the for loop function is implemented so that it can accept ; as parameter separator rather than , which is trivial in normal functions.
I am interested in develloping a web music player similar to the soundcloud one However, I can't figure out one thing: How player like soundclou one (and some other one) can "resist" a page change, continue playing without any latency, even if the page in the background is loading, the player is here and continue his j...
I am an experienced java developer.Of now I have started learning multithreading in java.I am able to grasp most of the concepts but still I am unable to visualize applications running on threads.I know the concept but somewhere if I am given a problem statement, I am unable to think or visualize it in threads.How shou...
Let's assume I have a hierarchy of several classes each derived from each other using virtual functions. The base class acts as an interface and defines functions, which may not be required by all of the derived classes. Now I wonder what the best practice is for such intermediate functions. Should those still be imple...
I have an architecture design problem which I think is appropriate for this site. Note that I have made an EDIT to this post below, reflecting my latest potential solution to this problem. General problem description: My primary goal is to design a software library/program (C#) to automate a very particular type of mic...
I've written a database model class in PHP and have written a controller class that specifically validates the data before sending it to db. I'm getting criticism that I should handle the data in database model class rather than controller class. I wanted to write a generic db class which can be used anywhere for CRUD ...
In 1989 Felix Lee, John Hayes and Angela Thomas wrote a Hacker's test taking the form of a quiz with many insider jokes, as “Do you eat slime-molds?” I am considering the following series: 0015 Ever change the value of 4? 0016 ... Unintentionally? 0017 ... In a language other than Fortran? Is there a particular anecdo...
I have a basic grasp of accepting clients without creating a thread for each connection using tools such as select and modern equivalents (kqueue, epoll). But where do I go from here? e.g async I/O and (periodic) timers. I could crack open the source to libev and friends but that's a little overwhelming to me to say th...
I am building RESTful API that manages persons and lists. There can be many List and many Person each with its own set of properties. Person can be in zero or more lists, List can contain zero or more Persons. I have implemented these operations for Persons and Lists: GET api/Persons/ to get all persons POST api/Perso...
I understand the reasons why I would prefer let a = f(x) over let a() = f(x), especially when f takes is a long running function. I also think it is correct to say, that, considering lambda calculus origins of functional programming let a() is truly functional, while let a is not. Please correct me if I'm wrong on this...
I'm working on a .NET application and I'm wondering if I should use separate methods to handle the click events of two different buttons. They essentially do the same thing, just on different objects on the form, in this case two separate maps. Same method: Private Sub SingleButtonHandler(sender As Object, e As Event...
How do you design your code-first approach in entity framework when your code should include user data (name, password...) without repeating/overwriting what the MVC framework will generate in terms of user tables, classes, authorization and authentication As simple example, if i have an application that will manage us...
I'm working through a problem in Programming Pearls -- specifically, the implementation of a program which sorts a file containing, at most, 10,000,000 integers, each of which is 7 digits long (Column 1, Problem 3). The problem has some very strict constraints when it comes to memory, so I'm considering reading and wri...
I've just read a lot of arguments against using Mockito.reset and can't make much sense of it. Put differently, I agree in general, but there's always a case which looks like using reset is useful or even necessary. Grossly simplified, my class under test is an encapsulated map like class Handler { private final Ma...
I have a Netty-based game server implementation that handles 40 or so distinct packets with their own serialization structure, for brevity I'll refer to them as FooPacket, BarPacket, ... These packet types have been assigned consecutive numerical "packet types", which are unsigned bytes. For example, FooPacket is type ...
Expressive Power is defined by Wikipedia as: .. the breadth of ideas that can be represented and communicated in that language. Does "ideas" refer to the things (operations, structures, algorithms, etc.?) we can communicate to the machine? Or does it refer to the "human" concepts that can be captured and communicat...
I'm using a programming language (more a scripting language) that does not support any bitwise operators like AND, OR, XOR, NOT (and shift as well). Common arithmetic and logical operations like + - * / % > >= < <= == !=, logical AND, OR, NOT and control flow (while, for, if,...) are supported however. It is like a "su...
I want to implement a protocol layer which sits on top of the TCP/IP stack. There is a limited set of PDUs that can be sent and for each PDU there is a class which represents it in a structured form. Each class has a function to serialize the structured data into a ready-to-transmit form, and deserialize them into a st...
I normally add lots of sanity check clauses in my code. In other words, lots of assertions where the code is instructed to "panic" (usually print as much information as possible when a certain condition doesn't hold and then exit). The point is, many of these sanity checks are obviously redundant one way or the other. ...
My program's aim is to determine the correct time zone offset (GMT+k) as a series of numbers are fed to it. eg: -4 +11 1 -4 -4 So, here -4 (the mode of the series) is the correct value. But this requires storing the series then analyzing it and I do not have enough storage (RAM and FLASH) for this. The running averag...
Consider this "legacy" code: public interface IPersistentCollection { IPersistentCollection cons(Object o); } Genericized in Java, it could become something like this: public interface IPersistentCollection<T> { IPersistentCollection<T> cons(T o); } Clearly adding a new item to a mutable Java collection shoul...
The LICENSE file of a GPLv2 application I am modifying contains a statement saying that certain resources used in the application were "used with permission" from 3rd parties - such as textual material from a published book and certain graphics. Question: in my derivative work based off of this application, am I requi...
Context: My work is to build financial reports using mostly Excel spreadsheets. This consists mostly of formulas and a good deal of VBA. Each person is built by a single person. We service many sub-departments under the finance / accounting department and we often have many projects lined-up. I have had a rough time in...
I am reading the book »Head First Design Patterns« from O'Reilly. Before explaining the Factory Method Pattern, they introduce a Simple Factory first. They are using the example of a pizzeria. In a first step they show the problem: Pizza orderPizza(string type) { Pizza pizza; if (type.equals("Pepperoni") { pizza = ...
Is it a good idea to replace getters and setters with a single function returning a reference? For example, instead of this, class Person { std::string name; public: std::string GetName() { return this->name; } void SetName(std::string& toSet) { this->name = toSet; } }; Is this a good idea, class Person { std...
I'm currently in the process of refactoring a very old personal project of mine, which used procedural PHP-in-HTML code. I'm modernising it as a learning project, using OOP where beneficial. I understand the basics of OOP but I'm wondering if I understand correctly as it would seem my old way of doing this was faster i...
I always thought that heaps and priority queues were synonyms - an abstract data structure that supports the insert, findMin and deleteMin operations. Some literature seems to agree with me - Chris Okasaki's Purely Functional Data Structures (chapter 3), for instance. On the other hand, Wikipedia's heap page defines it...
I've been playing with making image mosaics. My script takes a large number of images, scales them down to thumbnail size and then uses them as tiles to approximate a target image. The approach is actually quite pleasing: I compute the mean square error for every thumb in every tile position. At first I just used a g...
I started learning Java EE 7 and I am frequently coming across this term "standard", and I don't understand what it means. So, for example, here is a quotation from this book: Contrary to SOAP and the WS-* stack, which rely on W3C standards, REST has no standard and is just a style of architecture with design pri...
I'm starting to use continuous integration for one of my projects and had some questions about structure and architecture. It's basically a multi-device webservice that is split into one server repository and multiple device-specific client repositories. My question is the following: Since clients are dependant on the...
I am writing a GtkGrid-like container for my GUI library for Go, and I'm trying to write the actual layout part of the code. Basically, I have an unordered list of controls. Each control is a rectangle, and each list entry contains a pointer to the control to its north, south, east, and west. What I don't know is how t...
I'm going to have a mySQL table with elements in it and would like to rank them in the same manner than Reddit but not quite. I'd like to know how to add or remove importance to a variable in my ranking algorithm. For instance, what I have is a time (a timestamp, so a huge value) and a number of upvotes (a smallish val...
A lot of people claim that "comments should explain 'why', but not 'how'". Others say that "code should be self-documenting" and comments should be scarce. Robert C. Martin claims that (rephrased to my own words) often "comments are apologies for badly written code". My question is the following: What's wrong with expl...
C and C++ compiles adjacent string literals as a single string literal. For example this: "Some text..." "and more text" is equivalent to: "Some text...and more text" In other C-family languages like C# or Java, this is a syntax error (which is perfectly fine BTW). What is the rationale/historical reason for C and C+...