instruction
stringlengths
34
36.1k
We have a Unit Test Case where we want to assert that after a login operation, the SUT is able to call a method on one of it's dependencies. This dependency is a NavigationManager and the expectation is that it calls NavigationManager.NavigateTo(string). Up to this point, we are mocking the NavigationManager to isolate...
I'm creating a programming language as a hobby, but I encountered a problem with designing its syntax. The problem is the conflict between the syntax for defining zero-argument functions and the syntax for reassignment operations. The function definition syntax is taken from Haskell, and looks like this: name arguments...
I'm trying to decide the best way to handle communication between a UserControl that is nested within another UserControl and the parent Form itself. I have a Form, inside the form there's a UserControl with a TabControl. Each tab in that is also represented with a UserControl. An object (for binding) gets instantiat...
For example: if(5.0f > 1) { } Does it have a significant performance penalty? Compared to just doing if(5.0f > 1.0f) { }
Modify the car painting example car.color = favoriteColor ||"black"; so that the car is painted with your favorite color if you have one; otherwise it is painted with the the color of your garage: otherwise it is painted red. I am missing some functions. This is what i have: car.color = favoriteColor || "red"; function...
I recently followed the Django API tutorial. http://www.django-rest-framework.org/tutorial/6-viewsets-and-routers/ When I initiate a POST request my intent is that after inserting the record into database, launch a process. Example: POST server/ Will insert a new "server" record, return 201 to API client and behind t...
I did one AngularJs app which was rather complex, with multiple nested tabs, which had multiple nested views & controllers, needed ng-router, and was quite tricky for me to implement, as browser based coding is not my usual thing. Now I have been asked to code something for a friend. He was to have a column of buttons ...
I have reading about SOLID principles last week and decided to try to solve real world problem by using them. So I got the problem of real world ecommerce site managing totals. Problem Statement: We have to calculate some totals like subtotal, taxes, vouchers, coupon, total on a cart products. So I have decided to ma...
I have a stage in an interview process where I am supposed to do pair programming, or at least they want to see me working in Visual Studio with an experienced developer. This is a company promoting Scrum. How should I behave? How should I prepare? I would think I should prepare for NUnit and perhaps MS-Test. Are the...
It is exciting time of having Babel and being able to use all nice nice features. It got me thinking, what happens in the future? Nobody really talks about it. I mean some browsers would eventually implement different features according to specs, some will be lacking behind. Babel allows us to selectively disable any f...
I referred Compiling vs using pre-built binaries performance?. The post talks about performance and opportunities for optimization. My question is about reliability. I built both python and postgresql from source and they are running good on my development machine. I am planning to do the same in the production environ...
I am developing an App for iOS. In an attempt to avoid the pure MVC where everything is packed in the "Controller", I have added a Presenter layer and an Application Layer. In doing so I have come up with some questions that I need to clarify to do the things right. The questions are kind of conceptual, so it doesn't m...
I have seen other peoples code and each person has a different way of declaring variables. And I have been told by quite a few people that declaring variables in the Global Scope is wrong. My question is why is it wrong and what is the correct way of declaring variables while writing any software, application or system...
I know this is a language specific question and may not be suitable here but I would like to create an array of functions that will be called based on their index and I would like to know the difference between Delegates and Actions. I am aware that with delegates you string many of them in a single one and pass values...
As I start to code more and more, for example in C++, I tend to also want to learn more about the accepted standards for code. I'm trying to code a chess engine right now, but I'm unsure how to treat each 'module' of the program (which is separated into different files). For example, it makes sense to make a class for ...
I'm currently building a enterprise MLS / IDX system and I'm just wondering if there is any type of special considerations to be taken outside of outputting the data in the forms that external web services want to use/consume etc. I'm wondering if I need to register the system or have it approved by anything? Right no...
Our system is fundamentally a multi-tenant setup, where each client maintains a separate database with its own data and users. The authentication system on login issues an authentication token which is returned to the user on login; the login request contains a unique client code identifying which tenant the user is at...
In my application, I have a lot of SQL queries that have business logic embedded in them. For example, in searches I 'hide' results that are low ranked, less than -5 'community rating' because those results contain spam, inaccuracies, etc and have been flagged by the community. In my SQL query, it might look like: SELE...
A while loop can be written as follows in C# (and many other languages): int someValue; int someTerminatingValue; while ((someValue = GetSomeValue()) != someTerminatingValue) { // Do something interesting } Is there a name for this pattern of assigning the value inside the while loop's expression? NB I'm not aski...
Background: I'm writing a genetic algorithm to be used to control the weights of a neural net. To specify the bases ("bits" of the code) of the "DNA", I'm allowing the caller to pass in a List<T> of all the possible bases. When I need to mutate a base or generate a random sequence, it will be based on this passed List....
I tried to write the following: public class AdjacencyList<Vertex> { Map<Vertex, Set<Edge<Vertex>>> adj = new HashMap<Vertex, HashSet<Edge<Vertex>>>(); } But I get the error: Type mismatch: cannot convert from HashMap<Vertex,HashSet<Edge<Vertex>>> to Map<Vertex,Set<Edge<Vertex>>> Eclipse wants me to change the l...
First of all, i'm not talking about validation in the sense of the nullability or length of a field like in this and this questions where we can use isValid() methods in business classes or an external Validator. However, my question is related to validate or not in business classes. I'm using a layered architecture st...
A framework I'm writing (for learning) requires a specific PHP version to run, so I'm implementing a "PHP version check" to ensure the running PHP version is the minimum required for the framework. Basic setup htaccess redirects everything to index.php (front controller); index.php loads bootstrap.php (nothing else);...
I want to make a fairly complicated mathematical library for a personal project and then have a visualization/GUI to go along with it to demonstrate the maths - nothing hardcore like topology but just show the outcome and have some small animations to demonstrate. The library will involve matrix operations and I'd like...
I am looking to write an algorithm to cut rectangular images and straighten them in a new image. The bigger concept is that I will be scanning a bunch of physical pictures (on a physical scanner). They're all the same size (give or take a couple of pixels) and I can make sure they're all separated, so they're absolutel...
I've been working on a game the past few months and I'm finally starting to approach issues regarding the in-game economy. The game is sort of like an MMORTS, players create their own nations and they have cities all over the world map. I want players to be able to trade resources between their cities and other players...
I am programming a database similar to Cassandra. I use C++. Simplified database store its data in one or two "memory table" and several "disk tables", all stored in single directory. I have class that dealing with single "disk table" and another class for "memory table". I need to make a class that deals with array of...
In pre-Java 8 lambda-heavy libraries like Guava, the outputs use common Java Collection Framework interfaces so is easy to pass them around to external/internal APIs and still harness some lazy computation if the library method does it (e.g. lazy filter() and transform()). However, in Java 8 Streams, the call to get a ...
I've been reading some articles on how Rust does error handling using the Result<T, E> type and to me it seems like a hybrid best-of-both-worlds (exceptions and return codes) solution which can be very useful. I think it would especially be handy for APIs where you don't really know on beforehand if certain errors are ...
I got the models Post and Category. A Post is assigned to a Category. A Category has many Posts. They should be stored in a database. I implemented the following classes for it: Models/Post.php: class Post { /** * Title of the post. * * @var string */ public $title; /** * The categ...
Imagine that I have a method like User::validate($data), and mostly the developer expects only that is returns a boolean (true mean "ok, validated with success"). But, in some specific cases, he need check why validation failed. What is the best way to check that? I thought in following ways: Use an argument like User...
We're looking to hire a new junior C# developer. We're not looking for guru's or anything, so my boss asked me to write down a few questions and answers of varying difficulty to assess their skills. My first question was "What does the using statement do". So far after 2 interviews (both fresh out of college I think) b...
Having programmed a whole lot in python, using nested functions is a good way to not clutter the namespace with small helper functions that are only used once. Now I'm programming in go, and upon writing some code that I immediately wanted to refactor into an inner function, I found that go does not allow nested funct...
I'm trying to decide what's the best approach to instantiate a particular class. Basically there are two use cases for it: instantiate it in order to save a new entry to the database and fetch an existing entry from the database (and maybe edit the fetched entry and save it back to the database). The issue I'm having ...
I was just reading an article online about fork().According to what I get,the fork() system call creates a subprocess and the program counter is updated to the next instruction and the control is passed on to the child process and then control comes back to the parent process.On exectuting the following program: print...
We have 100 000 fractions: Let's consider following fractions. p/(2^q) such that 0 <= p,q <= 10 As you can see there are <= 10 * 10 different fractions, but we have 100 000 that we have to sort them (so there are little unique elements). Task is about thinking fast algorithm to sort fractions. I ask you for looking a...
I'm currently building a REST API in PHP & MySQL, and now I'm stuck at how I should structure the classes and the database connection. Let's say I have a table in my database for movies. How should I structure my code for connecting to the database? Currently I have this: <?php //Db.php class Db { private $db; ...
Suppose I have code that accepts html GET requests: server.get('path/to/some/endpoint', function(req,res) { function a() { //function goes here } } Is it better to declare functions (like a()) outside the server.get's callback scope? What are the pro's/con's to each?
I'm trying to get a better grasp of the applicability of object-oriented programming and design. I'm curious about some examples of situations where object orientation is not simply inefficient or overkill, but highly inappropriate and entirely not recommended. Nowadays it seems that OOP can be applied to a very wide r...
TL; DR: Is the output from a feed-forward neural a direct result of the activation function? I.e: If the activation function is the sigmoid function, will the output always be between 0 and 1? I'm having difficulty understanding the activation function, and the output of a feed-forward neural net. From what I underst...
I've been reading through an old-ish book on MUMPS ("M Programming", by Walters) to try and get some historical perspective on the language. The book was published in 1997, and provides the following list of then-extant vendors (I don't know whether this is exhaustive): InterSystems M (for Windows 9x/NT) InterSystems...
I'm under the impression that an object MUST support all methods/properties upon being initialized or else the program will create an error. However, if you see below I am defining 2 variables (doc and el) as htmldocuments. Thus any object assigned to these variables must in theory support all htmldocument methods/pr...
I was reading a tutorial on C++ as I am new to programming, and I was wondering why the sizeof operator gives different output depending on what you're programming with.
I've spent a great deal of time researching a solution to my issue with very little success. I'm rather new with .NET and vb.net so I apologize if this seems simple to anyone else. I had a first version of what I am trying to do which worked fine. I will provide sample XML and the vb.net code I used to render it. A...
I'm new to android developing and maybe my question is strange. If I want to make commercial apps, libraries, or services for android and use Google Android Studio + Oracle JDK (not OpenJDK) is there any problem? Do I need to buy license from oracle?
I'm currently interning at a company where I've been tasked with building an application from scratch. I've been working about 8 weeks, with 4 left to go. I've written a lot of code in that time, but now as I go over it, I'm realizing that it's really quite inefficient, ugly, and going to be hard to maintain for whoeve...
I've noticed while browsing Stack Exchange that there are dynamic notifications like "3 new messages, click to show". I want to have this kind of dynamic updating for what I'm about to explain. Let's say I want to create a carousel/slideshow of 10 recent news articles. I want this carousel to be updated hourly, in a qu...
For my project, I need to map integers so that inputting int X will output int Y where both X and Y are defined during runtime. I've used Dictionary<int,int> in .NET but its memory use is too high and the access speed is too long for my case. Instead, I want to make a custom class that essentially does what a Dictionar...
I work in a SaaS project in which each user can have a representation of some common data at a given point in time. For the sake of example, let's consider that each user's data is metadata about them persisted separately on disk as a JSON file: { "name" : "Bob" } As new requirements come along, this underlying repr...
There is a data structure idiom that looks something like this: [ { obj_1_id: { key1: value1_1, key2: value2_1 } }, { obj_2_id: { key1: value1_2, key2: value2_2 } } ] I've run into this a few times, and I have a number of issues with it. Fo...
The entity translator provides a function that takes one or more data contract classes as parameters and returns a specific business entity. Within the implementation of the function, a new instance of the business entity is created and initialized using data from the data contract classes. After a new instance ...
I have been thinking what could be the fastest way to show base64/img data to the user, i could generate the data when the user is registered and then store it to database, or generate it every time it is requested. this is something i am thinking to make the response fast and i could just generate the img data in clie...
So I'm making a method to create a salutation line based on two people from a database. There are four parameters: the two names (name1 and name2) and the two genders (gender and gender2). For every gender combination, I have a kind of different output. For example: if gender 1 is M (man) and gender 2 is also M, the ou...
JavaBeans and ActiveX both serve the same basic function: to facilitate communication among software components within framework "containers." These containers include Web browsers and other document viewers. Courtesy ActiveX controls and JavaBeans have a great deal in common. In fact, it’s not too challenging to map ...
I need for my app to consume a rest api service and since I will call it from javascript/jquery i need to expose it to the end user. In this case I would also need to expose credentials to the end user, which is something I would like to avoid. As an alternative I am thinking of using a token that would replace sensiti...
Context: User wants to edit entity details, say user name. Assuming the fact that the Read Model is eventually consistent with the Write Model is it conceptually wrong to query write model in order to get the most recent state of an entity for the page? If I choose to query the Read Model (typical implementation accor...
What are the benefits of using runtime proxies with an ORM provider like Hibernate or EclipseLink compared to bytecode instrumentation/enhancement? I know that bytecode instrumentation helps to optimize dirty checking. Because it can intercept modifications, ORM provider doesn't need to traverse all the objects in the ...
Let assume, I have some resource and time-consuming code, which I want to arrange as a separate method. In order to optimize the performance, this code should be executed in the separate thread. Now the question, where to define this thread: Inside (built-in) of this «heavy» method; Or to wrap the execution of this «h...
When I'm in charge, I typically model services separate from endpoints. For example: Company.Project.Domain.dll has all of the logic required to complete the services for that domain. In order to access it you either reference that library or, if I'm exposing the services through an endpoint, you can hit Company.Proj...
I am shifting from procedural C programming to OOP Python programming and I faced some problems while implementing binary search trees. I cannot make my Tree_Node null in case of deleting it. In C I could do this because I would handle the case in the function as follows: void insert(Node tree, int key) { ...
I was just brought onto a project with a service oriented architecture. There is a central WCF "profile service" that all projects call to get information on users etc. That central profile service in turn calls several other leaf services to CRUD user information. One of those leaf services is a third party service t...
A little background first: where I work we maintain about 40 .NET applications of varying size. These apps share many secrets (account credentials, connection strings, etc.) in configuration files. We encrypt all of our configuration files during build. However, our approach still has disadvantages: Whenever a cred...
We developed a product (prototype) P_OLD in language X and we are now rewriting it from scratch as P_NEW in language Y. Since P_NEW and P_OLD are the same product: Should P_NEW just be a brach of P_OLD old or should it be its own repository? What is the usual way to handle such big changes form a version control per...
In the current project I'm working on, some of the C# classes are being stored as source code in SQL Server database records, and executed as needed using CSScript. This is being done so that the server doesn't have to be taken down to replace the assembly in which these classes reside. While this seemed like a good i...
I'm making a website which has to do with money transactions. Everything was okay untill I came across the dilemma Should I have one table to store all transaction history or I should have a seperated table for every user? I tried to logicaly think the best solution and this is what I thought: One table for all Pretty...
So I am attempting to make an application based on the architecture proposed by this image; (source: ibm.com) [1] However, I am getting very confused with how data access is achieved between the data access layer which is on a seperate tier (from my understanding this means a seperate server/machine) to the database. ...
I am trying to build a simple chat messaging app with Android. I have an Android Studio project with a Cloud Endpoints module. I use this Cloud Endpoints API which is published on my Google App Engine project to communicate with my Cloud SQL database. I can do things like insert rows or delete them. The Cloud SQL datab...
Sometimes I want to delegate the construction of objects that a class owns to a separate function. Something like Vertex* new_vertex(const Options& options) { // do stuff... return new Vertex(...); } where the function is only intended to be used to within a class that owns the Vertex. Clearly this function can ca...
After contributing some weeks I noticed that the author name in my commits were incorrect. Does changing the git history with author info in the commits create any problems for my fellow contributors?
I want to write a closed-source desktop application that uses a piece of GPL software in the background. I know that I can't link to a GPL library (libgit.a). But if I embed a GPL application (git.exe) into a closed source application, unzip the GPL app to a temporary location, and then make calls to it using some for...
I am a Swift developer and am trying to adopt a functional / reactive style in my code. I have been using ReactiveCocoa in all my projects and I have started giving RAC 3.0 a try. One thing I have seen is that in project, there is heavy use of curried functions that have a global scope (i.e. not tied to an instance). ...
I'm working on an hybrid mobile application, and I'd really benefit of having the app version, OS build and screen sizes of the users that issue our API, just to know if issues come up due to a poorly developed feature or a bugfix that can't fulfill everyone's problems. That way, in a semi transparent procedure I'd be ...
Can someone explain if creating an object of a class that have in constructor the super call and the super class are missing from dependencies jar could throw a null pointer exception? e.g. a class that ApplicationFrame extends javax.xml.ws.Service and as construct let say it's: ApplicationFrame(String wsdlLocation, QN...
I have an interesting constraint/invariant and I would love to hear people's input on how to maintain it. Big bonus if it can be ensured at compile time... I have the types below, and the following conceptual invariant... If an attribute's id equals an attributeValue's id, then they must have corresponding types. How w...
I have a game that deals with opening and closing doors and the Door Engine deals with IDoor interface which has Open() and Close() contracts So far so good. the game is tested and works fine. Now a new feature is required, doors can be automatically closed with a timer, i.e a new contract- SetTimer() is needed. Only ...
I'm trying to understand how threading works when using a single core, not hyper-threaded processor. I have two identical console applications running on a machine that has one core CPU and 1 GB of memory. In this console application, I have a method that starts a new Thread(). I know that when we Start() a new threa...
In OOP coding, there is a long standing naming convention to name accessor/mutator methods getThing and setThing. These directly manipulate the properties, which are often private. Should these naming conventions be 'reserved' solely for manipulating the object properties? or can they be used in other methods - getFile...
I'm working in an environment where we regularly start working on a feature and then are directed not to release it. We then create other features that we do want to release. My typical workflow is write feature -> commit to default. This workflow has worked well historically but in this environment breaks because we ...
Assuming we are talking physical tiers, my understanding is that in order to pass data from say the data tier to the business logic tier the JSON format is used (or XML), so say I have an ORM (Hibernate) as part of my data access logic, I then serialize the resulting Object (pointed to by a REST call from BLL) to JSON ...
Experiment: I have found it is possible to define both a "Module" (Namespace?) and a "Class" (Namespace?) within a single .Vb element (Module??). You can try this at home: Create a new Console Application Project. *A new .Vb element named "Module1.Vb" is automatically added to the project. Add a new Class .Vb element ...
A coworker and I have differing views on how strictly we should adhere to the MVVM concepts. I try to follow it as closely as possible where he takes shortcuts almost every chance he gets. One of my biggest annoyances is when he has views binding to models. His justification is that a viewmodel would just be a reimplem...
I am learning OOP - I have read this answer a number of times and now slowly start to understand some of the practical uses of public interfaces (getters and setters). I understand there is no need to provide public accessors/mutators to every single object property as that breaks encapsulation. However, in the answer,...
I'm trying to switch my brain from Node.js/Objective-C iOS programming to C++ programming, and it's a little bit taxing. Node.js and Objective-C with iOS do not have a run loop that I am supposed to manage. So please also help bend my mind to the different concepts. I am setting up an EAGI program for Asterisk (http://...
I have multiple forms and use AJAX to submit them. I asked my boss if he needed any specific format for the form ID and he told me to generate a unique hash and keep it in session; check it whenever the form comes back to make sure it's a valid form submission and not someone just hitting an endpoint. What does that me...
What is the fastest way to divide two 256-bit integers? They are represented as an array of 26-bit words, each stored in 32-bit integers. I have access to a 64-bit type if that's useful. It seems like fast division methods in the literature all assume we are dividing a 2n-word number by an n-word number. Is there some ...
I am about to embark on a large analysis/data extraction project, which I intend to do with Python. My data to analyse consists of tier 1 files that include some details. and each file points to several tier 2 files. Each of these tier 2 files includes more details and references to PDF files (tier 3) that might need t...
I've recently started to work on an old project, that was originally written by two professors with no programming experience. Those professors left the project before they have finished it. Meaning there are many files that no one knows what their purpose, or if they are working at all. In general the code is written ...
I am trying to solve a quora hackathon challenge question. The question descrpition is as follows : For the purposes of this problem, suppose Quora has N questions, and question i (1≤i≤N) takes Ti time to read. There exists exactly one path from any question to another, and related questions form undirected pair...
For avoiding non-trivial C++ const related duplication, are there cases where const_cast would work but a private const function returning non-const wouldn't? In Scott Meyers' Effective C++ item 3, he suggests that a const_cast combined with a static cast can be an effective and safe way to avoid duplicate code, e.g. c...
I'm working on a website that needs to stream live video to users, and as such I've had to get my head around the sorry state of current browser-based video-streaming technology. The most popular solutions for live streaming at present all have compatibility issues; RTMP requires Flash, HLS is only natively supported o...
What is best (or commonly accepted) practice for where to declare COM object variables (scope) and how to handle cleaning them up when using structured error handling? I just spend a whole load of time learning about Garbage Collection and Reference Counting and dealing with releasing COM objects in .NET. Working with...
Several times in javascript I've seen a constructor function take in one parameter. The constructor will initialize all the fields for the object to default values and then use the parameter to overwrite a select few properties. This way you can create a mostly default object save for a field or two with all the remain...
From PHP manual: array array_change_key_case ( array $array [, int $case = CASE_LOWER ] ) What does comma signify in a function definition?
I'm new to using Java within a web environment. At the moment I have a Java application that we run on a local machine, we'll call it the server app. We want to add the ability to communicate with this application by means of a RESTful interface. I've been playing around with Tomcat and Glassfish and I have something t...
I have a security method I would like to be able to sprinkle into other classes throughout my program. It is currently an abstract class but I feel it would be more appropriate as an interface. Can someone help me convert it? I wasn't able to call PrincipalIdentity() the same way I could with it being abstract. public ...
I want to create hash based on random id, That hash has to be valid for only 15 minutes. Is there a way to do that? I'm using this for form submission. If some unknown submitted form or some one submitted after 15 mins I should be able to figure out when it was created? I am storing random id in session and when user s...
I've heard that it is recommended to validate arguments of public methods: Should one check for null if he does not expect null? Should a method validate its parameters? MSDN - CA1062: Validate arguments of public methods (I have .NET background but question is not C# specific) Motivation is understandable. If a modu...
I built a neural net, and planned on optimizing the weights using a genetic algorithm. I was informed though, that this isn't a good idea, and to look into backpropagation. I searched around, and found either very superficial overviews of the algorithm (which conceptually isn't that difficult), or very in-depth guide...
I originally started writing a question on StackOverflow about a clever way to optimise keeping a version history of large text fields in a relational database table, possibly by using deltas instead of incurring the storage cost of a full copy of the changed text in an audit table on each update, which is regularly su...
Using python syntax with below environment diagram, teacher taught us that there are 11 trees(orange boundary) in this diagram, including leaf. It has been taught here, lists are represented as a row of index-labeled adjacent boxes, one per element. Each box either contains a primitive value or points to a compound va...