instruction
stringlengths
34
36.1k
I am working on an application that is currently localized in six languages. Localization engineers occasionally test to make sure that all of their strings are contextually appropriate and appear correctly in the application. Something that's taking ever more time is their testing of error messages that are unlikely t...
When I'm creating a docstring, sometimes I want to refer to a value, for instance: def try_download(data, path): """Tries to download ATTEMPTS times, catching socket errors.""" Where ATTEMPTS is just a constant int defined at the start of the file. But would it be better to write it so that it's generating a strin...
After researching modern web servers, I feel that I am pretty ignorant when it comes to server design and concurrent task management by both the operating system and the server. I understand some important basic functionality such as thread/process blocking and that the operating system will context switch from a block...
I have to provide a Python CLI-based program to one of my clients. I will give him both the compiled version (using py2exe or something simillar) of the application and the source code. The application structure is the following: a cfg folder which holds some configuration files (the main .py parses these configs usin...
I am writing a website, and I've come up with quite a few scripts taking up a lot of space and ruining the aesthetics of my code. I came up with the idea of creating one script that fills a div below it with scripts, but that sounds like it could present some sort of problem. Is this an okay thing to do, or is this bad...
As part of my continuous integration server, I am running a bunch of performance profiling. If the performance profiling tests don't crash and pass a threshold then it declares them successful. I then manually take the log files, convert them to JSON, plot them in a web browser, then print the page as a PDF. This provi...
Today I was reading a lot of articles complaining about Java Generics or C++ Templates. Now, my question is: How can someone implement a collection data structure like Stack without using them?
I'm using a some C++ Facade classes like this: Suppose that there is package named "SubSystem" with a lot of classes inside, like in the picture above. I cannot name the package of the facade class "SubSystem", because there is already a namespace with the same name. What is a good standard or practice to name Faca...
Background I have been programming mainly in Python in the past years and mostly on my own projects. I have developed some of my own small stilistic conventions like leaving 4 numbers of empty lines between classes and 1-2 lines between methods, etc. Currently I moved to a company with 8 developers developing mainly in...
Since every time a web browser requests a page, we are almost certain that there are .css and .js files to be sent as well. Why do we wait for the browser to parse the DOM and discover those files before issuing a request for the CSS and JS files? The server has the HTML files and knows all the links to other resources...
I'm using SignalR with StackExchange Redis. What I gather from the basic usage doc is the way to implement this is using a singleton. I've never used this patter before. My class looks like this: public class RedisInstance { public static readonly RedisInstance Instance = new RedisInstance(); public static Con...
I'm looking at BDD test tools, like SpecFlow, MSpec or NSpec, and I can't see from the examples what advantages they offer over simple unit test tools like MSTest. As far as I can see, when creating a BDD test I would write a test method similar to a normal unit test that I would write in MSTest. The difference I can ...
I'm sure that there is a similar question like this already in existence, but I didn't see one that matched closely enough, so here goes... We use a third party company to host our site and do most of the code updates and the code is maintained in a Git repository. However, we haven't been too happy with the job they'...
I'm trying to understand how licensing generally works in software development, but this seems to be a rather broad topic that won't have a single straight-forward answer. Hopefully this example is specific enough to illuminate where my confusion on the subject may lie. The GCC compiler is licensed under GNU General P...
I have an application where I'd like to add ways for external modules/components to hook during the processes and data-flow and perform actions/modify data. For the first requirement—performing actions—I assume the best pattern would be to emit events and have other modules/components subscribe to those events and perf...
I have a kind of minimal language (sort of parser for CISCO-like CLI) that have parser described below. The parser should be serializable to JSON, that's why not Parsec or Attoparsec. I need a sort of completion tree for those commands, i.e for each prefix there are should be all possible sub-commands. Cp type describ...
For example, I have something need to do depend on user input: test.cpp #include <iostream> #include <fstream> int main(){ std::string input; std::cin >> std::noskipws >> input; if(input=="A"){ std::cout << "A selected" << std::endl; }else if(input=="B"){ std::ofstream myfile; m...
After long 3 months of debate and research in choosing between React (with Redux) and Angular 2, front-end team in my company has concluded to go with Angular 2 (given that it is more suited for our problem). We're into enterprise app business, which is currently comprises of many different front-end technologies (whil...
What were the motivations for java to use the @Override annotation, instead of creating a new override modifier? @Override public String toString() { return ""; } vs. public override String toString() { return ""; }
In the process of developing a realtime Single Page Application, I have progressively adopted websockets to empower my users with up to date data. During this phase, I was sad to notice that I was destroying way too much of my app structure, and I failed to find a solution to this phenomenon. Before getting into specif...
I've tried looking on google but can't get the answer I want to this. Is there a book or article or a video where various commonalities of different popular high level languages like Python, Java, C++ etc. are contrasted with each other ? By commonalities I mean: If you learned something in one language is it true fo...
In Scala is it acceptable to have id variables written as _id instead of the regular camel case notation? In the code most variables respect the camel case notation. However for variables referring to id, I like to append _id at the end instead of Id. To me it makes it clearer and also different from other variables. E...
We're in the process of shifting our datasource from Mongo to MS SQL Server. Our challenge is that we have two testers who are green. As a team, we're trying to work through the most sensible test approach. We have two datasources (one MS SQL, one Oracle) that are integrated via flat file feed to a MongoDB, which is us...
We have a codebase at work that: Ingests (low) thousands of small files. Each of these input files contains about 50k “micro-items” These “micro-items” are then clustered together to find “macro-items” The “macro-items” become the input to a variety of other important business computations and analyses. These macro-...
Imagine a domotic webapp, to command a heater. You could setup N plans, for a plan I mean a similar table: +----+---------+--------------------+ | id | name | target_temperature | +----+---------+--------------------+ | 1 | confort | 19 | +----+---------+--------------------+ | 2 | hot | 22 ...
I am trying to build a RESTful search api (POST request) that can return different types of resources (e.g A, B, C, etc). I have defined a data model for each of the resource type. There are some propeties that are common across all the types and there are some that are specific to some types. "A" : { "a_property1...
I'm java developer. We developed good back end application. Customer asked UI part for it, but UI part development in our program needs each time restart the server (to refresh WEB static files). Is it possible develop UI without restarting back end with ability update WEB UI (js) libraries and files (css\js\html)? It ...
Let's talk about three projects. I have a Cinema project, a Cinema.Engine project, and a Cinema.Client1 project. In the Cinema project, I have an interface ICinema and a factory class CinemaFactory. In the Cinema.Engine project, I have a class that implements ICinema... we'll call it CinemaEngine : ICinema. This projec...
I understand the recursion and find it useful and intuitive while solving problems on trees but for many other problems recursion never fails me to leave puzzled. Recently I was solving the following problem: Write a recursive function that counts how many different ways you can make change for an amount, given a li...
We design RESTful API for our system. 90% of resources have dependency from other resource called as "user", for example. "User" also can be used as an independent resource. We found two ways how to reflect it in API URIs. First-level resource. Pros: transparently for clients what resources depends and what doesn't. Co...
In the following DOM event handling example (using jQuery): $('#shopping-cart').on('click', function(event){...}); could I not call the shopping-cart DOM element the observable, and the function the observer? There is no "general" click event being hooked to, but a click event specific to the shopping-cart object itse...
If the goal is to be able to swap out backend DB providers (EF, OleDB, ODBC, etc) then I'm wondering where the different DB CRUD changes? Currently I have an interface (IGenericContext) that has Add/Update/Delete/Select functions. I then make an ADOContext which implements this and inside these functions is where I do ...
Maybe this question is not going to mean a lot if C and C++ are put into context, but I kept wondering why later languages such as Java and specially C# haven't been made simpler in regards of their syntax? That's why I was wondering if there's some important reason for this, because for me it looks like these language...
I'm trying to implement a branching model that is similar to git-flow, but simpler (no release or hotfix branches). The idea is to have the master branch always up to date with the latest tagged release, a develop branch that runs parallel to it, and feature branches to implement longer (more than 1-2 commits) features...
Lets imagine I have points in a 2D plane that I want to connect in a directionless graph. However, I don't want these connections to overlap. The only data I'm given is where a connection exists, and what direction is goes. For example, one of my (very simple) data sets might look like this 1 > 2 2 > 3 4 > 3, 5 5 > 3 ...
What is the meaning of the term "value" in statements such as: A Haskell function is a first-class value Every value has a type In both statements, I am left wondering what a value is and have a nagging conceptual gap when reading Haskell programming texts. So, bottom-line: is there a definition of a Haskell value? ...
Say you're designing a C API, and one of your big concerns is ABI stability (it's going to be deployed as a shared library, or whatever). You have a function exported int foo_bar(int a, int b, int* c); And you feel that someday, you may need to add one or more parameters to this function, but you don't know which on...
In assembly language, is there a difference between a function and a procedure? I use them interchangeably but I'm not sure this is appropriate a professional environment.
I try to find out not according to semantics but weight. I mean, should I take care when set a long name to a variable?
I am building a relational database-backed Line-of-Business application for my consulting client (or rather, I'm rewriting it - long story). This software product is a SaaS service for a niche industry. In this case, as far as we're concerned, it's a system which manages reports for woodchucks - it generates woodchucki...
We are developing a mobile app/apps which has two parties involved, creators and consumers. Creators first register themselves, get verified and then create the events. Consumers browse for desired events and if found interesting, register for the event. What will be the best practice to achieve the above scenario. Two...
I have a question related to modeling similar Class of objects in a DB: Suppose in the database i have a list of clients which can be in different categories - eg. Client --> can be in Category1 ... Category10 now, Client in Category1 has some behavior that is specific only to that kind of client, but Clients in Catego...
Usually the Repository pattern looks like : What would be the best practice to make the repository handle more gateways (for Cache Redis, FTS/filtering Elasticsearch, Db Mysql etc.) My ideas so far are to make a Repository array class that will loop through each repository when calling a method. Also where would I im...
In Python specifically (I don't know if this generalizes) is there a "best" way to return multiple items from a function? def func1(): return a,b #equivalent to (a,b) def func2(): return[a,b] def func3(): return{"valueA":a,"valueB":b} The first is what I see most generally, but I feel like the last one ...
Most places where I have seen prototypes defined for a constructor it was done like so. var Person = function(){ this.stuff = stuff; } Person.prototype.doSomething = function(){console.log("something")} var john = new Person(); But to me, coming from Java it seems more intuitive to define it directly inside the co...
I don't getFoo/setFoo naming convention, that is so spread that it become a standard. Instead, I am using more and more just: foo() and foo(value) for reading and setting value. I also see this trend in some libraries like VertX. While this is fine when I work on my projects; should I do the same for the 3rd party libr...
After asking it in stackoverflow : polymorphism-and-tree-structre I came to a conclusion that I am not being specific and my question is not about any specific technology so I will try to rewrite it. in the stackoverflow question I wrote about a grandparent/parent/child classes in order for my question to be concise, t...
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...