instruction
stringlengths
34
36.1k
I'm fairly new to programming and am currently creating a blackjack game in Java. I've progressed quite well, although could use some pointers with regards to the best way to implement a method. At various points during a game of blackjack it's important to show the user what cards are in their hand. I have a PlayerHa...
I'm implementing a data processing software. The software gets form the network thousands of events that must be processed in according to rules. I implemented a multi-thread service, which receives the event and insert it into the processing engine. This means, each incoming event creates a new runnable task and retur...
At some point a program is in development. Features are being added or removed or changed all the time. Every version is nothing but a prototype. So I don't waste much time on writing super clean code at that point because I never know how long something lasts. Of course I try to keep the code quality to certain standa...
We are using Scrum for more than a year now for a mobile game project. We use a printed Excel sheet pinned on cork board almost similar to one here on mountaingoatsoftware website. During the sprint we need to take customer approval mostly for design to mark that task as done. We put a question mark in the progress cel...
We have System A (an application and a database) that is built for a specific business department and therefore has business aligned data model and table structure. System A is a mission critical application. Downstream systems, as part of their business processing flows, retrieve data from System A via stored procedu...
I'm designing a system from which I will synchronise business data from the mobile device (that have an embedded application) that generates data and sends it back to the server. Each line synchronised generates a specific business log in the database. If what I synchronise generates data with a date (within the sync ...
The scenario is this: I have web based service that does regular request processing and it's doing persistence into db etc.. Fast response to the client is crucial. So now the average request is about 100ms which is great. The problem is that i need to send parsed request that I receive to the 3rd party service on anot...
We're building a new app and I'd like to include structured logging. My ideal setup would be something like Serilog for our C# code, and Bunyan for our JS. These would feed into fluentd and then could go out to any number of things, I was thinking initially elasticsearch + kibana. We have a MySQL database already, so i...
I've been thinking about this problem for a while, and I can only find a recursive solution but I'm feeling that there is a dynamic programming way to do it, I just can't figure it out. Is this a famous problem I don't know about? Q: Given a string and a pattern , return the number of unique ways of matching the lette...
I was wondering, if I have a black and red tree and I want to keep track of the number of nodes in the subtree, what is the most effective way to do so? I mean how do I work with these values while insertion, deletion and rotation of nodes, so that I don't have to process the number under every node again?
I work for a company that has a very large government contract. As part of the realities of a government project, we are bound to process requirements that come down to us from the Department of Energy, and are responsible for meeting those requirements in our Software Quality Procedures. The way we do most things aro...
I'm building an app that requires the user to purchase content and sign to a User Agreement Contract. However, I'm not too sure where to start with in-app purchases and saving data types to the users device permanently. My initial idea for the UAC was like such: boolean ucaCheck; user clicks button to agree making uacC...
We're doing a lot of unit testing and refactoring of our business objects, and I seem to have very different opinions on class design than other peers. An example class that I am not a fan of: public class Foo { private string field1; private string field2; private string field3; private string field4; ...
What is easier to understand, a big boolean statement (quite complex), or the same statement broken down into predicate methods (lots of extra code to read)? Option 1, the big boolean expression: private static bool ContextMatchesProp(CurrentSearchContext context, TValToMatch propVal) { return propVal....
Consider a test suite like this: public class MyTestSuite { @Test public void test_something() { testHelperMethod("value11", "value12", "value13"); } @Test public void test_something_else_meaningful_name() { testHelperMethod("othervalue21", "othervalue22", "othervalue23"); } // ... ...
I have two inter-related questions about attributes and dir(): What are attributes? Is it an object inside of another object? Or is it a method, property, etc? When you do dir(), what's the differences between the slots and the rest of the attributes?
I am working on a project to create a wrapper library which will be used to interact with a web service provided by the client's IT team. The reason for this library is that we interact with this service across multiple projects and we wanted to create a single library to interface with the service. I am planning on h...
I am a software developer, and I work in a small web development company. It seems to be a recurring theme that a middle-manager will ask me how long something will take, and when I give them my estimate, they think it is too high. If it's a more technical manager, or another developer, they will usually already have i...
I work in a system that can represent a "shipping estimate" in two ways: A specific date: The item is guaranteed to ship at that date A day interval: The item will be shipped "X to Y" days from today The information on the model is semantically the same, it is "the shipping estimate". When I get the information about...
I have an unpoliced piece of software and I must implement some control over who can install it via licensing. I already have an authentication server that implements OAuth 2.0 and OpenId that's used to control access to different API's Should I use OAuth authentication as a way of licensing? I can set the licensed dev...
I manage multiple apps in my dev: /var/www/ qa jt auth We have a QA vagrant which runs QA app in its own vagrant. My understanding was that each app would run its own VM but this would cause some issues such as: some apps require other apps to functions - for example, QA requires Auth to authenticate to fu...
I feel like, in web dev at least, that integration tests can't really find any useful bugs. I can't think of any, at least. If I can use unit tests to verify that one section of my code calls a certain method, and that another section of my code responds properly when it receives the exact same input, then what's the p...
I'm refactoring our current design for how we download static data. It's a mess of deep class hierarchy and callback hell and I want to convert it to a more elegant straightforward design. Here are two examples of the steps we take to download static data (JSON files): Example one, downloading main manifest: Attempt t...
When using the Visitor pattern, I have observed the following: The visitor has weak dependencies to concrete types (each visit method has the concrete element as a parameter or is a method that corresponds to a concrete element) The element (supertype of the concrete types) has a weak dependency to the visitor (the ac...
Reminder: If you have tips, please remember to put the reason objectively, such as "having two distinct SetInt() functions in the same file violates reader expectations that they'll be overloads, and stymies the ability to find the right function with ctrl+F." Problem: Occasionally, low level/dangerous APIs are needed....
I am very new to programming and a bit confused from reading\hearing different conventions from different sources: Does Object-oriented programming have 4 or 5 concepts? As a newcomer, I understand these are the 5 concepts: Abstraction Inheritance Encapsulation Polymorphism Modularity So how come I don't find a more ...
We have a PAYROLL issues by the client to make it dynamic i.e. to make the whole process computerized. It includes: Employees Allowances (Scale wise, which could change yearly or monthly or anytime) Incentives Some Allowances based on experience and districts Some allowances are calculated by applying 45% to the b...
Suppose I have a binary vector of sample size N with each of the two possible values (e.g., 0 and 1 occurring equally often). For example, if N=10, the binary vector is: 0 0 0 0 0 1 1 1 1 1 Suppose I have another parameter called 'limit' which indicates the maximum amount of times that the same number can occur consecu...
I have a few more related OOP Python questions: What does these attributes do exactly: __get/set/delattr__? Why not use just Myclass.NewAttr = value instead of __setattr__? Why does Python use __dict__? It keeps the attributes in the end of dir() anyway.
I have a large XML file that I extract information from. I am extracting the information using a list of classes with a main method of the type ParsedValue[] GetValue(BigXmlFile). This is a bit like a list of commands or strategies. Does this have a name?
I have an application built using an MVC framework (for argument's sake, PHP/Yii2) and have a question regarding where to carry out logic and generate values which will be injected into, for example, IndexView or AboutUsView. In this instance the 'About Us' page is displayed when the route /about-us is hit by a browser...
I'm working on a kernel for a proprietary embeded system. I've had no issues but I'd like to expand its capabilities directly. I made it run C. I did so pretty much by giving my kernel a stack. My question is C only required a stack to be able to execute cross-compiled code. What beyond a stack would I need to provide ...
Let's say I have a grid with square fields. For the fields I have an abstract Field class. This class has several subclasses, for example EmptyField or RoadField. Some of these fields can be connected to each other, thus I have an interface IConnectable that these classes implement. Now every connectable field should h...
Currently we need to interface with a REST API. The only problem we have implementing this is choosing the right approach. We’ve done this by using Resources – for example a Photo Resource that has certain methods to interface with the REST API. The only problem with this approach is that each time we use a certain Res...
I'm fully aware that pylint and other static analysis tools are not all-knowing, and sometimes their advice must be disobeyed. (This applies for various classes of messages, not just conventions.) If I have classes like class related_methods(): def a_method(self): self.stack.function(self.my_var) class m...
I'm using Visual Studio 2013, .Net 4.5 and SQL Management Studio 2012. I have a table that tracks offices in my database. On the application side there are a some display rules regarding the layout of offices. If a building is remodeled, offices are renamed, and the old offices can become inactive. It is important ...
I have a rectangular grid of square tiles, some of which are blocked/filled. I start at a random tile inside the grid with the blocked tiles, randomly placed. I can turn in 90° steps and check whether I can enter the tile in front of me, which is possible if the tile in front of me is not a blocked tile or the edge of ...
Background We have a piece of programmable hardware here at work that we integrate into almost all of our systems. This piece of hardware came with a native Windows DLL (for which we do not have the source code) as well as a wrapper to said library. This wrapper is responsible only for marshalling the calls to the nati...
I'm writing a brand new system and trying to stay true to the SOLID principles, specifically Interfacing and Dependency Injection. We are sticking closely to the Microsoft stack so we are using C# and the Unity container. I am in a relatively immature shop as far as SOLID concepts go so I try to keep things as simple...
Working on an API... Consider an example database like the following for some enterprise-facing application: +-------------------------------+ | tables | +-------------------------------+ | account_achievement_mappings | | account_company_mappings | | account_document_mappings | | accou...
I'm talking about very small changes such as spelling or meaningless syntax fixes. After committing a new pull request, sometimes automated checks are executed. Which is one reason I'm wondering if it's wasteful to do and commit minor changes on github directly as opposed to doing it all locally and only committing occ...
I'm trying to implement an autocomplete feature for a search engine. I have a database of words(stemmed) that occur in the documents that I have for users to search. What I am thinking of doing is: Constructing a graph with words as nodes and weighted edges with weights as the number of times those 2 words have been...
UML class diagrams (1st pic) and frames (which belong to knowledge representation and artificial intelligence) (2nd pic) look pretty alike. But do class diagrams exactly type of frames or they just look similar?
This is my scenario, I have this interface: public interface hitTheDataBase { public void insertMe(String [] values); public void modifyMe(String [] values); public DataTable selectMe(); } And I have these two classes that implement the interface: public Class hitSqlServer implements hitTheDatabase { p...
I'm trying to create an api which has a login that issues a JSON web token and then offers a handful of resources to authenticated requesters. User is a type of resource, and this is where I get confused about routes. In some cases, authenticated users GET information about other users, like this: /api/user/<any user ...
The synchronizer token pattern is the most effective protection against CSRF attacks. I understand the theory and implementation, but I do not understand why it can't be circumvented. Generally, the process requires you to visit a malicious site that has a hidden URL that will perform an action against the authenticate...
For a system that consist of multiple services calling each other (e.g. Front End -> Backend -> Storage), I often heard people using terminology such as "downstream" or "upstream" services. I'm not clear which direction these mean. Data flows in both direction. Requests flow from more user-facing to more backend servic...
Imagine I have an interface: public interface MyInterface { void CallMeFirst(); void CallMeDuringApplicationLifecycle(); void CallMeOnApplicationExit(); } What is the best way of enforcing the order in which the methods on this interface are consumed by calling code? It should be an exception if the method...
I never understood this: why is it that I can't seem to find a core collections api somewhere that Allows me to retrieve elements that have a direct .next() or .previous() method on them without all the boilerplate or having to implement my own version of a LinkdList. The benefit? I can iterate directly over my returne...
Does a software license have to be in text format? I am thinking of adopting the MIT license to my software. I have a documentation in HTML format, which is distributed together with the software, and am thinking of including the license in it at the beginning. Will it be effective if the license is in HTML? I can also...
This is one SW development problem that hits the sea of developers as they crash into the rocks of management. Somewhere down the line the estimate given by the programmer gets translated to a date and quite soon it translates into a deadline. Against this ticking bomb, efficiency can be increased, quite often quality ...
Is the visibility private of class fields/properties/attributes useful? In OOP, sooner or later, you are going to make a subclass of a class and in that case, it is good to understand and be able to modify the implementation completely. One of the first things I do when I subclass a class is to change a bunch of privat...
Think that when one Branch saved, a Customer entity must created in n tier layered system architecture. All validation has already implemented in CustomerService. Should BranchService create CustomerService instance to create customer? Branch service implement validation again for Customer and call CustomerRepository?...
Dependency Inversion is Good Inversion of dependency is good, it: Simplifies unit-testing Reduces coupling, allowing software components to be used interchangeably Keeps instantiation logic for a given object in fewer places, preventing repetitive code. For these reasons, I avoid instantiating objects within classes;...
I am implementing an algorithm which is going to be quite computationally complex, and want to try to make sure I'm not doing unnecessary work. There is an n x n x n cubic lattice, e.g. if n=2 this consists of (0,0,0), (0,1,0), (1,0,0), (1,1,0), (0,1,1), (0,0,1), (1,0,1), (1,1,1). From this lattice I will be recursive...
I am writing a program using a procedural style. At most I have some modules where the logic is present (one to retrieve data from, one to display the info, one with the saving logic, etc.), but my data is in plain object format (they are formally classes, but conceptually they are structs, or named tuples). All is fi...
I noticed that various scripting language interpreters leak memory even for very simple programs, like the canonical "Hello world!" program. To illustrate the problem with examples: Perl 5.22 leaks 388,809 bytes. use utf8; use strict; use warnings; print("Hello World!\n"); Python 3.5 leaks 456,502 bytes. print("Hello W...
In Google's MNist tutorial using TensorFlow, a calculation is exhibited in which one step is equivalent to multiplying a matrix by a vector. Google first shows a picture in which each numeric multiplication and addition that would go into performing the calculation is written out in full. Next, they show a picture in w...
I have the following code: class Car(object): def __init__(self, my_id): self.my_id = my_id self.color = color self.brand = brand self.get_color() self.get_brand() def get_color(): return requests.get('https://example.com/{}/color'.format(self.my_id)) def g...
We have created a message que system using priority messages. The idea behind this is as follows: We have a list of clients. All clients know if (and what kind of priority) messages they have available for sending. A client needs to send their higher priority message first. All clients need to keep sending, if there a...
Sorry in advance if this is a little confusing, it's difficult how to phrase this. I am currently using Spring MVC with some RESTful services mixed in for some AJAX client side logic. I am looking to move towards a more SOA style of coding our views. Since the MVC and the REST service would live in the same applicati...
Let's say my array contains integers. I'd like to create lists, so that every list contains indexes where a particular value occured in the array. For instance, if the array was 5,0,3,5,2,5,3, we would have 4 lists (as there were 4 values): value 5: 0, 3, 5 value 0: 1 value 3: 2, 6 value 2: 5 Currently I am attempting ...
Our project is about 11GB, 10 of which are binary data (.png images). Consequently, a git diff or git status operations take up more than a minute. Fortunately all data files are separated into a folder with the wonderful name data. The assignment is "Avoid compressing, diffing and other costly operations on binary fil...
So right now I have a single thread to handle all the requests for the database. Let's say I have 400 requests per second for logins / logouts / other stuff, and 400 requests per second which are only related to items (move them, update them, remove them, etc). Obviously, the problem is that If I want to load an item f...
I'm referring this chart of latency numbers, attributed to Jeff Dean at Google. The thing I don't understand is, do these numbers not vary from one set of hardware to the next? How can these be accurate for all different types of RAM, CPU, motherboard, hard drive, etc?
I sent the code for a job application and got the following review: Regarding the Project Structure: Physical separation is absent. Logical separation is present but not up to best practices. Things seem to be separated "by the order they were needed to the solution”. Regarding Coding Conventions: White spacing is inc...
Why would there be an advantage to use a static method and pass the reference to an object as a parameter rather than calling the method on an object? To clarify what I mean, consider the following class: public class SomeClass { private double someValue; public SomeClass() { // Some constructor in whi...
Background We (my coworkers and I) are architecting a high level C# API to interact with a hardware device's native Windows DLL. First I will discuss the hardware-architecture, then get to the software-architecture part. Main Device The device has the following components: Exactly 10 receive channels Exactly 4 transmi...
I'm new to theory of complexity and am trying to prove a fact. So, let's consider an algorithm T that receive at input an integer n. That algorithm has a time complexity for n = 1 : θ(1) and for n > 1 : 2T(n/2)+θ(n). I need to prove that algorithm T(n) has complexity θ(n log(n)). I tried to prove that with mathematical...
I was reviewing a coworker's code, and noticed that he was using Integer objects instead of ints in some APIs (getters, setters, instance variables, and method parameters). When I asked him why, he told me it was because he wanted to use null to indicate an uninitialized state, because there was no good default value. ...
I have a controller method as follow: public class RoomsController { @RequestMapping(method = RequestMethod.GET, path="/v1/rooms/{name}") public ResponseEntity<?> getRoomInformation(@PathVariable String name, @RequestHeader("Auth-Token") String token){ try { Room room = roomService.findByLogin(...
I am a hobbyist programmer and a beginner. Most of the time, I cannot solve the problem while sitting in front of the computer. For example, I was trying to find out if one number is a power of another. I couldn't figure out the solution until I grabbed a pen and a paper then analyzed the problem. In roughly 3 minutes ...
I'm using MVP pattern in an android app that I'm developing. I have basically 4 elements: The AddUserView where a new user can be added: The AddUserPresenter The UserInfo (the pojo) The UserInfoManager ( businness logic and storage manager) My question is: When I press the "Add" button in the AddUserView, it should ...
Can someone point me in the right direction: I need to make a website with a registration form, to create accounts with e-mail verification, to write the forms content in a database table or something and to use it later. I have decent knowledge in html, css, wordpress but next to none in php and back-end. Basically I...
Suppose I have two directories: house-1 and house-2. Each house directory needs to have files describing its windows and doors. I am trying to understand how to name the files and directories. My current two options are: house-1 windows.txt doors.txt house-2 windows.txt doors.txt or house-1 house-1...
I'm writing a small game of life implementation with Spring, but trying to avoid referencing the Spring context within my code. I have two interfaces, Board and Cell. In each implementation of Board it will create a 2d array of Cells at some point. The problem is that since I'm trying not to reference Spring in my code...
Let's say I have a server, where clients who connect are constantly updating their inventory. I could simply save the changes in to the database after an item has been updated, or I could update the whole inventory after the client leaves the session. If I go with the first approach, with my current specs, I can't proc...
I think one of the things a developer faces when using ngRepeat, is that the when the i has the same value in an array, as in ng-repeat="i in myCtrl.arr", then: angular.js:13236 Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. I think it is due to Ang...
I am solving an algorithm question and my analysis is that it would run on O(2^sqrt(n)). How big is that? Does it equate to O(2^n)? Is it still non-polynomial time?
A bit long, but the overall the question is: Should I have a status field in the table, or should I calculate the status in-memory from other information in the record? What are the pro/cons of each? PS. Gray area alert. This is not really a database-design question. Background Taking the example of a "Subscription"...
Ok, I know the title of this question is almost identical to When should I use event based programming? but the answers of said question have not helped me in deciding whether I should use events in the particular case I'm facing. I'm developing a small application. It's a simple app, and for the most part its function...
Seeing as how there are no distinct Unmodifiable Collections interfaces, aren't you just setting yourself up for runtime exceptions by returning Unmodifiable Collections from method invocations? example: public class Start { public static void main(String[] args) { try { List<String> listA =...
In the world of pirates stealing software, one common technique is to download a trial or demo, patch it and upload this as the stolen version of a piece of software or game. This makes me think: if I sell software one day, it would be possible to set up a custom server, that builds a specific package, personalised to ...
I have a user model in an application that I'm working on, which currently uses sub-types to encapsulate properties depending on what type of user you are - I just can't help but think that this is really bad design. To expand in more detail, a User in our Application can either be an Instructor or a Student, and below...
I'm looking for an advice reflecting my point of view. First, I will explain my point of view. My point of view I'm working in a big company as a C++ developer, we are using GIT. I'm going to make a talk on how our developers should organize GIT commits. The main idea is that most of commits should be pure refactoring ...
Is there a standard mechanism for javascript to detect TLS MITM? I'm looking for something along the lines of reading the fingerprint for a server cert out of the browser, and comparing to an inlined constant. Of couse, this might be of limited practical use, since a targeted MITM attack could also rewrite the content ...
For reasons too boring to go into here, I've written a small JSON library to add to the pile of them available for Swift. The interface of this library is inspired by, and similar to, that of SwiftyJSON, but the implementation is very different. Both SwiftyJSON and my library use the MIT license. I have copied no actua...
Hie guys. I have never been employed in the software development industry and when I do projects I usually just draw non-standard diagrams or used use case diagrams and class diagrams. This time a company wants me to develop a software for them and they say they want full documentation(e.g SRS, SAD, SDD mock-up etc) o...
According to the PHP5 manual, __construct() was introduced in PHP5 as a replacement for SameAsClassName() constructors, and from PHP7, the old style is marked as deprecated, so in future versions, SameAsClassName() will not be allowed any more. I am just wondering about the rationale about this decision. The manual do...
Invoking non-final instance methods in constructors risks downcasting from a constructor to an overridden method as such: public class Start { public static void main(String[] args) { try { ClassB obj = new ClassB(); } catch(Exception e) { } } static class ClassA { ...
My background: I was programming for many years, but have never used a version control system. I felt, that such a system would save me a lot of time and allow me to be more productive, but I never got around to learning one, because of a lack of time that I would need to spend for learning such system. I've finally go...
I am making an online ordering system for a restaurant as part of an A level school project. Do I have to include the restaurant's customers in the development stages? Do I need to have requirements from the owner of the restaurant as well as from the customers?
In C++, I've been accustomed to using threads in the following way: #include <iostream> #include <thread> #include <mutex> std::mutex m; int i = 0; void makeACallFromPhoneBooth() { m.lock(); std::cout << i << " Hello Wife" << std::endl; i++; m.unlock();//man unlocks the phone booth door } int...
I am defining the architecture for an embedded system provided with an LCD touch screen for interacting with the user. To describe my problem I can use a washing machine provided with LCD touch screen as an example for my system. Some of the user actions on the LCD are merely parameters change, like washing temperature...
Me and my colleague are working on a new application that should replace as soon as possible an old VB6/Access 97 application made years ago.This application has a lot of problems, adjusting them in the same environment is simply impossibile. What we are trying to do is rewrite all the code in C# and MySql. We're basi...
I have a class that is basically a container (or composite) of 4 other objects. I'm trying to figure out the "best" way of referring to these objects, while still allowing it to be robust enough, so that future developer can increse it to 5 or 6, or 20. This may be a case of YAGNI, but I'd like some some more input bef...
I am working on a Spring-MVC application(config XML based, no Main class) in which I would like to do testing. I have known that there is a way to test code which is backend+frontend code. For that, I thought there would be some way I can check by running the code automatically in browser, which fills up forms, logs me...
I have an app which gets data from the database (MongoDB) in JSON format. The returned data contains nested arrays and I want to access the values in the nested arrays. The returned JSON format looks like this: [ {"_id": "81724587125","name": "Object 1", "arrayOne":["1","2","3"]}, {"_id": "87687687687","name": "Objec...
I am really confused about the concept of Strongly typed programming language (AKA type safety enforcement). Based on multiple definitions from Wikipedia source I can conclude from how I understood it that Type safety is really about what can and cannot be done with a language as predicted by the language itself (corre...
In MVC usually the controller sets whatever needs to be sent back to the client/View, including HTTP status code, e.g.: class Controller { public function get(Request req, Response resp) { if (this.model.get(req.getId()) { resp.setStatusCode(Response::HTTP_OK) } else { res...