instruction
stringlengths
34
36.1k
Disclaimer: I come from a PHP background. In PHP, I could have thousands files, which are never loaded, if not needed, due to the autoloader feature (If some code is needed, it would be loaded) How do .NET's assemblies work? Do they load all the program code into the memory on application startup? For example, I can ha...
What do you consider that is there relationship between DDD aggregate and architectural component? I think that it is quite reasoned that services, which are related to specific aggregate, defined a component structure. When I'm modeling the domain model of my software, I'd find out several domain aggregates (with agg...
Let's say I have a set of objects, foo f; bar br; baz bz; I also have a string of JSON data, string JSONstring; Depending on the object type of the JSON string, I need to transform it into either foo, bar, or baz. Ok, cool, I'll have a method for that. public object parseJSONToFooBarBaz(string jsonString); What I ...
I'm using meanjs for a project. It includes a yeoman generator with some express tests (model.test.js & routes.test.js) The tests do exactly what they advertise. My question is though, should I be writing tests for my express controllers as well? Right now the routes tests make sure the server responds with the appr...
Maybe it looks like a weird question, but what term should be attributed inside the code for files that are not folders to differentiate them from folders? If I need write 2 functions isFolder() and isFile() 2nd one has a misleading name because folders are files too
This question is about applying rules of my application that confuse me. My controller is using service and the service is using repository. public class CommentController: ApiController{ [HttpPost] public bool EditComment(Comment comment){ commentService.Update(comment); } } public class CommentS...
I have a class with multiple setters and want to make atomic updates to multiple properties/variables. As far as I can see there are three methods that could work: Call all setters in synchronized block. synchronized { obj.setA(a); obj.setB(b); // ... } Use explicit locks. obj.lock(); obj.setA(a); obj.setB(b); /...
As a corporate developer who works alone I find myself creating and writing a lot of websites that consist of screens that are basically wrappers for a DB table. So for instance on a screen that updates companies I would have a controller like this: public class CompaniesController { private readonly ICompaniesMan...
Background: The company I work for uses different systems to hold their insurance data which is customer related. They want to have an app for their customers where they can find their insurance related things in. Some of these systems provide web services to get the necessary information, so proper user authentication...
When I work with handling exceptions, I notice that I often have to deal with the ones I had no idea about. Especially it is noticeable when I program a method that grabs data from web. An error may occur, for example, due to connection loss, I can handle it. But then another error occurs, a different error with the sa...
I need to send out a batch of reminder emails, never more than 100 emails per batch, using authenticated SMTP. This is happening on a WindowsService (no GUI). The SMTP library we're using raises a Sent event. In the Sent eventlistener, we grab some info from the Sent event's args and write some data to a SqlServer data...
I'm working on a huge legacy codebase that uses Bing Maps API as a service provider and I have got the task to scrap Bing which is the foundation of the software and has been referenced through the source code everywhere. There are no unit tests at all. Very few pages of documentation. Also it's a JavaScript code-base,...
I am in the process of writing my first true API. In the process, I am defining an interface for mapping complex data structures onto other complex data structures. At the moment, the interface contains a set method for the input data structure, a run method to kick off the mapping process, and several methods which ba...
Why would you run unit tests on a CI server? Surely, by the time something gets committed to master, a developer has already run all the unit tests before and fixed any errors that might've occurred with their new code. Isn't that the point of unit tests? Otherwise they've just committed broken code.
Recently I asked this question. As commented in the answer by someone who sounds like a numPy developer, this behavior is clearly not desired. The issue posted was closed stating that this is expected behavior but not a bug. Additionally there are plans to fix it. What is the difference between a bug and behavior wh...
I am trying to understands MVP using Winforms. I found this example. Why do UserModel and UserView need to implement the IUserModel and IUserView interfaces ?
I maintain an old Java app that deploys to Tomcat and which uses SSL (and hence a keystore). It is important to note that this app will not even start up if the SSL cert is bad/expired/invalid! Every year the SSL cert expires, and so someone has to replace the old/expiring cert stored in the JKS with a new one (provide...
Achieving Zero Downtime Deployment touched on the same issue but I need some advice on a strategy that I am considering. Context A web-based application with Apache/PHP for server-side processing and MySQL DB/filesystem for persistence. We are currently building the infrastructure. All networking hardware will have red...
return this (or similar construct) allows method chaining. Lack of it is painful, because you have to write such code (C#): var list = new List<string>(); list.Add("hello"); list.Add("world"); instead of list.Add("hello").Add("world"); Elixir solves it nicely for function chaining, instead of relying on callee it rel...
Right now in my current company I must "parse" a csv and extract some data out of it (in the sense of data mining). I surprised myself by defining the following data structure (Java 8): static List<Map<String, Map<String, LocalDate[]>>> intervalStructure Is this considered bad practice? Should I use a self-define cl...
Having lots of Interface that needs to pass in a constructor looks messy, is there any neat way of doing it? Code snippet: public class Foo { private readonly IRepository1 _repository1; private readonly IRepository2 _repository2; private readonly IRepository3 _repository3; private readonly IRepository4 ...
In writing PHPSPEC tests for a Zend Framework 2 application, I'm left wondering how far to 'dig'. Consider this very simple case: A DomainService (Domain in the URL sense of the word) should be able to list all Foo objects, works. Making heads/tails of the test is not simple. This DomainService is fed via DI with a ...
I have an issue with a client's requirement that wants to import a string of html text within a csv document. For example, a sanitized version of one import line: "IDNumber,TextIdentifierNumber,<p><strong>Hello, this text is **>** this text. 32 < 64</strong></p>" The issue here is not importing this text, but angle b...
Suppose you're writing an interface that's suppose to be your public API, let's call it Session. It's implementation is called SessionImpl and it's going to be injected by your DI framework. I'm stuck thinking about the class access for this SessionImpl class, whether it should be restricted to it's package (since the ...
I am currently reading Design Patterns - Elements of Reusable Object-Oriented Software. I am in chapter 1 at page 16 in section Class versus Interface Inheritance. There in the last line of the page it says " An object can have many types, and objects of different classes can have the same type. " I think I understand...
If I'm bulding an application like a social network and I implement a like / favorite button with AJAX, is it preferable to use one URL to like / dislike or 2 differents URL? If I use one, for example like.php, in that url I'd check if the post ID was already liked or not, and then do the opposite action. If I use two,...
Usually, real-time web-apps are built with websockets, right? Well, let me be radical here - what if I used Ajax? Okay, okay, I know it has its limitations. You can't build Agar.io, sending data packets up to fifty times a second, with latency in the milliseconds. But what about an app that had real-time updates that w...
I am fairly new to JavaEE, so I have some concepts still missing. I am learning Docker to use it in our DEV / CI Build environments. I could make it work on my machine. But for it to work in the CI server, my current approach would be to store the docker-compose.yml and dockerfiles in git and, in the CI server download...
I am studying user stories and use cases, and I'm curious about ways to combine both these techniques. Basically it seems to me that there is a 1:1 relationship between user stories and use cases, meaning that for each user story, there is a use case related and vice-versa. I'm not interested in any specific processes,...
I am trying to understand the Three way handshake in the TCP connection setup. My book states, the client first contacts the server, say we want an HTTP connection, so it sends a SYN to port 80. (1) The server then replies a SYN ACK package. (Here is my question) (2) And now the client sends a final ACK. (3) In the bo...
I always seem to write code in C that is mostly object oriented, so say I had a source file or something I would create a struct then pass the pointer to this struct to functions (methods) owned by this structure: struct foo { int x; }; struct foo* createFoo(); // mallocs foo void destroyFoo(struct foo* foo); // ...
In currently developing a project where I'm going to use a lot of combobox, in order to avoid repeating a lot of code I'm planning on building a user control containing a ComboBox that retrieve the data I need from my tables. What is the best approach for this since I'm going to use a lot of different ComboBox with dif...
You who have worked with a framework implementing the MVC architectural pattern most likely know how these frameworks are usually implemented. They contain a base Controller class, which you extend, where some part of the name of the controller indicates the begining of a route and methods, methods which you as a devel...
I'm creating an FSM in python (it's a step sequencer and sample pad based on a Raspberry Pi 2). Right now there are two states and the third is the Menu. This is handled by a class System which handles all the states. The Menu state has to edit the attributes of the other states, so I passed the other states to its con...
In my Python application, I can distinguish between entry points (scripts) and what I think of as library code. My instinct is to put the library code inside a package, and the scripts elsewhere importing from the package. It is possible using setup.py to reference methods inside a package to use as entry-points, there...
I'm coding tests in C# and I settled with this structure: try { // ========== // ARRANGE // ========== // Insert into the database all test data I'll need during the test // ========== // ACT // ========== // Do what needs to be tested // ========== // ASSERT // =========...
Supposing you work in a very large global company with lot of code at all levels (e.g. from embedded to mobile platform application code), and projects can last anything between 6 months to 5 years... What would be considered the best practice in terms of keeping static analysis information?, assuming traceability bet...
I was tutoring a student that came up with this assignment. It basically requires a data structure with the following characteristics: it holds a set of integers in {1, 2, ..., n} n is power of 2 O(log(n)) insertion, deletion and maximum O(1) for determining whether an element is in the set it uses only O(n) bits of ...
Automated testing is pretty hyped-up in recent years, with particular emphasis on TDD at the "unit" level. The touted advantages include things like: Stabilizing existing code: breaking changes are identified before deployment Coercing code, to some extent, into smaller, more testable structures A codebase that self-d...
I'm having a hard time understanding exactly what is happening in the code here and how this script is changing other functions. This is taken from eloquentjavascript.net chapter 5 on higher order functions. function noisy(f) { return function(arg) { console.log("calling with", arg); var val = f(arg); co...
The language I am using is C#, but I am looking more for help with the algorithm more than I am concerned with which language. I have been trying to develop this algorithm for a while now and I can't seem to get it down. I have a tree like structure which has many parent/child relationships. So leaf #1 can have child...
I've been following The Complete Android Developer Course in Udemy. I followed the exact steps downloading the same files, I've already downloaded and saved JDK_HOME in the environmental variables with the right path accordingly. I'm currently using Windows 10 and am not sure whether the files are supported. Any help w...
I was thinking to store all file operations inside an array, along with the reverse operations which are used for undos. Example: [ [ 'op' => 'move', 'parameters' => [$path_from, $path_to], 'undo' => [ 'op' => 'move', 'parameters' => [$path_to, $path_from], ] ], [ 'op'...
The company i'm working for is selling HRIS management software. It was built using ASP and mysql. But one of our client's demand is for it to be based on MS SQL Server. our team is made up mostly of junior programmers / fresh grad and we don't have much experience working in sql server and migrating from one db to an...
I'm having a hard time planning how to implement the architecture. The problem: > A user can save a number of profiles: > Name > URL > Time Interval Name | URL |Time Interval Sample1 |s.com |5 mins Sample2 |x.com |2 mins Sample3 |xxx.com |7 mins The main purpose of the app i...
Recently, I came across an issue about the design of scope guard. A scope guard invokes a supplied function object (usually performs cleanup procedures) upon exiting the enclosing scope. The current design is as follows: #define HHXX_ON_SCOPE_EXIT_F(...) ... #define HHXX_ON_SCOPE_EXIT(...) HHXX_ON_SCOPE_EXIT_F([&]() { ...
I have a question about best practices to design a database which have to hold the following data: There is a page with a questionnaire which has default questions like Firstname, Lastname, Street... (50 more fields). Now people can register to the page and add a another custom field to the questionnaire. Here comes th...
I'm programming a small lisp/scheme interpreter and I came across the following situation : When a quoted list contains lambdas, they are not parsed as lambdas. Here is a sample code (live on repl.it): (define list1 '( (lambda (x) (+ x 1)) (lambda (y) (+ y 2)) ) )...
Is there a formula, or generally accepted approach? Should I be measuring database updates and averaging their frequency then using that to determine how often clients should poll the server? I would like all clients to have up to date data, but there's no point in polling the server every second if the data only chang...
Is there any way to find every github project which: is GPL licensed has over one million lines of C++ code I am imagining that the Github API was designed to automate such requests, but I am not sure at all. In other words, is the GitHub API related to searching within all the existing github projects? Another reque...
I am developing an e-commerce product and I have been able to implement all functionality and am left with allowing users to create additional attributes for a product. Right Now I have two options. EAV EAV is largely frowned upon but seems to work for Magento. But after researching all the headaches it causes I am a b...
Is it true that ngBind and ngModel are very similar: bind the model (the data) the either static text element or changeable element, such as text input box, select element, or textarea. In that case, wouldn't it make sense, just to have one name, say ngModel, and let it work for all elements (and so we don't need ngBin...
I am trying to do a nightly package integration with one of our projects that consumes 6 other internal teams’ -PreRelease packages. Background Info We have our own internal ProGet Server that hosts only our company packages. Package IDs are in the format of: MyCompany.Project.Component We have VS2015 Enterprise (...
I am learning Particle Swarm Optimization. The problem is to find the pair of number whose sum is lowest. Lets say we have some numbers z1,z2,z3,z4 Number Value z1 -2 z2 -3 z3 3 z4 -5 The goal is to find pairs of number whose sum is minimum (z2,z4). Initially we have 3 available pairs to choose (...
My professor gave this example in a lecture: Example: Given an integer N, print out the values 1…N. for (int i=1; i<=N; i=i+1) { System.out.print(i); } The professor said that the loop was O(n) because it printed the values 1 to N. However I thought that Big O Notation was a reference to the amount of items in the in...
I'm asking in terms of a loop, obviously break is important in switch statements. Whether or not switch statements themselves are code smells is a separate issue. So consider the following use cases for iterating a data structure: You want to do something to the entire structure (no break needed) You want to do someth...
I'm revisiting old code, and I noticed that the main logic is in one method, which is longer than I'd like (~60 lines). So I split it, and there's a natural seam on which to do so: the first half gathers parameters from UI objects, validates them, confirms a file overwrite if necessary, and logs that the procedure sta...
I have a Entity Framework class that was derived from the database layout. I was wondering if there was any problems by extending the class by creating another cs file and using the same public partial class to add the additional properties? Much like you would do when creating a file for data annotations. I have tes...
I found a bug. Yay for me. The bug is such a mix of technologies I am not sure who I should submit the bug to. The bug is a mix of Adobe Experience Manager and Angular Materials. Neither is really at fault. It has to do with some very clever javascript inside of AEM and the use of Internet Explorer Media Query hacks th...
I have a remote machine where multiple developers work on the same repository. We use gitolite and SSH keys to manage git access. As for now we code on the local machines, commit, push, pull remotely and test. It works, but is time consuming and annoying. If we edit code on remote repo, we can commit and push, forwardi...
How would I write a unit test, say JUnit, for validating an XML file? I have an application that creates a document as an XML file. In order to validate this XML structure, do I need to create an XML mock object and compare each of its elements against the ones in the 'actual' XML file? IF SO: Then what is the best pra...
I'm developing a simple application that crawls in web pages to obtain some information. For this I used and tested some libraries, like crawler4j, jsoup, jaunt and htmlunit. I exchanged several times a API to another because sometimes perceived that one served me better in certain feature than the one I was using. I ...
Lets assume I have following base class: public class Base { public int Id {get; set;} public string SomeText {get; set;} public string SomeOtherText {get; set;} public static Base BuildFromOtherAssembly(ClassFromAssemblyA source) { Id = source.Id; SomeText = source.SomeText; ...
I'm designing a fairly simplistic stack-based programming language, and implementing it in Python. (no link, because it's not fully implemented yet.) The language itself is essentially intended to be the actually usable lovechild of Forth and Joy, but JIT-compiled (mainly so I can learn to write a compiler). Being Pyth...
I was once advised that a C++ program should ultimately catch all exceptions. The reasoning given at the time was essentially that programs which allow exceptions to bubble up outside of main() enter a weird zombie state. I was told this several years ago and in retrospect I believe the observed phenomenon was due to l...
Normal behavior of the SQL Table is to add new rows in end of the table. I want to query results of single row only. So mysql command is SELECT id FROM users WHERE country='india' LIMIT 1 this will give me the first entry with the country india. But i want to get the last person so i used order by DESC SELECT id FROM...
I would like to create a library consisting of two layers, lets call them A and B. There should be a class "Sample" in layer A. Layer B also knows about class "Sample" and enlarges it by some methods. Then I would like to have another project, referencing this library, so I can have the following scenarios for an insta...
I have often heard developers mention that Java can't "do Real Time", meaning a Java app running on Linux cannot meet the requirements of a deterministic real-time system, such as something running on RIOT-OS, etc. I am trying to understand why. My SWAG tells me that this is probably largely due to Java's Garbage Colle...
I have got a text file called "vholders.txt". I am making multiple threads as you can see here ,those threads work with their own given data and at last they write their own output to the vholders.txt. But I get IO exception cause file is being used by another thread. So how can I write to vholders.txt file without col...
I've read many times AGPL3 (http://www.gnu.org/licenses/agpl-3.0.html) but I have a question, maybe somebody with a deeper knowledge can clarify me something. I would like to use a source code which has this AGPL3, and I'd like to add a layout over it (new design, I'm meaning just to design, CSS, markup). I'm not refer...
Until now, I always believed that you should learn programming languages that make you do low-level stuff (e.g. C) to understand what's really happening under the hood and how the computer really works. this question, this question and an answer from this question reinforced that belief: The more I program in the abst...
I am developing a commercial closed software using Qt which is under LGPLv3. May I prevent my clients from giving copies to other people?
I have been trying to implement an optimization for 2D sprite rendering to fight the problem of limited fillrate on mobile devices. The idea is to render textured polygons instead of quads that will map to visible portions of an image with transparency discarding the invisble parts from processing. Thus far I have impl...
I would like to have a class creating any code from given options and output it in a chosen way. I have written class for generation of simple JavaScript code for such cases where is needed to prepare JavaScript in PHP. That class has some bug that causes some problems with assembling of output code into larger blocks ...
This is a very simplified version of the problem: You have an integer saved on a server called "B" and you have an script saved on a server call "A" exposed to the internet. The script pulls the integer from server B, adds one to it, and then updates the remote integer. None of this operations are atomic, the pulling, ...
I am working on a new version of the following system: A 'main control' service that runs on Windows Server (C#). Clients on the following systems, that communicate with the above service via Web Sockets: 2a. Windows 7 / Windows 10 (WPF C#) 2b. Android phones (Java) 2c. iOS phones (Objective C / possibly Swift) 2d. E...
I'm working on a side project, and I turned on all rules for code analysis in Visual Studio, and I got the warning notice: Warning CA1006 Consider a design where 'Vote<T>.CalculateWinner(List<Vote<T>>)' doesn't nest generic type 'List<Vote<T>>' And it really does point out a sore spot in my design. I have an abstr...
I've looked through the different threads, and there are a lot of conflicting information out there. The most useful article I found was this: Java theory and practice: Urban performance legends, revisited but it's from 2005. So I was wondering what is the state of the Java standard regarding heap allocation. In the re...
I'm writing a fairly simple authentication/authorisation api for an intranet application we are developing. It's my first roles based authorisation system and its a good opportunity for a first timer because it is located on a Windows VPS that is isolated to the internal corporate network with no internet access at al...
Suppose we have a abstract class EntityBase which is the base class for all our entities e.g. public abstract class EntityBase { public Guid Id {get;set;} } public class Customer : EntityBase { public string Name {get;set;} } public class Orders : EntityBase { public string OrderNumber {get;set;} } Where the int...
I would like to have some help. I must find a way that the output must be: A B C 90 60 80 50 100 70 100 20 100 10 50 75 Because the previous output is: A 90 50 100 10 B 60 100 20 50 C 80 70 100 75 And it gives me some confusion on how to get to that output. This is the codes that I have: char n[3...
I have a sort of whiteboard style question about efficiently querying The Movie DB API to find a list of characters in movies. My overall aim is to: Search for a movie by title (1 request) Look up all the characters played in that movie (1 request) Look up which movies that character has been in, played by the same ac...
I'm new to MVC and the different layers architecture and this is what I have currently: 2 models: User, Company 2 service layers: UserService, CompanyService 2 interfaces which abstract the database layer from the service layer: IUser, ICompany 2 database layers: UserDB, CompanyDB Here's the scenario - a functionality ...
I'm trying to write a compiler for a self-designed CPU with accompanying instruction set. The CPU has 3 registers, 2 input registers (B and C) and one output register (D). When for example an ADD instruction is executed the sum of B and C is calculated and stored in D. I'm trying to write the compiler with the visitor ...
We have the following BSD license in the LICENSE file: Copyright (c) 2006-2016 SymPy Development Team All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: a. Redistributions of source code must retain the...
Is there a design pattern that would allow a class from a hierarchy to 'subscribe to' concrete methods? For example, say you have an abstract base class that requires the implementation of a method. Public MustInherit Class Rule ' Common properties shared between sub classes Public MustOverride Function Validat...
Why are the constants in The Software Equation so complicated? Here is the equation. where E = Project effort measured in person-months or person-years LOC =Lines of Code estimate for the project t= Length of project measured in months or years B= "special skills factor" P= "Productivity Parameter" Values of B and P a...
I have seen programs using this strategy and I have also seen posts considering this bad practice. However, the posts considering this bad practice have been written in c# or some other programming language, where there are some error handling built in. This question is about the c++. Further, the errors I am addressin...
I am a relative DDD newbie, but I am reading anything and everything I can get my hands on to boil out and distill my knowledge. I came across this DDD question, and one of the answers has me intrigued. DDD Bounded Contexts & Domains? In one of the answers the poster gives the example of an ecommerce system with prod...
I've been pondering a really basic question about how far to take enforcing a class's invariant. Maybe that's worded badly, so as an example, let's say that I want to write a class which stores a limited palette of colours. The class's constructor should take the size of the palette - the idea being that you can add as...
I am integrating an LGPL application to my iOS application. As I am modifying the LGPL application, I am planning to open the modifications I make to the LGPL library. I am modifying the LGPL library in such a way that, I am integrating a new library to it. So the flow is like this: Appl Code >> LGPL Library >> New L...
I have a generic helper class (1) that can be used in other projects also. Imagine something like basic handling of file and folders, something useful and DRY that always come in handy. I have another class (2) that is project specific, but it uses the generic class (1) to accomplish things. The generic helper class (...
I have a web application that is hosted on an embedded device. This device has its own basic web server that can serve content just like any other web server. The web application in question is pretty data hungry. It requests about 15 XML files (usually less than 1kb) every few seconds to update a wide variety of modul...
I am working on an App which basically communicate with a third party API, it has no back-end. The front-end will be a SPA. Here is the overall scenario: The external API needs current user's Id to respond to the requested query. My server initially has the user information which it can use to query the API and get th...
I've seen this part of PEP-8 https://www.python.org/dev/peps/pep-0008/#package-and-module-names I'm not clear on whether this refers to the file name of a module/class/package. If I had one example of each, should the filenames be all lower case with underscores if appropriate? Or something else?
Suppose I have a stream of Things and I want to "enrich" them mid stream, I can use peek() to do this, eg: streamOfThings.peek(this::thingMutator).forEach(this::someConsumer); Assume that mutating the Things at this point in the code is correct behaviour - for example, the thingMutator method may set the "lastProcesse...
How can I enumerate (by expression tree size, for example) all of the primitive recursive functions that map natural numbers to natural numbers in a traditional programming language like C? For example, in Mathematica, one can express the basic primitive recursive functions as follows: zero = Function[0]; succ = Functi...
I know what SRP is, but am questioning my current design of an object I call an entity. Below is a picture of the design I am referring to. If I shift the code from the GeometricInformation and TransactionInformation objects to the abstracts GeometricEntityBase and TranslactionalEntityBase respectively, would this be...
I know the basics of why a database uses a transaction log - fulfilling ACID properties, ability to rollback/restore, etc. The basic algorithm that I see for a transaction is as follows: transaction changes data - data pages are changed in memory transaction log is written to disk (must happen before commit is record...
I've a RESTFul microservice written in Grails. This microservice has it's own DB. It also depends on two other microservices. A typical workflow of the service is: Receives a GET request from a client e.g. browser Calls another microservice through http to get some information Queries it's own DB to get some data Send...