instruction
stringlengths
34
36.1k
After many hours of research and thinking I have found an understanding, then coming to question it again, I am struggling to find something concrete which I can grasp and apply to my code in a practical sense going forward. I think I am referring to presentation logic and a domain model. I have read numerous articles ...
I don't know if this is a thing but here's a silly idea. Often there are cases when you have to refactor code such that you need to change code pertaining to some particular area. This may involve changing functions or variable calculations spread across multiple files. Let's say I tag these places with a comment sayin...
I have the following requirements: Load data from a variety of sources and fill a list with it Use a batch of data to perform some computation Some additional information: The algorithm for computation expects the list of data to be ordered by a key that comes with the data. I want to use a queue instead of a list i...
I have some data that I need to represent in a form. As an example, it might look like this (in psuedo-json): [ { "value1" : "int" "value2" : "{1, 2, 3, 4, 5}" "value3" : "int" } { "value1" : "{1, 3, 5}" } ] So when I display the first form, the user should have an integ...
Someone in a Stackoverflow post (I didn't bookmark the question unfortunately) commented, that Factories that only return one type of object are a code smell. I find myself writing these kinds of factories pretty often. Sometimes because i don't want to bloat my code with constructor overloads and sometimes because i j...
Is it possible to design an Applicative Functor with a few extra stack manipulation functions push, pop, and a specialized branching function ifA :: forall a. f Boolean -> f a -> f a -> f a, and achieve a model for computation that is equal in expressive power to a Monad? (Can express any program that a Monad can expre...
With event sourcing, you can project an event to create query-optimised read models. This I understand. What I'm unsure about is whether these read models can depend on each other? I'm considering pre-generating HTML pages and PDF reports in a certain part of an application. The HTML pages are not interactive, but rath...
What exactly happens underneath (I know it changes the paragraph tag's HTML when the circular div is clicked) when I run this piece of code? Could you please explain the callback function as well. <script type="text/javascript"> $("#circle").click(function() { $("p").html("You clicked the circle"); } <...
I'm developing a Java application that will handle huge XML files (up to 300mb each and hundreds of thousands of lines). They are grouped usually with 20 to 40 similar XML files that also need processing. Work will be mainly CPU-bound, with some IO-bound related to opening the files and saving back the results. I was w...
I have often wondered about the implications of shortening code by assigning temporary variables with shorter names to data accesses with long names. It's best illustrated by an example (in Ruby, but not that it matters): This long code is ugly, IMO: # Trim the description to MAX_LENGTH characters followed by "..." # i...
I'm working on an interface for implementing business rules in order to improve SOLID-ity; so I can move a lot of logic out of Web API controllers and into a business library. The Common Problem being that an action should occur if one or several conditions are met, and some of these conditions are likely to be require...
I have a system which consists of two applications. Currently, two applications communicate using multiple zeromq publish/subscribe sockets generated for each specific type of transmission. Sockets are programmed in C. For example, AppX uses a subcriber socket for receiving an information struct from AppY and uses a ...
The problem is maintaining in .net a list of rows that have a specific sequence where rows can be inserted, moved and deleted, and being able to save and restore that sequence from disk. In memory I can use a .net list with insert and delete by index position. The alternatives that I see for converting that to a disk...
An enterprise utilizes the source code of a network software product licensed under the AGPL v3. It modifies the source code but does not share the changes with the original developer and copyright holder, and keeps the changes private. It then hosts the modified version within its servers, but does not distribute the...
I know it's generally a design flaw to have an empty class, yet I'm wondering whether there are some cases where it isn't to have an empty (abstract) class to group objects. Especially when polymorphism is needed. For example I have a group location. They can consist of an area, a line (a road for example) or a specif...
This is a question more about using volatile to prevent optimization than about caching write/read of a variable. Particularly timer delay variables since I don't want to declare everything volatile and waste optimization in doing so. First off, I know the following snippet will not work if optimization is turned on un...
I'm developing a video web system like YouTube where users can upload, view, update and delete their own videos (CRUD operation). Original I drawn the use case diagram like this: But I learned later that it's better to use one use case called "manage video" to simplify the whole diagram where there are a lager number ...
I am using an array of objects to store data to render a page. A few examples of the type of data each object can contain: PHP filepath for an include CSS filepath for CSS files Meta data of the page Element data to build page elements Etc... I have an HTML template file that I parse with PHP and replace certain tags...
I always wonder what is the best way to design your property files. I have few questions that I didn't find an answer to them Do we place all our labels / error messages in one file? Do we split the files, one for labels and another for errors (more logical and practical solution) Do we make a property file per projec...
Our team is currently developing a hybrid application. It is similar to Sigma Estimates - a GUI with tables, forms, a sidebar with a tree structure, etc. The software allows a user to work with a database in the cloud - create table structures according to records in the database. If the connection to Internet is avail...
I use @SuppressWarnings("unchecked") and @SuppressWarnings("null") mostly above methods to let the code compile without any warnings but I have my doubts. Found this Stackoverflow question. Jon Skeet wrote an answer to it which I find intriguing. According to him, Sometimes Java generics just doesn't let you do what y...
Should I use HttpUtility.HtmlEncode or write an extension method? Pro for using HttpUtility.HtmlEncode is that other developers can instantly see and recognise what it's doing. Pro for using an extension method is that it's less code to write everywhere and less noise. So I guess I'm asking obvious readability vs tidi...
Let's consider the rule in python PEP8, coding standard for the linux kernel etc saying that a line of code are not allowed to be longer than N characters. To this rule there is normally a few rationales: On some terminals you can't see more than N characters on a line without wrapping. Optimal line length for readabi...
Let's assume you want to change what user sees on the website. There are two ways to do that: a) manipulate the DOM via JavaScript, but user has to download whole script, with possibility he may not need that script. More bandwidth is wasted. Also this limits what you can display. b) rebuild the whole page on demand (i...
I'm working on a graphics library that works a bit like the Android-type libraries and I ran into a question regarding the topic of margins and whose responsibility they should be. It seems very common for graphics libraries to put the margin on the element itself; ie if you want to clear 10 pixels of space around an e...
I have this random number generator, and have had it for quite some time, but despite how much I use it I don't really understand it. public static int Random(int x) { x = x + seed; x = (x << 13) ^ x; return (x * (x * x * 15731 + 789221) + 1376312589) & 0x7fffffff; } It works really well for my purposes - ...
Lately I've been working on a project that involves parsing a toy domain-specific-language. While building it out, I realized that an efficient way to handle parsing tokens would be to represent the parser as a state machine. To great success. Representing each possible state of the parser got rid of many problems I wa...
I have a Spring application, where we make few service calls to fetch data. There is a Data Layer in between the Controller and the Service layers. Controller (Request-Mapping) -> Data Layer -> Service Layer If we do not get the data from the underlying service, we intend to throw an exception. My question is regardin...
I have some (or just a little) experience in writing web application backend with interpreted language, php, python and javascript (node js). When writing the backend app, usually what I do is write some code, see the result on the browser, if anything wrong fix the code, see the result on the browser, and then add som...
I have been working for a few weeks on a new web project and I am realizing that all I am doing is basically calculations and transformations on data, and that most of my classes do not contain any state and could perfectly be turned into static classes with static methods. Therefore I am thinking that this could be a ...
Recently I have been reading the book, Scrum Shortcuts Without Cutting Corners by Ilan Goldstein. Goldstein mentions that when practicing scrum, you will write user stories and you will write task for those user stories that would then be assigned to one individual. The problem is when I got further into the book, Gold...
I have a somewhat popular open-source project on Github, and I'm getting ready to do a major overhaul - completely different directory structure, substantially different versions of major components, and lots of files that simply won't exist anymore. I don't want to create a completely new repo, because we will lose al...
There are at least two distinct memory management models: Java (we do it for you) C++ (it is your responsibility) I have two questions: (1) Is GC language specific or compiler specific? (2) Do most languages fall in one of these two categories? Are there other memory models in commonly used languages? The names of ...
I am working on a feature where I need to store some data and I am not sure what should be my best option to store this data. I am sending data to some third party and want to show some part of that data internally in system dashboard. Data is being calculated at run time and being sent to third party. Since the base ...
I just "fixed" an intermittent failure by this process: Observe intermittent failure Debug code; at one point near where the failure could be, pause execution, and inflict harm upon a variable (by, say, setting it to null) Failure occurs Fix the failure you just inflicted Declare success It's related to voodoo debugg...
I'm beginning an open-source project for logging work hours. The intention is to build something similar to Git, where instead of pushing code you're pushing information about work hours and progress. I intend to make a PHP SDK for interaction with this program (and hopefully SDKs for other languages in the future), bu...
In the build lifecycle in maven, I encountered the validate phase described as validate the project is correct and all necessary information is available to complete a build 1. what are the check points for a project to be correct? 2. what are these necessary information that needs to be available in completing a build...
Suppose, I have class Boss and Worker; Boss has a Worker and Worker holds a reference of Boss: Boss.h #include "Worker.h" class Boss{ public: Worker worker; }; Worker.h class Boss; class Worker{ Boss* boss; }; In C++, Worker doesn't need Boss to compile, but I am not comfortable to see the word "Boss" appear ...
Just a basic question on IF statements in programming languages, specifically C++. Consider the following basic code example: int i = 2; if(i == 2 || i == 4) { //do something } Because the first condition would equate to true, are CPU cycles wasted on the second condition? Sorry for the Programming 101 question, ...
I've been searching for tons of websites for how an interpreter works, but I found none of these explain how Interpreter works internally. But I found in many places how compiler works with all the steps and descriptions. So my question is, how does an Interpreter work?
I was modifying a class whose job is to load other classes from the same directory. Basically, everytime a new class is added you need to add a new CommandClass; statement to this class for it to be loaded. I thought that it's strange and violates "Closed for modification" principle, so instead of adding another line t...
This is a general question on a subject I've found interesting as a gamer: CPU/GPU bottlenecks and programming. If I'm not mistaken, I've come to understand that both CPU and GPU calculate stuff, but that one is better in some calculations than the other due to the difference in architecture. For example, cracking hash...
I've recently used typescript, and I think the ability to mention or not types is great. It greatly reduces the debugging time while also giving you the advantages of an untyped language. I could imagine a python language superset with the same functionalities, I'm sure the type specifications could be used to greatly ...
I am trying to figure out how an AMQP broker, such as RabbitMQ, can be integrated in our architecture. This should allow to easily scale horizontally in the future. For the sake of simplicity, let me ask the question via an analogy. Say you have: A set of bank accounts. We assume that the the number of accounts can gr...
UDP provides no guarantee for delivery and no protection from duplication and is connection-less protocol but why then DNS uses UDP protocol. Please make me clarify. At what conditions we should prefer UDP over TCP protocol?
I found out that the package name should follow the web domain you own for this application / developer Id. I published an app starting with com.health... (example) because I didn't know better at those times. In how far will I run into (legal) issues (if any), because I am not the owner of health.com (example). Should...
I have a requirement to write a POST endpoint where the payload is huge(not normal). In the order 10s of Megabytes. And this endpoint will be accessed by a lot of clients (in the order of 1000s) simultaneously. How should I go about designing this endpoint? The expectation is to validate the incoming requests and sen...
Password reset option should be given only if the link has come from that specific user's inbox and not from somewhere else. How to implement url in such a way that the required information i.e. Mailbox can be obtained from the url? Facebook and Twitter like companies seem to have already implemented it. Any suggestio...
I'm now doing my internship in a government company (in India) and I've been assigned a project to create an online forum for the company.. I'm about to use phpBB forum software to create it, which is licensed under GPL. The created forum will later be put online in the company's website. Now my question is, does the g...
I need to create a class which will have the following structure: public class MyClass { ArrayList<File> myList = new ArrayList<>(); public void addFile(File f) { myList.add(f); } public void DoHeavyWork() { for (File f: myList) { /// ... } } } I was thinking on th...
I've heard that it's ideal to have one assert (or expect or should, etc) per aspect of a component's behavior you're trying to test. Is this how it works? An addOne function would be tested like this, I suppose (example is written in javascript syntax): it("returns one plus its input", function() { assert(addOne(5) =...
As you read in the title, for example, i wanna login to my account in StackOverflow by sending the E-mail and password through a program developed in c language, so all what i have to do is to enter the required data (E-mail, password) in my program and after refreshing the webpage in the browser, i'm directly connecte...
Suppose we are using java or python to access the database. Then is it considered a wastage of time and unnecessary to learn the kind of data structures and objects being used inside sql? Please answer in reference to the software industry. Please try to tell in which cases it will be good to have knowledge of such thi...
Right now I have a webpage with various buttons and options that I'd like to use to send commands to a python script running on the webserver. The python script is being used to interface with devices over a serial connection as well as performing computations with the data received from both the webpage and the serial...
Does UI interface is just an Image created by graphics tools?. I need to know that when a user interface created to read an textbox in c#. When a text entered is it take values from keyboard by Readline.console method and displays on screen terminal or it display first to screen and reads from screen coordinates. Got ...
I'm making a piece of rendering software and I want to make the tools it encompasses extensible. I've built a UI that lets the user write custom C# functions for blending values. The functions (and accompanying values/constants) are added to a class and compiled using CodeDom, and the blend function is used from there....
When creating a table with similar bits or data such as names. Is it preferred to have the column name prefixed with a common value? Consider a table to store user information. Looking at the columns related to the users name they may be structured as follows: title first_name middle_name last_name Would it not be bet...
I have an architecture/performance problem. The problem: One voting based application with: 1 loadbalancer, 2 webservers and a database 10 candidates and 200k voting users. There may be more than 100 users voting at the same time. The database can only hold 1 write concurrently and does not support transactions. If t...
I am writing a wrapper function for database calls, and I am confused about the best way to handle the error cases. The function has only one argument, the id of the object to be deleted. I've handled two error cases : 1)If the object is not found i return false. 2)If the object is found but delete fails due to...
Given the following code in the DoWork() event of a BackgroundWorker object, how can the concept be converted to the Async/Await model? I wish to execute multiple downloads simultaneously in order to maximize bandwidth. I also will need to retain the ability to increment a progress bar on the dialog. Dim oChunks As Sor...
Having read about the 4+1 Kruchten, I am required to document a system architecture using this concept. Instead of the notations proposed by Philippe Kruchten, we decided to go with UML instead. I am particularly interested in the process view, as I don't understand how to map this to my processes. I know I can use seq...
I have a Python script that continuously makes GET and POST requests to a third-party API at about 1 request per second. It uses a while loop, so the requests all come from the same process. Currently, I just run and kill the script on my local machine with python run.py, but I'd like to be able to start and stop this ...
I have the following class that doesn't implement IEnumerable but is working perfectly with foreach. And also, arrays are working without implementing IEnumerable. So why does it keep saying that IEnumerable needs to be implemented in collections to use with foreach. I'm confused, please assist me. class Parent { ...
I need to create an immutable object but it requires several parameters to work like: class FooRepo { public string ConnectionStringName { get; } public string SchemaName { get; } public string TableName { get; } public Dictionary<string, int> ColumnLengths { get; } public Dictionary<Type, SqlDbType...
In my classes of parallel programming the teacher mentioned three models, dynamic thread creation (create threads according to demand), thread pool (create a fixed amount of threads) and mixed or hybrid (create a number of threads at first, but you can create more if the demand increases too much and then return to the...
I am trying to solve this exercise. It is about reimplementing the map function in haskell for learning purpose. I found a solution which doesn't browse all the elements of the list (simple linked list, so accessing the last element will browse all the list) at each iteration, but I didn't found one which is tail recur...
I have a question that is crucial for my end of year project. Background My web application allows users to build other webapps based on drag&drop (within the domain of the webapp). These web applications can contain regular elements, but also functional widgets in the form of ReactJS components that can even talk t...
Context I recently wrote a final exam that required using a BindingSource object with ADO.NET to populate a number of combo box and label controls from which the user could perform basic business functions. I got it working but had some reservations about my design choice. The setup When a user selected a product from ...
I'm writing a game in Java where each game object has a number of properties, but these can all be changed in one of two ways: Every second, a tick runs which may automatically cause a change. Users can send a request to the server and make a modification themselves. Should I lock the Object while the tick is running...
I want to show that in my new system, plugins are used to control the core software components. What would be a good way to show that in UML? I will definitely use sequence diagrams to show interactions between the core and the plugins, but is there some sort of static diagram that fits?
I recently (1 month) start working in a project and as I was going through the code I saw an using Microsoft.Practices.ServiceLocation and as I searched for the documentation on that library is says: This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still ...
I was playing around with variables in Java. public class Hello { public static void main(String[] args) { byte byteV = 127; short shortV = Short.MAX_VALUE; int intV = Integer.MAX_VALUE; System.out.println("Short: " + shortV + ", Integer: " + intV); long longV = (10 * byteV) ...
An increasingly popular definition of factory method is: a static method of a class that returns an object of that class' type. But unlike a constructor, the actual object it returns might be an instance of a subclass. From : https://sourcemaking.com/design_patterns/factory_method Doesn't it violate OCP? I h...
This is part of the code of a calculator that works on command line. It works fine and the math is correct but it's a little redundant: switch(Operator) { case "+": result = num1 + num2; printResult(); break; case "-" : result = num1 - num2; printResult(); break; case "*": result = num1 * num2; pri...
I'm thinking about whats the correct pattern to handle this case in CQRS / Event Sourcing: I created events to calculate a balance and system goes into production. By accident, this implementation has a bug and calculation of balance is wrong. Should I fix the implementation and rewrite the events in the event store as...
I am struggling with applying the "programming to an interface" guideline because I can't seem to decide in which situations it is necessary and in which ones it's overkill (or even counter productive). I would like to know of any heuristics or rules that you use in your projects to decide if you need to create a new ...
I'm working with scrum methodology. thus weekly schema updates are performed to the final product. However our customer is already populating the database. How can I update the database without dropping the tables? How can I deal with these schema updates? I am using DB First approach. this way I don't have Code First ...
"Singleton" is widely considered anti-pattern ("bad" in everyday language). What about this alternative modified singleton pattern? An object constructor for our class ensures that at any given point of time there is at most one instance of the object (yes, this uses a global boolean variable). If the user attempts to ...
In my current project, I have a screen which pulls data from several webservices, pulls data from database via backend API and checks that all resources have the same data or not. The other webservices are partial mirrors of the data in the db and the screen shows a table with the state of the data(if everything is the...
I am confused over Virtual Inheritance and disinheritance ? Is both are same ?
Are there any viable approaches to dealing with data coming from devices with unreliable clocks? We have a database system running on a central server. The latest addition to the system is a bunch of mobile barcode scanners running Android. We are creating a specific app and the devices will be completely locked down s...
Is this design bad? Does it break encapsulation? The structure class B is a component of class A. Therefore, class A needs access to class B's members. Let a house be class A. Let a housekeeper be a component of class A. Let a room be class B. A room, and therefore class B, is a component of class A. A housekeeper nee...
I have a question about how to structure a response where I return objects related to other objects (one-to-many/many-to-one), and to tell me if the way I've structured my endpoints are wrong or not, or if there is a better way. My scenario: I have an JS app built on Flux where I have these stores: - Meetings - Users F...
Assume that the parameters of functions representing operations of the relational algebra are represented by individual types: structs or classes. An operation such as (natural) join will have parameters of two types (T1, T2) as inputs and produce a return value of a third type (T3). There is a relationship between typ...
In a Winforms project I've been working on recently, I've been dutifully using using-statements for objects that implement IDisposable. I want to reopen a database connection, however because the using-statement that it was in earlier disposed the connection, I can't reopen it. So this leads me to the question, is it b...
I'm looking to implement dependency injection in a relatively large application but have no experience in it. I studied the concept and a few implementations of IoC and dependency injectors available, like Unity and Ninject. However, there is one thing which is eluding me. How should I organize instance creation in my ...
I want be to be able to re-write the code of an existing PHP function in an abstract manner. Here is an example: scandir() scans a directory for files and folders, and returns the relative paths '.' and '..' . While I could just create a new function to run scandir() and remove these entries, I want to try and re-write...
I'm just about to set up CI for my web application. I'm using Bitbucket and Pipeline beta as a CI. The web application is strongly coupled to the database, nothing can be tested without data in it. My team also has some issues with the local devenv, as due to frequent DB schema changes, Django migrations are irreversi...
The PHP codebase I'm working on has an utility class that returns a database connection. The implementation looks like this: class Database { private static $conn; private static $init = false; public static function connect() { if (!self::$init) { $cnf = new Configuration(); self::$conn = new Da...
I have the following app scenario where i would need to implement the cell-level encryption. Database - MS SQL Server Web Technology - ASP.net MVC Existing app scenario:- Currently the web application is serving multiple clients and the app is attached to multiple db's such as ClientX, ClientY, ClientZ etc. All thes...
I tried to repeat this results: 27^5 + 84^5 + 110^5 + 133^5 = 144^5 (Lander & Parkin, 1966) and 95800^4 + 217519^4 + 414560^4 = 422481^4 (Roger Frye, 1988, 110 hours this is the only counterexample for values below one million) The first counterexample can be found by a direct search in several seconds. The second cas...
I'm trying to create a nodeJS application. It allows users to rate a bunch of songs and it stores them in their user profiles. I use this information to compare them to other users, and try to find users with similar interests in songs, and I suggest them new songs based on that. Each user profile basically looks like ...
Imagine that I've got a piece of custom audio hardware that I'd like to be able to control in a multitude of ways via a tablet/touchscreen GUI. In particular, my goals are to have the tablet's control GUI be "pretty" (i.e. nicely animated and modern looking, as one would expect from an iPad), have it be cross-platform...
For a GameJam I'm trying to code a simple web-based text adventure game with sprites and small animations in AngularJS. I'm a little new to Angular and am having some trouble figuring out how to structure it. I think my trouble comes from my struggle with Controllers vs Directives. My game essentially needs to pull tex...
I would like to provide design decisions in the comments as well. I want design decision comments to be distinguishable from function contract comments, on cursory examination of source code. How to go about it?
So I would like to be able to call a function like this: void func(1, 2, 3, (void*)label) // can return normal or to the labels //some code label: //different code Is it possible, and is it bad practice?
I have a register page that uses text inputs as well as an avatar input. There's another part in the website where the avatar input is also used, but it's used alone this time. So I'd like to make it reusable and since it's coupled to a part of a view, I want to use a controller for this. Simplified, here's how it look...
When writing an unmanaged Win32 DLL that exports functions, it's not uncommon to have some functions, variables and/or classes that aren't meant to be exported and are only for internal use within the DLL. Since we were targetting applications written in both .NET and Visual FoxPro at the time, using a .def file inste...
I have a C++ program that read game data from memory process. For example, int points = 0; while (1) { points = ReadProcessMemory(..) // points will be read from game's memory Sleep(100) // Don't read too often } I want to sync the data so that it display this point (not necessarily real time but fast enough) ...
I recently started at a company as a Automation Developer. My job is to automate periodic reports (in Word) for all of our customers (~50), one for each. Each report is slightly different, so I am going to have develop code for each company. The position is new and there are no automation in place; all reports are com...