instruction
stringlengths
34
36.1k
I wonder if a constructor in Java can look like this: public double[] values; I'm not sure if the constructor can look like this, or should it be public values (double[] values){ values = someValues; }
According to Is it OK to split long functions and methods into smaller ones even though they won't be called by anything else?, I should split long functions into smaller functions even if they are used once only, but my question is , how should I name extracted functions? For example, I have code like that: var chang...
I'm making a library or two for and Android app and I want to keep the library's exposed interfaces to a minimum to avoid the abstraction leaking everywhere by avoiding making all of the classes 'public'. I'm also following Maven's package structure. Coming from C#, I've used the internal access modifier to accomplish...
I am confused in a scenerio, where i have a music player that has a music playlist. I need help on the following usecase of the music player. Title : Play the music playlist Precondition: Playlist not empty . . . Mainflow: 1) User adds music to a playlist. 2) User chooses the play option. 3) System plays the p...
I have a use-case named "Play a Video" in my project. The video is played from a purchased webserver on which i host the video only for my application's use.Now in the "Play a Video" use-case is "File hosting server" a secondary actor?. What makes me think it's secondary is that it is external to the main system and is...
So I'm stuck on this problem for around a week, tried different approaches and having a hard time coming up with a solution. What I'm trying to achieve is to fit blocks horizontally inside another block. Overlapping blocks would be "pushed" horizontally, blocks should resize to fit the container block. Please see imag...
A bit of context. The company where I work is starting to transition to a modular architecture (something similar to microservices) for our main product, currently monolithic. The first step is to build a service that is currently not present in the product, and we want to build it outside the monolith to stop increasi...
I am designing a project where I have to enforce IF, ELSEIF and ELSE conditions on collection of objects. For example: public class Box { private List<Item> items; } I want to define IF ELSE IF, ELSE conditions on grouping of items. For example: IF (X=='abc' AND Y=='jkl') ==> get items[0], items[5], items[10] ELSE...
I am relatively new to HTML/JS and am very much an amateur programmer. I have created a web app that works but I can't help but feel that the code is a spaghetti mess! I have been looking for JS/HTML best practices but nothing really answers my questions (I'm sure it exists online but I am perhaps not seeing if it appl...
Say you create a small online business from scratch, a nice Rails or Django app or something to that effect. With luck, you end up with a database full of customer orders and things. Now, aside from manually with code or the DB's own interface, how do people administrate this? What do people use? Surely everytime an o...
I have two (and more in the future) Python projects that I'd like to package into a global package in order to import its modules and use them in another external projects in the future. This is how it is structured now: I made it using git submodule, so I made that Project 1, Project 2, etc. were submodules of the gl...
I have a Chain of Command pattern implemented, with modules that implement an interface: interface IRequestHandler { public function handle(&$offset, &$tripData, $request = null); public function setSuccessor(OffsetRequestHandler $handler); } I set up a chain of modules that modify the $offset and $tripData ob...
I am working on a round-robin scheduling algorithm for sports. The goal of the algorithm is to schedule all given games across different weeks, in the given fields and given game times. These are usually round-robin or double round-robin leagues, but the number of times each team plays the other may not be the same. L...
My project has a integration with a external system. We need to send some important informations to this system. For this, we create a micro service to connect to this external system. This micro service receive async messages from our internal systems in a dedicated Queue for that, and the micro service read the messa...
I was working with some API which was used internally, and while looking at their code I found something like this: public class Parent { @Data public static class Child { private List<GrandChild> grandChildren; @Data public static class GrandChild { private String name; ...
I work as a backend developer in a financial organisation and the organisation has demanded that we migrate all our technical documentation (e.g. info about batches like the names and their scheduling and dependencies, the way calculations are done, which transactional systems are connected with the batches, etc.) to a...
From this discussion, there are two opinions of what Thread#activeCount() returns. An "active thread" is actually executing bytecode. It is a thread that was started and is not waiting on IO or on a lock. An "active thread" is in the run() method. I.e., a nonactive thread has not started the run() method or has exited...
Let's say we have the following scenario. We have user A and user B and an initial digital document D generated by B. What algorithms and infrastructure are required in order to guarantee/prove that neither A or B have changed the initial document D? Can this be done without involving a third party authority?
I have a large shared library, a collection of functions created from numerous .a files into libeverything.so. The code for the .a files is obviously compiled with -fPIC. I also have libeverything.a which contains a GROUP ( part1.a part2.a part3.a ... partN.a ) statement that includes all .a static libraries. I don't w...
Goal: 1) huge file read in chunks each 1 MB long, 2) each one gets compressed and written to an another output file. Note: I am limited to .Net 3.5 only. Is there a known pattern how to parallelize file-reading process? Even if I would have to use Thread manually. P.S. I am not asking for code, I am looking for a nice ...
Its a growing practice to run applications into containerized environments which provide an abstraction to the operative system resources. There already are reads about container overhead in certain cases, not all the reads out are critic, there are some where they test no overhead. Like this article regarding i/o. In ...
I've created jquery plugin that is using modern browser's (Node/Element) features. I'm going to publish plugin as npm package. My wish is not to include polyfills code into jquery plugin, bud declare the dependencies on them. Plugin created using Babel. What kind of options to declare those dependencies I have? Just li...
My colleagues and I are in the process of re-architecting our system. The old system is a ASP.NET monolith using TFS for source control. The new system is made up of ASP.NET Core microservices using GitHub for source control and a private NuGet repo in Artifactory. Our first go at it, we put all of our projects in a ...
I know that a memory barrier prevents the re-ordering of instruction from before to after and from after to before the memory barrier, for example if I have the following instructions: instruction 1 instruction 2 instruction 3 memory barrier instruction 4 instruction 5 instruction 6 These instructions can be executed ...
To better demonstrate the difficulties of reading/updating objects in a multithreaded environment, I'm looking for examples for groups of objects with a bidirectional or unidirectional relationship between them such that if one is updated then the other(s) may update also. Notes: updated equals to - the former state o...
I know this question has been asked many times in different forms, but I feel that there is still no definitive answer to it. Some say login is not a valid use case because login does not have any business value, yet others say login is, just like any thing that is part of users expectations, a valid use case. Can we g...
I work for a mid market manufacturing company with around 1700 internal employees and about 7000 external users (employees of our customers). We grew through acquisition which means we have many separate systems that serve that same function for different parts of our business (two ERPs, 3 CRMs, 3 e-commerce applicati...
I have functions like this: foo() { /some/script \ --opt1=val1 \ --opt2=val2 \ --opt3=val3 } This is brittle if I take out the last option, or add any new option at any line. The failures are relatively silent, when I re-source the function, meaning I've run these wrong without noticing. I use t...
Sometimes, I would write if-statements with conditions like it: if(a-b>0){ } but in fact, I can move 'b' from left hand side to right hand side: if(a>b){ } Similar cases like 'a-b!=0','a-b<=0' (not the case like 'a>0') may also applies it. My motivation to do it is: have shorter statement avoid magic number '0' Is ...
Process A take 10 seconds to finish an execution. Process B take 10 seconds to finish an execution. Is it possible to take 5, 8, 15 seconds to finish an execeution if they run stimulately.
Amongst the successful and widely used JITs out there (e.g. JVM JITs, JavaScript JITs, LuaJIT), is there a strong consensus on how the JIT compiler should interface with an assembler? The plausible approaches seem to be an internal assembler (or more generally, any internal generation of machine code), using a library ...
As application evolves, so does the metadata. What are the top considerations for transitioning into a more refined metadata schema? Two example cases, which in my opinion are quite archetypal. Case 1. New metadata is more structured and detailed. For example, Location field goes from free text to Country, City, and th...
Let's say there are two variables a & b, both a & b would have a value between a predefined range. a = x1 to y1 (range) b = x2 to y2 (range) Variable a & b are interdependent, if the value of a is x1 then value of b would be x2 and vice versa. For example. a = 5 to 35 b = 40 to 15 if value of a here is 5 then val...
This question is coming from a frustration when using the Entity Framework and ASP.NET MVC, but I assume it's a general frustration across more frameworks and languages. Lets say we have an object called Invoice. The Invoice has a Recipient. In my object model I have set it up like this: [ForeignKey("Debtor")] ...
I recently faced a problem when I designed the microservices architecture of our new system. To give more context on that, let's suppose that we have two different services. A service is responsible to make payments and the other one B service is responsible to keep track of the orders. We have a use case that we...
I have an enterprise system that is represented by a domain model, part of the requirement that the system should limit access to some of the features based on privileges of the logged in user. Should I put these privileges validation inside my domain model? but there will be a problem that it doesn't know which user i...
Disclaimer: I have limited experience building domain models, this is purely asked out of interest to those who do I have recently stumbled upon the concept of representing data models with ontologies. It seems like it would be a great method for specifying the domain model used by an organisation's software systems. M...
There's an interesting category of objects I've seen in jQuery and some other DOM tree traversal libraries. A traditional way of mutating nodes in a tree would work in some way like this: Elements matches = tree.findAll(condition); for(Element e in matches) { if (condition2(e)) { e.setText("Hello"); } }...
Problem: If running all test cases takes too long, I manually specify a subset of tests to run while developing. But when I finally push to CI, it can happen that I broke some other tests or a functionality that is checked by them. So I underselected tests to run. Similarly, sometimes after making changes I don't know...
Having confidence means Pull Request builds (in Jenkins) will finally allow you to merge the code after a Pull request builds successfully and is reviewed. You're 100% confident that it can go into production. What are the measures(intermediate steps and best practices) a team should follow from the first step of recog...
I have a program that communicates with an API to get information on different organizations, so I have an Organization class and an ApiCall class which are both closely related. As the API I'm using requires different tokens, url endpoints and authentifications to be used depending on the organization I'm trying to ge...
I am working with Martin Fowler's definition as a working base. I have a class called Condition that I am having trouble properly classifying. What makes me think this might be a value object: A given Condition is only valid within a context of a single entity; conditions are never shared, nor addressed independently....
I need to model the status of an object over time. I'm looking for the best way to model this so that concurrent database connections can look at the current status and update the status if the newer status is different. Suppose minimally a record containsobject_id, status_id, start_date. My first approach was to query...
I am pretty confident that this is well-known and solved problem. Suppose there are n uniquely indexed "packages" randomly getting into single entry point like .AcceptPackage(Package package). Packages might be different in term of length, so I can't deterministically compute one's output-file position knowing it's in...
In light of the recent Twitter logging bug, I've been thinking about something with my own web-app: how much information should I log in the event of a 400 or 500? I obviously don't want to be logging sensitive info such as passwords, but I also don't want to be logging to little info. If I did, I'm afraid that users r...
I've run into a debate between a few friends and I. They prefer general exceptions such as ClientErrorException and ServerErrorException with detail as fields of the exception, whereas I prefer making things more specific. For example, I might have a handful of exceptions like: BadRequestException AuthenticationFailur...
We are building an interpreter for a language as part of the requirements in one of our undergraduate course. Part of the project involves writing a lexer and a parser. The parser generates an AST. Obviously, the AST would have nodes. One of the nodes of that AST is the ArithmeticOperationNode. This node will be a node...
I want to implement a lambda service that would provide me random names (generated using patterns, some hardcoded values and so on) by GET request. For name generation I just use the set of prepared morphemes, small words and so on. To create a name I just randomly select part of the word, concat it and return result. ...
This is a use case diagram about the enrollment of students at a university. There are several flaws in it, and I have to find them. I am wondering what is happening when you get to use case "Choose course". Yes, you will also have to "Enroll", but what happens if you choose a course that is not available? You will e...
We offer a platform that provides certain data processing services. All our APIs are accessible via RESTful services. All services require authentication and authorization to work properly (user/client specific data are processed). All authorization works with JWT tokens sent using the Authorization http header. There ...
While educating myself about software architecture and design patterns I’ve noticed that in most cases some language features and design specifics are implied in the explanation. E.g. practically any article or book on that will illustrate the ideas using classes and interfaces. Everything one can easily find on this ...
Consider the following implementation of a static factory pattern... public class Names{ private static final Map<String, Name> NAME_MAP = new HashMap<>(); private final String firstName, lastName, strRep; public static Name getInstance(String firstName, String lastName) throws IllegalArgumentException { /* ...
There's a website where a person should pay to get some service/product. After a person has made a reservation/product by paid for it, I want to allow him to track the progress without having to or register or login. It'll be similar to page on airline website where one can enter their last name and the number of reser...
I have an Employee who can view items . he also can checkout an item independently (regardless of manage items use-case ). The problem is that when an Employee view items he can choose to checkout one. So I think one of the following options is true : the 'extend' relation from view items to checkout an item is not ...
I'm processing a stream of incoming records, for clarity assume they're numbered consecutively 1,2,3....etc. Most of the time the records are arriving slowly enough for me to process every single record. During busy periods they are arriving too fast to all be processed so I need to drop/ignore a proportion of them. I'...
I vaguely remember a quote from, IIRC Kernighan. Something along the lines of: when you find a bug, fix all occurrences of it I think it was either in the "Practice of Programming" or "The C programming language." And, IIRC, it was in the context of logical errors, so did not presume one was not following DRY. Does ...
I am developing a social network app, we chose MongoDB as the storage for our app and mongoose as an ORM. Everything was going smoothly until one dark day the client said he needs to let the users to deactivate their account. Now this seems a simple task but what is making me sick is that the client wants to be like Fa...
The previous guy had worked on local clone of LO(LibreOffice) for TB_LR script support during 2015, and now my job is to get all his commits on his branch to reproduce his work on current LO clone. I was told to cherry-pick his commit one by one, resolve conflicts, build, fix compile and link errors, then repeat the sa...
Like if I want to access an array element in C it's implemented like this: For example: If a = {0, 1, 2, 3} is an array if I want to access index number 2 I will write a[2] and the formula that is implemented internally is (a+2*sizeof(int)) to get the starting address of the index number 2. But this can be done because...
In a Web Application that has 4 layers: UI layer Business layer Data Access layer Data storage layer which is the database One of the requirements is to handle a list of objects with unique key. For the database it is obvious that I need to use a unique key constraint on one column. My understanding to handle duplic...
I have the following code, and I was wondering if I'm optimally iterating through my ranged for loop: struct data_type { int a; int b; }; int main() { // Assume I have initialized a vector storing data_type objects. // The vector is called "vec". for (const data_type& temp: vec) { ...
I have a waypoint class which i use to connect a bunch of other waypoints up. But i also have a special type called a consumer, this is not technically a waypoint but it needs to act like one in that waypoints need to connect to it. So i thought about using an interface due to this has a nature of the consumer so i can...
I see an interview question thats goes like this: Assuming you have an array with numbers 1 to N. Where N is at most 32,000. This array may have duplicates and you do not know what N is. With, 4KB of memory available, how would best print all duplicate elements in this array? If i'm not wrong, printing elements does...
In a website users can register through different social logins ex: facebook, google, github etc in addition to normal email registration. There is one users table to store these users, and in addition is needed a mapping to check if a user comes from 3rd party logins or not. One solution to store the users can be in ...
I have the following class: import Radar class Domain(Radar): URL = 'https://mxtoolbox.com/DNSLookup.aspx' ADDRESS_KEYS = ('mailing_address', 'city_name', 'state_name', 'zip_code', 'country_name') GENERAL_PARAMS = {'format': 'json'} BALANCE_PARAMS = {**Radar.GENERAL_PARAMS, 'account...
Lets say I have a free and paid version of the app. Paid version is a superset of the free version regarding features available to users, meaning paid version will have all the features of the free app plus extra. Is there a pattern to toggle feature availability based on a flag that loads at startup (e.g. free/paid)? ...
I want to create a service that would be running locally (not accessible from the internet) on a given port, then a browser extension will need to access this service. My problem is that I cannot know what port will be available in advance so I would need to pick one more or less randomly and I'll need the extension to...
Im working on the implementation of an IEC 62304 compliant development process in our company and I have a question considering SOUP (Software of unknown Provenance). Our goal is the develop a web application in the future. For this application we will use different open-source libraries on the backend as well as on th...
I am developing a mobile app that depends on some nearly static data. I will gather that data initially from an existing website by doing some HTML parsing. I could now create a database from that data and use this as my backend for the app. Whenever there is new data, I will manually run my parsing program again on t...
I'm currently an intern at a company. For my intermediate report I Received some feedback about displaying the relations between multiple applications. So in my image all 3D rectangles are a deployed application. The database figures are a persistence layer (doesn't need to be a database, could be a file). The feedbac...
I have an interface ICondition which only defines a single method, IsConditionMet This works well as it is the only information the parent entity needs from its conditions. However, there is a situation where a user needs to remove a specific condition from its parent that I am struggling to find a elegant way to imple...
We are using Jenkins extensively. We have several jobs, for building and testing. Our problem is that the current email notifications are not so good, so we are improving that. Basically, we are adding html to the email using information we can get from the pipeline. Now, each job is already complex, with its own scrip...
I'm wondering how best to model in a HATEOAS based API links that allow the client to set parameters. E.g. imagine a search response that returns a list of producst and then refinements that can be performed on them: { "results" : { ... } "refinements" : { "Size" : { "links" : { ...
this Wikipedia article did not address this contingency and i am having trouble finding a definitive IEEE-754 document that addresses this.
This might be an X Y problem, but here's my situation. I've got a QT5 C++ code base whose task it is to allow for the configuration of a "process chain". A "process chain" here means a list of linked elements who execute in sequential order, taking a single input and returning a single output to the next "process ele...
After writing some code, I have a habit of scanning it all over once or twice in order to look for any bugs. This is sometimes a painstaking and tedious process, and it takes up time. After reviewing my code, I then run it through my tests to verify it. Is this a productive way to perform verification? Is it more effic...
I have a fairly simple problem currently but I cannot get a solution, maybe someone here has a good idea. I am working on an open source CMS for artists called Jinya CMS. The whole project originated in a friend of mine needing a new website for her artwork so I started to build her a website fitting her needs. One of ...
In javascript, python, golang or rust usually you have the third party source code available in your development environment such that you can edit it and debug it. I am a beginner in java. What is the best recommended work flow to debug third party library?
Recently, I've been in a few situations where I needed to quickly come up to speed on old code and fix it sufficiently for people to be able to use it again. The code I've worked on tends to have the usual issues (no documentation, no tests, etc.), but compounding this is that I often have absolutely no idea (on a tech...
What kind of exception should I throw if the XML can be parsed, but is not structured in the way expected by the program - wrong tag names etc. Example - Expected <xml> <tag1>blabla</tag1> <tag2> <tag3>blabla </tag3> </tag2> </xml> Example - actual <xml> <tag1>blabla</tag1> <tag2> blabla </tag2> </xml> Is there a...
I encountered code like this below. I was told its fine, and boilerplate is not always better. I agree boilerplate might be bad, but I am not sure about something like this: if (entity.isSomething && wasCheckedBefore(entity.name)) showSomeMessageToUser(entity.name) if (entity.isSomethinElse && wasCheckedBefore...
I sometimes put a link to the site where I copied a chunk of code from in case I forget what it does. Is this a bad practice? Should I copy the explanation from the site instead of linking to it?
i have some experience (mostly as a student) with react and redux, and on the other hand i also have some experience with express, normally for my apps (all of them are really simple) i make a rest api with express, make express interact with mongo or any db im using and then retrieve the data to react. That's kinda al...
A group of friends are tracking the miles per gallon for each of their cars. Each time one of them fills up their gas tank, they record the following in a file: His or her name, The type of car they drove, How many miles driven since they last filled up, How many gallons purchased at this fill up, Date of the fill. The...
For example, sometimes I need to generate a link, but I don't want someone cache the context by url of the same link (e.g.:I don't want Facebook feed dialog to cache the page context), so I need something like this: https://www.facebook.com/dialog/feed?app_id=(my app id)&link=http://(my website)/myContextToShare/(some ...
I have a working web app that I version control using Git - call this v1.0. I learnt a lot during that development including some of the mistakes I made. I now want to re-write parts of the code to follow best (better?!) practices and allow better maintainability. Should I create a new repo or should I clone? (I am usi...
I am in charge of design an application (.NET) that has these features: It´s a desktop app (maybe in the future will be web-based) It´s functionality is to provide users analyzed data retrieved from database. It is done by performing heavy queries generating , graphs and grid-tables to show the information. Users a...
As noted by in the comments by @benjamin-gruenbaum this is called the Boolean trap: Say I have a function like this UpdateRow(var item, bool externalCall); and in my controller, that value for externalCall will always be TRUE. What is the best way to call this function? I usually write UpdateRow(item, true); But I ...
In C#, i can declare an immutable field on a class using readonly. This works for value types, but if its a reference type, there is nothing stopping me calling methods on the object to change its internal state. C# sort of solves this problem by providing concrete types and interfaces that simply dont present a way to...
Our application had a few vulnerabilities detected by AppScan and we had to add server-side validation to catch SQL injection attempts. But my question is, how far do you go in server-side validation? In theory there's no end to how complicated you can make it. Suppose I'm just validating there are no special chars in...
In my company, I'm currently working on a project with some (REST) web services involved. The development is based on the OpenAPI specification and the Swagger tooling. The target platform is an internal cloud platform based on OpenShift. As we make use of an CI/CD pipeline in our software development process (more or...
Context My projects are separated into one assembly with Interfaces, which I call the Core, and another assembly with the implementation, which I call the Implementation. In reality, the namespaces look like this: CompanyName.ProjectName.Core CompanyName.ProjectName The first project has zero business logic in it (Ma...
When i was developing a console app the algorithm was the following steps: first create a temporary directory then call another command that will create an xml file inside the the temporary directory then read that xml file and extract a name from it lastly rename this temp directory to the name extracted from xml ...
I have searched a lot on how to handle timezone in a web app. My application saves all dates as UTC in the database and returns UTC dates in json requests, so javascript proper handle conversions in the timezone of the user device. But I had stuck with the problem of timezone when the user needs a report that is genera...
I have a coupled web application (frontend and api backend served from the same application). It's worked well for our needs but I've been curious about the differences that would go into having a completely decoupled front and backend. I'm specifically wondering about how handling authentication requests would work wi...
I've heard some developers say that if a variable is only referenced one place, to just replace the reference to it with the value assigned to it. I've also heard developers say if a function is only called once, to just put its statements in place of the single call to it. The reasoning typically given is that when r...
If one wishes to upgrade from Node 0.10.48 all the way to the latest LTS version (8.11.2 as of right now) would it be smart to upgrade only to version 0.12.18 first, and then to 4.9.1 and so on? The idea being that every Node upgrade will imply breaking changes and it might be easier to deal with smaller bites of issue...
I've recently watched a few Pluralshigh courses on DDD by Vladimir Khorikov. He was encouraging to create a rich instead of anemic domain models. It all looked very nice in a small test-project, however I still have no idea how to put extensive business logic inside rich domain model. In rich domain model we are suppos...
//------------ let person = { name: 'John Doe', age: 22 } let e = document.getElementById('task-title'); /* Object.getOwnPropertyNames() Returns an array containing the names of all of the given object's own enumerable and non-enumerable properties. */ console.log(typeof person, person); console.log(Object....
I am working on a game, and I have many instances where I have to do something like this: Game.getInstance().getEnergyDropManager().getDrops() Or: this.dimensionSelector.selectDimension(Game.getInstance().getPlayer().getCurrentDimension().getColor()) This gets long to write and not as readable. I could have a class w...