instruction
stringlengths
34
36.1k
I am writing a program that needs to be able to process data from a number of different sources. The sources output data in a variety of formats. So, depending on which source is being used, I need to initialize a string list with a different set of column headers. The quantity of headers varies between 10 and 18 colum...
I have intermediate level of understanding on how TCP and serial works, I've also been able to develop system that uses 1 TCP client and 1 Serial 2 Serials 1 TCP Server 1 TCP client My problem is that whenever I am creating a new project there are different needs, sometimes it's 1 TCP client and 1 Serial, sometimes i...
Let's say we have classes something like this: public class Item1{ public Guid Id {get; set;} public string Name {get; set;} public decimal Price {get; set;} public int Quantity {get; set;} } And few more, which has additional or different fields, other have lists as properties. And those classes are b...
I have some platform specific code, such as a string needs different values at different platforms like it: test.cpp #if(PLATFORM==ANDROID) string url="android"; #elif(PLATFORM==IOS) string url="ios"; #endif I am trying to rewrite platform specific code using separate cpp: test.cpp string url=URLHelper::getURL...
I am building a program for a law firm. When a staffer is active (i.e. still works at the firm) he has a password to login the program; When a staffer is inactive (i.e. no longer works at the firm) he loses his password, but his data is still registered in the database (personal information, previous job description et...
Been thinking this for a while now, for example I have a UX that let's the user choose what IP to connect. I have numericUpDown1, numericUpDown2, numericUpDown3, numericUpDown4 to limit the user to choose numerical values only, then when the user choose save I will save it as string then concatenate the dot(.) to it to...
I have built a server-side Java application of about 10k lines of code and on a code review a colleague made me notice that when developing a new business feature , I have to touch several files. My explanation is the following: In a well-layered architecture, delivering an additional business functionality might req...
I have a class with several fields. public bool Active { get; set; } public List<Group> Groups { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public Gender Gender { get; set; } publ...
There is a debate in my company on whether we should use the JSON API specification or stick to plain JSON for developing APIs that will be consumed by mobile apps, mainly iOS and Android. One argument for JSON API is that since everything is defined before hand, if new developers were to begin work on the API they sho...
I'm struggling a bit with referencing between aggregates. Let's assume the aggregate Car has a reference to the aggregate Driver. This reference will be modelled by having Car.driverId. Now my problem is how far should I go to validate the creation of a Car aggregate in CarFactory. Should I trust that the passed Driver...
I am working on an application whereby I have designed classes to fit into several groups: Immutable: initialised through constructors, uses copy-and-swap idiom (inc. move), can deep copy (i.e. clone), only has "getters" (not "setters") and implements comparison operators (==, !=); Services: stateless classes that hav...
What is the "essence" of dependency injection? Is it the idea of dynamically swapping out/in core logical/structural aspects of a program at runtime? Traditionally, this is done in code via some DI container. For example, using Structure Map in C#: container.For<ICacheService>().Use<InMemoryCache>(); However, I've w...
I am creating a new site and will base it on ASP.NET MVC 5 & Dapper Contrib. I want to go all in with all these technologies - and get all the time saving / convention over configuration / terse code advantages available. I am designing the database in SQL Server 2014. Historically I have always named primary keys Tabl...
In our company we have a small program (.exe 500Kb size) that does mathematical calculation and in the end it spits out the result on a Excel spreadsheet that we use to continue our workflow. I want to modify the columns, spacing format and add VBA logic etc. on the Excel spreadsheet but since this parameters are not c...
Firstly, I am studying function with new type of signature and body, and in this code, I want to know, what type of object is values? It doesn't appear to be an array of strings based on my observation. Secondly, is there any method that returns the name of the class a particular object is? I thought it might be tost...
Given <div> <textarea></textarea> </div> Why is this <div> <textarea class="width90"></textarea> </div> .width90{ width:90%; } any better than this? <div> <textarea style="width:90%;"></textarea> </div> edit: I updated my example better. My question should be more related to generic styles like widths, ...
I'm trying to keep my controllers as thin as possible, so I keep my domain logic in services and factories. When I need to call a function in response to a user action like a click I assign the factory or service's function to the controller's $scope variable. $scope.saveStuff = myFactory.SaveStuff; myFactory.SaveStuff...
I have this 'table A'. It contains two columns; email and email_alias. A sample is below: ===================================== = email | email_alias = ===================================== = email1@abc.com | alias1@abc.com = = email1@abc.com | alias2@abc.com = = email2@abc.com ...
I've seen an increasing trend of people submitting code to SO that includes the use of .NET Framework data types. I understand that the .NET Framework has its own data types (like Int16, Int32, Boolean, etc) that map to the appropriate data type in the language you are using (like C#). But why use that over the languag...
In our database backed (C# WPF / Entity Framework) application, we want to build a system to enter, store, display and search arbitrary content linked to our main entity. The challenge here is to find a pattern for that. Data should mostly be entered as Key-Value-Pairs. Starting off with one or more pre-defined questi...
The Mono project used to have LGPLed libraries. In fact mbundle still says when you run it Note that statically linking the LGPL Mono runtime has more licensing restrictions than dynamically linking. See http://www.mono-project.com/Licensing for details on licensing. As of March 2016 they re-licensed them under M...
I have a shopping cart with a checkout page. On the checkout page is a payment button which takes them to a stripe payment form. I've read some books on building eCommerce shopping carts in which the order is created when the user clicks the payment button and the order id is passed to the payment gateway. In this sce...
Two of the top 3 security vulnerabilities in the OWASP Top 10 come from trusting user input (Injection and XSS). To deal with this, Ruby lets you "taint" Strings received from the user as unsafe. In a type-safe language like Kotlin you can (theoretically) take this one step further with a Tainted class that wraps a St...
Imagine a situation where we're using a library that allows you to create Circle objects, where you can specify the radius and the center of the circle to define it. However, for some reason, it also takes a required flavour parameter. Now let's say I really need to use Circle in my own app, but for the purposes of my ...
If a method has too many parameters, the suggestion is to convert them into a parameter object. Where to place such parameter objects? in domain/entity classes package? or if I have a separate package for DTO's, should I place there?
I was reading about implementation of producer-consumer problem with one producer and one consumer. Looking at this paragraph I see the implementation where shared resource access is not synchronized and producer and consumer can modify shared resource leading to its inconsistent state. semaphore fillCount = 0; // item...
What is the history behind the convention of naming constants in all uppercase? My intuition is that it started with the C preprocessor, where people developed a practice to name preprocessor macros in all uppercase so that they would effectively live in a separate namespace and avoid name collisions. My belief is tha...
I have a in-house messaging system, similar to a message broker. We have one master message broker and one slave message broker. A message broker just receives messages and sends them to all nodes. The slave is acting as a node, receiving messages from master and building state so it can take over in case of master fai...
I see a lot of questions revolving around accessing JSON keys that use hyphens (kebab-case), but now I find myself wondering should I just stick to camelCase or snake_case in my keys. I know hyphens also can create complicated mappings when ported between languages. I've seen some JSON deserialize libraries convert tho...
I'm writing an application for learning foreign words of exactly one language (english at the moment), which has currently an ineffective design. I use Java and SQLite-jdbc for saving the words. After starting, the application downloads a comma separated wordlist and inserts each value pair into the Database. I hosted ...
Here : https://github.com/gnufinder/prime-factor I submitted a contribution with the goal to find a prime factor of the number 2222+3333. The number has 3,638,334,640,025 digits, so ECM will take too long, but pollard-rho might be feasible, if there is a computer which can handle such numbers. With normal hardware, on...
It is true that we cannot be 100% technology agnostic when we are using a framework or tool, we will be always at least 20% dependent on the tool or framework. The thing is that I feel better if I can be as much agnostic as possible of the chosen technology. My main 2 reasons are: it's easy to migrate to a better tool ...
I'm looking for a notation that is familiar to modern developers and can supersede s-Notation. (additional insight into Rivest's proposal of s-Expression is here) Is there any Swagger, JSON or other notation that is very intuitive for ACL control?
If I were to write a header exposing functions in a sample source file that was licensed under the BSD 3-Clause License, what would I put up in the header? Should I simply copy-paste the license text in the implementation source file? Should I add a line saying I modified it or added the header? EDIT 1: I realised my...
I want to compare sequence numbers (given to this code from elsewhere) that may wrap around. Simply comparing two such values will not handle the case like 0x00000002 being greater than 0xfffffffd, but I can assume that the numbers being compared are close together, not nearly 4 billion apart. I get the desired result ...
I'm currently working on a neural network to try to predict movements of electricity prices in a big city with multiple power companies to choose from. I know from a friend in the industry that power companies base prices off of a blend of costs and competitors' prices, which means that reasonably good predictions of a...
I find myself writing a lot of functions whereby the first few lines "verify" the arguments, that is, they typecast, check falseness, range, etc. before doing any work. The main reasoning for this is to prevent idiots—human or otherwise—from passing invalid or illogical arguments to the function. An example in JS would...
I see only benefits to the onion architecture over the 3 layered architecture where the BL had responsibility to call methods on DAL (or an interface of DAL) to do CRUD. The onion has better separation of concerns, testability, maintainability and is cleaner. So is the onion architecture indeed better in all aspects a...
Suppose I'm developing an application with a simple graphical user interface, like a basic text editor. How do I choose a good default size of the application window? Should the height of the window be a percentage of the height of the screen? What about the ratio between the width and the height? Or should I just go w...
TDD is about designing code, guided by tests. Thus, typical layers aren't usually built upfront; they should slightly appear through refactoring steps. Domain-driven design involves a lot of technical patterns, defining well established layers like Application layer, Infrastructure layer, Domain Layer, Persistence laye...
I am new to rest API's as well as mocks. Please help me .. I have a set of rest API's for which I need to write unit tests. rest API in turn calls another service , gets the JSON response and sends the response [data] back. Basically it's querying a list of master data's like users, suppliers , countries etc etc. My qu...
So recently I was working on a project where I had a base class that provided some common functionality. It had several virtual (overridable in vb) functions. I noticed that some of these methods expected the override method to call them first before doing any work, and others expected the work to be done before the v...
I really enjoy the actual programming part of programming, and actually writing the code, and figuring it out. But on this project I've been working on, most of my time has been spent on kind stupid stuff (trying to run a Java program in the background (I swear javaw does the same thing as java) and trying to put a jar...
I was thinking, we are taught to perform code reviews, inspections etc. but in reality, does anyone really do formal (Fagan) inspections? I cannot find anything on the topic.
I have a MVP implementation, inside my presenter i have a lot of public methods like onSendMessage() for example. I need to track some of that methods, meaning track just call a trackClient.trackSendMessage(). That actions could be over 20 more or less and i dont want to make dirty my presenter with a bit of logic abou...
Seeing this UML class diagram : FileHandler, Uploader and Deleter are abstract classes. The four bottom classes are implementations. They extend on FileHandlerInterface which requires a handle method to validate the contract. But this method isn't in the implementations, it is in their parents (Uploader & Deleter). I ...
Let's say I want to create a shop/order system. I'll have an Order DTO to which I'll map the data from a request and results from the database. The object will consist of an order number, a customer number and a list of articles. The order number is pretty simple, I'll just use an int to store the number. But what abou...
I was trying to solve Problem 279-B. Given an natural number, t, and an array, a[0],...,a[n-1], of natural numbers, find the maximum length of a continuous subarray, a[i],...,a[j] in a where a[i]+...+a[j] <= t. e.g. a=[3,1,2,1] and t=5 -> 3(1,2,1) ; a=[2,2,3] and t=3 -> 1 I thought of an O(n2) solution. Double lo...
I am learning Java and JSR-353. My question is quite forward. Having the method below: public JsonObject createJsonObject() { return Json.createObjectBuilder() .add("address", this.getAddress()) .add("city", this.getCity()) .add("state", this.getState()) .add("postalc...
In my code I often need to differentiate between messages intended for logging and those displayed to users. I'm looking for a terse term for naming variables and methods that indicates a user-readable message. I've tried "userReadable", "userVisible", etc, but they all feel too verbose, especially when combined with...
Thanks to my new job, I recently discovered the inversion of control design principle (with windsor castle in C#). I really enjoy using it but something's bothering me. For me the good part about strongly typed languages is the fact that you can see errors at compile time and you avoid having your app randomly crashing...
We are moving to SCRUM - in our sprints, we work on a version 1.1, while version 1.0 is being in production. However, ocassional bug from version 1.0 is reported and have to be fixed. I found no information about how this should be handled - it does not seem right to me to make them part of the sprint (as they are from...
Does it make sense to talk about "agile development" or claiming that you are applying an "agile methodology" if the code base you are working on has 0% unit test coverage? (And you, as a team, are not doing anything about it). To make it clear: to me, it doesn't make sense. In my personal experience I found that unit ...
I have an application that I want to be MIT and I have a roo gem in my Gemfile (roo is licensed under MIT) however it depends on spreadsheet that has GNU license. Am I allowed to use roo and have MIT licence?
I have a slight case of OCD. That means I've read multiple questions that are similar but I'm still paranoid. I'm distributing a commercial application that relies on a 3rd party library that's licensed under Apache 2.0. In order to prevent DLL HELL, I've simply re-assembled the library under a different assembly name,...
I´m looking for the best way to solve following problem: I have three lists of different objects: AppleJuice, OrangeJuice & Juice. All Juice properties exists in AppleJuice & OrangeJuice and I only need these from AppleJuice & OrangeJuice. I can´t change the AppleJuice & OrangeJuice implementations since they come fro...
I am designing an application, which will store sports statistics, show them in different diagrams and do few more operations on them. Allow user to do some mock drafts etc. I choose to build a domain first, and then create a database via code-fist approach. So I have my entities: - Player (name, teamId, list of stat...
I have a simple list in Java that I need to search using one of two methods. The first method simply returns the position in the list of the first matching element. The second filters out any elements that don't match. Here's some pseudo-ish-code: public int positionMatch(String search) { for (Element e: myList) {...
I want to build an API (Java) that heavily relies on a connection object to a data server that manages a connection to a real device. All i have is a DeviceConnection object. Currently i have a big class that presents the user with everything the device can do and manage the connection object inside that class. That wo...
I'm creating a point of sale system for a small shop. I am particularly interested in finding patters from all items purchased, which I will log in their entirety. I'm thinking of even making queries on things like temperature to sales of specific categories of products. Should I use a plain text based database such as...
I have a table with employees information: id, active, first_name, last_name, gender, id_number, address, picture, password, comment Every employee has an entrance time and an exit time for each day of the week except Saturday. It is possible that an employee has two entrance times and two exit times (when he chooses ...
I am trying to improve a brute force algorithm for letters of the English alphabet [a-z][A-Z] and numbers [0-9]. The length of the generated permutations should be 8. So far, I've built a simple brute force iteration with Ruby and later I broke down the master iteration to smaller ones of 100_000 items each. Also, I am...
We have quite a large project where and tend to apply risk based approach to stringency of unit tests and code reviews. E.g. components classified as A need to have higher coverage than components classified as B. However, it is nearly impossible without a support of static analyser - is there a way how to instruct (e....
Reading the literature of DDD I came up with the following layers: Application Outsider World (Controllers, Crons, etc) Application Services (or UseCases) - which orchestrates multiple Domain Services or Infrastructure Services. They are called from Outside World. They know what things have to be done Domain Services ...
This is more philosophical question, which address .NET platform, but maybe it is useful also for other languages. I'm doing lot of Unit Testing and especially when I'm using third-party components I often struggling with. In .NET is enormous claim to component design(er) to choice which method should be virtual or not...
I have a feature where scanned exam answer books need to be digitally annotated and marked. The scanning portion of the work is with another vendor who refuses to scan in any format other than PDF as it's more secure and unalterable. I need to develop code that can show the 20-odd pages in the PDF on screen using a web...
This question has bothered me for a few days, and it feels like several practices contradict each other. Example Iteration 1 public class FooDao : IFooDao { private IFooConnection fooConnection; private IBarConnection barConnection; public FooDao(IFooConnection fooConnection, IBarConnection barConnection) ...
I am starting to develop a REST API with Jersey to retrieve a schedule for a given sport tournament. The client sends a JSON containing a tournament with its different categories, domain, definitions and configuration. This will be unmarshalled by Jackson. And the response includes a JSON with the calculated schedule f...
I need to perform a payment and I have two payment methods: FirstPayment and TokenPayment, which both implement PaymentInterface interface PaymentInterface { public function pay(PaymentRequest $request); } According to a specific condition on PaymentRequest I need to choose whether to use FirstPayment of TokenPaym...
I am a very inexperienced programmer, so apologies if this is a stupid question to be asking. And similarly, if anyone answering could assume that I know basically nothing at all and treat me like an idiot, that'd be great... I have some code in C++ that is an interface to a physical device. Importantly, part of this i...
I often use smaller data types in structs/classes when it is needed in memory savings. I also use them in network/disk IO. My question is if intermediate code that use those objects with smaller data types, should be of the same type, or just plain types like int and cut them when storing. For example: struct Object { ...
Symfony2 is handling all its things in bundles in /app or in /vendor. This is fine if you are handling and managing all by yourself or Ops that handle all needed things. But I haven't found a good way for some kind of 'plugin system' in SF2 till now. I have tried to find an answer for several days now on the net but di...
I am developing a program that polls a device for actvity. In the past I have always used a USB device with a pure USB device driver. The upside of this was that that device was blazingly fast. The downside was that it limited me to the DLL the manufacturer distributed with it. For certain reasons beyond my control I h...
I've been considering doing some kind of application that allows users to track events in mythical settings. However, not all mythical settings allow for normal times. What if one user wants star dates, another wants BD/AD (Before Debbie/After Debbie, the heroine of an adventure?), another wants to count ticks from the...
I have been playing around with Guava Multimaps and I ran into an issue with tracking when an user is damaged (more the way it's displayed, really) Let's say I have a Multimap<User, Hit> and Hit consists of 2 fields: damager (string), and damage (double). Here is an example of what my collection might look like: dang...
I've been programming for a long time, but very rarely with anything asynchronous (and not often with anything to do with multithreading, either). Mostly for the fun of it, I'm writing a program to download song lyrics, and save them to music files (via e.g. ID3v2 tags). I have most of that in place by now: I have two ...
At my workplace we use CVS tags to the extent that nobody ever retrieves the HEAD version of the trunk. Is there any reason why that version still needs to build fully? The reason I ask is because recently there was a need to revert to older revisions of certain files, and instead of moving those versions to HEAD, we s...
I have a set of data about a family, and I want the software to find a house design that fits the data (which includes stuff like preferences and whether they want a pool. The current way I am going on about it right now is rather naive. There is a predetermined set of relationships between categories, or roles, of Roo...
I'm working on an application with about 50 or so microservices that have separate multi-tenanted databases. The problem arose of taking a tenant's data offline meaning that any requests for a certain tenant's data should be denied regardless of what service the request is being made for. Normally in a single tenant da...
#include <stdio.h> int main() { printf("Goodbye, World!"); return 0; } Why do I need #,<>, .h, and ()? What are their purposes?
I have some methods defined in a controller which most of them returns JsonResult, and some returns PartialViews. So I have two questions, 1) Is it a good practice to access those methods that return JsonResult from other controllers? 2) Is it a good practice to access those methods that return ActionResult from other ...
I have the following requirement for an application: Store large files (order of megabytes) which I will use as input for non regression test and some expected properties of the processing result Allow business users to add additional files and properties Being able to track over time which files (and properties) were...
I am reading through PHP Objects, Patterns and Practice 4th Ed and on page 41, Constant Properties chapter says: Constant properties can contain only primitive values. You cannot assign an object to a constant. But objects are also primitive values according to the official documentation, as shown here: http://php.n...
I'm just having a debate about the best (future-proof, safe, user-friendly, developer-friendly, technologically nice) approach to localization of a web-application. We are using basically processing on the server, prepare pages there and use some JS, also use Syncfusion (who offer "something" with their latest release)...
Why are most computers byte addressable instead of bit addressable? By B/b addressable I mean that processor can operate on level of single B/b. Bit addressable advantages: Booleans have size of one bit. You can directly access single bits in integers (without some dirty hacks like shifting). Byte addressable advant...
Referential Transparency is one of the corner stones of functional programming that allows us to apply equative reasoning to our code. However it does so at a cost to performance, by use of immutable objects. Some functional programming languages like Idris solve this performance problem via the use of Uniqueness Types...
Recently, two guys contacted me and asked me to build their mobile app. They have a brand new concept and want an app quickly. I told them that I need some user stories and some specifications by example in order to accurately know what they expect from the app and to be able to make an estimate of the tasks and delay...
I am developing program with asp.net MVC and I feel like I'm doing it wrong in these parts: I'm populating all process in controller, because I don't know how to put it in model (how to call it). I have read some reference and people say that we must put process in model (?) Many of my action have same process (repeti...
I have a web app that makes use of node.js in the backend and angulajs on the front end. Let's say I have a user who has the ability to login via multiple systems; I must allow multiple logins. I am making use of jsonwebtoken module to generate token for a user after he is authenticated and that is saved in the redis...
I'm trying to understand what happens with dependencies (Ninject) when a same Interface in injected in multiple classes. I am specifying InRequestScope for my bindings so as I understand there should always be a single instance of let's say my IUnitOfWork in a single HttpRequest. Is there a way I can check how many ins...
I'm not sure if this is a thing. I'm sorry about the ambiguous title--I wasn't really sure how to explain it. Basically I have a ASP.NET web page that runs two SQL queries and does some logic to produce a status page for our delivery department. It refreshes / updates every 30 seconds, therefore the database is bein...
Question I apologize if this question has already been posted. I tried searching but I couldn't find the answer. I often find myself trying to use DI and DIP where I need to open a file or a socket. Using DI comes naturally when doing TDD as it is sometimes hard and/or ugly to test that something has been written corre...
This is bugging me for quite a while and even though I decided to do it in a certain way I am still no convinced that I decided well. Here is the background to it: One of the core features of my application relies on textual data which will reference other entities in my system. Let's put it into a simple example: This...
I have a specific case for this inquiry, but hopefully it can be generalized to anything else. I'm working with an aircraft simulator and have been tasked to implement a module whose goal is to improve the performance, if you will, of the existing module. After reading up about how to write proper requirements (and the...
My question is not how to call a web page in code but rather what the correct architecture for it would be. I have an MVC web app that displays certain data from our database when the user visits a page. The data in question comes from another site, and I need to load it into our database once an hour by calling the ot...
When creating a C++ class what is best practice> Put the entire class definition and member functions in a header file Put the class definition and function declarations in the header file and put the function definitions in a separate source file Put the entire class definition and declare member functions in a sourc...
So i am creating my first larger scale application (by larger scale i mean something i see myself publishing in the app store) and i am not sure of how to handle user authorization. The client will consist of a application for android and iphone, and they make HTTP requests on a server. My data is stored in a postgreSQ...
I have spent the last few hours reading up on the use of static classes and trying to figure out if I should be using them or not but still have not come to any sort of conclusion. It seems that the argument could go either way. In my application I have created what I call "helper classes" which contains methods that w...
At our company, we maintain three products, which are quite similar, in 2 Projects. All Java, using Maven for dependencies. These three products evolved out of another project, which is now a maven dependency of the two Projects. Let's depict it like this: Project A and B are so similar, that essentially every bug f...
I was reading this question in SO, and it contains the following: A non-static nested class (sometimes incorrectly referred to as an 'inner class') (...) And it confused me. At 350+ upvotes, I assume that the answer is basically correct, and I did further research on the difference between "non-static nested class" a...