instruction
stringlengths
34
36.1k
Brief Summary This question is asking for guidance on how to deal with Zend Form library that allows me to specify how to construct each form element (Controller side) and how to render each element (View side), essentially creating 2x amount of work, when compared to a non-Zend-Form approach where each form element is...
For instance, would this c++ function be a good idea? void doSomething(not_nullptr<MyType> arg) { // stuff } With not_tullptr being a template wrapper for pointers, that will throw an exception if a null value is ever assigned to it. It has the advantage that it finds errors fast, and clearly documents assumptions...
Background It is now well understood (if not always well communicated) that the following logic does not apply to software development project estimates: A project that would take 1 developer 12 days, would take 2 developers 6 days, would take 3 developers 4 days, etc. or a...
This is bothering me a long time. I feel like I am doing mistakes on the code design relative to the performance. I never had any teacher to indicate my mistakes so its hard to me to make it right in practice. The code is about a server I am creating. I divided the program in some main classes like the "Receiver", "Se...
We all know 0/0 is Undefined and returns an error if I were to put it into a calculator, and if I were to create a program (in C at least) the OS would terminate it when I try to divide by zero. But what I've been wondering is if the computer even attempts to divide by zero, or does it just have "built in protection", ...
Example to question in title: List<UUID> ids = dao1.getContactsOfUser(userId); List<String> contact_names = ids.stream .map(uid -> dao2.getContactByUid(uid)) //is it ok? .filter(contact -> contact.getPhone!=null) .map(contact -> contact.getFullName()) .collect(Collectors.toList()); I know that it work...
For example I need to update the status of a "Purchase Order" from "Draft" to "Sent". What's the best way of doing this? Do I just the update the status field in the client side and then just POST the whole entity to /purchase_order/1 And how about events? For example I want to trigger that all Purchase Orders be set t...
Background: System call overhead is much larger than function call overhead (estimates range from 20-100x) mostly due to context switching from user space to kernel space and back. It is common to inline functions to save function call overhead and function calls are much cheaper than syscalls. It stands to reason tha...
I have a collection of classes which model Logical(Boolean) Expressions. There is a base abstract class LogicalExpression, and derived classes : UnaryLogicalExpression, BinaryLogicalExpression, LogicalParameter, LogicalValue. Some code samples public abstract class LogicalExpression { public string[] parameterName...
Let's say I have several points / vectors (in 2D to keep it simple, but could be of any dimension) [x1, y1] [x2, y2] [x3, y3] .... [xn, yn] If I pick some point [x', y'], how do I find the closest point to it? For a more concrete / practical example, imagine these are coordinates of houses. If I have th...
normally, I'll use a dependency injection container (unity) in c# like this example: class SomeClass { private readonly ILogger _logger; public SomeClass() { _logger = DependencyContainer.Resolve<ILogger>(); } public void DoSomething() { var someOtherClass = DependencContainer....
In a multi tenant application with separated databases for each tenant, what would be the best way to authenticate connection to each of these separate databases. My goal is to: Main security requirement is to avoid accidental or malicious data access of different tenant Achieve this in MySQL. For failure tolerance, ...
Not for the first time, I wanted to do something like this: if condition1 result1 elseif condition2 result2 else result3 else result4, so 'if result3 did not run' then run result4. But this does not exist. One could nest the ifs or use additional variables, but both are more complicated to write and read. Instea...
My team is tasked with creating a publish/subscribe system for incoming REST messages. 99% of the time, this system will be used for notifications between different processes on the same cpu, but we will need to support notification over the network as well. We are considering a REST based model, where a client subscr...
I'm working on allowing my users to create their own ruleset for data that's coming in. All of the data below is sample mock data and not in relation to our product. Example of a rule (there can be many): CONDITIONS: (IF) 1) title = 'some*' 2) user = 'john' OUTCOME: (THEN) 1) e-mail me 2) deny request so in the ...
I have been reading the following Uncle Bob post on TDD. He explains that there are cases where TDD is not needed. Mainly in a case where your tests and code are both very specific, and your code is not tending to more general algorithms. He suggests that logic should be TDDed, and everything that isn't logic should be...
The first version of pseudo code I consider a code smell because of (I think) the Command Query Separation principle and/or the S in S.O.L.I.D. What I like to see is in the 2nd version. Should I keep dinging these in code reviews or let it go because everybody seems to do it? #1st:version Class ServerCollection { Se...
I have an opinion (which I am sure will be shared by some) that passing anonymous functions which contain more than a few lines of code, as arguments to other functions affects readability and self-documentation drastically, to the point where I feel it would be far better for anyone likely the use the code to just dec...
I have some code where Controller depends on the Model, and in my case Model acts like a Database Access Object. use FQDN\Model; class Controller { /** @var FQDN\Model */ private $model; function setModel(Model $model) { $this->model = $model; } function showPage() { // mo...
I have a really old install of Debian on my Thinkpad, and I want to refresh it now that I'm using it again. However, I have a LOT of old scripts all over this install for beauty fixes, shortcuts, and keybinds. These scripts are in various locations all over the install, and I want to send them all to a single 'catch-al...
I have this Java project called Server. Server is essentially a single-threaded application that listens to events from external applications. These events are crucial and missing one is a huge deal. What Server does is that it listens to events, does some calculations based from the events received, and stores the ca...
I'm new in web programming with SQL database. So please forgive my ignorance. I'm using some modern framework to make a REST server with a SQL database. I'm using transaction only when I think I need it. But during the development I find out that parallel operation land me to dead lock and inconsistent data so I starte...
I've got some legacy code (both in the sense of code that has no tests, like the definition given in Working Effectively with Legacy Code, and of relatively old code) that I have to extend. There is this one class in particular, which is extensively used through the 'simple' expedient of accessing its member variables ...
I have an DDD application that makes use of two external APIs: Google Calendar API and Google Gmail. In one of the application services I want to create a calendar event (using the Calendar API) and then send a confirmation email with Google Gmail API: public ValidationResult CreateEventAndSendEmail(string emai...
Microsoft suggested that variable names should not match field names. However I saw this extensively in Java (e.g., this tutorial), especially in setters and constructors. So, among these two styles: public class Class { private int var; public void set(int var) { this.var = var; } public int get() { retur...
I recently started reading about programming in Assembly. To my knowledge, in Assembly, a programmer, when storing and retrieving their variables, has to specify the address their variables are stored in from the RAM register to the CPU. Now my question is: What if in multi threaded CPUs, two programs that a user runs ...
I'm writing an app that continuously monitors user location 24 hours a day using a mobile phone with readings every 5-30 mins (about 50-300 readings a day). How do I cluster readings and extract user significant locations taking in account the following requirements: The output must be a chronological list of visited ...
Why do languages' random number generators tend to return a value exclusive of the upper bound of the range? For example, an implicit range - JavaScript's random() method "Return a random number between 0 (inclusive) and 1 (exclusive)" An explicitly specified range - .NET's System.Random.Next(minValue, maxValue): maxV...
In my current android projects I'm using a sqlite db to store my collections of structured data. The database is accessed by a ContentProvider called by a Loader which updates the UI. It looks like my app is now an old-school piece of code, since RxJava became a frequently used standard, the popularity of MVP pattern ...
I plan a complete rewrite of my project, using another framework etc. It would be nice to keep the old code including history for reference. What is the best way to do this, in order to avoid risk, confusion and surprises? My idea is to create a new branch, replace there everything and get a basic "new" version running...
Java 9 will have modules in addition to packages. Usually languages have one or the other. And most programmers perceive two terms as synonyms. Modules are built on top of packages, treating them as primitives. Composite pattern suggests to treat primitives and composites uniformly. Otherwise bad things will happen. Fo...
I was wondering if it was possible to get path coverage(executing all paths) but not condition coverage? Also, how about the other way, condition coverage, but not path coverage? A concrete example would help. I know that path coverage does not imply condition coverage because you can execute all paths without making a...
I have a small application with classic layers Controller-Service-Dao. Controller actually is REST resource, which deals with JSON data. And the questions are: 1. where is the best place to create business objects from JSON primitives? Controller or Service? Should controller pass primitives from JSON to service metho...
It is well know that if your class have a constructor with many parameters, say more than 4, then it is most probably a code smell. You need to reconsider if the class satisfies SRP. But what if we build and object that depends on 10 or more parameters, and eventually end of with setting all those parameters through B...
I've got a question about a correct usage of Spring. I know that some people use the DI "aggressively" so that they always use spring and completely eliminate the usage of word "new" in the production code. On the other hand, I know that spring suits better for integration. For example like stated here this really loo...
What I'm looking for is a way to auto-generate a simple web-based CMS for a simple pre-existing SQL database. To be used by 'app administrators', not the general public. Something that: allows basic create/update/delete operations on the DB tables understand simple table relationships and hides db keys to the CMS user...
I've read a lot of posts that explain what monads are, how unit and bind work, some of them plunging straight into category theory so abstract (for me at least) that makes the eyes bleed, some ignoring that altogether and touching on weird analogies of burritos, boxes and what not. After a few weeks of study and a lot...
I have master and nodes infrastructure. Master executes remote jobs on nodes. Each job returns success/failure message back to master. So the flow of execution is the following: master receives command master creates remote job and sends message to node to execute remote job master returns 'accepted' remote job is exe...
Say: I have a website that contains a single toggle switch with 2 states. There are currently 2 (or more) clients viewing the site. and 1 client flicks the toggle switch. How can I reflect that change across everyone currently visiting the site? The simplest way I thought of was to save the current state of the swi...
I have a tilemap and I want to add walls to it. I painted 16 images, one for each possible combination. For example: A lone wall tile would get a image that has walls around. A corner would get either four of the corner images. A T intersection would get one of the 4 T intersections. etc... I could make 16 statements...
What are some of the conventions you use when naming variables in mathematical/scientific code? I'm looking to establish a set of conventions for an upcoming project. So here's an example formula to compute instantaneous velocity: u'i+1 = u'i + 0.5dti (u''i + u''i+1) Some possibilities include: def up_next(up_current...
The G-Code and M-Code that we used to instruct CNC lathe, 3d-Printers and engraving machines, to my understanding, is not a programming language, but a scripting language like Python where scripts such as G00, T01, M18 etc would instruct the micro-controller to call a functions (e.g. some numerical mathematics). Where...
Seeking thoughts on the following design. I know the design could be lot simpler if use Sockets. But I wanted to think of a design with pure POJO classes. User string id; string displayname; ChatWindow User user; ChatManager room; //interface to access ChatRoom readDeliveryReceipts boolean; LinkedHashMap<id-userid, A...
I often struggle with the idea of deploying applications in productive, dev and test environments (not unit testing, I mean like a sandbox) when it comes to databases. And no, source control is not an option. Three main reasons: 1) I don't necessarily want developers to look at sensitive information (like passwords, cr...
I am writing a physics simulation program in C++. I am a novice in OOP and C++. In my program, several objects need to be initialized based on data from an input file. For example, an imaginary input file: # Wind turbine input file: number_of_blades = 2 hub_height = 120 # Airfoil data: airfoil1 = { chord = 2, shape = ...
Six months ago I launched a free app that I developed and self-funded. From peak usage of a few thousand users, it has now bottomed out at a few hundred. It was an interesting project, from which I learned a lot, but I was never profitable and am now looking to discontinue service or sell it. The main driver for not ju...
I have the task to migrate a large silverlight business application in a new living technology. I had choosed asp.net MVC and web api. As we know, silverlight uses MVVM design pattern whereas asp.net mvc is obviously using MVC pattern.It looks like migrating silverlight logic to mvc wouldn't be easy at all. As I know ...
In an experimental personal project I (along with a "team" of friends) did some time ago, we used a REST API to provide all data. The frontend (a JS-only webapp) then just called this API using AJAX. We used a homebrew version of OAuth and some makeshift token mechanism to handle authentication, and it worked quite wel...
So I was lucky to be able to contribute to DateUtil in python(just a small documentation). I recently received a mail regarding the release 2.5.0 . So I was all exited because it was the first time I saw my name in a very known open-source library. But the problem is I dint reply to those mails. I really don't know wha...
I want to distribute a single exe file, which is a simple http web server. This exe contains all the dependency html/js files (mostly licensed under MIT and New BSD) I really don't know if that's distribution in binary form. Do i have to reproduce the copyright notes in the documentation, if the client is able to see t...
I am working on a Spring-MVC based project, in which I would like to add Timeline functionality. The most important object in our project is the Note, there are objects associated with it like NoteHistory Attachments, etc. Timline functionality here means where Users can scroll through Time in the front-end and objects...
I know that one can not securely restrict normal CPython's capabilities to properly run foreign code without allowing it to access some builtins like open() or allowing other kinds of I/O. So I researched more and found the alternative interpreters PyPy (written in Python) and Jython (written in Java). Which of those i...
At my job we have a fairly elaborate specifications model. Basically we need to create 3 layers of specifications where each subsequent level elaborates on the previous. We've got: the top layer which is are the requirements the middle layer which is the functional spec the bottom layer which is the design spec Usual...
Under IPv4, the de facto standard notation 10.1.2.3:1234 is completely clear: it is an IP address with port number. This is understood in URL's for instance: http://10.1.2.3:1234/doc.xhtml. If I have a sockaddr_ipv4 class in some code, its tostring method can return this colon notation and everything is cool. In a fit ...
I'm evaluating my options to structure an in-memory database and I have a few ideas of how to implement it. I would like to know your opinion of what the best design choice is. I have a column class which is parametrized to represent different column types. template<typename T> class Column<T> { public: std::string...
Purely out of curiosity, I was hoping someone could explain how ORMs (like Hibernate or Entity Framework) determine the order that they need to execute SQL UPDATEs, INSERTs and DELETEs. Is there an algorithm for building up a topological dependency graph? Or do they cheat somehow and temporarily turn off constraints? E...
First off, I'm relatively new to C - I know the language somewhat, but never looked too much into the whole build process. From what I'm seeing, if I want to use a third party library and have it in source code form, I would compile that library separately (which yields a platform and architecture specific binary blob?...
In the object-oriented analysis approach defined in Object-Oriented Analysis by Peter Coad / Edward Yourdon (Yourdon Press, 1991), a method is provided for analysing and modelling complex problem domains using "subjects". A subject is a group of closely related classes & objects that are represented as a single entity ...
I have an architecture similar to this: User (Name, Email, ID...) ---- Studios (Name, Location, Description...) ---------- Videos (Title, Description, URL, Length, Views...) Simply put, a user can have 1 to multiple studios and a studio can have 1 to multiple videos. Each of these are Classes in my PHP application (Us...
For a recent personal project, I started working on an interpreter for my own programming language. One of the ground rules I set for myself on this project is that I need to properly test as much of my code as is practical as I develop. I have scoured the web searching for guides or discussions about testing a parser...
I'm stuck on a lightly philosophical question for me. I have three classes and I'm not sure how to make them related to each other. I have few competing approaches all of them standing on equal ground for me and I'm not sure which one has more cons and pros. For example I'm designing system where I can command a device...
Design Problem: A department aligned system (an application/UI and database, which we'll call System A) is used to manage both customer information and customer transactional data like orders, charges, billing information, etc. Connected to System A are 15 downstream systems - all with UI (about 12 are department align...
So, a scrum sprint is a fixed time period during which a specific set of features should be implemented. And a scrum team consists of all the people committed to delivering those features, the majority of them typically being developers and testers. Having established these rules, one might wonder how to keep all of t...
I recently wrote a protocol I call RPEP (https://github.com/Tixit/RPEP), partially in response to the unfortunately named WAMP protocol. I'm looking for feedback as to whether the protocol is specified completely enough. In particular, I'm wondering if my specification about connection establishment and closure is spe...
Say for example I was running a popular image host and all my images have an ID which they can be accessed by. If I wanted this ID to be sequential and not random what would be the best way to make sure two images uploaded at the same time don't get assigned the same ID by different processes/servers. The best way I ca...
Let me sketch the situation: I have multiple users, with certain properties (2 enums) For each user I need to fetch data, for some with some basic filtering, for some extended filtering (= basic filtering + extra filtering). I'd like to do that not separate for every user, but I'd rather group the users and do it in t...
I'm working on a mobile app that has been developed for iOS and Android (both native), localised into over 10 languages. A lot of the static string content in the app is common between the two versions. Currently, the strings are stored in a shared spreadsheet, which is a terrible solution. I would like to improve two ...
I've found description of vulnerability here. The kankun smart socket device and the mobile app use a hardcoded AES 256 bit key to encrypt the commands and responses between the device and the app. The communication happens over UDP. An attacker on the local network can use the same key to encrypt and send unsolicited...
I'm designing a RESTful API and faced with the title problem, restated for clarity: Should I fail fast if a client sends an unrecognized parameter? For example, http://example.com/api/foo?bar=true&paula=bean In the above, bar is a valid parameter but paula is not specified by the API. Should I Warn the client of the ...
Say I have an REST API for creating users in an application. The request goes to a controller, which marshals the request data into a domain object, and passes it to a service to create a user. Now, there are certain uniqueness constraints on a user. If the user service receives a request to create a duplicate user, is...
I have a data model that looks like this: Group 1 --Sub group1 ----item1 ----item2 ----item3 --Sub group2 ----item1 ----item2 ----item3 Group 2 --Sub group1 ----item1 ----item2 ----item3 --Sub group2 ----item1 ----item2 ----item3 There will be n number of each group and I would like to display this data on screen. ...
We are a young company that's developing a web app in node.js with the microservice architecture. Actual development workflow: Each microservice is stored in a private repository Different developers/teams can access to specific repositories (microservices) Each developer can work locally using docker. He must pull a ...
There's no escaping Internet Explorer 11 as it will be around until 2023 as the default browser of the most popular desktop operating system. Yet, Internet Explorer 11 will not get new updates to JavaScript, CSS3 or HTML5. Assuming most of the missing features can be transpiled via Babel or polyfilled, what's the bes...
Most modern languages (which are somehow interpreted) have some kind of eval function. Such a function executes arbitrary language code, most of the time passed as the main argument as a string (different languages may add more features to the eval function). I understand users should not be allowed to execute this fun...
I don't know how in else languages, but in PHP seems to me that they are very unsafe way how to set value of any member variable - because one setter cannot easily validate input for many variables (mostly if they are of various types) Most examples of magic setters say only public $prop = array(); public function __...
I have been tasked with connecting an existing Angularjs app to a third party service via API using Basic Auth credentials I got from the third party website. I am not as experienced with Angular and APIs as I would like, although I am familiar enough that I can research and find my own solutions. I've created a local ...
I have a website with an already-established authentication system. Once a user logs on to it, one of the features is a statistics application based on AngularJS. The app communicates with an external REST API (built on Spring) that basically just provides 3 functions: Receive a GET request, prompting it to retrieve ...
A fairly common workflow for working with git is: Fork master Make changes/add functionality in branch Make pull request for your branch vs master Merge pull request (after code review, automated tests, whatever) It is also possible to run this in parallel to another fork - perhaps you are adding FeatureB and simulta...
I have a 2d coordinates system with some points on it, like this one: Now I am looking for an algorithm (or just some approach) to find neighboured points. So, if you have the coordinates of one point, and a list of other ones, how to find all neighbours of that point? I really have no idea how to do this. If I look...
Say I have a large object - think EntityManager of an ORM such as Doctrine, or a custom DAO object, or what have you. Object, output of which is required to be used inside a class, but the object itself could be transient - do its job and then go out of scope. It does not always matter if such object is large or not...
Is it possible to use TFS Application Lifecycle Management features (ie, user stories, tasks, work items, gated commits, all the good stuff) against a repository stored in GitHub? How would one go about setting up the configuration to do this? The reason is pretty simple - we're using GitHub because work says we have t...
I intent to start learning desktop gui programming, so I've been looking to Python and it's Tkinter, PyGTK and PyGame. But I want to make proprietary software, so I'm concerned because of the licences (PyGTK and PyGame are LGPL, I don't know about Tkinter). That said my questions are: If I create a desktop application...
I'm reading about UML class diagrams and notation for visibility, and I can't tell if this book (Learning UML 2.0 by Russ Miles) has a typo or is just not explaining itself. Consider these two diagrams: Protected Member: Private Member: I fully understand the concept of visibility, as I am a seasoned Java developer.....
Microsoft releases upgrades and changes to .net, msbuild and Visual Studio quite frequently. How can I be sure the MSIL code created by msbuild or the Roslyn compiler in VS 2015 will be the same or behave the same after the updates? Completely testing an application after every Microsoft update would be time prohibitiv...
To help with an application that manipulates and works from an XML structure to produce other information, I've created a class structure that closely follows the XML structure. So, the XML is: <document> <group attr1="thing"> <title>Some group of things</title> <information> <content /> </informat...
I'm trying to create an IOT hub that can be controlled locally (Intranet) or from Internet. The problem I'm facing is of state synchronization. The following points depict what's happening at my local and cloud server. Let's say for an example on my my connected Device is at state A. Local Server Shows it at state A C...
I'm developing a BNF parser in PHP, for my own flavor of BNF. To keep the resulting parse tree, consisting of objects, as lightweight as possible, I decided to use the flyweight pattern for literals (terminals): class Literal { private static $cache = array(); private $string = ''; // private constructor for fl...
I have a large data structure that gets read in from XML. I've been given a large list of constraints that should hold between data members. For example, one of the constraints might look like some_complicated_function(data.childOne.fieldTwo.bar) < sqrt( data.childThree.fieldFive.foo.quux) My best idea so far ...
We have built a complex Angular application that sends multiple HTTP request to a REST service that is also built in house. Since both the frontend and the backend is being developed in parallel, bugs can happen in either side. It could be a bug in the REST service, or it can be a problem with the HTTP Request generat...
I'm creating some kind of a "personal assistant" application which is basically a web service that receives a message and then does something according to it. For example I send "what time is it?" and I get the current time as answer. Other examples: "tell me a joke" -> queries and sends some joke from an public api ...
I am working on a C# class library for my colleagues to use when programming industrial cameras. I'm trying to determine both the most compact and elegant method to write the class. The commands are strings, of which much is duplicated, for example 1) cmdCamera ID:1 Pan:Right Speed:127 2) cmdCamera ID:1 Home 3) cmdCame...
I currently have a website running PHP laravel. We came to a point where we want to add a user-backend -- where users sign-up and can access functions when logging in. My question is; Is it possible to build a backend running Ruby and Ruby on Rails, while still keeping the front-end website in PHP Laravel? Would we ha...
Many people mention that this is a good practice, but the work pace of junior and senior developers are different and, often times, junior developers can feel intimidated by the constant presence of a more skilled professional alongside.
I'm going to release a XUL Application to my users. It is a freeware (and maybe it will be opensource-ed later). Previously I used to package it with XULRunner and ship them all to the end user. Now I have to use firefox -app /path/to/application.ini instead. However, these slight modifications are required: I'd like ...
We are developing a website for students on which they first have to fulfill specific tasks in order to use our service. The problem is, that those tasks are on another website, which has nothing to do with ours and is currently placed in an iframe on our page. One mentionable thing is, that after the user finished th...
I have seen many libraries provide high level API in the language like python or lua. For example: The linear algebra library "Trilinos" provides a python API. The deep learning framework "torch" provides a lua API. However, I can hardly find C/C++/CUDA libraries which provide APIs for Java/Jython/Scala or any other ...
In the wikipedia article on Parametric Polymorphism, is the following commentary on C++. Can anyone explain what it's referring to when talking about "ad hoc aspects"? (I think it needs a citation). Some implementations of type polymorphism are superficially similar to parametric polymorphism while also introduci...
Many teams (such as Google have rules how code should look, including how indentation should be done, how many spaces, in which order should includes be included, etc. Some of those thing can't be automated away. Fine. But a few definitely can. All (major) IDEs nowadays support reformatting code. Why doesn't Google jus...
I have been programming for over 30 years now. I've developed numerous applications and worked in several programming languages, operating systems and hardware platforms. Recently, I interviewed for a regular 9 to 5 with a startup company that vaguely seemed promising. I did an online chat that asked me a bunch of sill...
We use Scrum. We have a month long sprint. In the beginning of the sprint we estimate tasks from the backlog and then depending on what capacity we have, we add tasks to the current sprint. However, the nature of our work is such that (we develop stock market connectivity solutions) we often have to wait for long peri...