instruction
stringlengths
34
36.1k
I have a methodological question. I am faced with a reasonably large legacy system (Java Enterprise). I am new to its codebase -as everybody in the team- since it's a product we had in outsourcing that the business people decided to bring in-house because it became business-critical. The current state of the project is...
Recently, there was a rise of interest toward asynchronous programming in Python community. First prominent expression of this interest was the appearance of Asyncio —codenamed Tulip— framework [PEP 3156] in the standard library, and then, after a couple of years, the capability to write async code was introduced to t...
At our company, we have a single version control repos with a structure like this: /client1_product /client2_product /... /shared_lib1 /shared_lib2 /... After almost two decades of development, this list has become long and confusing, mixing active projects with those long dead. Orientation is difficult for newcomers....
Below is the function count_leaf, that appends mutable list branch_counts, which is not stateless. def count_leaf(tree): if is_leaf(tree): return 1 branch_counts = list() for b in tree: branch_counts.append(count_leaf(b)) return sum(branch_counts) Below is the program that uses list com...
Introduction / background: CSS components For a relatively large website we are working with SASS, and trying to manage CSS in components. The basic idea of components is that a component should look the same everywhere, independent of container elements further up in the DOM. So, we want to avoid stuff like this (SASS...
Kind of a follow-up to Should I write HTML or CSS first? On a relatively large website, we are considering to use SASS and/or Bootstrap. From previous projects, there seem to be different ways to go about it: A framework (e.g. bootstrap) provides a bunch of css classes (esp for the grid layout). We may even add to tha...
I have to model and manage a time-based configuration. Typically - without an OR mapper - I would start with the database tables. Screen Color ColorScreenMapping ------------- ---------- -------------------------------------------- id | name id | name valid_from | screen_id | color_id...
I am working on an app that will be open-sourced and published on GitHub. But, the problem is, that the graphics my client gives me contains some in-house characters that the company owns. We have a deal that the code will be MIT or Apache 2.0, but how do I handle the images? Do I have to omit their upload on GitHub or...
I am currently planning an upcoming project and am looking for an algorithm for searching a database. The search is as follows; There will be some specifically labelled criteria (or fields) and I would like to find any objects in which its fields match the specified criteria. As well as this it needs to rank partial re...
I've got bunch of strings with variable-length prefixes (or postfixes - I can always revert them) as follows: 0155555555 523455555555 755555555 ... 87129999999999999 119999999999999 09119999999999999 The prefixes are random and of unknown length (could be 0 too). The common part are not fixed digit (used it above as a...
A common practice for SVN tags is to tag different releases in order to be able to find them with ease later. As I understand it, tagging is the same thing as branching, that is in two cases, it just creates a copy of the trunk in a separate directory (would it be branches/something or tags/1.2.3), which means that: T...
Original question here I am learning OOP and SOLID. I have a 'main' class that performs some actions after reading variables from a config file. This 'main' class is not the focus of this question but it can be described as a concretion. I am trying to split up the process of reading the config file and using its setti...
I read once that a method should either have a return value (and be referentially transparent), or have side-effect(s), but not both. I cannot find any references to this rule, but want to learn more about it. What is the origin of this advice? Out of what person or community did it arise? Extra credit: What is the c...
If my header looks like this: class foo { public: foo(); ~foo(); QString b(); QString c(); QString a(); void setB(QString s); void setC(QString s); void setA(QString s); private: QString m_B; QString m_C; QString m_A; }; Should my source neccessarily correspond like this...
here is my workflow. I have master as the most complete version of the program. If I want to add a feature I'll create a branch named with -feat as a suffix. as bugs come up, I'll create new branches from the feature with a -bug suffix. as bugs get solved they get merged back into the parent feature. If the feature bra...
Here is two methods that does the same thing. One is repeating the call to the method Print where the other one does not but has an additional variable. class Program { static void Main(string[] args) { Snippet1(args); Snippet2(args); } private static void Snippet1(string[] args) { ...
I have a design question for working with databases in object-oriented PHP. I have a table in my database called products. Then I have 2 classes for this table in my PHP project. ProductsRepository.php and Product.php. ProductsRepository.php currently looks like this class ProductsRepository { private $db; pu...
In my job we work in a data driven web application and performance is a important business feature. So, queries in the model tier are frequently large and contain much of the business logic. As a result we have many Integrations Tests that rely in XML datasets used by our test framework(an abstraction to DbUnit) to pop...
I have some code that I'm refactoring, right now its just a list of functions, primarily jQuery. The code is a form builder. The user adds sections, questions etc using jqueryUI drag/drop/sort. They can get quite long in the range of > 1k questions. I've been debating between patterns,frameworks, etc. and have settled ...
If I had a method like: private void someMethod() { runSqlQueryA(); runSqlQueryB(); runSqlQueryC(); } My understanding is this method will be one thread. In weblogic, the thread will appear stuck if it's been running for longer than 10 minutes (by default). My question is - if these SQL queries are routi...
I made a program, which was supposed to run every night as a windows scheduled task, let's say the program is just one method, called Do_Task(). Usually you need to press a button to run the Do_Task() method, but In order for it to run as a scheduled task, I had to call the Do_Task() method in the form loading event. (...
Well, first of all I don't really know how the hardware of a smartphone is, and I've just programmed for Android. But it feels safe to think that a smartphone is just an old PC with some particular things, but an old PC anyway, I think even the worst smartphone today likely has more power than the an standard PC equipe...
I've noticed some projects like to store constants in their own file, i.e constants used globally and in the main program loop might clutter the main file so perhaps they look to place them elsewhere and then reference/import file/class. I understand that when writing an OOP class that you'd want to keep all constants ...
Not sure if this is the right venue to be asking this but here goes. A little background. I'm trying to build an ecommerce app that would allow sellers from other venues--like, amazon and newegg--to import their products using their export/import files. An example would be a user having an XML feed that looks somewhat ...
I have recently become responsible for a legacy tool that analyses code and provides a log as output. As part of the JUnit suite for this, there are ~100 tests that rely on successfully matching the produced log with a static expected log. Now this means that if the format of the log changes at all, it will break the u...
I'm trying develop an add-in for an application using it's API and I have Option Strict turned on. Trying to work with these COM objects is causing multiple compile issues saying Option Strict On disallows implicit conversions from 'typeA' to 'typeB'. I'm currently overcoming the issue by using DirectCast, which ...
I am new to repo management / continuous integration. I designed a repo in the following way PROJ |-src |-include |-lib |-config PROJ_Unit_Tests |-src |-config PROJ_Doc When I now do continuous integration, i.e., running unit test on the build server, should they run on every branch or only on the develop branc...
I'm looking at a very large object within the application I'm working on, which is there to basically hold all the data together at a large level. Recently, we have started moving some methods out of other objects on the ModelData to the ModelData itself, because these methods are changing drastically now that we are i...
I am working through the Shunting-yard algorithm, as described by wikipedia. The description of the algorithm when dealing with operators is as follows: If the token is an operator, o1, then: while there is an operator token, o2, at the top of the operator stack, and either o1 is left-associative and its precedence ...
With a new feature in PHP 5.4, we can access a class member on the same line as instantiating the class. e.g. // Instead of $obj = new myClass(); $obj->myMethod(); // PHP 5.4 allows $obj = (new myclass())->myMethod(); I have a class which doesn't need the object (variable) from the instantiated class, because the...
I see a lot of texts, especially functional programming texts, claim that certain CS concepts "don't compose". Examples are: locks don't compose, monads don't compose. I've been having a hard time tracking down exactly the meaning of this phrase. When I think of composition, I think of either function composition or ob...
I've recently been assigned to a new project because I'm one of the only developers at my company who has used Python extensively in the past. My first task was to clean up the code base and make it more Pythonic - while doing so I came across this: import logging # The builtin logging module def logInfo(message): ...
Suppose I have a user story of size 20 that can be split in other 2 user stories, making the original story an epic. Should the sum of these user stories add up to 20? What's the best practice in this case? If they don't add up that could mean in practical terms that the overall complexity of the project changed.
What term can I use to describe something with O(N log N) complexity? For example: O(1): Constant O(log N): Logarithmic O(N): Linear O(N log N): ?????? O(N2): Quadratic O(N3): Cubic
I need some help to improve the architecture of a site I've built. What I want to achieve within a single Django project is the following: I want a site that comes in several versions (one per year), such that each version has a set of apps that are related to that version. I want to keep all the old versions of the s...
Consider the following: I have controllers and views in a client-application. As this runs purely on the client side, each controller must only exist once. At first I thought about implementing everything as Singletons but this doesn't really feel right for a few reasons. A few is instantiated like so: abstract class ...
Suppose I create some widget, and decide to share it with Github. In this widget project, there's some configuration/preferences file. I need to share what the values being set are, so that if anyone else wished their own widget they'd know what to set. But I don't necessarily want or need to share my own settings. Thi...
So I am changing my code over to a table driven formula system to make it sustainable in the long term. So basically I have 5 foreign keys that will get me to a single formula to use. However I'm not quite sure how I should store the formula. At the moment I am just using a char(100) and parsing it in Java on retrieva...
When the program run successfully, usually the program will return 0 status. If there any problems, the we can return value other than 0 at exit. With Exceptions, (as long as the problem is not undefined behaviour), we can return 0 value even though program is unsuccessfully finished. My questions is: Is the status co...
I understand the difference between partial function application and a curried function (f(X x Y x Z) -> N vs f(X -> (Y -> (Z -> N)))), but I do not see what the consequence of this difference is when developing software.
Since sequence diagrams depict messages between objects in a system, the messages have to be representing method calls. My question is if I have two objects in the diagram lifeline A --- doSomething(parameters) --> B which object is invoking the method? Is A calling its method doSomething which in turn uses B in its im...
I'm trying to implement an architecture that's similar to the coreos's production architecture (shown below) Should I run the database as a central service or one or more of the workers? I figured the database needs some kind of replication, which makes me think that putting it in the worker cluster makes more sense, ...
The FAQ states: ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original. That makes sense - if I want to include a graphic under that license and modify it, then I have to make that modification publicly available under the same ...
Googling this question has proved somewhat useless, so the ¬ symbol: What is it for? What is is called? Is it used in any programming languages?
This program (written in ruby) finds the largest 3 numbers in an array (without sorting the array). It has a while loop with three pointers. My fist instinct, since there is only one loop is to say this solution is O(n). But, the pointer's j and k get reset when they reach n which seems the same as using 3 for loops, ...
I'm trying to make sort of a game where I have a a grid of 20x20 and I display a player (P), a target (T) and three enemies (X). All these have an X and a Y coordinate which are assigned using rand(). The problem is that if I try to get more points in the game (refills for energy etc) they overlap with one or more of t...
This seems like it should be fairly straight forward but I'm having a devil of a time with it. Hoping some of you fine folks might be able to lend a hand. I'm using PHP & MySQL, and want to calculate the flow rates of traffic to certain web pages. Ultimately I want to be able to send myself alerts when flow rates ris...
Just curious, from a syntax parsing perspective, why does Scala actually require parentheses around the condition of an if statement, given that the only thing allowed after if is (?
Context I am creating a e-commerce website. We sell products in a really limited amount (+/- 10 available items per product). Problem How to deal with stock updates when a user makes a purchase? Example We have 5 items for a product. The user checks out his cart with 4 items, fills in his details and goes through the p...
If I am collecting data that needs to be posted to a web service on a regular (~5 minutes) basis, and that service has temporarily gone offline, what is the best practice to ensure we don't lose any data? Of course, we could simply buffer in memory until the service is back online, but what if the service is offline fo...
I have a cron job running that is a Scala application. I want another job, that runs forever, to do something when this one finishes. It seems to me some kind of signal (Unix/Linux signal?) has to be sent for this. For e.g., the first job writes to a file and after it finishes the second job (which is already running) ...
I am currently trying to refactor some code and one of the problems I came across was the constructors had far too many parameters (15 in fact) and was being initialised by another object which had the same amount of properties. I am meant to be reducing the amount of classes we have so creating a set of classes which ...
I'm firing up an MVC project in which I'd really like to use Dapper as my ORM, as I like to be as close to the database as possible for performance and SQL tweaking reasons, yet still have the power of an ORM. However there is one big snag, and that's identity & role management. MVC scaffolding makes this nice, quick, ...
I am new to databases. I am using MySql. What I have is a student system which stores rules for students in a school. Each student may or may not be a part of a group (Soccer, Guitar, etc). Different rules are imposed on individual students and also on groups. Student table: |Student_id|Student_name| |----------|------...
I have a given byte array in C and I need to match it against several byte arrays and return true if there is any match. I can make various memcmp's but I feel that it is very inefficient. Do you know a better way?
I would like to solve the following problem. On my website, I have a list of my publications. I also have my list of publications on a latex file of my cv. The issue is that I update these manually, and it becomes tedious and error-prone to keep both in sync. I am considering writing a program that will automate the pr...
I often find it cleaner to write a generator than to return a list. For example, I prefer def my_func_gen(foo): for i in foo: # Do some stuff that's too complicated for a list or generator comprehension yield whatever to def my_func_list(foo): result = [] for i in foo: # Do some stu...
The company I work at is initializing all of their data structures through an initialize function like so: //the structure typedef struct{ int a,b,c; } Foo; //the initialize function InitializeFoo(Foo* const foo){ foo->a = x; //derived here based on other data foo->b = y; //derived here based on other data...
I am writing a console application and have a class called ApplicationConfiguration that contains methods to check some of the settings and also return values from my app.config file. For instance the following method in the ApplicationConfiguration class returns the location of log file from my app.config file: publ...
So JavaScript's bind supports currying, but most people use some other library like lodash or ramda to do currying. From first impression It seems like bind supports context changing, since that is it's intended role, e.g. var replaceTest = replace.bind(this, 'test') replaceTest('beta', environments) The other curry ...
Whenever I'm writing code, I always stub out my methods like this (not necessarily using generics): public T MyMethod() { T result = default(T); // or null return result; } This always puts me in the right place to fill out the logic and make sure that I have a return variable to track throughout the process....
I'm working on a small application where I need to model tables and columns from a relational DB. I've been reading some material on nested classes, which is recommended to be used sparsely. However I'm thinking that this might be such a scenario. I wish to implement these objects as follow: 1. Table contains List<...
If I am not concerned with unit testing and switching my data access out at a later time, would using my entity framework objects as my business objects be okay? I have an existing database for which I generated entities and a datacontext, and have partial classes for holding my methods and any additional (non-database...
We are using some open source code licensed as Apache License 2.0. From what I understand, we cannot endorse the company that made the code. We are using it to develop an free app with micro purchases, but the code isn't actually located on the app, it's located in the cloud on our processing servers. Our app doesn't a...
Suppose I have a users table and in that users table I have a role_id. In my roles table I have: users - id - role_id roles - id - name roles id | name 1 | admin 2 | normal Now in code I want to disallow access to the admin.php page. So at the top I put if ($user->role_id != 1){ header('location...
I'm currently working alone on a project, but I still use Git since it is a really powerful tool. I use gitflow workflow methodology, and today I have merged to master with 77 commits. I was surprised since I wasn't expecting this big number, but it made sense since I had added over 4 features in a 2 week iteration. Wh...
The problem is: The team , I am working in has 10 developers to 2 testers ratio which means we are going to churn out code more quickly than it is "Test" done. So, What should be the right approach to track activities in such scenarios according to agile experts? My fear is that soon the day will come , when there is a...
In discussing push vs polling with a colleague, we were trying to figure out if there is a well-defined difference between two sides of a conversation being 'connected' vs being 'disconnected'. For an example, think of a TCP connection being 'open'. We ended up deciding that the notion of 'being connected' is really ju...
I have a Python-Flask app in which users can place files into a folder. As of now the directory structure is something like: /app /storage /templates . . . server.py The user can create directories and subdirectories within storage to organize files. So far I am making AJAX calls to the server ...
I had an argument with my PHP developer today who tried to convince me that REST API has to provide all the request from PHP since a server is faster than client devices such as desktop. As I am a REST API developer, I told him that it would be better if client can reduce the number of API request since since client de...
I'm working on an algorithm that's split up into multiple parts, each of which performs different tasks but is more or less separate from the others, by which I mean the only interaction between the parts is the passage of a single piece of data from one part to the next like a conveyor belt. I was doing some unit test...
I am assuming because it is a standard practice in the Angular world that, any sort of module system has to be wrapped as an Angular module and angular should be the only global variable used which will avoid any conflict.
Imagine a cube based world (such as Minecraft, Trove, or Cube World) where everything is made up of identically sized cubes and all the cubes are of the same kind. The goal is to represent the world with the fewest number of rectangular boxes (by merging cubes but retaining convex shape (aka, a rectangular box shape))....
I really don't know if this is the right forum for this but I need help designing my database. Also I apologize for the horrible title: I don't know how to summarize the issue below in a single title. I am building a reservation system where one reservation can have multiple services. Something like the following (sing...
So I've been writing a lot of JavaScript lately. Despite what many people say I think JavaScript can be a simple and beautiful language. What I've pondered of late is how to structure the code so it is best readable to the human eye. Sometimes there are cases like this: mainFunction = function(){ var init = function...
I'm creating a program which takes a document, extracts it, and then moves this into a database. I've done most of this now and I've realised that I haven't made any instances of classes I've made (I have made instances of other thing such as buffered readers and arrays etc). Is this bad? I seem to just have classes w...
I assume this is largely language-agnostic, but I'm working in C# if it's not Let's say interface I3 inherits from I2, which in turn inherits from I1. I could write this: interface I1 { ... } interface I2 : I1 { ... } interface I3 : I2 { ... } Or alternatively this: interface I1 { ... } interface I2 : I1 { ... } int...
I'm writing a toy compiler for fun. Basically, my problem is that I don't want to clutter the AST with stuff like debug information (symbol tokens, locations of tokens, etc) as well as data that the semantic analyzer computes. For example, the semantic analyzer does some type inference and the result type is stored bac...
At my company, we have a solution composed of a WinForm (multiple per client) and an API (one per client). This solution is deployed on different clients that require the solution to behave differently according to their desires. The same code base must support UI customizations (client logo, buttons visibility) and fu...
In this issue, the microphone at point A records audio, compresses it, and sends it to the server at point B somewhere "in the cloud." The point B server then figures out what rooms the recorded data is going to, and distributes it over the devices in the rooms. The issue is that, of course, since the server is off-si...
When writing a library function, such as double getAvg(double[]); how should one handle the empty array? (Note that, mathematically speaking the avg of an empty set is undefined.)
Is it possible to write a C++ program that, say, passes an int array to a java program without writing it to a file? Motivation for question: I was wondering what matlab is and how it came to be an application that was written in several different languages (as opposed to being available in different languages i.e., th...
Empty interfaces are generally consider bad practice, as far as I can tell - especially where things like attributes are supported by the language. However, is an interface considered 'empty' if it inherits from other interfaces? interface I1 { ... } interface I2 { ... } //unrelated to I1 interface I3 : I1, I2 { ...
Watchpoints and data break points make it possible to watch the changes of a value in memory in many languages. Much of the justification I have seen for getters and setters and private variables hinges on the getters and setters being clear places in which break points can be set. If watchpoints and data breakpoints m...
I have a class with two readonly int fields. They are exposed as properties: public class Thing { private readonly int _foo, _bar; /// <summary> I AM IMMUTABLE. </summary> public Thing(int foo, int bar) { _foo = foo; _bar = bar; } public int Foo { get { return _foo; } set { } ...
This one still occupies my mind. How do you model 1:N relationships. Consider having a category and product (typical e-commerce scenario). Every product can (don't have to) be associated to only one category. Should I model such relationship as: (pseudo-code) Product { Category category; } Category {} or on Categ...
The client side of my application is written in VB.Net, it accesses a java server. Server logs every request that was made by client, client shows every exception to the user (with an option to send it to support). The question is: would you add logs to the client side? If yes, what information does it make sense to ...
The example below is totally artificial and its only purpose is to get my point across. Suppose I have an SQL table: CREATE TABLE rectangles ( width int, height int ); Domain class: public class Rectangle { private int width; private int height; /* My business logic */ public int area() { return widt...
Background Support and Sprint are the test branches for bugs and tasks Each bug gets a new branch from master, which is merged into Support, when tested good, a pull request is made between the Support branch and master. Each task gets a new branch from master, which is merged into Sprint, when tested good, a pull req...
I've recently finished reading "writing effective use cases" by Alistair Cockburn. I'm looking at building a web application that sits upon 2 web services. Should I have use cases for "web application requests data from service" that corresponds to "user wants data from web application". I see 3 options. Treat the un...
If someone makes a request with a Content-Type that doesn't match the syntax of the request body, how should the server respond? Is there a standard way of handling this (seems like there would be), or is it up to the discretion of the service implementor? EG Someone posts something with Content-Type 'application/jso...
Where I define Cyclomatic complexity density as: Cyclomatic complexity density = Cyclomatic complexity / Lines of code I was reading previous discussions about cyclomatic complexity and there seems to be a sort of consensus that it has mixed usefulness, and as such there probably isn't a strong motive for using it ove...
When I'm on a git project, I have a workflow that goes something like this: Start a new feature (open a new branch) Write some code, commit some code, repeat Push the code to a remote, possibly with my initials in the branch name, and 'WIP' commits, indicating that it's unfinished Once things start taking shape, squas...
I am drawing sequence diagram for large integration project where one system will initiate the REST call to another system and there is a proxy in middle which will pass through the request like A->b->C where b is a pass through system. I have shown 200 returned from C->b->A. I am wondering how do I depict when C retu...
EDIT: Apparently the below question is too specific. Let me rephrase: I'm looking for a way to fit a letter into a list of specified ranges such that, if given the letter S and the ranges A-F, G-M, N-T, U-Z, it would select the third range. ORIGINAL QUESTION: So let's say I have a file: John_Smith.pdf And I have a dir...
I'm currently working on a project to develop a relatively small framework with the goal of supporting game development efforts for students in a course. The scope of this project is an OpenGL-based renderer and a 3D scene graph, and must be written in Java. (That's the course pre-req. for students.) I'm familiar with ...
While I was trying to concrete the concept of design pattern, I came up with a question: As I asked in the title, Is MVC(Model-View-Controller) architecture kind of Design Pattern?
I'm developing a web app for internal file sharing and one of the requirements is to have PIN code protected folders. What I came up now is a folder like structure with the following: Folder without PIN code entry - only Open button which directly forwards to the folder Folder with PIN code entry - text field with Ve...
I recently started working in domain of mesh generation . My programs usually contains large chunks of procedural code consisting of several phases. Eg. class MeshAlgo1 { /* A very long function */ void DoSomething(MeshData data) { // Phase 1 ... // Phase 2 ... // Phase N...
Take this code: requestAnimationFrame(function (timestamp) { console.log('one', timestamp); }); requestAnimationFrame(function (timestamp) { console.log('two', timestamp); }); // logs: // "one", 184.6999999834225 // "two", 184.6999999834225 The timestamp is milliseconds since the page loaded. Note these two rAF ...