instruction
stringlengths
34
19.9k
I heard a friend say: The first real use of Chris Okasaki's book was in Clojure's data structures I heard another friend say: No, they influenced the design of Scala in quite a subtle way. My question is: What was the influence of Chris Okasaki's data structures on Scala? (An assumption is that this is a pre-Scala...
I know a system contains a set of use case diagrams and not one use case diagram, but anyway in the first step to find the system requirements or to analyze them I have problem in distinguishing the actor of a use case. suppose the system is : Library one actor is the Member and one actor is the Librarian. a typical ...
I know some nouns in the use case scenario are candidate to be class, for example member, customer, student .... I can find such entities and some attributes of them, but my problem is that I can't easily find any method for these classes. Which part of use cases are candidate for methods or functions of classes? Pleas...
This is a classic problem which I'm sure has been solved many times by many different people. I don't have any formal training (I've not studied computer science or any other such academic subject) and so I'm not sure of the best way to solve the problem I'm about to describe. If we imagine the below diagram is an exam...
I have a BusinessLayer.dll which calls DataAccessLayer.dll which ultimately makes the tcp connection to the SQL server. Each business layer method has a corresponding method in the data access layer which then calls its respective view in the database. Now the question is what if I have a requirement where I need to g...
I have this little bit simple and general question. Let's say I build an android app which requires an online server to communicate with. The thing is that I want to make the communication on my own ( because now I know only with http post/get). Are there any libraries or how do you do this at all?
I am having difficulty figuring out an efficient (thread-safe) code design for the following problem. I have been at it for some time now and would really appreciate some advice and input on how best to approach this. I am basically searching for various patterns inside a data set. I would like to have one "master" cla...
I have a question regrading usecase diagram which im rather confused when to use extended and include. Ive gone through a tone of documents and tutorial and examples. But im rather confused. I have a scenario where it says "you can make a booking for either fitness classes or personal trainer session". So the model I h...
I am developing a typical Web Application with the following layers UI Layer (MVC) Business Logic Layer (BAL) Data Access Layer (DAL) Each layer has its own DTO object including the BAL and DAL. My questions regarding this are as follows The DTO returned by the DAL is simply converted to the corresponding DTO in the...
I know when a file is created date information such as date created, last modified, last opened, is automatically updated as meta data on that file. Is there other meta data though? Specifically, is there a way to tell what computer-name/user/whatever created a given file? What is the extent meta data can be modified?
I'm looking to mock responses from an external API service that returns JSON during live events. The first response would contain (fake) events that have happened up to time X, the second response would contain (fake) events up to time X + N where N is the interval between requests. I'm not sure how to do this. Up unti...
Which is the best approach when developing a dynamic web app with multiple views and dynamic content. regarding server load and responce times: use a server side mvc (such as Sailsjs or ASP.NET MVC) to render and then display views or use an api to get data from the server and a client side MVC (such as angular) to re...
Let say I have a list of sets, defined like this (3 sets in this example) : A = [1, 2, 3, 4, 5] B = [4, 5, 6, 7, 8] C = [1, 2, 3, 4, 5, 6, 7, 8] Total number of elements defined in sets : 18 I'd like to find which subsets are common in sets, in order to simplify the sets definition. In this example, [4, 5] is common t...
In this chart about the features that are in or out of the next version of Roslyn (specifically, for C#), primary constructors are out, but auto-property initializers are in. The best use case I've seen for the auto-property initializers is using them in conjunction with the primary constructors, i.e.: public class Cus...
When talking about things like "building your systems/applications around the cloud" or "using cloud technology for scalability", is "cloud-scaling" (from a provider eg. Amazon) this: When placing your (eg.) web application into an AWS data-centre located within your office-region, the folks working at AWS have some t...
Scala does not have break or continue, so some loop behavior takes a bit more of thinking. Ending a loop early requires tail recursion, exceptions, or scala.util.control.Breaks (which uses exceptions). The rationale for this is that, like goto, they are flow constructs that obscure flow, and can be accomplished in bett...
I have a class that represents a button on the screen. This class has two methods: one for click event; the other for long-click event. Both events do different things. So, according to Single Responsibility Principle, a class must be responsible about one thing then must be only one thing that forces you to change the...
I have some EF bounded contexts like follows public class BoundedContext_1 : DbContext { IDbSet<A> As { get; set; } IDbSet<B> Bs { get; set; } } public class BoundedContext_2 : DbContext { IDbSet<C> Cs { get; set; } IDbSet<D> Ds { get; set; } } public class BoundedContext_3 : DbContext { IDbSet<D>...
I am currently studying about pattern matching in Haskell from here. The author gives an example of the implementation of "head" function (which returns the first element of a list) as following: head' (x:_) = x He kind of explains the use of the operator but it's not clear to me. I understand that we can use it to ap...
I am building a website with a large amount of sounds that should be played upon clicking elements. (It is a language learning website, and many words and phrases will be clickable, to hear pronunciation.) In an earlier prototype I simply load the sounds on the page, and then play them in elements' onclick-event. I'm w...
The below interface inheritance is illegal in PHP, but I think it would be fairly useful in real life. Is there an actual antipattern or documented problem with the below design, that PHP is protecting me from? <?php /** * Marker interface */ interface IConfig {} /** * An api sdk tool */ interface IApi { publ...
In DDD application, I know that Domain Factory should be the single point of Domain object creation (input from the UI, the results of queries from persistence) - but I'm facing a problem that for very complex queries, we use stored procedures with multiple data sets - so data are translated to structures (classes) hig...
I already read dozens of articles and questions/answers on SO and Programmers but I can't understand what config and bootstrap files are, in the context of a web application. So my questions are : What information should I put in config files? What should my bootstrap process do? How should I call in to my applicati...
I'm working on a document processing system. I feel confident with a Document class which represents each document being processed. The issue: Each Document can have a CoverSheet, and if it does, we need to get CoverSheetInfo from this CoverSheet (for renaming and processing). But checking for a CoverSheet and coercing...
As a junior developer, I'm working in a company that develops software for the airline industry. We have a test team, so I don't have any motivation to learn testing software. My friend is working for a small company as an back-end developer. Their team doesn't have any specific test team, and they do their tests on th...
I have received a very specific requirement from a client and am not sure what solution to use. My client would like to play an online streaming video while overlaying texts and images in a sort of augmented reality fashion. These texts and images would be tempered with/animated to fit accordingly in the video (stretch...
This question has been asked here, but received poor answers and didn't clarify the issue. I believe it justifies asking it again. I understand that you can have duck typing with either dynamically typed languages or with statically typed ones (but examples for these are rare, such as C++'s templates). However I'm not ...
I tried to find an existing topic on this subject but I could not find one that was a good fit, my apologies if I was not thorough enough. Basically we have a web application that serves multiple clients at multiple corporations (single code base - 'forked' where necessary to accommodate different needs). This project ...
Duck typing is deciding on the type of an object, based on the operations it supports and the attributes it owns. Structural typing is... the same thing? What exactly is the difference?
I have this javascript project which has a unit test suite(about 200unit tests) that covers about 11.31% of the code that it was testing. The project has evolved greatly but the unit tests where never updated since. Now, I have two options: Spend some time to update the existing unit tests and then write new unit test...
I have a web application built in PHP. I want to use Git to manage the different aspects of the deployment. Some of the files in the web app are specific to a client (logos, database connection string, user uploaded files (ckfinder), etc. The rest is the same for everyone. The application is heavy so I'm afraid to make...
Is it good design to use many user controls to help refactor a web application? In my case, it's a VB.NET Webforms ASP.NET website. All our pages are organized into sections that, while related and belong on the same page, don't need to interact with each other. Each section contains many asp controls (text boxes, labe...
I have written a simple program that reads character input from the keyboard within a For loop. My professor has taken away 10 points for not checking the input using cin.eof. I don't understand why this is necessary? Presumably any non-integer character should be acceptable. The prof specifically said not to check for...
I have twenty small methods (m1, m2, m3, etc..) in a class quite different between each other, and after every method i would like to do some common actions, like increasing some counters and in the case write those counters to a file. Let's call those actions ACT. I know that I can create a method that does ACT, but t...
I'm using GCC on ununtu 14.04. My program is written in c++ and in a case i need to check the amount of time the program needs to read a large integer array. what is the best way to do this without causing unnecessary compiler optimization?
I am working on an audio software that uses The EchoNest web service to identify and retrieve metadata about audio songs and I would like to have some advice on implementing a background processing chain. (to get the full picture, I'll show you what I did already) I've implemented the following chain that is mandatory ...
Say we have a class that is frequently used in a single-thread context: public class Foo { public List<Bar> Data; public virtual void ChangeData() { for(var i =0; i < Data.Count; i++) { if(i % 4 == 0) { data[i].Baz(); } } } } ...
Given the following pseudocode: List dohList = new List(); Foo foo = A.getFoo(); if ( foo != null ) { Bar bar = foo.getBar(); if ( bar != null ) { FooBar fb = bar.getFooBar(); if(fb != null) { dohList = fb.fillList(); } } } return dohList; The whole poin...
Looking at questions such as these If immutable objects are good, why do people keep creating mutable objects? What are the drawbacks of immutable types? At what point do immutable classes become a burden? When is it inappropriate to make objects immutable? it looks to me that people are asking "why not immutable?" a...
A simplified example: function logTheColor (color){ if(color == "red"){ color = "The color is red " } else if (color == "yellow") { color = "The color is yellow " } else { color = "The color is blue" } console.log(color); } Is there something wrong with overwriting the v...
Is there a term for the above? When building a new system developers are sometimes instructed (that is a different issue) to "keep things as they are", regardless of how inefficient or unusable they are, albeit in the name of usability, training or something along those lines. Is there a term for this? And if there ...
I'm not sure how to approach this problem. I require a big chunk of data records from the SQL server. This chunk is based on variables, so I don't know before what records I need. I need to do a large series of calculations and each calculation requires one (or more) records from this chunk of data. Again: I do not kno...
I'm looking at using hexagonal/ports & adapters design in some code I'm working on and for the most part I'm happy but there is one part that I'm struggling with which how to handle the need for different return values from a single call. I'll use an example to better illustrate, this is pseudo code so names aren't rep...
I'm building a prototype web application using ASP.NET MVC 5. Part of the application is the display of a grid of records, each of which has a button action to 'Archive' that record. Another page displays the archived records. A WCF service provides the Model and persistence. I have built a controller for each of the p...
Some customization projects require vendor-provided "boxed" software to be installed as a platform. The custom development then consists of creating scripts or development of plug-ins. The required software packages can easily amount to several gigabytes in size. I'd like to have all 1st and 3rd party dependencies for ...
I want to know how whileTrue: works. I searched the implementation that is in BlockClosure: whileTrue: aBlock ^ [self value] whileTrue: [aBlock value] And another implementation with no parameter: whileTrue ^ [self value] whileTrue: [] But I don't know how that works, that's a recursive method, but this led ...
We need to create a SQL commandline tool for querying a proprietary json based datastore. I'll be using java. Any suggestions on the primary OOP design pattern I should use for building this API? I've thought about using the builder pattern in the backend that would compose the json nodes based on statements built up ...
After getting into a "heated discussion" with someone, I figured I'd ask this question for the sake of posterity. I'm willing to be corrected if my assumption is incorrect but I'd like to hear a third-party opinion by someone with more credibility than myself. Let's assume that we need to calculate and store numeric v...
I am trying to write a script that will take multiple paths to files on various servers, search them all simultaneously, and return a single list of results to a user. Initially, I was just using Python threads to do this, however I quickly ran into some noted problems: I wasn't controlling how many threads could be k...
Background I have a class TextDrawable which draws text on top of a shape. There are a number of properties that can be set while creating a TextDrawable object. Mandatory Properties: Text Shape Optional Properties: Color Width Height Font Border ... ... etc. The class will have constructors that look like: publi...
I understand that decorators solve the problem of needing to mix and match behaviors, but it was suggested that I could use the decorator pattern to solve issues of brittleness that might arise due to changes in the underlying base code. Specifically, Microsoft provides an ActiveDirectoryMembershipProvider that has vir...
I am trying to design my classes in the optimal way for the following scenario. A city has metro lines covering a number of stations.There are 4 lines represented by 4 colors.The user has to enter start and end stations and we should return the shortest route to take and cost of travel.The cost is constant from one sta...
I’ve come across this blog article: Implicit Conversion Operators are Bad. The article discourages the use of implicit conversion with reference types. The article describes problems caused by implicit conversions of reference types, which boils down to the following [...] main question of this post: why are implicit ...
This question is regarding Interface Segregation Principle Best-Practices. I use abstract examples below, but the question arises from actual code I've seen that performs what I can only call "Implementation Coupling". If I were to break my concrete MilkMan class into his respective roles, I would see that MilkMan has...
Conventional parsers consume their entire input and produce a single parse tree. I'm looking for one that consumes a continuous stream and produces a parse forest [edit: see discussion in comments regarding why this use of that term may be unconventional]. My gut says that I can't be the first person to need (or thin...
In a hobby project of mine, a "smart home" for controlling lights, I'm planning to create a feature which turns off all lights at a given time of day. There are also several other features which runs on command. I've created a stack of events which are checked on an interval of (n) seconds. The program simply iterates ...
Consider a class that prints an "outline" table for a particular product line. Say you have several, A, B, C, D. The mechanism of the table generation is the same, but the data is different. I could create a "base" class called OutlineTableGenerator, and one class per product line each that extend that base class. ...
This one may actually be 2 questions in one. Studying some APIs I came across an api suggesting to have operand different from equal (=) inside the query string (http://www.salesboard.com/api/): mycompany.salesboard.com/api/contacts?CompanyId!=5 or mycompany.salesboard.com/api/contacts?Id<=5 Is that possible?? and by ...
Using the MVC pattern, asume a simple situation where you want to send a number (for example the number of pages in a book) with a controller to a setter. Now, the set method looks like this public void setPages(int pgs) { pages = pgs; } and the controller, which retrieves the information from a textbox in view, recie...
Can someone please assist me with the following question. Write a BNF rule to parse into C -> E C -> E && E C -> E && E && E so that C generates as many E && E as needed and enforces left association. Is the following correct? C -> C && E | E It should force left association because of the left recursion and make as ...
I am designing an API where- 1. There can be multiple devices under a gateway. 2. There are multiple sensors on every device. GET /devices/d1/sensors/s1 returns the status of sensor s1 on device d1. Moving forward, I need to allow querying sensors across multiple devices. Something like- GET /devices/d1,d2,d7,d30,d45...
I'm looking for a method to describe fields in a structured way, so I am able to reuse it in various languages and levels of my application. For instance, if I'm developing an Android application about food items, I might be dealing with fields like Name, Description, Price and Kcal. However, these fields will appear m...
So a few years ago I came across a statement that most of the Doxygen generated documentation out there is quite bad. "Bad" in the sense that defies the purpose of documentation and doesn't help in understanding the code. To an extent, I think this also applies to other automatic documentation generators. The majorit...
I am currently trying to understand the best configuration for caching. I am using Azure In-Role caching (currently Colocated, but Dedicated at a later point) in a Web Api 2 application in .NET 4.5.1. The transportProperties element in dataCacheClient have two seaminly important attributes, maxBufferPoolSize and maxBu...
When developing an ASP.NET MVC application that allows the model to be updated, you need some way to know how to take the updated view model and match it back to the model that is now updated. There seems to be a few different ways of doing this and I'm wondering if any of these are not proper MVC (much like having yo...
I am looking for an algorithm that does as follows: Given a 2D grid of X,Y and a number of tiles T, places a tile in each cell of the grid such that the surrounding tiles are not the same. This should also ideally be capable of providing a random seed to randomize the output. I understand that for not all values of X...
I have never used Snapchat and do not intend to but I have been reading up about what happened to them with respect to the recent media coverage about pictures being leaked especially because I am also writing an api for my app right now and I want to avoid this from ever happening to me. Having looked into what happen...
I am learning TDD using c#, as far as I know test should drive the development, that is first write a failing test after write the bare minimum code to pass the test then do refactoring. But it is also said that "Program to Interface, not Implementation", so write an interface first. This is where my confusion starts, ...
In an agile team, who is responsible for making high-level architecture and design decisions that affect the entire system, not just the work being done in the current sprint? Maybe product owner, scrum master, the scrum team or someone else?
When the value of a normal parameter is unacceptable (and the requirements can't be checked completely at compile time), we check at runtime and throw an ArgumentException if the check fails. When the "value" of a type parameter is similarly unacceptable, what kind of exception do we throw? Are there any guidelines on ...
I wanted to as this question about VMs in general, but focused it to JVM implementations only so this doesn't get closed as too broad. The JVM has a concept of a "heap". If my understanding is correct, the heap is simply the "free store" where you can save data, i.e. anywhere in RAM that doesn't have another purpose (s...
I have an A* algorithm with a heuristic to best guide the best path. The problem is that each node can have up to 240 children and each subsequent child also... So doing a breadth first approach is going to get me nowhere unless the heuristic is very accurate. The problem is when each child node's cost and estimate is ...
When writing code, I often want to do something like this: try: foo() except FooError: handle_foo() else: try: bar() except BarError: handle_bar() else: try: baz() except BazError: handle_baz() else: qux() finally: clean...
Currently, I'm working on a system that enables users to add Tag's to available TagTypes on specific pages. For instance, we would have a TagType called "Installer" and the user wants his name associated with it (his name then would be the Tag). A requirement of this system is that administrators can add constraints t...
Some of my API actions require SMS confirmation due to security reasons, like creation of payment and CRUD for scheduled payments. Right now I just return an entity with AwaitingSMSConfirmation state and confirmationId. And then POST /SMSConfirmation with one time password and id. Is my decision with state correct? Is ...
public function obtenerColumna($delimitador='', $columna=0, $incluirRepetidos=false, $eliminarEspaciosAdyacentes=true, $filaDesde=0, $filaHasta=0) It obtains a column from a set of records of fixed-column length, delimited by a char. You can specify if you want to include repeated records and delete trailing a...
Given that a method's name might change in time, is it a good idea to specify the name of the method whose return value I am asserting as a part of the Unit Test method's name? What about the message that will be output to the caller? For example, I have a Foo object that has a Bar method. I would like to assert if Bar...
It's commonly accepted that Java generics failed in some important ways. The combination of wildcards and bounds led to some seriously unreadable code. However, when I look at other languages, I really can't seem to find a generic type system that programmers are happy with. If we take the following as design goals o...
Our company has been using newer versions of the Dojo framework, which have progressed to an AMD-based loader format. I'm currently trying to find logical ways to separate layer files, taking a module and all its dependencies, and wrapping them all into single minified files. My goals are generally as follows: Minimiz...
This is not a very general question, so it may not exactly be appropriate here, but I could sure use a suggestion if you have one: I have an object containing a dictionary keyed off of an enum, something like this: namespace Application { public enum Material { H20, CO2, Na } public class Container { ...
I'm trying to build a RESTful API using ASP.NET Web API for a game, and here are the methods I have so far: /games GET /games/:id GET /games POST /games PUT /games DELETE /users GET /users/:id GET /users/:id/games GET (fetch user's games) /users POST /users PUT /users DELETE I have two questions: Where would I place...
Actually the problem is very common. Let me describe this by example. Imagine you have a web service where users register and pay for some gold status. There is expiration date. The question is how to remove the gold status in time? I see at least two solutions: Write a daemon that checks user statuses and current ti...
Guidance on good application architecture / design is not in short supply however most of the examples focus on some business object, like Customer and its behaviour and persistence. There is little guidance on software that is focus on integrating existing systems. For example integrating SharePoint with an applicati...
Many (most?) AngularJS folks seem to advocate for breaking AngularJS apps up into many modules. Brian Ford in his blog already states that packaging by layer (controller, service, etc.) is a "silly" notion, so I won't even go there. (See http://briantford.com/blog/huuuuuge-angular-apps.) But let's suppose that you modu...
Could you please show me an example how to compute the location of an element in a multi-dimensional array. It is illustrated in Robert Sebesta's book Concept of Programming Languages that location of an element is given by the formula location(a[i,j]) = address_of(a[1,1]) + ((i - 1)*n + (j - 1))*element_size where n ...
I have a nodejs project in which a sample.js include two function function A depends on function B's callback . // smaple.js Both function are included in the same file function B ( arg1 , callback ){ // do some async async.map(arg1 , function(item, cb){ va...
I own a Raspberry Pi and would like to use it as some sort of websocket relay, so that all people who visit a specific webpage would be able to communicate with each other. The key thing about this is that I want to define my communication protocol in Javascript on the client side. (IE: The messages that clients send t...
I've heard a lot of talk about using lightweight data modeling as of late. Especially in relation to the Clojure programming language. What is it and how it differs from traditional classes regarding long term maintainability and flexibility of the design that relies on it?
I'm trying to develop a little game and for this I'd like to separate the UI from the game logic. So I'm thinking of using an "Animator" class that will be responsible for rendering the objects, but I have a bit of a dilemma here. I can think of 2 options to implement it: Option 1: for each object the "Animator" will h...
I'm looking for a proper name of a class template with the following features: It's interface would look something like this, where Foo is a placeholder for the name I'm looking for. template<typename T> struct Foo { T* operator->(); T* operator*(); } So, it imitates a pointer to an object, much like std::uni...
I'm working on a small project in which I'm attempting to practice relatively strict adherence to two ideas: Tell, don't ask (TDA) Immutability The main concept in this project is a Map (as in a geographical map, not the data structure), which holds a 2D array of Tiles. The tiles can be thought of like squares on a c...
I'm trying to port a very basic dual contouring algorithm written in Python (here) to C++. I'm not a Python programmer so some of the language syntax is a bit foreign to me. Specifically, this block of code is giving me trouble: # Estimate hermite data h_data = [estimate_hermite(f, df, o+cube_verts[e[0]], o+cube_verts[...
I am working on a project wherein we are to use SVN as a source repository and we need to identify a branching strategy. I am aware of branch by release & branch by feature strategies to certain extent but I am no expert and I am not sure which one or if at all either is more suitable to our requirement. We have 2 env...
I am starting my first year (in college) in Computer Science next year and I write mostly in C (if that is to matter). I have tried searching but most of what I find assumes knowledge of lambda calculus. Why is lambda calculus considered so much more useful than single variable calculus in prograrmming? Is there a rela...
as I understand it micro-services are autonomous and have complete control over their own data and therefor each micro-service has a dedicated database. I was wondering what would be the approach to implement reporting in a micro-services architecture, if reports depend on data that exists in multiple databases where e...
I keep hearing the phrase "Favour Composition over Inheritance" from GoF, which is being annoyingly mentioned repeatedly by my friend, who thinks it is a valid blanket statement. But is it not more sensible to consider that the real reason why inheritance exists is not just for behaviour reuse, but for the case where a...
I have a list of strings say L and an array of words say A. I want to find a string from the list L that is a best match to a string created from the permutations of the words in the array. The array of words has about 200 elements and each string in the List L is of the same length say at max of 150 characters. Somet...
I translated a GPLv2 C program to Python, but found it was hard to extend as designed and rewrote significant portions of it. The program is now structurally completely different, but there are several verbatim translated functions in use. The Ship of Theseus Paradox (as stated from Wikipedia) "raises the question of w...
I am writing a Multiset in Ruby. The Union, Intersection operations where simple and return a MultiSet. But, I am not sure what the return type of the cartesian product should be, should I return an array of tuples? is that a good api? MultiSet.new([1,1]) * (MultiSet.new([1,2]) In Math it is {1,1}*{1,2} = {(1,1),(1,1...
To give a complete example, let's say I have a template class that I now use to generate a type definition: template <typename T> struct A {}; using X = // I'm not asking about this A<int>; // I want to know what this is What is the name of A<int>? My initial thoughts were that it was a generic specialisation of A,...