instruction
stringlengths
34
19.9k
I have read a few asserts vs exception questions already; I ask specifically about package visible classes though. When you write a package, the classes marked with "public" are exposed to the outside world, thus exceptions are used to let users of the package's interface know they're using the package wrong. The class...
I understand that C++ compilers are not compatible with each other. However, I was unable to find anything on this topic for C in particular. I know that the C standard leaves a lot of room for compilers to implement things however they see fit: for example, the size and alignment of most (all?) data types is implement...
I am working on a project where I am trying to decide between using a standard SQL relational database or JSON objects to store data about an event or activity. The project will store data on multiple event types so I have decided to just describe one event type for this question. The live music event (described in fu...
I've always wondered what other programmers think about the idea of creating pure aesthetic functions. Say I have a function that processes a chunk of data: Function ProcessBigData. Say I need several process steps, only valid for that data: Step1, Step2, Step3. The normal aproach I see the most in source code is to w...
I have been coding for a good bit, and I found a project I want to work on -- a python web app using django + mongodb. I know what I want my web app to do. When you are in this circumstance (just starting a brand new project) where do you start? What do you code first? Do you code the views first? Hope this hasn't bee...
For an API I'm building what it does is load an XML file that is passed to it as a string, drill to the correct element, modify values, and return the modified XML. I'm doing something like this in my code if (valid) { XDocument docRoot = XDocument.Parse(XMLstring); var node1 = docRoot.Descendants(namespace + ...
There is a <fieldset> tag for a set of fields. Why isn't there a hierarchical child for fieldsets? <form> <fieldset> <legend>Thin Sandwich Options</legend> <field> <label>Meat</label> <div class='inputs'> <label> <input type="radio" name="m...
I have a client who is requesting that we develop their fairly small web application directly in their environment by RDP to the server that will host the app. They have had a contractor do this for a while and it has worked "fine" for them, so they are comfortable with that approach. The client's biggest concern at th...
I might not have had a counterexample when I got the reply "A pointer is just an address, what's the difficulty?" but I didn't really buy such a simple explanation and at assembly code it's not obvious what's a pointer for 2 different C programs that generate the same assembly. cat pelle.s valle.s .file "pelle...
I am implementing a Canny Edge detector for a class which I have based off the code found here. For the first derivative mask that I will convolve with the image, I am using the Sobel mask, although the website uses the Prewitt. As you can see in the samples on the website, the code is perfectly functional. However, I ...
Firstly, I'll try to describe the real world model of what we are trying to express in C# code. We have a device called M100. It's purpose is to read\write data from\into cards (plastic or ULTRALIGHT cards such as MIFARE). It can be with one up to 3 antennas (the device read\write data through antenna). One of antennas...
Let's consider the next situation: We have a module A which has a class Crt570 intended to interact with a device. We have a module B which uses Crt570 in the class called M100Communicator. We have two applications C and D and both of them wants to use module B. Application D wants to use B, but doesn't want to use Cr...
I've been looking on Google for a clear diffrentiation with examples but couldn't find any. I'm trying to understand the differences between Dynamic Dispatch and Dynamic Binding in Object Oriented languages. As far as I understand, Dynamic Dispatch is what happens when the concrete method invoked is decided at runtime,...
So I've noticed a trend lately of .net web developers using angular.js on the client side of applications and I've become more curious as I play around with angular and compare it to how I would do things in asp.net mvc. I'll give a quick example of what really got me thinking. I recently came across a situation at wor...
I have studied some persistence frameworks mainly Hibernate, DORM, TMS Aurelius and I'm wondering. In a model of type: TOrderFiscal < > ----- > Items < > -------- > TOrderItem ------- > TProduct TOrderFiscal --------- > TSuplier --------- > TCidade -------- > State Each class of this with countless attributes, all ma...
Is it a common or normal practice to encounter schema changes, especially renamed or removed columns, in a production database, without having been notified of the change? If unexpected schema changes are anticipated in the production database, how are they guarded against, other than basic exception handling? I've ...
My question will be about how do you think it would be fit to name some methods in a fluent interface. Let me try to demonstrate the problem. Consider this relation tree: A person can have dogs and cats, and a dog can have bones. Pretty simple. What i'm trying to do is create a domain specific fluent interface for det...
The Decorator pattern is usually used to extend the functionality of an object by extending one of it's current methods. To illustrate, please consider an object object and a decorator decorator. object has one method called methodA(). decorator, because we're in the Decorator pattern, also has this method by inheritan...
In my earlier days of programming, I was using Visual Basic for learning. It taught me many concepts, and I was able to make some cool programs (in my opinion, anyways...). I have expanded my horizon to basic C/C++, PHP, and MySQL. One of my most favourite projects, I want to turn into a multi-platfrom (for x86/x64) wi...
I'm involved in a project which involves implementing a binary protocol that will be transmitted over TCP. During our early discussions we have hit a brief snag on deciding whether byte stuffing is required if we decide to include the packet length in the field header. For example. If our packet structure was like so...
At some point I had to create some class "Class1" and that class needs a method "method". So I have the following: Class1MethodTest: A total of N tests that check the behavior of Class1.method Class1 method: A full implementation of the method But a bit later I need a different class "Class2" to have a completely simi...
For example with: Total population = 400000 Number of villages = 800 The average population is 500 How can I randomize the amount of people in each village using a specified deviation (eg +-50) so that it equals the total population? I came up with a solution using this normal distribution class Basically I created a n...
Let's imagine I have an abstract class named ProtocolA that represents the basic operations to work with the protocol A. Such protocol is in version 1, but new revisions are expected in the future. Version 2 is coming. How should I name the classes that implements that abstract class for each version? ProtocolA1 and Pr...
From what I understand, SVM's take a discrete number of x and y values from which to learn from, then when given new x values map it to one y value (category). Is it possible to use SVM's or something similar to instead map x values to probabilities of y values? Let me give you an example, say your x values are arrays...
I'm currently learning Clojure (my first functional programming language), and I'm curious as to its order of evaluation. Here is an example: (take 10 (cycle [1 2 3])) If the cycle expression was not wrapped in a take expression, this would cause a memory error, as it would iterate infinitely through the vector. So, ho...
I've been told that when I have a hash table of size m and m=2^k, I can use the & operator as num & (size-1) instead of num % size, to fit the hashCode to my table size. I've also been told that the the command Num&sizeMinusOne is more than twice faster than num & (size-1). My question is, why? And isn't the operati...
In my current company we're using Scrum with 2 week iterations and a regular planning session. How planning normally works in our company is that we take a predefined , prioritized (by PO before the planning) product backlog of user stories / PBIs, take PBIs from the top one by one and break it down to tasks to then e...
I'm using Rails engines to break up a big app into smaller pieces. The parent app mostly handles users and authentication. In one of my engine tests I want to log in a user before each test. How should I access this user log in functionality, which exists in the parent app, from the engine? It seems there are two optio...
I have used Factory pattern where I have multiple classes which does similar sort of work, but I don't want client to worry about class instantiating and return types. So Instantiate the necessary class dynamically depending on input and pass the values. These classes have similar methods but does slightly different wo...
Lately I've been reading about Hypermedia as the Engine of Application State (HATEOAS), the constraint that is claimed to make a web API "truly RESTful". It boils down to basically including links with every response to the possible transitions you can make from the current state. Let me illustrate what HATEOAS is base...
I'm currently refactoring an existing design, which was created without TDD. There is a class hierarchy with one abstract base class and two subclasses. In the original design, these classes were mostly just data holders without much behavior. I have identified some functionality which should be implemented in the base...
I'm looking for the kind of a certain datatypes. The main idea of this datatype is to describe a productionline containing several steps. Each step should be represented as a "vertex" containing an object of any type. Then for every "vertex" there are possible "subproductionlines" joining the line. So it could look som...
I am writing up a user registration application in PHP as part of my learning process. I have written up the general rules my code should follow. Please let me know what you guys think of it. Have a form with the email address and password. Generate 2 random tokens to be appended to the URL to validate the email and ...
I'm learning Scala at the moment via Odersky's Programming Scala (2nd). I'm upto chapter 10 where he starts introducing parameterless and empty-paren methods. I just can't get my head around it. So far, all I understand is that I should use empty-parens if a method has side-effects and parameterless methods otherwise. ...
I thought I understood inheritance and polymorphism, but I was given this question, and I can't, for the life of me, figure out what the proper answer is or what they're trying to get at: The process of determining which method in a class hierarchy should execute is known as: a) inheritance b) polymorphism c) is-a ...
Preface: I am working in PHP (Abandon hope all ye who enter here). Background: There exists a large set of global functions in PHP, a number of which are miscellaneous system calls, like sleep (and others). Now, I use sleep (and others) in a bunch of different scripts I run in a bunch of different places, and I have f...
I'm trying to come up with some data structures for rendering my map on OpenGL. It is going to be ~ 100x100 blocks(squares) total, with each block being around 100 pixels. However, the screen will only display about 20x10 of these blocks at a time, depending on character location. So from this post: https://stack...
When I look at things like Twitter, it seems like the idea is so simple to implement initially that the founder does not have to be very technically talented. Basically it's just a guy with a good idea. But when an app / software blows up and entails much harder engineering problems, how does the founder deal with it? ...
I got confused about if a domain is required to access an external service in some state of it's life cycle. The business rule is this : If an Employee is accepting a JobSeeker's JobApplication, then the Employee must create an Appointment and have it e-mailed to the JobSeeker. My current solutions are: 1 - Leav...
I want to learn to Design Hash table with simple hash function for better understanding. I understand that the hash table will work as long as the hash function maps each key to a non-negative integer less than the size of the hash table, but it will only perform well if it distributes different keys across different b...
The usual way (that I'm familiar with) to divide the server side is the n-layer architecture : DAL - data access layer, usually has the Entities and the context (and maybe include also a repository) BLL - business logic layer Contract - Interfaces Services - classes which implement the interfaces ( could be a Web API ...
I've heard, that parsing HTML using the Cthulhu way is not very good. But what are the right ways to parse HTML? Or is it possible to parse it at all?
EDIT The original title of the question was Is there a non-derogatory term for 'monkey patching'. As I have learned that the term is actually not derogatory, or is at least not meant to be, I changed the name to free it from mistaken implications. I would like to describe a piece of software, and try not to use emot...
I would like to modify and use code of a MIT project within a MS-PL project. Am I allowed to do that? I've already searched for it with Google and Bing, but I could not find anything like "Yes (No) you can (not) use MIT code within a MS-PL project". I am no jurist, so it is quite hard to interpret any license.
I'm working on website for the game of bridge and I am process to designing the table to store the bidding. Shortly about the bidding. 4 people at a table will bid clockwise until 3 players has passed so it could be many rotations of bidding with a one of the four to start the bidding like this: North East South West P...
Okay, so the goal here is to implement a strategy pattern that can be tested using any sort of automated testing tool. I've been struggling with this problem conceptually for a few weeks now and I want to clarify it. So the current setup is something like this: <?php // CreateReportUseCase.php class CreateReportUseCase...
This might be a silly question, but I've reading a little bit about NoSQL databases on the past few days and I'm trying to understand when really they help us. One thing I've realized though is that it seems that NoSQL databases are closer to OOP than RDBMS. I say that because usually when we deal with OOAD we don't ge...
I want my unit tests to be able to verify that some events were subscribed or unsubscribed at specific points. Currently, I see two options. VerifiableEventHandler Each client subscribes using the common += and -= notation. Each class that has a verifiable eventhandler needs to implement IsSubscribed(), which can quer...
I am sure many people involved in the software development projects came up with this question, but I could not actually come up with satisfying answer. How to explain to a manager used to having a huge gantt-chart, resource allocation, critical-paths (etc) benefits of using agile process tool such as Scrum or Kanban?...
I'm currently refactoring an application which periodically downloads content from various sources (http, ftp, sql, etc). There is a schedule which controls the times during which the application can be active. For example, it can download content between 8AM and 16PM. The application has been written in an object orie...
I have found myself a few times in the situation where a client reports an issue like 'I can no longer login to my account'. Sure enough when trying to login with the client's credentials myself everything works. After that, you start testing in other environments and situations, but still it works every time. After ...
So in a nutshell I have an abstract class : public abstract class Member { public string PCode { get; set; } public string Reference { get; set; } public DateTime? ElectedDate { get; set; } } And this is inherited by 3 other classes: public class Fellow : Member { // some class level properties here } public class ...
I will give a simple example to help you understand my question. Suppose we have a rectangle and a Utility class with a method that creates a buffer arround a shape. The .createBuffer method has required and optional arguments: required: radius optional: direction (for example "inside" or "outside", default is "outsid...
I am developing a retail management system with inventory management module, I am facing a logic design problem and I don't really know how to address the problem in an easy way, so I wrote an example which illustrates that problem: Let's say I have an item (e.g. Cola Can), this item have a Barcode (11...1), this is s...
I am currently checking through the syllabus for the ISTQB "Technical Test Analyst" certification. This syllabus (henceforth called "TTA syllabus") contains a chapter dedicated to "condition testing" (apparently this is also called "condition coverage" or "condition coverage testing".) Condition testing as defined in t...
As far as I know, deleting a non empty directory could work the same way as deleting an empty directory: by removing the pointer to the directory's metadata there would be no pointers to the items it contained, effectively deleting all its children recursively. If that's true, then why must directories be empty before ...
I'm developing software in VB.NET and C#.NET and planning to release their source codes as fully open source. Are these projects "open-source" safe? My doubts are: VB.NET and C#.NET are using the .NET framework which is not open source. The source codes depends on the compiler and the IDE, although there's 100% open ...
Class Sub is a subclass of class Sup. What does that mean practically? Or in other words, what is the practical meaning of "inheritance"? Option 1: The code from Sup is virtually copied to Sub. (as in 'copy-paste', but without the copied code visually seen in the subclass). Example: methodA() is a method originally in ...
Let's say that a user requests for some piece of data. Usually the data is processed via a server and then returned in XML/JSON format. Im guessing another piece of processing happens to convert it into HTML/CSS so that it could be displayed on a browser. Why do we bother returning XML/JSON for API requests? Why can't...
I have a system in which I will perform queries to a database. I want Query1, Query2 and Query3 to use the same methods in their way to the data source layer. To do that I would like to make something similar to Strategy or Template Patterns, where I have a part of the code which is a default behavior for all queries (...
Are there any valid uses for the classes in the System.Collections.Specialized namespace any more or are they all superseded by the classes in the System.Collections.Generic, System.Collections.Concurrent and System.Collections.ObjectModel namespace now? The classes in the namespace are: HybridDictionary ListDictionary...
I have a first project has a feature to viewing, inserting and updating an employee record, with this possibly I will create a java class for the UI and another for the database connection with commands for viewing, inserting and updating a record. Then I have a second project that will compute the salary of employee. ...
I have a small C# project that reads a file and gives me an output: a string that does not contain spaces nor any types of punctuation marks. It may also contain a few misspellings. Ex. Output: THEQUICKBROWNFOXJUMPSOVERTHELAZYDOG I wonder if there is a way to analyze this string by using text mining/data mining and/o...
Factory pattern (or at least the use of FactoryFactory..) is the butt of many jokes, like here. Apart from having verbose and "creative" names like RequestProcessorFactoryFactory.RequestProcessorFactory, is there anything fundamentally wrong with the factory pattern if you have to program in Java/C++ and there is a use...
I've written a program in Java, it's only fairly small and I started programming and ended up just building one big class with everything inside it. The program works fine and exactly how I wanted it to, however, when writing up the documentation I've realized that it doesn't follow any sort of architecture pattern lik...
Suppose I have a list of Ingredients In My Fridge which are going off soon, and a list of Recipes which use up various Ingredients. (Some of which I don't currently have.) Is there an algorithm which produces the optimal set of Recipes, where an optimal set maximises the number of Ingredients In My Fridge used up and m...
I have the blocking code shown below. Is calling monkey.patch_all() enough/optimal to make it non-blocking? Does Gevent handle iterations like these? # front page def front_page(): database = db.posts.find() # find all items in posts collection return render_template( 'index.html', ...
We have two C++ classes named Important and Small The class Small use a few methods and attributes from the class Important, but not all. Since our application is performance critical, instead of copying all attributes (possibly pointers) of Important that are needed by Small and redefine the few methods in Small, we ...
I need a class where this can be done: // user program elder_tales.Player p = elder_tales.generate_player(); elder_tales.level_up_player( p ); but not: // user program elder_tales.Player p = new ...whatever p.set_stats(); p.set_server(); p.calculate_experience() elder_tales.level_up_player( p ) Basically, I want the ...
How do I measure team productivity over time using consistent story sizes? To take a simple example, if I can do a story every two days, then I can do five stories in a two-week sprint. By definition (as one story is two days), I will continue to complete five stories per sprint forever. In order to demonstrate improve...
I'm employing TDD quite a bit these days and really enjoying myself - everything seems to flow better and be naturally better constructed and organized. However, while writing a bit of IO code, utilizing System.IO.Streams, and I was wondering - when is it ever worth not using a factory? Because in Streams case, it cert...
public static IEnumerable<Type> GetAccessibleTypes(this Assembly assembly) { try { #if NET40 return assembly.GetTypes(); #else return assembly.DefinedTypes.Select(t => t.AsType()); #endif } catch (ReflectionTypeLoadException ex) { // The ex...
I am currently implementing a lexer that breaks XML files up into tokens, I'm considering ways of passing the tokens onto a parser to create a more useful data structure out of said tokens - my current plan is to store them in an arraylist and pass this to the parser , would a link list where each token points to the n...
As a web application developer, recently my work in creating Social Applications has taken a lot of momentum (specifically, Social Login buttons.) Is it ok to use my company's social network developer credentials for this? I don't want to sign each client up for between 1 and 20 different services based on their needs....
Suppose one would like to use in an iOS app only one function from a GPLv3 library that contains a large number of them. One cannot simply link the whole library beacuse otherwise the resulting software, having to be GPLv3, would be incompatible with the App Store. Can one "take inspiration" from the source code of the...
I was having a conversation with a colleague and although my opinion makes sense to me, I wasn't able to back it up. I'm in the process of creating an API that will be hit hundreds of thousands of times per day. It's fairly simple, and will just be doing some inserts into a relational database. There are essentially 3 ...
MongoDB is dual-licensed with AGPL (the engine) and ASL 2.0 (the drivers). In a nutshell, merely using MongoDB through the drivers does not dictate to release your source code (due to drivers' ASL 2.0 license). AFAIK, only if you directly call the mongo engine, you need to give out your code that's using it (but still ...
Consider a class that implements IDisposable, and that has members in such a way that it will never become eligible for garbage collection when it is not disposed. And as it will not be garbage collected, it will not have the chance to use the destructor for cleaning up. As a result, when it is not disposed (e.g. unrel...
I'm working on an cross platform C++ project, which doesn't consider unicode, and need change to support unicode. There is following two choices, and I need to decide which one to choose. Using UTF-8 (std::string) which will make it easy to support posix system. Using UTF-32 (std::wstring) which will make it easy to c...
I'm developing an ASP.NET webforms application with pages which displays information based on the authorization level of the authenticated user (very typical). I will write a simple example of the issue I'm facing: Let's pose I want to have a page with 4 buttons: 1- "OnlyForAdmins" button. 2- "OnlyForManagersAndAdmins"...
One has established design patterns so ingrained in their brain, that when sometimes somebody does something unexpected, it is a revelation. My colleague in an iOS project did call the delegate method from the delegate class itself. That means the delegator was not involved in invoking this method at all. Does this bre...
What is the difference precisely between an Embedded System (like Tegra, Raspberry or similar) and a Microcontroller? I understand there is a difference but I'm finding it difficult to understand. What does one intent when he says: "are you able to develop for microcontrollers"? Does it mean simply program in C/C++ for...
I have a website (which is actually mainly a Web API site) and I'd like to be able to simultaneously access multiple versions of it. What I'm currently doing is creating a new website for each version under IIS and referring to sync2.site.com, sync3.site.com etc. This solution is not very scale able nor maintainable. H...
I have a wrapper DLL that interfaces to another DLL that contains the following function: char * Foobar(void) { // BLAH is the function from the DLL this wrapper interfaces too char *array = 0; // Set up an array pointer for dynamic memory allocation. int NumOfChar = 0; // Build array for (int n=...
Is it possible to convert a list of object directly to byte[] (and vice versa) to gain performance (by avoiding serialization/de-serialization)? What I have in mind is that a list is somewhere in memory(heap). If I could read the bytes in heap for my list I could just assign it a variable (of byte[]) in my program. Is...
I'm creating a 2D game in plain ANSI-C using SDL2. I'm planning to let users create their own graphics. So, to achieve this, I'll use an information file which will hold some data such as Width, Height, X and Y position of each frame. But I have two views of this. One is to use a single file which will hold the informa...
Let's pretend I work on a project tracking application. The application is a database backed, server hosted, web application. In this application there are Projects which have many Activities which have many Tasks. A Task has two date fields an originalDueDate and a projectedDueDate. In addition, there are dynamic f...
Every developer advocates test-driven development, but I am coding a website in NodeJS and I am not testing my app. This is not because I don't see any reason. I know it allow me to check at each commit whether my code is right, thus avoiding security flaws. I don't do any tests because I don't know how or what to test...
I'm pretty sure that the following two snippets are equivalent but I wanted to double check: CALLBACK STYLE function foo(input, callback) { // do stuff with input callback(); } function bar(input, callback) { // do stuff with input callback(); } foo("hi", bar("bye", function() { ...
this is my first time here. I'm a physics grad student and I've recently found a research group to work with. We study statistical mechanics using computer models, so there is a significant programming aspect to it. My first job has been to take the old data analysis code (written in java) and clean it up in c++. The ...
When building a unit test, is it appropriate to use a mocking tool to assist you in setting up an object even if you will not be mocking any behavior or verifying any interaction with that object? Here is a simple example in pseudo-code: //an object we actually want to mock Object someMockedObject = new Mock(Object.cla...
In mark-sweep-compact garbage collection algorithm you have to stop-the-world when relocating objects because reference graph becomes inconsistent and you have to replace values of all references pointing to the object. But what if you had a hash table with object ID as a key and pointer as value, and references would ...
I have a function which receives a buffer and returns some data in the buffer. The data can be smaller than the buffer capacity. Which is the best and safest API for this? int fn(void *buffer, size_t buffer_len): the size of the data written to buffer is returned by the function. Downside: the return value must also h...
So while I've been doing some lengthy compiles I decided to take the C++ general test on ODesk and came across this question. If I'm not mistaken, given the wording (or lack thereof) all of these could be true. a. int Foo() { } int Foo(int bar) { } b. Well, return void; would be incorrect semantically but functions ...
Imagine your customer want's to have a possibility to add new property (e.g. color) to product in their eshop in their CMS. Instead of having properties as fields: class Car extends Product { protected String type; protected int seats; } You would probably end up doing something like: class Product { protecte...
I'll keep it simple, I want to make C#'s methods work like javascript's functions. Mainly so I can convert this - function makeVariable(terp) { var me = {value: 0}; return function () { terp.stack.push(me); }; } into C#. Is there ANY way, no matter how complex or time consuming, to do this?
In most MVC web projects there is a User class. Many times a user has something else in a one-to-many relationship, i.e. orders. If we have a user class that has many orders, should methods that add, edit or delete orders for a user be placed in the user class, or in a separate Order class? i.e. 1. user.add_order(order...
The project I'm currently working on has an issue: bugs and tasks are often assigned to people who are too new or too inexperienced and their work ends up producing more bugs down the road. The problem is that parts of our software are much more "dangerous" to work on than others due to code quality issues. I've been t...
I'm building an Internet of Things solution that has a number of real time feeds. I need to make a couple of design decisions with regards to the data store and reporting and looking for input. I have two deployment models, local where a small Linux server captures multiple streams usually a new data point each second ...
Imagine there is an application (ASP.NET MVC) that processes some documents. The document must be revised several times by different group of users. state/role rules: simple user can only publish document; (priority: low) userGroup1 can switch it to next state or reject it; (priority: higher) userGroup2 can confirm p...