instruction
stringlengths
34
19.9k
What would be the best way to store data in a database for geographical calculations? Say I have an ItemsForSale table paired to a Users table which holds their geo location. I know I can use latitude and longitude to look up items that are within a certain mile radius by using Lambert's formula for long lines or the H...
I've found a library (that I'd like to fork, if it makes any difference). On NuGet, the project file says it's distributed under the MIT license (with a link to the license). However, in the GitHub repository of the project, I don't see any mentions of the MIT license (or any other license) either in the source code fi...
I'm trying to decide if this might be a good idea to help reduce the size of some of my xaml resource dictionaries on a large project. Except I'm concerned about any potential performance issues going this route so hoping to get some insight from other technically proficient folks. So as example, say there's dozens of ...
I am very new to Git and I am planning to contribute to some open-source project on GitHub after discovering a small error in it. Upon forking it and fixing the error, I purposed a pull request and I noticed this showing up: Failed — The Travis CI build failed Looking into the details I discovered it was caused by ...
I'm working on a simple application for a game in Java that allows a user to record whether they have collected a given item and how much experience it contains. This will work for multiple item types (weapons, armor) and each will have its own tab with a list of all items that qualify under it. Making changes as new t...
So this may be a question that is born of my inability to properly express my intentions to Google. In a fully connected non-directional graph such that any three points can be properly represented in a triangle in Euclidean geometry it would seem that a greedy first algorithm which chooses the shortest edge would find...
I have ported libsodium and NaCl to .NET. NaCl is the original project that is in the public domain while libsodium is a derived work from NACL and is using the ISC license. I looked at both projects to port the code to .NET. For my project I prefer to use MPL v2, but I'm not sure I'm allowed to change the original li...
I'm interested in learning how a virtual machine/sandbox actually works. I have developed an 8051 emulator and also wrote a dissassembler for x86, so this part of a virtual machine is not really the problem. What I'm interested in, is the sandbox functionality of it. To illustrate what I mean consider this example. Let...
Memory refresher/My understanding: A 2-3 tree is a balanced search tree that allows two types of nodes. 2-node: Normal node with two children. LChild < Parent and RChild > Parent 3-node: Node with two parents and three children. Parent1 < Parent2 LChild < Parent1, Parent1 < MChild < Parent2, RChild >Parent2 A...
Does this IConvertible interface satisfy the Interface Segregation Principle (ie. the "I" in SOLID)? Here is the definition: public interface IConvertible { TypeCode GetTypeCode(); bool ToBoolean(IFormatProvider provider); byte ToByte(IFormatProvider provider); char ToChar(IFormatProvider provider); ...
Sometimes I think it's useful to cite a webpage (e.g. Stack Overflow questions) to justify and explain a piece of code. Is this considered bad practice?
I'm trying to sort out whether this is just a personal preference thing or whether it's actually bad practice to do this one way or another. I did try to reference PEP8 first, and I did not see an answer. What I'm talking about here is the use of more than one return statement. In these examples, it's not such a big de...
The Composite design pattern allows us to call an operation() on a 'composite' node in a tree structure, and this operation() will be called on all of the children, subchildren and so on. When an element's operation() is invoked, it is it's responsibility to call operation() on all of it's children, and so on. Each chi...
I know three terms that have to do with storing objects or data. I'm not sure I understand the exact differences between the terms. Please confirm if what I'm about to write is accurate. A data structure is a group of data types or objects of the same type, grouped together in some formation. A collection is the same a...
My application is currently quite a mess and I'm trying to untangle it all. My current idea is that I should have 3 separate layers: data layer that knows how to keep stuff in database (and handle data schema changes, so it's not really that trivial) domain layer (is that correct name?) that does all the magic changin...
Apparently naming things is one of the hardest things in programming..! I have a synchronisation implementation which uses timestamps (number of seconds since unix epoch) to sync. Currently, the timestamps have simply replaced an older revision field. My question is, does it make sense to name it "Revision" or is "Time...
I get how to do a derivation of a BNF. My text books do a good job of explaining it (much better than the on-line lecture notes of many profs etc). Example below then my questions: <program> => begin <stmt_list> end <stmt_list> => <stmt> | <stmt>; <stmt_list> <stmt> => <var> = <expression> <var> => A...
As an Android developer, the target market I create apps for is very fragmented. While I can specify certain requirements - e.g. my app only supports Android version x.x or above, sometimes errors may occur that are only evident on one specific phone model. Are there any strategies to handle device-specific errors, wit...
Recently, I've stumbled across question about predicting the output of code which heavily uses post/pre increment operators on integers. I am experienced C programmer, so I felt like at home, but people made statements that Java just blindly copied that from C (or C++), and that this is an useless feature in Java. That...
how would you recommend for me to design an android app where i want it to 1) send location update every 10 minutes 2) to show push notification I want both actions be available even when the app is closed. Here i might ask for your explanation what "closed" states an app can be in? a) removed from recent tasks stack...
I saw that the Unreal Engine is going open-source on github (see link1 and link2) and that made me wonder: "is open-sourcing a previously commercial engine a smart move?" What's the benefit to Epic Games in open-sourcing their core code in this manner? How can they not be concerned about people stealing parts of it ju...
I've spotted a nice WordPress (GPL) theme for sale. I know somebody who bought it. I have 2 questions: Has the company selling it the obligation to send the source code to whoever (customers or not) ask it? Can the person who bought it give me a copy for free which I could use in production?
this says header files are bad design, but I don't know why. The answers specified there are about the inefficiency of header file when building. Why it is bad design is not really touched upon. As far as I know: - headers lets you break the source file up so you can compile smaller things faster - headers lets you s...
The Question What are the origins of the Public/Private function paradigm? Background A question came up in chat about Header files in C, and their usage being mainly to help the compiler, not the programmer. It's my understanding though, that this is the first usage of the concept of "Private" functions, or functions ...
Is it bad software design to have JDBC/raw SQL and also use an ORM? I don't mind using an ORM for boilerplate CRUD, but some queries are better in SQL (for me). I'm not arguing for or against ORMs. I've read about them until I'm blue in the face. I used JDBC in my question, but it could have been DBI, or some other ...
Requirements: My application is latency sensitive. Millisecond level responsiveness matters. Not all the time, but when it acts, it needs to be fast. My application needs to log information about what it's done in those times. The actual writing of the logs does not need to be that fast, just the actions. However, th...
I'm new to Javascript. I'm learning the concept of hoisting in Javascript. Based on the Javacsript tutorials in Mozilla website, I came across this word hoisting. According to those tutorials, variables in JavaScript is that you can refer to a variable declared later, without getting an exception. But, my question is o...
I am preparing to write a database system using PHP and MYSQL which will store every piece of info sent to it as an individual row. Each row will store several piece of meta data (time stamp, who created it, version number, attribute number) and one piece of 'true' data (file name, phone number, username, etc.) Rows ...
How do I call functions defined outside a source file given you shouldn't use header files? -- EDIT: generic(?) question below So, first, a problem should be broken down into simpler subproblems. Then, each subproblem is solved by implementing new code for a subsolution or reusing an existing subsolution. If done cor...
In c++, is there any other way, besides header files, to use a function defined in file A.cpp, inside file B.cpp that would be considered good programming practice?
I have a class named Product, which takes a product model number and number of wheels for that product as part of its creation information, and then it instantiates the product by doing a computation on the number of wheels and on various base parameters For example, Product(5, 22) creates a model 5 product with 22 whe...
Consider a service which updates PersonDetail tables in database. I am Using EF which maps the table to this Entity. When a record is updated, it is not actually updated but a new record is created and old one is made history by setting HistoryCode to 0 Class PersonDetail { int age; Date birthDate; DateTime effec...
I am currently developing my first serious piece of software in C#. It is a good learning experience so far. My software is basically a task scheduling tool with some advanced features and capabilities. I am not near the finishing stages yet, but I was wondering what people's opinions are on trial versions of software...
I recently wrote some code that I thought very inefficient, but since it included only a few values, I accepted it. However, I'm still interested at a better algorithm for the following: A list of X objects, each of them are assigned a "weight" Sum up the weights Generate a random number from 0 to the sum Iterate thr...
We are developing a data model for a marketing database that will import transaction, customer, inventory, etc. files and the directive is ONE process that works for every client. We have been told every client will have different import layouts and different columns that identify a table's primary key. Our initial id...
i'm a data scientist and python noob, but I seem to have found a bug with scipy.stats.percentileofscore. it may be "by design" but please bear with me. if you have an array, you will get an upper bound of 100, but never a lower bound of 0. The lowest percentile you will get is 100/len so if I have an array of 30 it...
How does the client know to send request to server only when the confirmation box result is ok and stay on page if cancelled? Also, is this mechanism any different in ASP.Net and ASP.Net MVC? I want to know the internal working of when user clicks OK/cancel what happens internally. How does browser come to know it has ...
I am a commercial software developer and I want to make use of open-source in my proprietary software. As I understand the concept of copy-left, it uses the original authors copyright to ensure that their ultimate end users (which would include my customers) are not deprived of benefits of the original work that the or...
I'm currently working with Wordpress (GPL). I understood basically when you write a plugin/module/etc. it becomes GPL since it's considered dependent of Wordpress. But on the contrary images and css from themes, are not due to be GPL (they are considered independent data files that could have meaning even without Word...
I'm new in unit testing. For last two days I'm thinking how to test non-atomic methods with unit tests. When i need to write tests for some simple, atomic method situation in pretty easy - i'm taking all scenarios for this method that i can imagine, and reforge each of it in unit test. But what if i have methods tha...
So far the most confusing portion of git is rebasing onto another branch. Specifically, it's the command line arguments that are confusing. Each time I want to rebase a small piece of one branch onto the tip of another, I have to review the git rebase documentation and it takes me about 5-10 minutes to understand what ...
I hear the term 'bolt-on' used in many contexts, specifically in my organization where PeopleSoft is used extensively. I don't know exactly how it differs from an 'extension' of an existing product, a new module within an application, or an 'add-on' like you would purchase for a product you own. Is there a more forma...
I am writing a simple webmail where I want (obviously) to display the emails. I'm wondering if I should take any precaution while displaying HTML emails: is dumping the email content into a <div> a security risk? I'm guessing that yes since the email could contain anything (could it contain Javascript?). But then how s...
Should an API be aware of a client version? The idea of that really goes against the grain for me, but it seems like it is being pushed for in my current project. Am I wrong? Can I get some reasons for or against this that I can present or understand why it might be good. The API is a RESTful API.
The problem I write a lot of exploratory code in my research. As I go along, I put functionality that I'd like to reuse in a central location. A project might look like this: ./mylib ./exploration /experiment_1 /experiment_2 /experiment_3 Where each experiment uses some functionality from mylib. Now I come...
I want to draw a class diagram that shows the following for an application: An external content management system that publishes some news items. The class that represents the news item in my application. The question is shall I include the external content management system as a class in my diagram (and maybe give i...
this is not a question on how to write unit tests this is not a question on what to test this is a question on reducing the typing needed overall for a personal testing framework I know you can send function pointers as arguments to functions in C. Is there a c++98 version? Or, since c++ can work backwards, should...
I am only coding in Objective-C and I have no experience with backend coding, only a high-level understanding. I understand why a lot of programming projects require backend servers but I'm not absolutely clear on a high-level perspective why Mailbox needs their own. They get their data from the Gmail API, It is my und...
Im currently looking for a way to test a lot of requests in the shortest amount of time possible on my web application. My current workaround is to just import the modules I want to test into another python file and shoot requests directly into those functions, but I'd rather have it go through the web server framewor...
I'm currently developing a responsive website with CSS media queries. It would be much easier if the server returned a different HTML/CSS for each viewport. I was wondering why couldn't the client include its viewport information when requesting an HTML file. This behavior is already common for returning websites in th...
I created a general class that accepts a string when it is constructed, and it spits out that string when a user calls what(). This is all it does; on throw, it returns the initializing string. class Exception_As { private: std::string message public: Exception_As(const std::string& message) { // const...
With little or none previous experience of testing, I'm looking into adding automated testing to a continuous integration process of SharePoint applications. I've learned how this can be achieved using coded UI tests that are run before deployment and during the build and I've used Selenium with Java before, where we d...
I have a Message class which can contain multiple types of payloads (or sometimes no payload), each derived from a common Payload class. However, this becomes problematic because the Message class wants to know about the Payload subclasses for various reasons such as: Checking for Message equality if (message parts be...
As far as I can tell, you can make your interface known to others by providing your .h file. Your .cpp is the implementation. Then they can see the function names, the parameter types, the return type, maybe a description of how to use a function, and maybe what it does in the .h file. Then I read in posts here abo...
If Java is a general purpose language, and building a program is something that can be described using the Java language, why isn't this the best way to write build files and instead we use tools like Ant, Maven, and Gradle? Wouldn't that be more straightforward, and also remove the need to learn yet another programmin...
I'm newish to programming and would like to know what people have found to be the most supportable option or rather what people find more understandable. I'm the only one writing code at my firm, but gradually will hand this off to someone else in the future. The Project The project I'm working on is parsing a huge te...
I work on a fairly large web application. The main solution containing the web application project has over 100 projects. The average build time of that solution is 2 minutes on a 12 GB quad-core machine with an SSD. We are looking into ways we can improve our deployment process. I am going to work on a proof-of-conce...
Considering I have a for loop in a method of a class. Should the incremented variable be declared as member of the class, or should it be declared in the method it uses it(or even in the for loop, directly)? While declaring it inside the method seems easier and cleaner, doesn't declaring it at the start of the class ma...
I'm trying to find the best way of developing a portal that a user can log in to and then be presented with a range of different apps (angular). They should share the same api-backend. I think that each angular-app could (and should) be developed separately. The only thing I think I need to do is place the dist-folder...
I'm now writing a program, which will allow processing data expressed in the form of graphs. These graphs will determine workflow of the processing and they are actually an essence of this program (in terms of being the main object being edited by the user). It is very, very tempting to put all the processing, data co...
I'm working on scaling an application which is currently polling a mySQL database to send async jobs to a background processing system. A state machine is being used to keep track of the entities progress throughout a workflow. For example, we might have three states: Scheduled Processing Complete My plan is to add ...
Requirement: We need a tool that simulates a hardware device that communicates via RS232 or TCP/IP to allow us to test our main application which will communicate with the device. Current flow: User loads script Parse script into commands User runs script Execute commands Script / commands (simplified for discussi...
If I link a program dynamically to a LGPL library (here GTK+/GLib), I'm allowed to distribute the program on my own terms (non-copyleft). Now, the LGPL library provides loadable modules. Place a shared library (.so, .dll, .dylib) in a certain directory, and it will attempt to load it, using a well-defined interface. Am...
Mine is a typical website developed with LAMP stack. Due to scalability issues we are planning to incorporate NoSQL for the application. For the implementation, we are planning to implement hybrid solution: using NoSQL only for few of the high volume tables in database and keep on using MySQL for all the other. So, we...
I recently started at a new job. The existing system works OK but is poorly designed and hard to maintain, and they are planning to rebuild it in MVC and I fear it will be much worse. (Not because of MVC) I want to discourage the lead dev from using an anti-pattern Existing issues include Hard coded strings in the bu...
So i understand the semantics of derivations as far as Backus Naur Form goes. One thing I cannot find in any text book or the various lecturers' notes that are on-line is this. When would a right most derivation be beneficial over a left most derivation? Would a compiler or generator always use either left, or right, ...
My team is in a situation where we need to create about 30 different processors. By processors I mean code that takes data from a DB and sends it to a remote service somewhere else in the world. They each do fundamentally the same thing, only with different data. Only some of these processors will be deployed to server...
We are developing a desktop application and I am responsible for GUI testing. Currently we have around 500 tests which take 8 hours to complete. The tests are testing almost every button/menu/field etc. in the application. Some functions are taking 3 - 15 minutes because the application is actually measuring something,...
I've been searching for the different uses of the keyword mutable. I've found that it is generally used for caching, lazy computing, mutex, ... But I'm wondering if it is coherent to use it for a cursor on a readonly object. For example, I have a sound class, and I want each sound to be able to keep track of a play cur...
In Spanish-speaking countries we use more than one last name, like: First name ↘                           ↙ Last name                 Pedro Arturo Rodríguez Loyola         Middle name ↗                               ↖ (?) I'm trying to model data for patient name. In our country it's important, so I can't neglec...
what is a basic block called if it contains a branch instruction? How about a block that does not contain a branch instruction? Thanks,
A while ago, I asked a question on SO about something written in C++, but instead of getting an answer to the problem at hand, the comments went all crazy on my coding style, even when I indicated that it was a WIP piece of code and that I meant to clean it up later when I had the base case running. (I got so many down...
I have some methods im trying to test which use a StreamReader dependency that i mock using Rhino mocks. But it is a large xmlFile. In the spirit of unit testing im trying to keep away from using a test file in my test project. On the other hand copy-pasting 100 lines of xml into my test class seems sort of ugly. What ...
I'm reading data from a stream in buffered series of bytes (say 1024 bytes at a time) and do some comparison, checking, or processing, before writing it back to the same type of stream. Currently data comes from file. But in the future it may come from other sources (memorymapped file, TCP etc) Is there a design patte...
Analyzed one web-server. for the http request I got: apache 2.2... what redirects to https, and for https got apache-coyote 1.1. and the server runs XWiki java app. Trying to understand how it is implemented. After googling an hour trying to find any simple page what explaining java technologies for a java dumb perso...
I maintain a relatively popular github repo. When a pull request is good to merge I usually ask the author to rebase it to a single commit before I merge it (especially when there have been multiple small edits). Is this good git practice? Is this acceptable/standard GitHub etiquette? So some benefits: I get a nice cl...
Specifically asking about the default constructor Given that the constructor initializes all the data for an object, if I create a class that can't be used without proper initialization, is it not the case that the default constructor is useless? Consider: // A class for handling lines in a CSV file class CSV_Entry { ...
I've been writing a small C application that operates on files, and I've found that I have been copy+pasting this code around my functions: char fullpath[PATH_MAX]; fullpath[0] = '\0'; strcat(fullpath, BASE_PATH); strcat(fullpath, subdir); strcat(fullpath, "/"); strcat(fullpath, filename); // do something with fullpat...
How to ignore bracketing styles when doing code comparisons or diffs? We have several formats of bracketing and I would like: function foo(){ } to be considered the same as function foo() { } Right now I use Araxis merge which does a direct line-by-line comparison and we are getting a lot of "false positive" changes....
I am playing with dependency injection, but i am not sure I am doing it right. Especially, I am not sure what should be the correct way to build classes with injected dependencies. Say I have a class A that creates class B. Class B depends on class C and class C depends on class D. Who should be responsible for creatin...
We are experimenting with "Github Flow", as defined here. In short, every change starts off as a well-named branch off of master. When it's done, you open a PR for that branch, it gets reviewed, and then gets merged into master. It's a very simple workflow. However, we have run into this a couple of times: I develop fe...
If you are trying to hide implementation, would declaring STL variables be too revealing? // in Word_Bucket.h class Word_Bucket { private: std::vector<std::string> contents; ...etc } ... but then if you wrap it up, to hide the implementation, won't you have to reveal it in the wrapper's interface anyway? //...
This is a follow up question to the following post: Injecting dependencies (DI) in c++ applications In a system that uses DI, someone, somewhere should be responsible to create the various objects and "wire" them. I find it difficult to figure out who should do this. I read about one option that it should be the "root ...
I'm a coop (in college but I work 3 months, then do classes for 3 months, work again for 3 months, etc until I graduate) at a company in their IT department. My job usually has to do with writing software but we are not a software company and much of the software that is is written in India. This work term (3 months) I...
Dependencies are services required by an object to perform its responsibilities. In OOP context it can be thought as a parameter in a constructor. In my experience I've never found a case for a valid cyclic A <--> B dependency. Every time I find this it turns out to be one of two cases: A and B should actually be a si...
I have a system in place where a Cache is made up of many Cache Nodes. When one is added, a CacheNodeAdded event is raised by the Cache. The Cache has a redundant set of Monitors listening for this event. Monitors are responsible for notifying on Cache events. Since I have multiple Monitors, but only want to be not...
There exists a general OOP principle that methods should return local variables rather than set object fields. For instance, say I have the following piece of code (example in Java): public class Number { public int myNum; } public class Horrible { public static void areYouSerious(Number num){ num.myNu...
Disclaimer: I think the rules are almost the same in most OO languages, but since I'm most familiar with C# I'll be relating to this specific language. I think that the use of attributes and reflection could be largely reduced if static members would apply the same principles as OO instances. Static properties and meth...
I want to illustrated my question by way of a (hopefully) representative example. Lets say I have a situation where I am developing a class library in C# to be used in some simulations. I want to define the planets (Earth, Mars, Saturn, etc.) and have each of them have some properties and methods that are common in ...
I'm currently designing a somewhat large program that will involve the simulation of math/physics models and collection of data (I have not implemented any code yet). One of the main problems I'm facing is how to pass data around easily without having to have multiple copies of data (that may potentially be outdated an...
I am trying to implement an algorithm for finding the zero crossing (check that the signs of all the entries around the entry of interest are not the same) in a two dimensional matrix, as part of implementing the Laplacian of Gaussian edge detection filter for a class, I understand everything up to step 3 of page 25 of...
I have an XHTML document that defines several text entities in its internal DTD. I want these entities to be available in other XHTML documents without having to cut and paste the internal DTD everywhere. The answer that seems to keep coming up for other XML files (not specifically XHTML) -- for example, here: https://...
If I work for a company and write code for them but I choose to buy a tool for myself and use it to write code for the company, do I need a commercial or personal license? Specifically, in this case, I am asking about WebStorm IDE JetBrains have Commercial (For companies and organizations) and Personal (For individual ...
I'm working on some software at them moment and I'm not sure which route to take with this. I have some data to store somewhere on a mobile device. The data will never change, and has a hierarchical relationship, and will be used to populate the display. There is a reasonably amount of this data. I have the following o...
I've been reading Clean Code: A Handbook of Agile Software Craftsmanship by Robert C. Martin. One point he makes: G34 Functions should descend only one level of abstraction However, I'm wondering about the functions that actually create the objects for an application. Say we have dependencies App -> Book -> Database ...
I can see two ways to fill an empty file with data: $ run_program arg1 > data_file or, specifically write code that manages a file and write to it? ie. a file stream? Which is better to implement?
I'am planning my website over here based on MVC. And I am thinking about a webservice (who knows, maybe one day I'll create an android app or something). The site and the webservice will behave diferently from each other. So what should I do? Write different controllers for each... or stuff IFs all over the place? For ...
for a list of files, coming from a list like from a file dialog is it better to store the list as a list of strings or should I convert each file to opened Streams stored in a List? For example List<string> files = new List<string>(); List<FileStream> fileStreams = new List<FileStream>(); fore...
A little confused with the notion of stateful/stateless architectures. Forgive me if I'm unclear. Questions: Can we consider a clients interaction with a web server to be stateful if the web server maintains state via session variables or cookies? What if we assume that any change to this information comes from the cli...
Lets focus on a domain object that is related to more other (different!) entities. Sometimes we need one relation and sometimes the other. Let's be agile and say: we don't know in a front how many other relations there will be. In other words: we have object A that is related one-to-one to B and one-to-many to C and ag...