instruction
stringlengths
34
36.1k
I want to use certain piece of software for my commercial project. The software that will be making use of is open source and I will modify the source code to suit my needs. Say at a later date, the open source software is licensed under GPL version 3, what happens then? Am I allowed to use the original unlicensed ver...
I have strong web-developer background, where in order to show client a demo I've uploaded a solution to demo environment and sent over a link. If case client asked to make changes, I did them in PhpStorm, dev-tested on local env, deployed in one-click from IDE and asked them to reload the page. In was that simple and ...
What is the difference between these 2 PHP operators ? The first one is = and the second one is .=.
I'm asking about C#, but this probably applies to most other languages as well. Imagine I have a project with a lot of complex logic, split up into a lot of small components. Let's say that, among other things, it contains a ComplexProjectFacade with a single method accepting some parameters and returning some value - ...
My first thought here is to use a dynamic array, but I am looking for something better. Currently I have the text files open into "chunks". Every word or group of spaces makes up a "chunk". Then I have a line number in this structure and a chunk number for ordering on a line. typedef struct TextData { char* chunk; ...
I often find myself in the situation where an object contains a set of objects, and I want to access one of these objects based on one of its properties. How I currently do this in C++ is to put those objects in a map, where the key is a copy of the object's property. For example: map.insert(make_pair(obj.getName(), ob...
In many articles all over the web the terms Inversion of Control and Dependency Inversion Principle seem to be mixed up and used as synonyms (further confusion is enforced by the tools that are called "DI-Containers" and "IoC-Containers"). A Wikipedia article does a nice job trying to explain that IoC is not the same a...
I have some input that I send to a computational library, which processes the input and produces some output. Question: What considerations do I take into account to help me decide whether the output data type should be an array, or an object? Similarly the same can apply to an Input object that's fed into the librar...
Before any down voting or blaming, please bear in mind that this is my first "serious" Python project. Before this I have only coded a program that uses several Google API's to do stuff, and not much more besides lots of various code testing and exercises, but I haven't get much in to classes yet. Now, I am coding an a...
In general it makes sense to me to unit test everything besides glue classes which have no logic. They often catch mistakes and code smells even at the time of writing let alone protecting you from regressions later on. What I'm less sure about is higher-level tests. In particular for traditional MVC web-apps you often...
We are starting on a greenfield project in ASP.NET MVC. I've used the MVC pattern in other stacks (PHP and Ruby) and I keep running into the same problems of where to place business logic, UI logic, and where should this system interact with other remote systems (i.e. web services and e-mail). I was reading Advantages ...
i have a grading system which works like this: You have a array of intervals with grades: [9, Inf) => A; [7, 9) => B; ... (-Inf, 1) => F But you can create also inherited grading system by new array: [10, Inf) => A+; [7, 8) => B-; ... Now when I need to get the grade I go from bottom to top and always check whether t...
A function f() uses eval() (or something as dangerous) with data which I created and stored in local_file on the machine running my program: import local_file def f(str_to_eval): # code.... # .... eval(str_to_eval) # .... # .... return None a = f(local_file.some_str) f() is safe to...
Let's say I have a Car class. Objects of this class will be stored in a collection, and every object should know about other elements in the collection, because for each car there's a value to be calculated based on the elements of the collection it belongs to. That's a generalization of my problem, but I think it capt...
When I'm looping through files and coming up with dynamically created Ansible playbooks and stuff like that, I've quite frequently had to work with a single variable that contains the IP and port of something. Can I refer this as a "socket" or does that name always refer to a handle? Is it better just to refer to the...
C, C++, C#, Java, as well as many other statically typed languages have the type before variable like (int a =5, auto c = 4, etc.). Non-statically typed languages (such as Javascript, basic) use var (or let) before the name (var a = "asd") Why does Kotlin, a statically typed language, use a mixture (var i: Int)? Why no...
I wrote a C# Winform User Control as follows when Executable is Run: My question is how we can use this Winform C# user control in one ASP Page. I know about WEB User Control and using in ASP but what about using WinForm User Control that design in C#?
Typically for a single instrcution, 6 machine cycles are needed: FETCH instruction DECODE instruction EVALUATE ADDRESS fetch OPERANDS EXECUTE oepration STORE result My concern is regarding the fifth step; excute operation. This is done in the ALU which is simply somehow a group of digital circuits which do ADD, MUL, ...
I am introducing Google Test into our development environment at work, and would like to encourage a TDD mindset, making this as accessible as possible for new developers to start using. I am looking for recommendations on standard project structure to follow for relatively simple C++ Eclipse projects. These would gene...
I am creating an android app for pharmacy duties for different cities. My approach: I created an Interface with method getDuties, and for every cities I create a class named with name of the city example: public class AthensProvider extends CityProvider Inside this class, I have the logic for parsing and returning dut...
I am creating a plugin that uses a metric to determine a score on one page and allows the user to click through to see a more detailed breakdown of the score on a separate page. The trouble is: I can't decide whether it is best to re-implement the logic used to derive the initial score when generating the breakdown. On...
I am coding a visualizer of graph algorithms. Each vertex of the graph has a style (color, size etc.). As long as the algorithm has done nothing to a vertex, that vertex has a default style. The default style needs to be configurable at run-time. I came up with the following solution based on the singleton pattern, wh...
I am working on my API and would like to return some stats. Those are stored and collected in code, and I can choose my way to return those. My first approach was using hash, so my data looks like: { 'obj1': { 'in': 23, 'out': 22}, 'obj2': { 'in': 33, 'out': 19} } Is this style acceptable or should I use bette...
Consider this example: public class SimpleValidator { public virtual bool InRange(int x) { return x >= 6 && x <=12; } } public class OffsetAwareValidator : SimpleValidator { int offset = 0; public OffsetAwareValidator(int offset) { this.offset = offset; } public overri...
I am writing some new code and would like to write it using async and await, but the calling code does not currently support async. Is it right to write the new code in async and call it sync until the calling code supports async? Or should I write the code sync and then convert it at a later date? And would it be cons...
I am building a support web front-end for our team from where we can perform various support functions for a number of different sites at which our products run. This typically involves running some sort of data query and viewing results to solve specific process issues. Each user is given access to which sites he may...
I am working on an application which works with an old version of a dependency. Due to a recent change request, there is a need to update to a newer version. I have the option of not upgrading to the latest version and only upgrading to an intermediate version because the required functionality is available in the inte...
CSS variables supported natively it's a powerful feature to develop complex web apps without some additional step as preprocessors. So, this is fantastic. But (at first) the syntax of defining variables does not look very good. element { --main-bg-color: brown; } element { background-color: var(--main-bg-color); }...
This is a problem I have been trying to wrap my head around a couple months now. It has shown up again in a learning project I was working on last night, so I will use that as an example. I am building an entity-component system, and have a Movement system that controls the movement of each entity on each turn. clas...
I'm looking at eXtreme Programming and its release iterations based on User Stories. But I wonder how to integrate huge internal processes into this particular mind-set. For example, the Google crawler doesn't relate to a specific User Story, it index web pages in order to make them available to the User Story "As an ...
Im designing a database structure and I would like that it's design could prevent erroneous connections. I'll make a simple example, that I think it will be easy to understand, bellow are the tables: Brand - Vehicle - Engine - Fuel Emision for Diesel test - Fuel Emision for Gasoline test ...
I am currently issuing a problem while forming the program-design, which is exact like a File-Directory relationship, and to ease it, I am using that as an example. I think it is usual, that a Directory has a collection of it's File instances. I take this as kinda axiom, correct me if this is not usual. But , when the...
I am writing a small app that manages a couple of recipes. I have a MySQL database that is used by my data persistance layer. I need some kind of id in my business objects representing the recipes to use my persistence layer. Currently i am just calling SELECT LAST_INSERT_ID() on my database after i inserted a new reci...
I know the difference between static and dynamic linking. I know why the notion of a library is important. And I even know why you'd want to link something like OpenGL, platform-specific APIs, or OpenSSL dynamically; lots of applications use them (possibly simultaneously), so why load them into memory more than once?...
I have a class named "Category" to handle all the operations and data about my categories. Now, my class is created however I need to find a way to build an object for each of the categories in my database. In a PHP OOP structure, how should I do this? I was thinking about maybe making some kind of CategoryCollection c...
I have a list of courses taken by a student, as well as several requirements. Each requirement consists of a list of courses that fulfill that requirement and the number of such courses that must be taken. How can I determine whether a student has passed all of his or her requirements, given the restriction that a sing...
An aggregate can represent a somewhat stable system boundary. Does it make sense to write input and output test aggregates to do most testing? In theory we could use an aggregate as a data driven way to do testing. We can create data that is going into our system without a database layer and we get a processed aggregat...
In all DDD books I read so far, they say a bounded context can have its own implementation architecture, which suggests a single architecture per bounded context. In my journey of DDD and also CQRS, I found in a bounded context, certain domain concepts are suitable for a rich domain model so I will have aggregate roots...
Mission-critical software system (such as systems-control software in spacecrafts) often employ multiple redundant software modules developed by different teams (sometimes using different programming languages), to same interface and behavioural specifications. The idea being that software bugs that surface only during...
I worked with Ruby on Rails and RESTful api before and now with Django Rest framework. For this question let's say we only consider the case of JSON but not XML. It seems that when we expect an array as a result, if the result is 1 or above, we can happily get back an array with the proper content, but if the result ...
The following for example: i = readString(&packet->data.play_server.updatesign.line1, pbuf, ps); It has a large amount of nested structs/unions. Is this generally frowned upon in code cleanliness, or bad for performance?
THE SCENARIO I learned about basic database design concepts such as basic CRUD operations, referential integrity, relationships, etc., years ago. I've messed around with databases and used this knowledge in an "unofficial" capacity over the years while learning about C# and WPF. Now I find myself at the beginning of my...
In C#, when you override a method, it is permitted to make the override async when the original method was not. This seems like poor form. The example that brought me to this was this — I was brought in to assist with a load test problem. At around 500 concurrent users, the login process would break down in a redirect ...
I have been providing a Web API (.NET MVC 5) of an Oracle Database to people who are making a mobile app. I have to admit that I am not very good at it. I have found that I can easily produce Data Transfer Objects to make very simple JSON displays. My question is whether it is feasible to ask the mobile developers to m...
I have been working in embedded devices business more than 5 years as a software engineer. Most of the times our hardware manufacturers provide a Software Development Kit for their reference boards. They are mostly Linux embedded devices. The problem is most of the times we find the management interfaces (Web UI, CLI,...
I've been very interested in Service Oriented Architecture, and Microservices. Many resources talk about having services in containers. To me, one of the big benefits of seperating an application into services is performance. I can have each service live on a seperate server and if some services are using more resource...
I was trying to solve the following question in software architecture. A software system crashed 20 times in an year and for each crash, it takes 2 minutes to restart. Calculate availability in that year I used the formula MTBF/(MTBF+MTTR) as given MTTR =2 minutes. But how can I calculate MTBF and availability? MTBF...
Using async I/O operations from boost::asio I often need shared pointers (and enable_shared_from_this and shared_from_this in callbacks) to avoid deleting objects too early. I think that it could be done by keeping unique_ptr or just object (ownership) in class (as a member) For example: Only foo method use sender. 1st...
I'm implementing a factory like this: public interface IMyProduct { void DoSomething(); } public interface IMyFactory { IMyProduct CreateMyProduct( string aParameter ); } internal MyFactory : IMyFactory { public MyFactory( ISomeService someService ) { _someService = someService; } pub...
I'm writing this code here: import java.awt.FlowLayout; import javax.swing.JFrame; import javax.swing.JTextArea; import javax.swing.UIManager; public class FirstJavaClass { public static void main(String[] args) { try { UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exc...
I am working a in a Telecom company. We have some code generation tools that generate C style files based on a MIB definition. We compile them with C++ though. It boils down to the fact that these generated files just contain a bunch of empty functions and that we have to implement them. Needless to say that this code...
I need to copy a method from an Apache licensed Javascript library into my GPL licensed javascript library. Can I copy and paste the method into my library in this license context? If so, how am I to include the proper Apache license details? Or do I need to save the method in a separate file and include the Apache lic...
When I read factor V of the Twelve-Factor App I see only one clear and obvious end result being described: it is impossible to make changes to the code at runtime Perhaps it is supposed to be obvious, but as I'm writing an internal document for my coworkers why we should observe more best practices (like the Twelve-F...
I use UML I, like most (I think), use UML as my main diagramming toolset. UML is clear and useful for representing OOP and has sufficiently diverse diagrams that there is something for whatever area you are modelling; whether it be class trees, component relationships, or specific interactions between classes. This mea...
Our .NET web application has the ability to add roles dynamically and assign functionalities (we define them in an application enum) to that role. So those functionalities are defined by us (our client) based on his business requirements. Some of them can be really specific and it makes the code really unmaintainable a...
We're a relatively small team and we are trying to implement an 'agile' scrum methodology around here for our projects. All of our work is project based (i.e. we do not have a particular product that we are continually working on). We've been planning our sprints around the user stories that we want to deliver for ou...
Design by contract is based on Hoare logic where a proof of correctness of a program is established by reasoning over pre/post conditions and invariants. What are the means and prerequisites of a language that make such reasoning possible? Can it be checked statically or is it only a form of runtime assertion?
I have something like this Class App Module A Module B Module C Module D Each of the modules have a single responsibility and are pretty well encapsulated (public interface, private implementation). The problem is, these modules need to reference each other a lot. (No reasonable way around this, I thin...
I'm implementing a solution for IoT/home automation, starting first test on my house... Is going to use MQTT to exchange messages using a central broker model. This are the components: cloud server, central home server, home nodes [sensors+actuators]. At the moment I have the MQTT broker on my home computer... My quest...
There is one thing I can't really understand in JavaScript or Python, and that's the delete or del syntax. In JavaScript: obj = {ha: 123, hi: 3.14} delete obj.ha # now obj is {hi: 3.14} In Python: d1 = {"ha" : 123, "hi" : 3.14} del d1["ha"] # now d1 is {'hi': 3.14} But, what does delete o...
Let's say I'm designing an RPG type game, and this game has a turn-based combat system. There are some things that the player character/non-player characters can do inside and outside of combat. For example, while they are not in combat, they can move around the world, use items, talk to other npcs, and the player (not...
My general rule for web development is that the server encodes HTML tags in any user-generated input when it is first submitted to prevent XSS. However recently someone suggested that instead of sanitizing the input on the server end, angular could do the sanitizing on the client side when displaying. So basically you ...
I am developing a web application for my coworkers, and from a little management app it is becoming a more and intense large project that is involving more people as I go. I am pretty sure my boss will ask me to add even more as I will go on. So I became unsure if I am doing things right, because I never worked on larg...
Memory (and resource locks) are returned to the OS at deterministic points during a program's execution. The control flow of a program by itself is enough to know where, for sure, a given resource can be deallocated. Just like how a human programmer knows where to write fclose(file) when the program is done with it. GC...
I mostly code in C# & VB, but I think this question is pretty universal. I try to limit loops to increase performance. For instance, string functions that split the string into an array, or do a lookup or replace. I think if I were to write some string functions with those kinds of capabilities, I would need to includ...
I have a couple classes in a project I'm working on that only register event handlers. public class EventLogger { public EventLogger(EventRaiser someObject) { someObject.EventRaised += logThatEvent; } } The EventLogger is either running or not based on some run time status checks at program start...
I'm giving a lecture to novice developers on security and would like to explain ssl and the basics of certificates. For this I would like to convey a vague intuitive understanding of asymmetric key encryption. As far as I can think, there is nothing in nature or society to liken public keys to without giving up a ton t...
The project in which work is private for commercial purposes and not its source code is distributed to anyone. Only the functional application shown consumers through a website. It has the following structure: The source code is written in PHP, the only part where third-party code is used when using Composer and PHPUn...
I am wondering about the following scenario - it's in the land of Spring/AOP and Ehcache. Happens in REST Web Application - REST/Service/DAO layers - I have objects in cache (@Repository + @Cacheable). Upon particular REST request (let's call it /notUpdateRelated) execution, after the request completes successfully (in...
I've noticed something lately looking at some popular projects on GitHub, that there's no develop branch. And in fact, the GitHub Flow guide doesn't mention it either. From my understanding, master should always be totally stable and reflect production. If developers are working on feature branches, and then merging th...
As I was TDD-ing some code, it occurred to me that one of my typed exceptions could potentially throw a NullReferenceException while creating its error message. Here's the constructor for the typed exception in question: public class MyTypedException : Exception { public MyTypedException(String expectedValue, ICollec...
A couple of months ago I started working in a new project, and when going through the code it stroke me the amount of static methods used. Not only utility methods as collectionToCsvString(Collection<E> elements), but also plenty of business logic is kept in them. When I asked the guy responsible for the rationale behi...
Given a language that enforces checked exceptions (let us assume Java), how do we design an API that can throw exceptions without violating the Law of Demeter? To put this question in the proper scope, let us assume we are writing a publicly accessible jar library. Some of the classes will be the public-facing API: oth...
I think that code reviews are great and very helpful for everyone. With that being said, from time to time I've received feedback on a pull request (leading to the PR being delayed for at least as long as it takes for another round of responses from everyone involved, if not longer) that I think is so completely out of...
A noob iOS dev question: How do iOS developers develop their app with non prod REST URL endpoints while then using a prod REST URL endpoint for actual use by customers? I'm not aware of a way you can "toggle" back and forth between prod and non prod URL's when using an app. For our web app dev we deploy a properties...
I am currently charged with taking over a lot of code that is written with fields names placed into Java constant at the top of the file, and then the SQL queries constructed using string concatenation with the field names. At the top of the file is the following block: private static final String TABLE_VALID_USER = "...
I am currently refactoring some old code and I am facing some architectural problems. Currently 3 applications are working with the same Database (as follows): Content inserted by user Content moderated by a team Content listed by a website Each application is using a generated DLL which implements the functionalitie...
I have parametrized test with 2 variants: NULL value and any NOT NULL value From this value is depends one assert: In case NULL it should be checked if object has field1 with value1 In case NOT NULL it should be checked if object has field2 with value2 As I mentioned (see xUnit Tests Patterns ) using condition...
For Web front end programming, since any JavaScript can set up an event listener for "mouseover" or "mouseenter" for an element, if we are to track down what is the code that is responsible for making a hover box come out? For example, if you see that when you hover the mouse over an element, with the class hover-box-c...
Let's assume there are 2 classes: Country and City. Both of them have names, so a map would suit as conainer map<std::string, Country> countries; In the country class there is a similar map that contains all cities - for the sake of simplicity, let's say it's public: map<std::string, City> cities; Now on top level if...
This might me a stupid question, but since I don't have anyone to discuss it over a coffee, I think I'd ask it here. So, I'm reading the book "The Haskell School of Expression" to learn myself a bit of Haskell and they have the following type: data Picture = Region Color Region | Picture `Over` Picture ...
I am a hardware/test engineer currently writing a C# application for a device that does not have any event/interrupt mechanisms. Because of this I am forced to poll the device's internal control registers using their provided API for any change in state. I realize that a dedicated thread will be needed in order to take...
Situation I receive message from a 3rd party, and these messages are use to create or update database information. Message and data to be updated can be de-serialize in object form, but are not exactly identical, so I need to use an object for mapping the properties of the incoming message object to the resulting entit...
I have a large SQL query that relates 6-7 different tables and returns fourteen different rows as distinct sets, in a union with an equally-large query, that at times can return over a thousand results. Luckily for us, we have the option to simply return the first 100 results of that query, which significantly reduces...
The new ASP.NET documentation under Fundamentals/Working with Multiple Environments it has a detailed description of how to handle multiple environments (surprise surprise) in code. I was wondering if this is the "best practice" when dealing with multiple environments or should it be handled by something other than cod...
Reading the book The Economics of Software Quality, it reads that: To further complicate the definition, quality often depends on the context in which a software component or feature operates. The quality of a software component is not an intrinsic property - the exact same component can be of excellent quality or hig...
I am a C# developer, and my team and I are trying to start automated functional tests. (Note that we don't want to do Unit Tests; we expect to develop tests which test one function point per test) Our software has several modules, but they have something in common: one input (can be File, string or database row) and so...
We've been learning about reference parameters in my Intro to Programming class. I understand perfectly that reference parameters give you access to the place where an argument is held in memory, while value parameters create copies of the arguments. Why would I want my function to have access to the argument's memory ...
Assume I'm working on a JavaScript application and make extensive use of the module pattern with one file per module. Now suppose I have two folders/modules: one for module A and another for module B. Module A uses module B, and B is not used by any other module. Should I put B inside of A, or should they be equals? Wh...
Here, the term of branch is understood as a git branch. I don't know how branch works in other VCS, but its probably VCS-agnostic. Given a branch base, and around it many other "satellites" branches, incarnation of optimizations, base_opt_1, base_opt_reducnode,... Each optimization has its own branch, and touch many ...
Suppose that I have the following Java code: int i = 0; PreparedStatement statement = con.prepareStatement("SELECT * FROM table " + "WHERE field1 = ?, field2 = ?, field3 = ?..."); statement.set***(++i, fieldValue); And there are like 14 fields like that. Then we have another prepared statement, but this time we s...
I'm implementing the view transformation part of a graphics pipeline (basically a matrix which translates coordinates from world coordinates to camera coordinates given a camera position and direction). Other than the simple case where the point has the same coordinates if the camera is at [0, 0, 0] pointing towards [0...
Sometimes in a programming exercise, boilerplate generation, putting guide rails around the tasks for a junior programmer to implement, etc., it happens that the programmer is presented unimplemented code and told to "fill in the blank." For example, a unit test that may compile, but fails, or a class declaration with ...
Let's say we're given n positive integers in random order. What's the most efficient way to find the m largest elements and what's the complexity? For example, given 1000 values, find the top 10.
I have a static block which fetches data from database. This data is then being used by instance method. Since static block will be loaded once I fear that the data won't change in its lifetime. How can I load the class (static block) when a new instance is being created?
I have to clarify first that the status column is not intended to reflect the status of a real-world item represented by the record (row) in the table. Rather, it is intended to show the status of the record itself. It can be as simple as Active/Inactive or complicated like Approved/Deleted/Locked/Pending/Rejected, etc...
I am not 100% sure of the meaning of these terms. Is a business process a flow in an application? (e.g. creating an invoice) Are business rules parts of a business process? and, are business processes part of the business logic?
This is a generic question about the idea of inferring some of the system configurations from the existence of a file or the lacking of it. For example, we have a module of the system which is optional, and it requires another software package, what we are doing inside the code is to check the existence of that package...
I have designed a simple PoC system that processes a feed of prices that tick. It consumes a stream of "Ticker, Price" objects off JMS and updates a map, so that the map simply contains the latest price for each ticker. So far so good. Now for the final design the system needs to be scalable. The first naive approach i...
I came across this (Java) code yesterday and can't figure out why someone would have done this in any language. In what scenario, language, paranoid delusion would "removing" values from an ArrayList like this improve performance? Try to avoid getting dragged in to the general design of the worker. I know it's bad and...