instruction
stringlengths
34
36.1k
I know what IllegalStateException is for, but I wonder if in some cases I should actually use it or it's just a matter of design. Let's say I have a Tournament class that models a sports tournament and a tournament has a Schedule, which needs to be calculated. So unless you actually launch the resolution process that g...
Programming is complex. And throughout the years new technologies emerge that lay/depend upon older technologies, resulting in the need for deeper knowledge in a broad set of technologies in order to achieve a single goal. One example of that affirmation could be the web development scenario. Once only what was needed ...
In an int?[] garunteed to have original values, I wanted to find the index of null, which will only be a single index. I drilled into the Array.IndexOf(T[] array, T value) .NET and, after all of the contracts and index checks, it comes down to this method: internal virtual int IndexOf(T[] array, T value, int startIndex...
I would like to know the best practice for designing a REST API for a resource that has a has_many relationship with another resource. In my app, companies have many technologies, and technologies belong to many companies. In the frontend, I want to render companies and their technologies. I want to implement /companie...
I'm a novice programmer i draw two class diagrams for calculator Project, i want you to check each one of them and tell me which one is better and also, i would appreciate it if you point out the parts that are wrong or could be better.
I have always thought that “descriptive” models says “what” but do not specify “how”, while “prescriptive” ones do exactly that. But when I started checking the topic, I found a lot of contradictions. Some say that process reference model in ISO 12207 is not prescriptive, while others say it is. As common examples of p...
I'm new to programming and I have taken over the development of an app that we provide to our helpdesk for support. The app is simple and developed in C#. All it does it launch the command prompt or powershell under an admin account through Citrix. However, I need to write code that gets around the Citrix session. I am...
I have a class Game. This class needs to take three arguments passed in it's constructor: List of game pieces Board Size Game piece placement 'engine' I am dithering about the design of the game piece placement 'engine'. This object needs the list of game pieces and the board size to determine where the pieces are to...
So I decided to look up some source code for a simple text editor in C, and it required me to use a header called conio.h. This got me thinking, how did people write programs like text editors or web browsers before you could google up headers and other libraries?
Does anyone know of any tool that would help find classes that are taking on too much responsibility? E.g. By visualizing a file's size compared to the other files in the code base, it can be easy to spot massive classes that should probably be split up into much smaller ones. I'm looking for something similar to the b...
We have a requirement to add share buttons ( Facebook, Twitter, G+, LinkedIn, WeChat) on all the pages of our website (excluding some of the landing pages) We did a POC for the same with the AddThis plugin and it integrates very well and quite comfortably with our website . But we have been asked by our architect to us...
Let's say we have schools with some data including a name and a list of students, and students with some data including courses they're enrolled in and a reference to their school. On the client: I'd like to show a screen that shows information about a school, which includes a list of all of its students by name. I'd...
Here's the scenario I'm trying to solve: In my application, users provide files to other users. I want to provide a way of verifying that files have not been tampered with. I wonder if this means some sort of third party, independent online data store of file signatures can be referenced to ensure all is OK. I don't kn...
Title says it all. Can't seem to find what is most common out in the world. I'm brand new to programming. If the answer is "it depends", I would love to know what it depends on. Here to learn.
Pair programming is quite famous now-a-days. It has several advantages like: Programs with fewer bugs. Post production maintenance cost is much less. Established practices are challenged resulting in emergence of new ideas. Programmers learn from each other. Programmers develop soft skills. But what are the disadvan...
I'm quite new to Python and learning it on Lynda.com, which does not seem to have any way to ask questions about lesson content. In a video about while loops there is this code: a, b = 0, 1 while b < 50: print(b) a, b = b, a + b that results in: 1, 1, 2, 3, 5, 8, 13, 21, 34 . Out of curiosity, I changed the a,...
We have a large legacy Java-based project, the availability of certain features throughout the application is determined by its corresponding value in a "feature_enabled" table in a SQL database. Much like Windows enables features based on Registry values. Lately, we have been working to significantly reduce the numbe...
All the SQL in my app... Should I be confining it to its own special class? For example a MyDatabase class that extends SQLiteOpenHelper and implements all the create-tables, defines all the table names, column names, queries, holds all the CRUD methods for all my objects, etc. Or should I be putting all this stuff ...
I need to build a Tile-based Map Editor in #C Winforms. My main concern is drawing the tiles. In what space should I draw the tiles? Within a Panel? A Picture Box? Also, I obviously need to draw textures over the tiles too. Does this mean my tiles need to have a pictureBox component? Or can I do this some other way? I ...
We have two very similar modules in our MVC project - one for reports and one for exports. Just to explain our nomenclature - exports is only used to generate flat files, and reports is only used to display data in the GUI and to generate PDF files via the GUI. These modules are distinct in the code, but a lot of the l...
I have an interface IFoo that only gets implemented by objects with a fairly high level (framework) base class. It would be very useful to me to not only get the Interface members, but also the implementing object itself. Would it be bad practice to have the interface include its implementer as a property? For example:...
A function (or any discrete block of code) can be considered as having various forms of "correctness" or "safety", for example if a function does not access or mutate any shared-state (or does so safely, e.g. using locks) then it is deemed "thread-safe". In C++, a function is "const-correct" if only the absolute minimu...
I would like to develop and release and SDK in an open fashion, via GitHub. That said, I would like to have a team of developers work on this, make commits, create issues and comments etc in a private fashion. It would be nice if I could only push the desired code to the public. The public section would also allow publ...
I will try to explain my objective with an example which will be easier to understand. Suppose I have a sentence like "A B C D E F G H".(Each word seperated using single space). I have a Database like: B C D E A B F G C D E F G .. I need to find the maximum number of units from the database that match the sentence. T...
I'm posting here and snap from Book "Java The complete reference". I tried to test the statement made in this snapshot. Result is 20 for both b1 and b2 which shows that objects are linked. But the book says Objects are not linked and any change to b1 should not affect, b2. Where I am making mistake? public static void...
I am trying to decide how (or whether) my Data Access Layer should deal with existing security and integrity protections on the database. The architect in me says that separation of concerns is a priority and duplication of duties is wasteful so I should leave the database to handle access control and let the Object Re...
I have no enough experience in web development and I need advice from more experienced developers. I have been exploring SMACSS and BEM methodologies for a few weeks, and I like them, it makes really pretty and structured CSS code with reusable components. I am building personal web-site, I have used free template f...
We have a large LOB application that does fairly complex transaction processing of various types. All our code is written in C# and consists of class libraries, console apps, windows forms apps and web applications. The class libraries contain the core functionality and business logic and is reused in the application ...
I see a lot of advice lately about making code reviews more granular, and as small as possible. For example, a lot of recommendations say "no more than 400 lines of code for a code review". This sounds like fine, idealistic advice, but I have run into situations where I don't see this as practical. For example, say you...
I have 2 micro-services. One is a Django API, the other is a worker. Each one of these lives in side a docker container. The API is a public API for the web front end. It handles CRUD operations for users of the web application and it only has an authentication backend for endusers. Some REST actions by the user creat...
Background: I am in the process of writing a suite of applications and have been tasked with tracking "metadata" across the app. This task requires me to process, export, then import, a large amount of data. The (M)ain application, will be running and serve as the main collection point for data. Each client will be ...
Given an array of numbers, count the total number of subarrays (consecutive elements) where all elements are equal. Example: For below array [1,1,3] Ans: 4 Below are desired subarrays: [1], [1], [3], [1,1] So I first wrote a Java program whose efficiency is bad: import java.util.*; public class EqualSubarrays { ...
Let's assume we have something like that: class Page{ Header header; Body body; Footer<TFooterModel> footer; //TFooterModel is a type of content (subcontrol in some sense) that loaded inside footer. public Page(Header h, Body b, Footer<TFooterModel> f){...} //Let's assume that we setting part in const...
Current Situation I maintain a website that has a simple form that users fill out with simple engineering data. They press Submit, and the PHP code takes over and does various basic arithmetic on those numbers, according to the hardcoded formulas. Every time there is a change, user has to talk to me, and I have to cha...
I've heard that variables should be declared as close to the point that they're used as possible. However, I've also heard that member variables should be used to describe something that is a characteristic of a class. I find that these two pieces of advice sometimes conflict. For example, say I have a class the parses...
I want to create an application using the Qt framework, but can not at all afford a commercial license. While looking at the licensing comparison table, I noticed that the LGPLV3 license said this: Possible to keep your application private with dynamic linking I understand what dynamic linking and static linking are,...
How should pagination be implemented in DDD with DataMappers? I thought about creating objects Range and Order and pass them to the find methods, but I don't know if that is a good solution since the pagination in this case is a matter of UI and performance and not a matter representing the model. I read about CQRS(htt...
I am fairly new to MongoDB document-based storage, and my background is in tabular databases and I am having trouble understanding the right way to model this relationship. Currently I have a collection called users, I would like to add a structure for posts, which are owned by users, and on these posts users can leave...
I'm curious about how the flight/train search engines combine the results from multiple sources. For example, let's say I'm asking to go from London to Paris, and let's assume there are no direct flights for whatever reason. However, there is a flight from London to Lille (North of France), and then a train from there ...
Short Problem: How should I check if integers are undefined, just as I can check QStrings for having NULL values? Backstory: This is my coding style when I am trying to avoid overloading my functions. myclass.h public: QString string(); // Return private member variables int integer(); void setS...
I'm facing a situation that does not seem to have a clear solution to it, which leads me to believe I'm actually doing something wrong. Here I am seeking advice once again. To rapidly let you understand my issue, I'm having trouble releasing apps / developing apps, in terms of separating the production code with the de...
In commercial proprietary product library1 is used which is under LGPL. According to LGPL library1 is distributed separately as shared library. library1 statically linked to other library library2 which LGPL licensed as well. Is it ok distribute both libraries as single shared library? Or to meet LGPL requirements shou...
This question is in the context of an Android application written in Java. I have this class which performs a specific action and returns the result of such action with a callback implemented in the activity where it was called. This class depends on the current activity reference. This is not a singleton because this ...
Enviroment: I need to share some kind information (see HashMap) through different part of my code. I think that Singleton could be a perfect design pattern - except for one thing: Information retrival (read init HashMap and populate it) is demand to another class (MVC). So, my question: is possible to assign to my Sing...
I'm doing some datetime manipulation, and I've implemented a really slow algorithm. I'm hoping for some suggested improvement. I'm asking here (instead of StackOverflow) and keeping it language agnostic because this is a question about choosing the right algorithm, not about how to implement it. The function has three...
I have API accessible via REST. I want to develop library for it. Now, question is, how heavy should the library be? What is the best practice here? Should I wrap the whole API in objects and basically write REST-object mapper? Or should the library handle mostly the calling/getting/parsing/auth/... and just return dat...
We’re building a platform of different APIs (every API is written by different team, different timezone). We want to implement unified analytics for all of the APIs to have one data lake as a single source of truth. We are using Apigee as our API proxy for all of the APIs. Now the question is: where would you impleme...
Consider a playfield, with various player types (let's say Hunters and Animals), all moving on the playfield (and doing some other things). E.g., in a unit test for the Hunter class, there can be such test cases, as a Hunter collides with an Animal and a Hunter collides with another Hunter. The latter could look someth...
What would be the issues or advantages to using SMS messaging for inter-application messaging? more or less reliable than http? etc.
Going through an ASP.NET project that isn't mine and I noticed it queries the DB, converts the data to xml, then sends that to the view. In the view it calls a class that uses xslt to convert the xml to html and that html is returned to the view. I've never seen this before. Does anyone have the history of something li...
I have Windows 10 with Git installed. This Git uses my C:/Users/MyName dir as the HOME directory and the /.ssh/ dir within, appropriately for sourcing my private SSH keys. I have just enabled and setup "Bash on Ubuntu on Windows" (what a mouthful!) and installed Git therein also. I would like both Gits to use the same ...
This has been driving me crazy for weeks. What's the word for when a program or API is being shut down? The servers are being twilighted. The API is being moonlighted. I know that neither of these are it, but they're all I can think of when I'm trying to remember this word. To prove that I thoroughly did try finding ...
Is it still called monkey patching if you are only adding new methods instead of changing existing method behavior? What is this called? Example: String.prototype.contains = function(needle) { return false; } That may not be the best example, but it shows how you can achieve this. What are some pitfalls of this techni...
I'm kind of new to OOP, so I still have quite some doubts when it comes to how different objects should communicate with each other. I have a concrete case in which I can't figure out which is the best design between the two that came to my mind. Basically, I'm building a web user-interface (HTML+javascript) in which t...
In TDD you write the smallest unit of code to make your test pass. For example if building a Stack object you will want to test the push and pop methods. That is pretty straightforward. Those are both small units that can be tested in isolation. No external dependencies. It is about that object and what it does. This i...
I am writing user documentation (an SOP) that involves third party programs that I am trying to describe well. One such program is a server that offers little indication of it's startup besides a graphic that shows during its initialization/startup routine. As a developer, I have used this window as a quick status indi...
I find several sources claiming that power-of-two bits in a binary word (such as 8-bits per byte) is a "good thing" or "convenient". I find no source pointing out why. From What is the history of why bytes are eight bits? we read in the approved answer: Binary computers motivate designers to making sizes powers of tw...
I'm a self-taught, novice-ish coder, so I apologize if I don't nail the programmer lingo. I'm working on a project in which I am providing data, which will be continually updated, to developers who will essentially create a tool to generate reports from queries on the data. It seems that everyone involved thinks that t...
I'm working as part of a team of 10 on an agile project, this is our first time using GitHub. We write our code, create a pull request and then start on our next task. 95% of these pull requests are being reviewed by our scrummaster/manager who tests whether everything is working but generally doesn't look at the code....
Is there a naming convention for protocols and concrete implementations of them in Objective-C? Specifically regarding a protocol that's used as an abstract 'service' or 'manager' class declaration. For example, in Java you might have an interface SomeService to describe some data service and call its implementing clas...
I see a lot of shader code on the internet where PI is simply defined as an approximate decimal near the top of the code. In general I try to let computers take care of doing math for me instead of approximating values with constants (i.e. (1./3.) instead of 0.333) Pi seems like one of those things that would be easier...
Imagine a simple module-based architecture, there is the Core system that contains an array of random values. It's possible to create modules/plugins that will interact with this array. Plugin A wants to prepend a value in some global array Plugin B wants to the same but a different value Plugin C will put a value to ...
I am 1 of 3 developers. The other 2 use Web API and angular to build web apps. I prefer ASP MVC with a repository and EF. The stated argument is that a service is more secure when accessing the database. I think my way is just as secure if not more so. And I don't want to have to learn Angular. I could use Web API t...
Description I've got a series of events (points, objects, letters, what have you) that occur during a labeled time period (category.) Events can happen during multiple categories. I want to find the event which is most representative of each category. Put another way, for each category, I want to find the event that ha...
tl;dr: Would there be a language-agnostic definition of Symbols and a reason to have them in other languages? So, why did the Ruby creator use the concept of symbols in the language? I ask this from the perspective of a non-ruby programmer. I've learned lots of other languages, and found in none of them, the need to s...
Problem Changes to product requirements/specifications during the development cycle are inevitable in a professional setting. In particular, I'm constantly dealing with changes to the specification for an embedded system's software parameters: I/O, user settings, calibration data, logging information, etc. Are there an...
I am slowly creating a simple programming language (a bit like Lua). The interpreter has 2 important methods, exec and evaluate. exec reads the tokens 1 by 1 and does stuff as it says like creating new variables, etc. evaluate basically interprets a bit differently. It understands ==, new numbers (5.3), +-*/^% and new ...
Let me be upfront: I love the RESTful constraints for network-based software applications, especially when they cross organizational boundaries. That being said, I find that RESTful constraints go against business requirements laid out by people above me: "No, we need to keep client state on the server to keep the cli...
I'm using OAuth2 to secure an API. This API will be used solely by a known website and some Cordova apps. The website will send always send a corresponding referer header. The Cordova app will always send an x-requested-with header. I have two similar questions regarding this. May (or should) these headers be used t...
Why is this OK and mostly expected: abstract type Shape { abstract number Area(); } concrete type Triangle : Shape { concrete number Area() { //... } } ...while this is not OK and nobody complains: concrete type Name : string { } concrete type Index : int { } concrete type Quantity : int { } My m...
I need to navigate to js method source that I'm calling in sublime (for java script file). I try 'Ctrl'+'click method name' and nothing happens (It works for almost all IDE (eclipse, sts, netbeans, idea...)). I believe SubLime tool should have same ability (if it does not possible I need special plugin). Can someone su...
This is an optimisation problem involving string matching with wildcards. We have a set of wildcard patterns, each tagged with a numerical "score", as below. Pattern Score *AA* 20 *ABB* 10 *BA* 5 *C* -5 *B*A* -10 *AAAA* -100 In this example the vocabulary, V, is {A, B,...
I need to compare the Background colour of a Button with the colour of a Rectangle. Based on what I found, I did this and it works. However, since I am not completely sure why, I am asking if this is the preferred way to compare. Especially since I don't understand why I have to cast them, if they are the same type any...
There is a company that I am pulling data from which has a unique ID for each record. However, the ID is alphanumeric (even contains a special character too). When I asked about this I was told that this is because the leading alphanumeric portion indicates the "type" of record that it is. Is this a proper format to u...
Does a pull request review consist of testing, code review or both and how long should the average PR take? I don't know whether the testing just involves testing the functionality that's been altered, or thoroughly testing the whole app and what purpose this has if the author has already tested this. If it involves a...
I was wondering if there are general guides or standards which can be followed when trying to show if your own database implementation is ACID or BASE compliant? For example are there any specific tests I can run?
I'm writing software that needs to be fairly configurable in nature. At this point what that means is that it first reads in a users configuration file and then builds the objects it needs based on that configuration. As a result of creating objects based on a users desired functionality it seems to me that Inversion ...
In the latest version of languages like TypeScript or ECMAScript you can use async/await constructs to write code that combines the clean structure of synchronous programming with the performance advantages of asynchronous code. Take this as an example: async function isAdmin() { // Async IO request... return f...
I am developing a reporting framework that requires multi-step calculations for numerous customers. An added complication is that customers have specific though similar methods of calculations. For example some customers include datasets from stat holidays and some don't. My question is around how I should stage these ...
Does anyone have any comments on how to write unit tests for 3rd party applications like kamailio...that allow you to write "configuration scripts"? https://www.kamailio.org/wiki/cookbooks/4.0.x/core/cfg#the_configuration_file I'm looking for more an approach vs. specifics. In this particular case, these configuration...
We have developed a web based application for name matching. It operates by breaking names into parts and the Soundex value of each part is stored in a database. The Levenshtein distance metric is used to apply percentage matching of sound as well as spelling against a given name. At runtime, we load all records into m...
I have developed in the past always classic ASP.NET solution. I am starting currently to develop ASP.NET MVC solutions, but i have a problem understanding what a Model is and what it should contain. In the past i had an Object. For example one for User, Product and an object for Countries and one for Product Categories...
Today, virtually all C++ developers agree that std::vector<bool> was a mistake since it is deceivingly not a container, and its use cases largely overlap with those of std::bitset anyway. How did it get voted into the standard? Was it controversial at the time? What were the main supporting arguments?
For example, say I have two XML Strings that I want to merge: <Test> <A>false</A> <B>true</B> <C>Transfers!</C> </Test> <Test2> <A>false</A> <B>false</B> </Test2> Where the final result looks like (notice, B is now false, because I would like a place to do some sort of logic to determine the final...
Company A is building 5 separate in-house WPF applications, and they would like to share UserControls, ResourceDictionaries, and ADO Entity Data Models between each project. They would also like to incorporate 3rd Party libraries using Nuget. Should they incorporate all of these projects into one solution, or should th...
we have web application which stores information in backend SQL 2014. currently the way is set up that central database stores all key information for the customers and then we have seperate database for each customers. Now tables structure for each customer's database is same for particular product. e.g. if one cus...
This would be behind a spoiler tag if I could get the markdown to work. Sorry. As soon as I typed in "circular dependency", I got a ton of suggested results. Such as: How to handle “circular dependency” in dependency injection How to solve circular dependency Is circular Dependency Injection a good practice? Circula...
In my application, I have resource A that is super class and A1, A2 that inherits A and other properties that are specific to them. A cannot exist by itself, it must be either A1 or A2. This is a classic example of hierarchical schema. I want to design an API that will return resource A with its subclass properties as ...
My current process using asp mvc is: Talk to the client a few times to find out what they want Extract from m y notes a list of nouns, or entities that need to be tracked. Make a list of the business rules to be enforced. Build the database, based of the list of entities. Do a wireframe that roughly lays out all the U...
I've looked into numerous solutions for the simple version of this problem, but I've found no solutions for advanced cases, short of sorting through all possible permutations. I don't know where to begin this question, but I'll do my best. In my case, this will be in reference to a machine shop. In order to run a part ...
Say we have a class structure like the following: // implementation.ts export class A implements IA { constructor(private b: IB) {} } export class B implements IB { constructor(private c: IC) {} } export class C implements IC { } // ... interface declarations Using an IoC container, it is possible to inject de...
I want to write a Python application that "wraps" a command line utility, passing through all parameters intact, except for the parameters that I choose to modify. I imagine there's an easy way to do this in Python but there's any number of ways to make this really hard. Is there a "right" way to do this? Any suggestio...
Using C++ I'd like to do something along the lines of: Try to get a reference to something in, say, a map If it throws, then return straight away Otherwise, go and use the reference However because we can't declare a reference object without initialising in C++, then we can't do this directly. For example if I was ha...
I was looking to use OpenCV to program an image recognition app for iOS. One thing I wanted to check is if I were to charge $0.99 or $1.99 for the app, would I be breaking OpenCV's license? I didn't see anything in the license regarding this.
I have been using Java for a while and PHP recently. Some things I miss from Java is Code completion suggestions from the IDE Error detection before runtime Find places where a method/function is called While these seem like IDE features, from what I understand, it has to do with how the language is implemented. (bec...
I'm currently working on a software project in Swift that requires several different types of sorting mechanisms. I have been searching, to no avail, to find an algorithm to do a sort with tie-breaking. In other words, say you have a data set that could be represented like so: [Name Of Data]:[Someone's ID]-[Same Someon...
I have a new requirement to delete sensitive data when requested by the user. The problem is that the system is complex and there is a lot of existing data in the system and they are all related. If I simply do a cascade delete, it can easily affect how other functionality might operate in unpredictable ways. How shou...
I have two classes: Employee and Conversation. Conversation has a property with the employees which participate in the conversation: List<Employee> Participants { get; set; }. On the database, I store for each participant, whether or not there are messages in the conversation he didn't read yet. How should I store this...
Is it possible to pass dynamic data to the browser when it automatically GETs link and img and script etc tags after it has parsed the html containing them? Ultimately would want to pass an authentication token to allow the server to decide whether or not to return the resource. Context: I am trying to help somebody wi...
I'm about to create a specific file format for a particular project. There is no special metadata related to the file, as it can be saved in the database, in a file, etc. So the extension of the file, the date, etc. don't matter at all: only the content does. I now know that the format will have several iterations, so ...