instruction
stringlengths
34
36.1k
I have a file editor. It reads from a file, creates an object with the read data and can then write that data into a same (or another) file. Every time user opens a file a new tab is created and a private instance of the object is assigned to it, containing it in the tab. The object itself is complex and is composited...
I have a weird question for community. One well respected by management developer is strongly against putting data files for JUnit tests in the Maven project directory so that they are committed to the version control system (VCS). His reasons might be formulated as: Project managers do not have convenient access to V...
Again and again I find myself in situations where I want to do this: class Outer { private static final Runnable Inner = new Runnable() { private static final String CONSTANT1 = "foo"; private static final int CONSTANT2 = CONSTANT1.length(); //'static' gives error private static final ...
Is the #include order guaranteed by the standard to be the order of the -I options in the invocation: example: having the folders and files: A/foo.h B/foo.h can it be guaranteed that #include <foo.h> when cpp is invoqued with ... -I A -I B ... will choose A/foo.h ?
We're multiple users working on multiple apps using one same database. The database schema is used in production, preproduction and development environments. Right now, we're keeping it updated using migrations across all environments, but this leaves us with hundreds of migration files and it's incredibly messy. Is th...
I have a class which will have a huge number of properties (30 to 50). A huge numnber of these properties will be read only on the client. Is it a good practice to have one class with lots of properties or have smaller classes and use them as properties in parent class? Note that objects of this class will be sent to c...
We want to serve different applications on the same domain, based on path. For example mydomain.com Serves a WordPress website and mydomain.com/app serves a google app engine application. My natural choice was to point to mydomain.com at a cluster of NGINX machines, which are configured to proxy based on path. My quest...
I just came across this question telling how to store ListView Data(basically ListView.Items) into a text file but it got me thinking that, is it the best way to do it? In terms of efficiency, basically running available operations of the data efficiently, because storing large ListView Data might take time to access w...
I am highly confuse while calculating time complexity of Merge Sort Algorithm. Specifically on the Dividing Step. In the dividing step we have to calculate the mid point of "n" i.e. "q = n/2". How it will take constant time. If we assume that divide is an elementary operation and take very less time, then also we s...
Introduction Many of the mainline vector graphics rendering engines have an algorithmic flaw in them. They render each shape separately, and antialias by calculating pixel coverage and then compose them on top of each other. Yes it is simple but the correct solutions are even simpler. This leads to a conflation problem...
According to this article on Appropriate Uses For SQLite it says that, while SQLite is limited to 140 terabytes, a client/server RDBMS may work better: An SQLite database is limited in size to 140 terabytes (247 bytes, 128 tibibytes). And even if it could handle larger databases, SQLite stores the entire database in a...
I am currently implementing my own programming language. Until now I have written: An Error class for errors (to be thrown) encountered while processing the input source code; Some SyntaxError functions (each one with a different tag, passed with a template, like SyntaxError<malformed_number>() or SyntaxError<unexpect...
I'm implementing a state-pattern design in Java to calculate the current position of an object following a trapezoidal trajectory. The pattern consists of a Context, State and states classes. Currently, the variables (accel, max_vel and target) are passed as parameters to each state object upon instantiation - in effec...
I have created a standalone application with WPF and I need to use some of its functions via web. In few words, I would like that an user can access a web page and have the chance to insert some data and invoke some of the functions present in desktop application, which is running on a remote machine. My idea is to cr...
I'm writing a compiler that compiles to C, one thing I'm attempting to do is implement a construct like Rust's match: // { some function let mut foo = 32; match foo { 3 => return "hey", 4 | 5 | 6 => return "foo", 9 ... 12 => return "blah", _ => return "bar", } // } How would...
Under static scoping, by its definition, how can we determine the scope of a variable inside a recursive function? For example, in a pseudo-language, int i=1; function myfun(){ if (i > 4){ printf("%d\n", i); } else { ++i; myfun(); } } myfun(); i changes in each call to myfun According to static s...
In previous applications I've worked on, I've had a single factory class which built my object structure, and all dependencies were passed to each class through its constructor parameters. I'm now considering using a DIC framework such as Pimple, in which case it seems like you have a global dependency container which ...
I've been having some trouble coming up with a design that would alleviate most, if not all, the issues I've been running into, and I'm wondering if it is my base design. Our company accepts orders. We accept different types of orders based on the product line they belong to, but all orders share some functionality and...
I currently work inside a system that any new tools get created as an ASP.NET custom server-side control, rather than a Forms or MVC page. One of my most recent projects is to convert a Forms page into a control (basically moving from an old site to the current one), and as far as I can see, this requires very few cha...
In C, the assignment command also returns the value assigned, so it is also an expression. Similarly, initialization, which happens when defining a variable, also assigns a value to the newly created variable. In programming languages, does a command for initialization ever return a value, so it can be used as an expre...
So I have an unsorted data set with x and y float coordinates as keys. The data is in a txt file. It looks like this: x,y,data; x2,y2,data2; etc I need to retrieve all data in a specific rectangular area multiple times with different areas each time. What would be the fastest algorithm to do this. (I'm working in C#) M...
Is it possible to use static or dependent types to prove a function is idempotent? I've searched Google and various places on StackOverflow/StackExchange for the answer with no luck. The closest I've found was this conversation about Idris: https://groups.google.com/forum/#!topic/idris-lang/yp7vrspChRg Unfortunately, t...
Added Just found two related questions https://math.stackexchange.com/q/1759680/1281 https://stackoverflow.com/a/2582804/156458 In programming languages, from Michael Scott's Programming Language Pragmatics In general, a value in a programming language is said to have first-class status if it can be passed as a para...
I have an app with the following structure (simplified a bit here)... var RecorderApp = function(canvas) { this.state = undefined; this.states = { record: recordState, save: saveState }; this.init = function() { this.audEng = new AudioEngine(); this.waveDisp = new WaveformDisplay(canvas); this.mouse =...
I'm reading this article, Low Level Programming of the Raspberry Pi in C, which explains how to access the raspberry pi on a low level. It states that the virtual gpio address is 0x7E200000. Therefore a macro is defined like this #define BCM2708_PERI_BASE 0x20000000 #define GPIO_BASE (BCM2708_PERI_...
I'm working on simple 8086 simulator. But I'm not sure how to implement lock prefix. I know this prefix used in semaphore implementations. 1) For now I have only 8086 core and no other cores like FPU. Manual says lock prefix used in multiprocessor environment. So how treat lock prefix with 8086 alone. 2) How to treat ...
I'm working in a corporation that has two products. One is a desktop application the other is a web-application. I'm in on the part as backend-engineer on the web-application. I design the web-interfaces. We use SOAP as the interface technology. Now as the product develops there are lots of changes in the current not r...
Our build process changes the version number of all AssemlyInfo.cs files, so that the version number can be managed completely by the build server. Right now, we commit the changed AssemblyInfo.cs files after successful build. During evaluation of TeamCity, I couldn't find a way to do that without using svn via command...
For some reasons, I need a child-first ClassLoader. Such ClassLoader doesn't exist in the JDK, so I'm writing it. Since this is a key component of my use case, I'd like it to be heavily tested. To ensure it's not changed without breaking the behavior, I want to be extremely thorough and test all that's testable automat...
I am currently building an application that consists of multiple small rest services that communicate between them. For example, a request to service A might make requests to services B and C in the background. The question is, how can I mock the services B and C in order to test A (that includes checking if the reques...
I'm working on medium sized ASP.NET MVC 4 web app, that is about 2.5 years old. Around 25-30k lines of code. The project has never followed any of the good .NET design practices. It is a very tightly coupled solution. There are not interfaces at all. Do you think it is worth to upgrade the legacy/spaghetti code to foll...
I'm writing a Java client library for a simple API service and I was wondering how much should I be strict for invalid values. For example for an endpoint a parameter should not exceed a certain value. Should the client check this parameter and abort the request, execute it anyway or log it as a warning? If the API doe...
I work in a small programming team supporting a larger organisation. This year our manager has decided we are going to use Oracle Apex technologies to handle the vast majority of our company data. This would be ok, except we only have one Apex server. Our manager has decreed that everything happens in that one instance...
I am trying to decide the type of relationship (or association) there is between the following two classes: Class Stable { private const int MaxStableRooms; private Horses[] Horses; public Stable(int MaxStableRooms) { Horses = new Horse[MaxStableRooms]; for (int i = 0; i < horsecount; i++) Horses[i] = new Horse();...
First let me explain what is my understanding of the terms statically typed language and type safety: Statically typed language: a language that does not allow you to change the type of a variable at run-time. Type safety: type safety means that you are not allowed to mix incompatible data types. For example, you canno...
I believe, in Python defaultdict inherited from dict violates Liskov Substitution Principle. defaultdict doesn't raise KeyError while x in d is still False, for instance. Is that so? If it is, why developer decided to make such a sacrifice?
In the context of MVC sometimes I find myself creating a Factory and injecting the factory with Repository. While it is certainly possible to use Repository as layer inside the Factory, I wonder if it is an anti-pattern to do so. i.e. is it advisable to keep Factory Repository-free? Example For example, my QuoteFactor...
tl;dr-ers: How does a lexer normally deal with none-inline statements. statements that do not end with a specified statement delimiter. Such as control flow statements? I believe that I have a fairly good grasp on lexical analysis, and can move on in my quest for understanding lexers/parsers. I do however, understand ...
Lets say I have a function that takes an argument, does some action based on the value of that argument and returns false if there is no action for that value. (pseudo-code): bool executeSomeAction(someValue) { switch (someValue) { case shouldDoAction1: action1(); break; case shouldDoActi...
Should I use an easy readable code like this if (var.isServicePGM() || var.isStandardPGM()) { //Much code if (var.isServicePGM()) { //Some code } else if (var.isStandardPGM()) { //Some code } } or should i use an faster code like this if (var.isServicePGM() || var.isStandar...
Often I see the implementation of the builder pattern (in Java) to be like this: public class Foo { private Foo(FooBuilder builder) { // get alle the parameters from the builder and apply them to this instance } public static class FooBuilder { // ... public Foo build() { ...
You could setup special mouse events using Javascript that fires when the pointer is enter or hovering over a specific HTML element (i.e: object.addEventListener("mouseover", theScript); ). But how does it work? Is it like a classic collison detection? When the mouse pointer X and Y coordinates is inside the boundaries...
Rust needs external linkers (e.g. GCC) to generate final output. Why doesn't it provide a bundled one? Are there any languages that does the similar?
I'm testing on my laptop a C++ TCP proxy listening on a fixed port given to command line; the proxy works with the usual bind and listen and loops on incoming connections with accept, forking for each accepted connection. GET and CONNECT requests are managed. Now I'm planning to deliver the packets not as they come, bu...
I am developing a complex web application, which is working fine on Chrome and IE, but recently has developed huge performance issues on Firefox which lead us to block it's usage completely to avoid a poor UX while the problem isn't solved. Below is a screenshot of the Firefox profiler: The file is available here for ...
I'm considering different designs for a generic role library gem. The first is based off the Rolify gem but with a has_many through: relationship instead of HABTM. HABTM tables are "headless" in ActiveRecord and cannot be queried directly which is a huge con. class User < ApplicationRecord has_many :user_roles has...
For nested if constructs, some languages provide constructs similar to if Bexp1 then C1 elseif Bexp2 then C2 ... elseif Bexpn then Cn else Cn+1 endif All I have seen provide elseif. I wonder why not further provide thenif? Is there a need for thenif? Thanks.
I am trying to create a new variable with class Lamb (called hold) using a variable (main), which also has class Lamb. Lamb has two parameters (x and y). I create a variable called main with class Lamb where main.x is a list. I then create hold using main.x and main.y (see code snip 2 below). When I try to change h...
Suppose I have a conceptual Ledger that is populated with Line Items. Assume that Line Items themselves are stored in some type of persistent storage. The ledger is shown to the user who can add/remove Line Items, or update variables inside a particular Line Item, such as price/quantity/description. To handle this,...
Recently, I have been coding in Cordova a lot for the company I work for. For those of you who don't know, Cordova is a cross platform development tool for mobile applications which is web based. Essentially you can use your HTML/JS/CSS to make Android and iOS applications. However, I come from a heavy OOP background a...
Collections class in Java consists only from static methods, as stated in the specs This class consists exclusively of static methods that operate on or return collections. It contains polymorphic algorithms that operate on collections, "wrappers", which return a new collection backed by a specified collection, ...
What is the best method to parse events in daily batches from external source (csv file) that produces entries in a separate table if any of a multiple of conditions are met. Conditions can vary through time and need to maintain certain level of flexibility. They are simple conditions though, either a field is equal, s...
Recently, I've been getting familiar with COCOMO II model to calculate the effort (person-months) and duration (calendar time in months) required to develop a mobile application. To calculate the effort, the following formula should be used according to COCOMO II Model Definition Manual. PM = A * Size^E * (Product of ...
While most of the top IT companies will ask you (during the interview) to solve a problem applying some data structure, is it good if you define your own class for that data structure? Like if I know this problem is going to b solved by applying a LinkedList, should I make my own implementation of a LinkedList class or...
How can I manage my code to exactly wait for a certain amount of time (say 10s), if all * time functions on the system are not reliable and return immediately ? Sleep(10000); // Do not sleep for 10s and execute directly the next function MyFunction(); The solution should if possible, consume the fewer possible CPU cyc...
As the title states, what is the difference between -> and . I thought they were the same thing?
Question: Talking about software development, how to provide good approaches to achieve a repository of reusable components inside a project? Context: Working on a team of 10 coworkers may be very interesting but could be also unorganized. Duplicated services, components, in other words, shareable code. Documenting and...
I'm designing a RESTful API and wondering what's the best format for validation error messages. For example, my account creation endpoint accepts a JSON object: user: { first_name: string, last_name: string, address: { street: string, city: string, zip_code: string } } My responses will be in the f...
Apparently this algorithm is well known. The algorithm will build the square root answer bit by bit starting from the left-most bit to the last. Let's say we will support squaring up to a 8 bit unsigned integer for simplicity. let res be result let x be 8 bit unsigned integer let n be the nth bit in the result where th...
I've been toying with a project idea for a while now but can't quite settle on one important detail. The plan is to write a client that can author and upload WebMs to a server for global viewing (should the user wish), however, I only want to allow WebMs made with the official application for the sake of consistency. ...
I'm building a web API that is going to be consumed by several internal systems. Naturally the different systems have different requirements. The consumers may create change requests to the API, when they need new features. Everything is within my organization. How do I know when a change request is too specific and wh...
This is a re-post from my question in StackOverflow, so here goes: For the past few weeks now I've been studying Concurrency(Multithreading) in Java. I find it difficult and rather different than anything I've encountered in the Java language so far(or in programming in general). Often I have to reread and reread over ...
According to DDD and the clean architecture, entities should encapsulate data and related logic. So, how do you design a class to represent a particular real world entity? Two alternatives among lots of possible strategies: Firstly, define properties of entity (ask which information should be stored.). Then create req...
This is an embarrassingly basic question, but until recently I have avoided properly understanding IO in Haskell and now I need to. I am writing (with someone else) a program that takes as part of its input a library of background data. So as part of main I'll have a couple of lines such as lib <- library.txt let libra...
I have a test class with about 25 tests that are testing the different aspect of it. I wonder Should I break it down into smaller classes? If so, then what is the best naming/packaging convention? Lets say my class name is abcService and I want to break it down into x, y and z aspect of it. Name test classes as xTe...
I've been learning functional programming in javascript of late, and there's one thing that's been confusing me. I can't quite understand if it's ever okay to redefine variables. Something like: a = a + 1 immediately throws up red flags. a is mutating, so that's a no go. And certainly declaring a variable like so: var ...
I am currently working in an aleady developed C++ project. The existing files are the following: -main.cpp -HydroModel.cpp -ODESys.cpp -HydroModel.hpp -ODESys.hpp -ODESysSol.hpp In the file HydroModel.hpp there are some constants defined in the namespace config, for example namespace config { const unsigned ...
I am testing a REST api. Let's say it returns a JSON structure. What is the best approach to testing the server? Each test step can only succeed if all previous were successful. Structure A: test everything at once - Test method 1: - make server request - assert http response code was 200 - assert returned ...
I am working on a piece of server software that is licensed under the AGPL. I would like to require that all clients to it be released under a free license (GPL preferable, but I'm open to other licenses). Is there a way to do this? Is there a standard way to do this?
I have a save game editor. It uses a library that can read the file and return it in a form of an object. Within that object is an ItemSave object. Also, to be able to interpret the data in the ItemSave object, I need more info (from an xml) which I get by a method in my own code that returns the ItemData object. They ...
I am designing my own little OOP program to simulate Vampires, Wolves, Humans and Trucks and am trying to implement my own limited understanding of Interfaces. (I am still abstracting here and have no code implementation yet, so it's rather a question of OOP design...I think!) Am I right in looking for 'common behaviou...
I'm new to Java, I've been mostly a scripter. I recently started working at an all Java shop and have been investigating the architecture. I've encountered more than one project with a directory structure like this: | src/ ---| api/ ---| app/ ---| dal/ ---| sal/ ---| metrics/ ---| worker/ API, app, metrics are pretty ...
What do you call a tree where each node has an arbitrary number of children (i.e. not necessarily 2)? I'm trying to research some algorithms online, and Google keeps returning results for binary trees when I specify just "tree". I'm looking for a word I can add to my search terms to specify arbitrary branch counts.
The questions are: Do generators break the functional programming paradigm? Why or why not? If yes, can generators be used in functional programming and how? Consider the following: function * downCounter(maxValue) { yield maxValue; yield * downCounter(maxValue > 0 ? maxValue - 1 : 0); } let counter = downCounte...
Is it reasonable to use Makefile targets as scripts? So for example, instead of having a script script_A, script_B, etc, and running them as standard executables with ./script_A, we have a makefile that has targets script_A, script_B, and run them by invoker make script_A. There are no dependencies between the scripts....
For a real-time forum app I'm working on currently. It takes about 1-5 seconds for the sockets on my node.js server to connect and deliver the first payload, which is some database results from mongo. I want to do something while this is happening, since otherwise I get some angular {{ vars }} action going on, which is...
From https://en.wikipedia.org/wiki/Recursively_enumerable_language a formal language is called recursively enumerable (also recognizable, partially decidable, semidecidable, Turing-acceptable or Turing-recognizable) if it is a recursively enumerable subset in the set of all possible words over the alphabet of th...
The Principle of Least Astonishment is a design guideline that you should make your behavior match what people would expect. Don't redefine equality, behave consistently, choose sane defaults, etc. At my company we have several code bases which were written at different times by different people in different styles ...
Consider the following code snippet: class Foo { Baz baz; // ... void bar() { int p = this.baz.doSomething(); if (p == this.x) { throw new FooException('Invalid values', FooException::INVALID_VALUES); } this.x = p * this.y; } // ... } Baz::doSomething() can throw exceptions of the Ba...
In a recent internship, I worked on a project involving traffic detection using radar. The company developed their own unique hardware and ran Windows Compact Embedded on an ARM processor. I thought this was a bit odd (I mean Linux is always better, right? :P) Turns out the root of the concern for the company was, beca...
I'm developing some Javascript front-end code using JQuery with some back-end JSON webservices. IDE is Netbeans, and debugging using that and Chrome. Coming from a C++ background I'm used to small source files, each encapsulating one (or a small handful) of classes. With JS, the lack of simple 'include files' means tha...
In my intership I used the D3.js framework to visualize data, now at the end of the internship I'm going to write a documentation about the project as a whole. Only few people in my team have been involved in the project. None of them were involved in the JavaScript writing. As far as I know not many know how to write ...
There are some programming languages, like the many dialects of Lisp, that allow for macro-metaprogramming: rewriting and altering sections of code before the code is run. It is relatively trivial to write a simple interpreter for Lisp (mostly because there is only very little special syntax). However, I cannot underst...
So I've been programming for a few years mostly as an amateur/student, and I'm aware of the fact that using exceptions is generally frowned upon when used as a lack of consideration for input and just a catch-all (e.g., lazy programming). But I have a specific question regarding a programming interview question: Given ...
I'm working on a special project where I need to create a new application with a similar but restricted functionality of an original application (basically a type of free application with limited functionality). Now, the problem comes with the maintenance of the code. I'm using Visual Studio 2013 for the development an...
I have worked in company A for less than 1 year and I was given the task to do a security code review for a small project I was involved in the late 3 months. Until now I have been mainly been reading about common security culprits like SQL injection, XSS, etc. and trying to find these in the codebase. During the revie...
I've started working on an existing project (an sdk) at work, and the code base uses listeners like there's no tomorrow. Pretty much every second method takes some sort of listener argument and I have yet to find an occurrence where the listener is not the calling class or an anonymous class declared when the method is...
In my application - I have to expose services using JAX-RS(for mobile platform) and consume the same set of services in a JSF based web app. Now, I have @Entity beans for persistence layer, @ManagedBean beans from presentation layer and another set of beans for mapping JAX-RS related request objects. Lets take login op...
Recently I've been learning about the different ways languages handle concurrency under the hood, and would like to know a bit more about the shortcomings of M:N threading. Please forgive me if I get some facts wrong in the following paragraphs. I understand event loops (at least the style of event loop used in a langu...
In our business logic we occasionally have methods defined something like this: User.ResetCourse(Course courseToReset) The problem is that both User and Course are Entity Framework proxy objects. This means that when we hit navigation properties on either User or Course it can cause a huge hit to the database because ...
I am using an application, which I know, is c# with WPF. I want to grab data from some of its windows. In detail, i want to grab a grid with all content and the header. If I do copy+paste, i just get all content, but no headers. Is there any way to connect to the process and get a handle to the control and access the c...
This is more of a nomenclature (technical writing) rather than a purely technical question. I am trying to write a refactoring proposal (and get it assigned to myself) centered around expanding dependency injection in our application. While we do use Spring for autowiring beans, there are still instances that instantia...
I have try{ var progress = raw_progress[module_id][modulette_id][tab_id][track_id]; if(progress.started){ count += 3; } if(progress.complete){ count += 3; } return count + 'of_6'; }catch(e){ return '0_of_6'; } ... and the raw_progress object might not have a match on any of ...
Suppose I have Project and Task entities for a to-do list. If Tasks are required to be in a Project, the Task routes would probably look like this: GET /projects/{projectId}/tasks returns all tasks for the specified project POST /projects/{projectId}/tasks creates a new task in the specified project But it's not ...
Why do some Java methods throw exceptions that are subclasses of another exception that they also throw? One example is org.apache.commons.httpclient.HttpClient.executeMethod(HttpMethod method). It throws the HttpException, which is a subclass of the IOException, which it also throws. Syntactically, it would have been ...
This question may apply to other languages but it is explicitly about JavaScript. I've been trying to write a lazy evaluation implementation to filter through an array of elements. The filter process can be made up of 2 functions, F and G, that each check an element against some logic and return a Boolean that is used ...
I have basic viewmodel on server-side, let it be on C# language and ASP.NET Core server-side, for example: public class BookViewModel { public string Id { get; set; } public string Name { get; set; } //other properties removed for brevity } Then, I send it to client page. On client-side, I have rich ...
When I call Stream.sort(..) is there a new array of elements created and the stream iterates over the newly created sorted array? In other words, how Java 8 Stream does sort under the hood?
A web application I'm working on has a tool that queries a database and returns up to several thousand rows. When considering pagination, at what point does it make more sense to get the entire result set at once, and store it in memory, as opposed to making asynchronous calls each time a user changes pages on the tabl...
Trying to understand how experienced programmers tackle programming when they are stuck with a really hairy issues. The situation that I face a few times is like I am stuck with code for quite a few hours, trying to nail down some issue that I don't understand. The approach that I have tried to get out of the situatio...