instruction
stringlengths
34
36.1k
Say I re-implement a method for finding the position of a string within a string. So I get either the position which is an integer, or a "magic number" like -1. I see this pattern in so many programming languages, where some return a value like null, some return some random "out of range" value like -`, some totally th...
I'm quite new to designing large programs in C++. I'm writing series of operations, each of which have their own class, which will be invoked by the ProcessMgr class. I'm using ProcessMgr as an interface class, from which each operation can be invoked: class ProcessMgr { private: class OperationOne; class Opera...
I structure my Android application following Uncle Bob's Clean Architecture which basically comprise of at least following relevant layers:- Presentation - Using MVVM approach. This layer contains Android's Activities and their corresponding ViewModels. Interactor - This layer encapsulates application's use cases logi...
Out of curiosity. Say I have a class with a data member: class Base { public: //methods and constructor,set and get, operator overload etc private: int data; }; class Der : public Base { public: //just overload of some of the methods in the base class, please note there's no data member } The idea is bas...
We have an ASP.NET MVC application and a bunch of libraries that are used by the application. There are cross-cutting concerns and dependencies like loggers, repositories, user tokens etc that almost all of these libraries need to work. Some libraries are dependent on other libraries and so on. For example - ...
Say you commit, pull, have a conflict, resolve the conflict, and then commit. Since the local change already has a commit with a meaningful message and the remote change being pulled has its meaningful commit messages too, what should the message be for the commit that resolves the conflict? Often I find myself making ...
Rstudio has a community version for free: https://www.rstudio.com/products/rstudio/#Desktop But mentions the license is AGPL v3. Does this effect the licensing or IP rights of code written on the platform or is it referring to extending the IDE itself? The paid version commercial license seems to be talking about exten...
I have a bunch of classes which deal with validation of values. For instance, a RangeValidator class checks whether a value is within the specified range. Every validator class contains two methods: is_valid(value), which returns True or False depending on the value, and ensure_valid(value) which checks for a specified...
How do I create instances of classes which require a huge amount of components and attributes? Take for example a car. A car has hundreds of sub components each with their own specific properties. There would be thousands of parameters to pass or work with. Some components even repeat themselves inside of the car (whee...
Hi all: I've gotten this question like four times interviewing in silicon valley. What is the correct solution? Shuffling a deck of cards. The problem description is as follows: You are given a deck containing n cards. While holding the deck: Take the top card off the deck and set it on the table Take the next card...
Let's assume that I have the following interfaces and classes: public interface ITest { } public class Test : ITest { } In NinjectWebCommon.cs: kernel.Bind<ITest>().To<Test>(); And after this I want to use my ITest interface: public class Vehicle { private ITest _test = null; public Vehicle(ITest test) ...
Assume we are building a system for managing large, tree-like domain-structures like banking loans or insurance contract. At the root of the domain model is a Loan class. It serves as an entry point to the layers of the domain model e.g. loan parts, collection information, contractual parties, collateral, associated i...
As a general rule, programming languages are designed for use by humans, and thus for entry using a US-QWERTY keyboard. (This makes some number of conceptual skips, myself as proof as I'm doing most of work on a BE-AZERTY, but indulge me and join me in this leap of faith.) Using the letters of the alphabet for reserved...
Stack overflow suggested that this question my be better suited here. I normally work in c#, but I'm working in a vb.net net application currently. So feel free to respond with vb.Net or c#... Essentially I have a singleton that does all of the heavy lifting of getting global settings which are stored in the database;...
(I've seen this question, but the first answer goes about auto properties more than about design, and the second one says hide the data storage code from the consumer, which I'm not sure is what I want/my code does, so I'd like to hear some other opinion) I have two very similar entities, HolidayDiscount and RentalDisc...
If I have ten classes, and they all need CRUD operations, how does an Aggregate Root and the Repository Pattern solve me having to write lots of boilerplate code (the DRY)? Take the example of a School and I have a Student, Teacher, Subject, Schedule, Room, ..., etc. If I did nothing, I'd have a service or class somew...
This is my current CQRS use-case setup: Command DTO is received in application layer handler where we map Command DTO to appropriate domain objects if needed, re-hydrate aggregate root from repo and call some method on AR class CommandHandler{ handle(Command command){ Dom1 dom1 = new Dom1(command.d1); ...
I'm currently trying to better design a database structure for defaults where a reference to preset defaults is maintained globally, but the system is flexible enough to allow for new defaults to be added. Database: Default Fruits ---------------------------- ID: Name: Colour: ---------------------------- 1 ...
There are some Tech Leads that perform code reviews for each Git pull request. Apparently, a very good practice to be aware of the evolution of code. Basically, they expect to inspect a few lines of code differing from previous code in order to ensure "quality" easily. As a lot of good developers know, another very g...
How does a programmer figure out multiple uses or applications for the original software he/she has written. I am an artist who has designed a RPG game with several different and separate applications that are all linked and combined in the software that I am attempting to find alternate uses/applications for. Since I ...
Say we have 1001 clients that construct their dependencies directly rather than accept injections. Refactoring the 1001 is not an option according to our boss. We're actually not even allowed access to their source, just the class files. What we are supposed to do is "modernize" the system that these 1001 clients g...
In my day job I work on a tightly controlled project with features and overall scope ultimately decided on by committee. Often the final features are the result of a single (or multiple) member's needs. Thus every now and then an idea lands on my desk that can, technically speaking, be implemented but may not actually ...
Often I change code but I don't know if I might need the old one, I can leave it under comment but then I find myself with lots of green lines while I hardly can read the real code. Thanks.
I was trying to understand how jQuery's cross-browser events work, when I noticed these two functions in the source code: function returnTrue() { return true; } function returnFalse() { return false; } Further down in the code these are used like: if ( fn === false ) { fn = returnFalse; <--- here } els...
So one day i was reading about RSA and over there it was written that we can secure the data using the public key. So as an idea can I secure the data on the client itself before sending it to the server using the public key provided. And decrypting using the private key on the server?
Is it good design to have a controller for each object of your API? I know this is a short question, but it's really a fundamental question that I do not know. Say I have a school or a CRM. That is a lot of controllers. I don't know another way to do it, but it feels like a DRY problem. I am using ASPNET Core if th...
I wrote multiple times different apps that have following requirement. CRUD Operations via DataGrid control... Everytime I start new prject I write new code for same requirement over and over - what is the best way to make custom DataGrid control which is reusable and generic. I'm a junior developer and I'm having hard...
I have a method processDataAssumingLinkedHashMapInput() that processes a Map. The Map must be a LinkedHashMap ordered by values. Data comes from getStrIntMap(query). This method gets resultSet from SQL and puts it in a LinkedHashMap. Here is the code: public void processDataAssumingLinkedHashMapInput(){ String quer...
Let's say I have a three tier application structure, with Presentation, Service and Data layers. The data layer is managed by an ORM and has two models/entities, Show and Episode, with a one-to-many relationship (one show consists of many episodes). In the service layer there is a ShowService, which can manage shows. T...
I have been working in large multi module projects over a period of time. One major issue I faced is, how to communicate to other teams of a new feature which they may be interested in. Consider this scenario. Projects X, Y and Z depend on a project P. All depend on version 1.0. Now I work on X and P, do some fixes and...
Protobuf is nice and dandy, but it was not made with self-description in mind. Now this is totally okay if you're using a well-defined protocol and want to replace e.g. SOAP-messages or just want to replace a restful JSON API or the like. However I would like to use it over a Websocket though and instead of closing and...
Suppose that you are modeling and application in which you'll have 4 kinds of entities, say a Person a Job a Machine a Chemical Now you have to model all possible relations (N:M) between those entities, because your business logic is such that it really does make sense, so you end up having many tables: Person_Job (...
I'm writing a Python tool to convert/store the data from a commonly used plaintext file format for volumetric data generated by computational chemistry calculations into the binary HDF5 format using h5py. The plaintext files are often huge, frequently 100MB or more, and in cases where certain types of semi-lossy compre...
I am working on a local copy of a large project on github. Most of the changes I make are modifications to tailor the application for a speific use case, as such they are not going to be accepted by the maintainer. I am trying to figure out the best way I can regularly update my local branch with changes made in the ma...
Suppose I am developing mobile applications using C++, and I found some methods are not suppose to change once written, for example: class MyClass{ public: float kmHrToms(float kmHr){ return kmHr/3.6; } std::string toString(){ return "this class is used to..."; } . . . } a...
Suppose the following situation: A CI server generated regular snapshot artifacts At some point, an artifact is considered "stable" and is given to QA for testing If it passes, it's deployed as an official release If it doesn't pass, a newer snapshot gets tested until one passes Given an arbitrary build, we want t...
Progressive enhancement usually refers to web content, and the idea of having a page that is readable before it's fully functional. I'm suddenly preoccupied with the idea that I can't progressively enhance my code. I want to be able to add methods to my values. I might have a string property. If I want to enhance it wi...
Take an HTTP API endpoint which spits out the following response model: { "type": "Dog", "name": "Jessi", ... } The type field has been described in the documentation as being one of Dog, Cator Fish. Would adding a new option,say Rat, be considered a breaking API change? Is adding an option to a finite li...
There some times appears a task when you have a sequence of object and you need perform some action when a particular pattern (subsequence?) occurs. As more concrete example we can imagine a log monitoring solution which should alert when a predefined sequence of messages is detected (A followed by B, followed by C, bu...
I have a software which logs various events into a database (SQLite). Currently the stored datas are : Message Date Category Criticality The logs are written in the current software language. Which mean that the message : User "admin" logged in can become L'utilisateur "admin" est connecté if the software is in...
I am using semantic versioning 2.0.0. In my situation I have a concrete implementation of some interface A in one library. And I have the interface that's being implemented (call it B) in another library. I understand that if I were to add new methods to the interface B then that would be considered a major change for ...
I believe everyone encountered this example numerous times, where there is a primary/foreign key relation. Now, I am interested when to add just a foreign key ID instead of all/some relevant foreign key information. For example Product ID Value Name Description Order ID ProductID Value Name Description vs Order ID Va...
I've been dealing with a Sr Dev recently that loves unit testing. That's great! I'm not sure I agree with his testing methods though, contrived example: function foo (String $var) { switch ($var) { case 'hello': return '-world'; default: return 'good-bye!'; } } function ...
I have been reading the source code of some Java library classes, specifically CompletableFuture. I noticed that the authors are making extensive use of cryptic (single-letter) variables in the code, which makes the code arguably unreadable and difficult to track. Is there a specific reason/rationale behind this appro...
We have a solution containing a web application project (mostly webforms) and two separate "config" projects that are copied over depending on which client's specific output is needed. Presently to "deploy" we zip up the web application folder, but of course it picks up files that were do not want such as project files...
I have finished learning about java beans, and from what I understand, they are regular classes just that they are serializable, all the properties are private and are accessed through getter and setter methods, and they contain a public no arguments constructor. I can see the advantages and disadvantages of writing be...
I see wikipedia entries for: https://en.wikipedia.org/wiki/Source_lines_of_code aka SLOC. Shouldn't there be some other kind of metric like SCC? (source character count).. or maybe there is and I just haven't found it?
As I try to deal with the possibility of failure when I invoke RESTful endpoints or in general any HTTP endpoint I've been wondering if there is any standard or pattern in the HTTP specification or in the industry to deal with the problem of determining when an exception is transient and when it is not particularly for...
Our organization is looking to standardize the way we use const T& and T const& and while we initially looked at clang-format to solve the job, it doesn't reorder tokens so there is no way to swap const and T. Does anyone have an idea as to how I can reorder these systematically?
I'm trying to consume an API (tumblr) in an asp.net-mvc application and I feel like there should be a better and cleaner way to handle the response data. I have these models: public class TumblrEnvelope { [JsonProperty("meta")] public TumblrMeta Meta { get; set; } [JsonProperty("response")] public dyna...
I am currently writing a Java bridge to a eyetracking library written in C. The whole thing works very well, but building an actual application with it is hard, since eyetracking is done by polling for new data. Polling becomes a problem as soon as you have a graphical user interface, as a poll-loop blocks the main eve...
I have a backup application written in Delphi. Now I want to add Delta capability by using RDiff.exe + cygwin1.dll. cygwin1.dll is covered under the GNU GPL License . Does this imply that I have to give my entire Delphi application as Open Source ?
Suppose I have a REST API backend and it is used by a mobile app. Authentication is based on tokens (JWT) with expiration time. Mobile app user does not want to enter credentials so often, even for weeks. In other side I think token must not have expiration time more than 24 hours or so. If I do not include token inval...
I have a short question for you: let's imagine that we have a class similar to this one. public class StreamTradeDataProvider : ITradeDataProvider { public StreamTradeDataProvider(Stream stream) { this.stream = stream; } public IEnumerable<string> GetTradeData() { var tradeData = ne...
How would i design a stack which in addition to push() and pop() ,also has a function min which returns the minimums element ? min() must operate in big O(1) time
So I'm building a card game where each card has cost, damage, and durability, as well as name and description. Obviously one would think of creating a Card class: class Card { int cost int damage int durability string name string decription } werewolf = Card(5, 10, 120, 'Werewolf', 'Deal double dam...
I have a finished Chinese-English dictionary website as a personal project and it works pretty great. I'm using node/Express with node-dirty, which is a barebones file-based JSON database that loads everything into memory on start-up. As I keep adding more features though, I have to continuously update my database gene...
Much has been told about the advantages of agile development and Scrum in particular, however, most of these assessments assume that an organisation comes from a very rigid methodology of Waterfall. But what if a company is organised less strictly than advised by Scrum, not more? The organisation I work for is a former...
I'm building a native app which currently has zero backend infrastructure. With services like Firebase's Authentication, database and notifications means that all interactions are handled client-side within an Ionic app and consumed via Firebase javascript API. I would like to start sending triggered emails and communi...
I've been struggling to figure out a clean way to validate things when objects have complex relationships and the validation requires expensive operations (e.g., making DB queries or other RPCs). Looking around, I couldn't quite find something that answers this question, so here goes. I've read a bit about domain drive...
A lot of my code seems to be going through the following evolution - Iteration 1 interface IAccountManager { void Import(string importData); } class SalesAccountManager : IAccountManager { private int GetAccountId(string data) { //Some data conversions, database references, calculations etc ret...
I am working at a robotics startup on a path coverage team and after submitting a pull request, my code gets reviewed. My teammate, who has been on the team for more than a year, has made some comments to my code that suggest I do a lot more work than I believe to be necessary. No, I am not a lazy developer. I love el...
Why does the 1st map method below treat element #2 as undefined but the 2nd map method does not? const a = [undefined,,42]; // Note the two consecutive commas. console.log(a.map(x=>x)); // -> [undefined, undefined, 42] console.log(a.map(x=>x===undefined)); // -> [true, undefined, false] I expand on this wi...
Code 1: private static int myCompare(String a, String b) { /* my version of the compareTo method from the String Java class */ int len1 = a.length(); int len2 = b.length(); if (len1 == len2) { for (int i = 0; i < a.length(); i++) { int intValueOfStringA = (int) a.charAt(i); ...
I'm trying to create a Html file input field which can add multiple files to the form, instead of replacing existing chosen files. This is the basic file input element for uploading multiple files: <input type="file" id="fileupload" multiple> But it replaces previously chosen files :( I can't believe that html doesn't...
I am working on a web api c# project using onion architecture and repository pattern and entity framework among other things. Doing some research I discovered a technique called side-loading https://developer.zendesk.com/rest_api/docs/core/side_loading that basically helps client load additional information in a singl...
In the old days we used to create a single .gif file for the entire application to avoid too many trips from the browser to the server. Similarly, we used to combine different types of information in a single response to avoid unnecessary HTTP traffic. Did all this change with the microservice paradigm? Is it better t...
I built a post processor for creating CNC machine files to which I'd like to provide a web interface. Currently the program takes a file path as input and then spits out the results into another file. I'd now like to be able to turn the program into a server that receives JSON data. It's trivial to open a Unix Domain ...
I'll start by explaining what I mean in particular. Background In Javascript, arrays do it all (more or less a Lispy trait). Not only can you initialize, push, and pop, but you can also iterate, filter, reduce, transmute, and so on. You can also check includes (contains), and with the overloading provided by huge libs ...
I will host a blog using Github Pages, is it possible to add a secondary license in the assets folder so if people fork the project they would have to provide their own assets and not use the defaults one that came with the project? I was thinking of a Creative Common Type of License for the assets folder in specific.
I just read this question and the answer claims: "Lets assume db connection object is singleton in my application" This is a must not. Your database connection MUST NEVER BE (yes, bolded and with capitals to make sure you and every reader never make this mistake) a singleton object. Your Connection con MUST NOT be par...
When considering the value or ROI that we reap from our efforts in implementing and using BDD it is realitively straight forward to measure your savings for the test automation element. You can compare the old manual test design and execution times against the new automated design and execution times over a time perio...
I've been developing a C++ library for multiple precision computations (integers/fixed point), assume positive numbers. The class is something like: class Integer { public: //constructor //destructor //set //overload operators private; uint32_t *mem; int n_bits_stored; }; Specifically the //overload ...
Right Now I design Time & Attendance System. If I have the following entities : Shift (Id,Name,start_time,end_time, ...etc) EX :1,Morning,08:00,16:00 WorkSchedule (Id,Name,Type,...etc) EX :1,General,1 Where the Type may be(Traditional,Daily Flexible Hours ,Weekly Flexible Hours) And WorkSchedule has detail using Sh...
Our team is experiencing some growing pains with regards to source control. We use Team Foundation since it integrates so easily with our existing infrastructure, but are definitely open to other options. We deliver a software service to 15+ very different clients that require constant code updates. Right now, we have ...
I have a template wrapper class around the container std::priority_queue that supports multithreading. The short version of it is below. In this class I employ the function IsReady() that checks whether the element is ready to be popped or not. Implementation of IsReady() depends on the type T. At first I made IsReady(...
This question is in the context of a server application - an API that feeds data to its clients. Here is the obvious: if I have some data, I can search and filter on that data however I please. Let's say I have some data with the following basic structure: [ { name: 'Paul'; location: [51.6689134, -0.15818313]...
I'm working on software to play back log files. We have different types of logs from different providers. I've created an interface that different classes will implement to play different logs. For example, ClassA will hande "somelog.txt" from ProviderA, ClassB will handle "another.log" from ProviderB, etc. public inte...
I am developing an API that has one call that accepts a big JSON object. Based on this object, there are 10 possible parsing scenarios, i.e. if field xxxx.xxx is present, go with scenario 5. We currently have around 10 if statements in a controller function of over 200 lines, which decides which scenario to choose. The...
Our company uses a 3rd party platform to manage a pretty large portion of our business, but the platform is built on top of JSP and MySQL. However, our own products are written in C#/.Net. We're currently researching methods of being able to implement an SSO between these two services without too much overhead. The SSO...
On a SCRUM meeting the product team was debating about a feature on an API that will be consumed by mobile app. We had a mock up that showed how the screen should look like and what key elements it should contain (a "layout"). Based on this and the discussion I had with the product owner I created a prototype for an A...
In our company we have to development teams. The Product Team and the Delivery Team. I am working in the Product Team and the Delivery Team is consuming the framework, libraries, and services we are delivering to them. They use them to create their own version of the Software, driven by their customers, and end-users. ...
I have very little experience of using a version control system and my work colleagues have no experience though I would like to introduce one into our team as the current workflow (non-existent workflow) with shared directories, multiple file versions, reliance on me to make changes and no review process is eventually...
Please help brainstorm/dream about an important problem (I believe this is a valid question, if you think it's not a valid question, please give me concrete critique so I can work on it). Almost every language used is text- and file-based. This has drawbacks, e.g. refactoring, renaming symbols is often painful (renami...
As an agile team member, when do you sign-up/self-assign a task/Jira ticket? Does this happen before the iteration, during the iteration, during the daily stand-up meeting or it can happen anytime during the iteration?Is this observed as a practice during retrospectives? Quoting any example would be highly appreciated!...
I'm working on a web application project which uses Tornado as the web frontend. Currently, I'm in the process of writing up docs and adding docstrings to the code base with Pydoc. As a web API framework, Tornado applications are structured with each API endpoint having a handler class, and with each handler class havi...
How can I design a good REST API for actions, like in the following cases? lifecycle start a device stop a device ... conversions convert a file from one format to another In both cases I would always use the abstraction of ActionRequest, something like: url: api/device/1/start method: GET or POST body: StartRe...
I have always been taught that in order to in-keep with encapsulation objects should be responsible for performing calculations on their own data. So in this case here is this breaking rules of encapsulation and considered bad practice? #include <iostream> using namespace std; const int SIZE = 10; class safearay { pr...
As a beginner in both java8 and functional programming, I think I'm missing something when reading about function composition since I cannot find a reason why there are two methods that do this, andThen and compose. Since f.andThen(g) is exactly the same as g.compose(f), why are both needed, in which cases would using...
I have couple of files in my folder, some of them can be checked for integrity. I have a xml file which describes which files can be checked for integrity and their checksum. In OOP, let's assume I have a class called File. Then, I have a class called FileWithIntegrity which extends File. I could create a class called ...
I am currently trying out Gradle for my embedded development project. The existing tool is GNU Make. Across the internet I have read a lot of articles where people say that their build logic becomes "too complex" and they would like to reduce "complexity". This I believe is basically a developer's or build author's per...
I'm at a bit of a crossroads with some API design for a client (JS in a browser) to talk to a server. We use HTTP 409 Conflict to represent the failing of an action because of a safety lock in effect. The satefy lock prevents devs from accidentally making changes in our customers' production systems. I've been tasked w...
I have the following scenario: Joe is working on the feature-xx branch. Richard is working in another feature-yy branch. Their company has a qa.myapp.com environment where testers work. Joe pushes code to Github repo. Build passes. qa.myapp.com is updated with the new Joe's branch, so testers can test his work. Richar...
In our company, we have a relatively big data structure, with terabytes of historic information stored, and there are lots of different views, editors, and reports for all the data. With the years, there have been several "hands" involved in the underlying code for data retrieval and storage, which we've found out that...
I have a large data structure that is about to be persisted to the database. Before that can happen I have to validate it and then update a bunch of it's properties based on various specific conditions. Which style is more readable, having a bunch of if/else statements which determine which functions will execute ...
I am developing an AngularJS app, and the server side PHP, step by step, implementing features and then polishing them. I currently periodically request data from the server, of the order of a few thousand records of 5 or 6 items each. As the next step, I had planned to send a CRC with the request and have the server r...
I am looking to replace a framework from the ground up. It works as it is, but I've been tasked with understanding it, so I want to know if anyone else recognizes any glaring design issues that I could address in a re-write. Currently, the system works as follows: Server/producer very quickly inserts data into shared ...
In our internal architecture, we have several Tomcat servers which distribute the workload and isolate the different processes of our business. We are planning to move into an approach where several tasks (mostly BD related) will be handled by a Tomcat endpoint (load balanced for availability and performance), but we a...
I'm currently working on introducing React in the company I work for. As the only one having done courses on the topic, who can I ask for a review to make sure the code is following 'best practices' and is implemented correctly?
I have read several questions here, and searched over the internet, but didnt find an answer to my question, thats why I ask, with Agile Unified Process, I have to build all the UML diagrams that I have to build with Rational Unified Process(RUP)? I want to know it because, i want to use an agile methodology for a thes...