instruction
stringlengths
34
36.1k
PROBLEM: In Javascript I use closures to encapsulated methods inside a class. It helps building hierarchy inside and minimize amount of methods at root, but they become lengthy. RESEARCH: Applied to library classes or GUI frameworks classes (prototype-based inside). QUESTION: Should I consider refactoring each root me...
Wikipedia's definition of a "computer system" is: Computer system is define as the combination of hardware software user and data with referring to communication and procedure involved in between them. Which doesn't make much sense to me. Whereas the definition of an operating system is: An operating system (OS) is ...
I'm trying to design the data schema and the restful api for a specific case. In my system I have several users and several books. Every book can have several users as authors and at the same time every user can be an authors of several books. Now the hard part, users are interested to have a list of their books and to...
I've ran into a problem trying to calculate prorating of a service. Hoping to get some help/hint from the community. I apologize if this isn't the right place to ask this question - will appreciate help in finding the right StackExchange service. Given: An online service that issues "licenses" that can be purchased fo...
I am using an embedded system with a web server. I really have no way to dig deep into the webserver and see how it works, so I am asking a more general question: How do servers or back-end scripts (like PHP) handle HTML FormData objects? For example, it is easy to send form data to any web server/script processor like...
I am an experienced C++ developer but new to JavaScript. I want to write an ES6 JavaScript class that maintains state. How do I tell when state has changed? I can think of two ways to do this. One way is to inspect an instance of the class to see if it is "dirty" since the last time it was marked "clean". I.e. mark an...
I have a class Foo that creates instances of other classes A, B, and C in its constructor. A, B, and C share the same constructor parameter and are used in other parts of the codebase, not just in Foo. A, B, and C access an outside resource configured by the passed parameter. In unit tests, A, B, and C are mocked out w...
So far I've been building applications abstracting data entity operations behind the use of Repositories. Each of them would encapsulate the domain that corresponds to their defined entity. For instance: UserRepository would encapsulate domain logic regarding the User entity, such as changePassword(old,new), createAcco...
I'm trying to explain to someone that the way they've written the code makes it hard to understand, and if you refactor it then it's easier to read. This style of code I'm driving at is commonly called 'idiomatic' code'. But the phrase idiomatic code brings with it baggage of moral correctness, which is not a great mo...
If I am assigned a bug, I sometimes check version control to see when it was introduced. Should I notify the developer that introduced the bug, even if I already fixed it? The advantage is that it could help learning but the disadvantage is it could seem like criticism
I have this project that has several license notes (all GNU GPLv3) on the top of the source files. They are all following the "rule" that the year in the copyright notice should be the year on which the file was last modified. I wonder if I can substitute Copyright (C) 201X Bernardo Sulzbach by Copyright (C) Bernardo ...
PROBLEM: GUI built above database entities usually consist of creator window (pane etc.), editor window, maybe grid or other view window. To represent an entity for user it usually requires building several predefined windows, and the same for each one. Entitites and its fields could not be in similar relations to trea...
A PySide project I've been working on for a while now has started to grow to a point where it's becoming large enough that I've had to step back and re-think the overall design. I've spent some time with both Flask and Django, so I'm familiar with the MVC design pattern conceptually, but had the advantage (or maybe dis...
I have been learning C++ recently, and upon reading up on pointers I had a moment of thought. I'm still attempting to grasp the very idea of pointers so excuse me if this doesn't make sense beyond comprehension. Is it possible for a set of pointers recursively point into one another's memory location upon trying to pri...
A major limitation of node.js is its single threaded execution and the fact that JS is slow with computations. What are the advantages/drawbacks of using C++ to do the application's heavy lifting while using node as "glue code"? Obviously there are security risks using C++, but let's assume for the sake of argument tha...
I'm writing a real-time operating system for microcontrollers in C++11 - distortos. Currently I'm thinking about a C++ framework for various peripherals. The most basic peripheral which I would like to have there are input/output pins. Because such input/output pins can both be built into the chip or be external (I2C e...
I am currently working on a system where there are Users, and each user have one or multiple roles. Is it a good practice to use List of Enum values on User? I can't think of anything better, but this doesn't feel alright. enum Role{ Admin = 1, User = 2, } class User{ ... List<Role> Roles {get;set;} }
I've generally been working with PHP warnings and notices off, since I work on a lot of projects where it's already in live production. Now, if I turn on the warnings and notices on these live production websites, they'll be overloaded with them. The projects that I work on at home, on local, I usually try to work away...
The primary use for Node.JS is of course as a full server stack, and I've used it in that manner to great success. However, a number of useful, interesting NPM packages deal with things like transpiling a styling language, adding typing information to typeless JavaScript, running JavaScript unit tests, even having a "p...
I'm currently trying to learn C# and want to enhance my understanding of Object Oriented Programming (OOP). I'm hoping to accomplish this by experimenting with a small program that keeps track of my school assignments/information. I've constructed classes relating to my Institutions, Semesters(Terms), Courses, and Assi...
My application will have at least two types of users: clients and companies, these are the types of profiles. Because each type of profile requires different additional information, it will be required to create a table for each type of profile. How should I create my relationships so a user has zero or one client prof...
I will use C# here as an example, but my question is about any language. My question is from framework to compiler perspective (i.e the solution can be by implementing given idea inside compiler) Consider such code: if (sequence.Any()) ... and let's say the sequence "holds" 1 million items. This condition will be ex...
We learned in Intro to Programming that if you divide two integers, you always get an integer. To fix the problem, make at least one of those integers a float. Why doesn't the compiler understand I want the result to be a decimal number?
Lets say we have the famous Joshua Bloch Nutrition Builder and we want to change it so it be a bit like dynamic builder which restricts visibility of setters and propably uses generics : public class NutritionFacts { private final int servingSize; private final int servings; private final int calories; private final i...
I have a discussion with my team recently and I heard a suggestion for deploying multiple releases. Such as version (newest) and version (old). But I am thinking what would be the reason for customer want to use the older version. What if the bug was introduced in the older version we would have to make additional supp...
I have a container class similar to the one below (with much of the logic omitted): class Container<T> { Dictionary<T, TWrapped> contains = new Dictionary<T, TWrapper>(); public void Add(T item) { TWrapped wrappedItem = new TWrapped(item); contains[item] = wrappedItem; // logic inv...
I have my main project set up very simply in TFS. I've recently begun making a few of my project components generic enough that I can sell them to other organizations using the software for which I made my custom components. I want to pull these components out into their own branch so I can make minor tweaks and so th...
I am building an API that will connect to multiple databases. I am using Emberjs on the front end and the default rest adapter seems to prefer shallow routes. Say, I have the following routes api/databases api/databases/1/employees At this point, my routes are already 2 levels deep. Any further nesting makes it hard t...
Let's imagine. I have following data from database. ====================================== id | Title | parentId ====================================== 100 Asia NULL -------------------------------------- 101 India 100 -------------------------------------- 102 Tamil Nadu 10...
We currently have a .Net MVC web app with a SQL server back-end database and two web services that perform periodically some computing tasks in the database. I am thinking of packaging this app for the cloud, where a client would "instantiate" it as a whole package. This process would allocate automatically the pieces ...
Is it a good practice to replace constants used outside of classes by getters? As an example, is it better to use if User.getRole().getCode() == Role.CODE_ADMIN or if User.getRole().isCodeAdmin()? That would lead to this class: class Role { constant CODE_ADMIN = "admin" constant CODE_USER = "user" private ...
I have the following code: subroutine foo(int index) { // Check A. // Critical: Check A must precede Check B below. if (index == 1) { return true; } // Check B. if (index - 2 < 0) { return false; } return true; } The code is a simplified representation of a rea...
I am currently planing an application that will be used in a company. It is required to build a Desktop Application. At the moment they are not sure if the application should be available on mobile or browser in the near future. I have two possibilities: Access the database directly from the Desktop Application Cre...
I've been discussing about whether "logging in" is a use case and I've been wondering: is there some "official" standard where to look up the definition of a use case or what the point of a use case specification is?
The general version of the question is above - a a little more detail, I am using Django Rest Framework, but am happy for answers to be dealing with the problem in abstract. So, I have data with ~200 countries, ~10,000 regions (the countries subdivided) and ~600 extra small districts in the UK. My plan is currently to ...
In languages that support currying, I can't think of many cases where using a tuple as function input parameters would be better than breaking the tuple apart into multiple parameters, which then allows you to enjoy the full power of currying. In which situations is keeping a tuple as function parameter better than bre...
I am developing an app where I need to divide the entire world map into fixed sized square blocks. For simplicity, think of it as a problem of dividing the google maps into a fixed sized block. I can choose any arbitrary point in the map and my app needs to create a block of fixed size around that point. The primary c...
When comparing floating point values for equality, there are two different approaches: NaN not being equal to itself, which matches the IEEE 754 specification. NaN being equal to itself, which provides the mathematical property of Reflexivity which is essential to the definition of an Equivalence relation The built i...
Edit: this differs from a similar question because I'm interested specifically in how Django works with the front-end. I.e. what is considered best practice when developing using the Django framework. I am learning Python at university and need to produce an implementation project. I'd like to write a web application ...
I was wondering if it would be good practice for commit messages to contain the ticket number they were apart of. It would be like 2568 Fix heating issue Summary of the issue with a bunch of detailed comments It would be a bit of a pain to get the ticket or isse # in each commit and I am wondering if people ...
Today while programming I stumbled upon the following question - are there any compilers which optimize based on mathematical assumptions? For instance in cases like unsigned int i,b; (i,b not constant) if(sqrt(i) == b) ... In this case it would be a lot more effective to use unsigned int i,b; (i,b not constant) if(i ...
Long question context, skip to tl;dr for the meat of it. I am designing an integration between two web applications, and have come to the conclusion that a message pattern would be an appropriate solution to the problem. The gist of the requirements is that data in System A should be synced to System B, through an inte...
Sometimes when I resume work on a project after a long break, I forget where in the many files and lines I stopped working. I can usually find it after a minute, but I'm wondering if any popular IDEs have a built-in way to indicate where you stopped working. I currently use XCode/C++, but I'm curious if other IDEs hav...
We are designing coding standards, and are having disagreements as to if it is ever appropriate to break code out into separate functions within a class, when those functions will only ever be called once. For instance: f1() { f2(); f4(); } f2() { f3() // Logic here } f3() { // Logic here } f4(...
Question Background: I have a rather large project that I started before I learned about a beautiful thing called version control. Now, I have a ton of files labeled with the convention "ProjectName_Date." Question: I'm thinking of deleting the old files and starting a new repository with the latest version. However, ...
How does the current copy and paste work on a computer? Such as being able to copy some formatted text together with an image, and then when pasted to a text editor, it will intelligently paste only ASCII or UTF-8 text, while if pasted to some webapps or Microsoft Word or Pages on a Mac, it will paste the text togethe...
I am a second year Computer Science student currently on a placement and I am currently developing a Java EE application that collects meta data from several sources and then visualises the data. This is the first major programming project I have done. (Nothing like university with 200 lines of code for an assignment) ...
I'm not in the field, so I don't have any professional experience from projects following the TDD design. I am trying to adopt this pattern, but I'm confused as to when I start actually writing the tests. In my example, a personal blogging app. I'm starting from complete scratch using ASP.NET 5, MVC 6. I've built the m...
I was thinking about it and I was curious as to how one would code an efficient repeating alarm clock in C? Would you set an alarm time and then offset the time with the ms time equivalent of a day (or two days or a week depending on how often it needed to repeat)? And then poll periodically to see if the times are equ...
In C++, it is possible to write an overriding for a base class's method even if the visibility declaration of the two don't match. What are the possible design considerations under the decision of not considering the visibility in the overriding rule? Consider this piece of code as an example: class A{ public: virt...
In TDD there is Arrange Act Assert (AAA) syntax: [Test] public void Test_ReturnItemForRefund_ReturnsStockOfBlackSweatersAsTwo_WhenOneInStockAndOneIsReturned() { //Arrange ShopStock shopStock = new ShopStock(); Item blackSweater = new Item("ID: 25"); shopStock.AddStock(blackSweater); int expectedResu...
Based on the following snippet HTML <table id="example" class="display" cellspacing="0" width="100%"> <thead> <tr> <th>Name</th> <th>Position</th> <th>Office</th> <th>Age</th> <th>Start date</th> <th>Salary</th> </tr> Javascript var tableNames = { "example": "#example" }; function main() { $(tableN...
How should I structure a piece of code that executes an operation, but may have slightly different behavior depending on, let's say, user roles? Example: My app has a 'manager' and a 'employee' roles. There are many managers in my app, and each of them have many employees. I have a dashboard where managers and their em...
I am working on a new project in which we are currently deciding which technologies and frameworks we will be using. The application will eventually be cross platform. Therefore, for the server side, we will be using a REST api written in Java Spring. We are now deciding on which technology we will be using for the fr...
I have a group of methods that is going to be very large. I need to be able to call methods systematically from a large group, in two different ways. The methods create a new item object with variables specific to the type of item created, for instance the rubber(); method makes an item with itemId = 12, weight = 1, n...
I am trying to understand these classifications and why they exist. Is my understanding right? If not, what? P is polynomial complexity, or O(nk) for some non-negative real number k, such as O(1), O(n1/2), O(n2), O(n3), etc. If a problem belongs to P, then there exists at least one algorithm that can solve it from scr...
I have an interface whose job is to communicate with repository (that implements some interface). It doesn't seem to make sense to implement this interface without receiving a repository,so I'd like to inject it. I then ask:where should I receive the repository? Since it is required in almost every method call it seem...
I'm currently on the process of creating a website/webapp. My application is based on Node JS with the express framework. My core backend concept consists of routers: handle http request. Like [POST] /api/team controllers: business logic behind routers model: interface between database and controller I'm not sure i...
I'm playing with Google's voice recognition for a personal project and I have a fun little Q&A program written in Python using it. The problem, as it were, is that it means I have to be connected to the internet to access the API or the program doesn't work. I'm wondering if there is a way I can download the entire AP...
Have you ever being implementing Option<T> functional type? It is discussed here: https://app.pluralsight.com/library/courses/tactical-design-patterns-dot-net-control-flow/table-of-contents Basically it is about using IEnumerable<T> with no or only one element instead of potentially nullable object reference in C#. We ...
I am reading "The Go Programming Language" right now and I have read package initialization chapter which tells (or I read it wrong) that Go uses eagerly initialization. So in time we saw say C++ eagerly initialization, then Java with on demand initialization, C# also on demand, and Go back with eager initialization (t...
Recently I came up to something illogical, reading the latest ANSI C paper. It was talking about linkage but it never mentioned a way to declare internal identifiers inside block-scope (or at least in a useful way). Imagine something like this: int main() { //Here how to declare the identifier 'b' //with inter...
I'm developing a C++14 application and would like to take advantage of the new multithreading features, in particular std::async. I have seen a number of applications which allow the user to specify the maximum number of software threads that can be used for the duration of the program run. However, the recommend usag...
I was wondering if there is a time line when I have to distribute source code for a binary that has been released under the GPLv2 license. To my understanding, I would need to release the source code along site it (ie. immediately). I'm asking this question because I've heard that Apple does not update its open source...
According to Wikipedia: In object-oriented programming, the command pattern is a behavioral design pattern in which an object is used to encapsulate all information needed to perform an action or trigger an event at a later time. This information includes the method name, the object that owns the method and values for...
Lets say a user has a set of data. This data is stored in user_data table. This user_data table is referenced by other users in some way. In case the user wants to delete a row from the user_data table, referential integrity dictates that it cannot be done as long as there exist a reference to that data. Let me explain...
Suppose I am limited to use C++ by the environment in the project. Is it good to prevent the use of some language features that C++ has but Java doesn't have (e.g.: multiple inheritance, operator overloading)? I think the reasons are: As Java is newer than C++, if Java doesn't provide a feature that C++ has, it means ...
Suppose I have a segment of code to connect to internet and show connection results like it: HttpRequest* httpRequest=new HttpRequest(); httpRequest->setUrl("(some domain .com)"); httpRequest->setRequestType(HttpRequest::Type::POST); httpRequest->setRequestData("(something like name=?&age=30&...)"); httpRequest->setRes...
Since I started programming, I've always been taught to leave a trailing blank line at the end of my files, the reason usually being something relating to how it makes concatenated files easier to read when using cat. While I can't find an example right now, GitHub indicates missing blank lines at the end of a file usi...
In Java or Scala if I have an argument configuration: Conf, I can look for Conf class/trait/case class and see its construct so I know which arguments to pass. Recently I started dealing with JavaScript, I see function like this: function init(conf) { some body // as external developer to init I should not mess ...
I heard that semantics and type systems are very important for all programmers! But I why are they so important? I don't understand. Maybe they are imortant only for theoreticians and compiler developers? In my practice I never think about semantics and type theory. As for me it is enough to know that the semantics def...
I am trying to explain segmentation faults to someone, and I was thinking about the level 256 kill-screen in Pacman, and how it's triggered by integer overflow, and how similar the behavior is to the "unknown state" oft-described in a segmentation fault. I want to say this is a good example of what I call an "unhandled...
Vernon and Millett describe several patterns of getting data for ui (reporting in general) needs. Though some pros and cons of each approach are discussed, I could not get a robust understanding of which to use when. Consider ad hoc queries. Vernon calls them Use Case Optimal Query, but does not say too much. Millett j...
Not sure if this is the right platform for this, but here goes :) Throughout my career I have been generating reports for users, and most of the times it always started from a Word template (.dot/.dotm) handed to us by a user, containing all the required/wanted layout/logos/texts, which we then edited to insert correct...
I need to forecast budgeted hours for 2 departments to help them schedule staff as currently the best they can do is just wing it. When we receive a job proposal I'll have the person submitting the form input that job's budgeted hours into each department as float field. Jobs can have hours budgeted for Dept. A, Dept....
I was going through several blog posts at stackoverflow and programmers and I am still a bit confused. You can install NLog (or some other logging lib) and start logging quite fast and then you can install the application insights and an adapter to actually gather the data into the Azure Application Insights. Is it rea...
Following up on my ambiguous question, here's a question that is probably more focused. Consider the following code snippet form a Haskell program: data NightWatchCommand = InvalidCommand | DownloadCommand { url :: String } | PauseCommand { gid :: String } | UnpauseCommand { gid :: String } | StatusCommand { gid :: St...
It's a discussion about follow very strictly the SRP (Single Responsability Principle) vs. be more flexible when you write simple codes, like setting or getting properties values, even out of a direct context. My first doubt is about where SRP should be included. I always read about SRP should be applied on classes. B...
I am forking a BSD 2-clause licensed project, adding some AGPL-licensed files, and re-distributing as AGPL. The existing project comes with a LICENSE file, and the files themselves have various copyright holders. How do I modify the LICENSE file to make it clear that this project is distributed under the AGPL ? Thanks...
I am setting up a PostgreSQL database with a very small number of tables for a simple website. I am looking at ways to make it as solid and auditable as possible. Is there any particular reason why I should or should not create a PostgreSQL role for each user account on the website? The idea is that I could then use...
From what I understand the deployment process consists of these steps. Compiling, linking/packaging, deploying. What does the packaging refer to? is that just a reference to packaging the object files together?
Suppose there is a primary resource "/accounts" which has Profile (name, national id, DOB), addresses and contacts(email, phones). I am considering them as sub-resources because they cannot exist without an account. To update them I am thinking two options Option 1 PUT /accounts/{accountid}/address PUT /accounts/{acco...
I am trying to animate a texture in OpenGL. I feel like it should be easy, as I know how to animate in SDL and other libraries but I am having trouble. I have a x,y,w,h that holds the texture coordinates for the frame I want. My vertex data has a x,y for the vertex, and a x,y for the texture coordinates. I know how to ...
I have a web API that accepts Authorization headers to allow access. It responds with the requested data in addition to setting a session cookie. Subsequent requests can be made with no auth headers as the cookie is used in its stead. Originally, no auth was handled on the node server. API requests were all made direct...
I currently want to improve an application which is licensed under GPLv3. I wanted to improve it's design and Interface and use icons from google which is licensed under Creative Commons Attribution 4.0 International Public License. On Gnu website it seems like it's compatible as I understand. But because of this line ...
Consider a software which runs on a dedicated system (basically a Linux box), and controls some machinery. The system has all the required hardware interfaces for the task. The software also has a GUI for controlling said machinery. However, this system should later be able to be used from external devices, so other so...
In a product we are rebranding a feature. For example, we have tweets and we are rebranding it to news. On the code side we have tables and structures like tweet, user_tweets, favourite_tweets and so on. Does simple rebranding justify renames and migrations in code and Data base (structure names, file names, fields, t...
For my angularJS application I'm using asp.net web api backend. For B2C I'm normally have one scalable backend application and each customer can have an account to use the services. There is one database and each customer has access to it like Facebook or Foursquare. But how would I do that in a B2B SaaS application?...
If I have a method to look for a valid email address in an array, that could either: Return the email address Return false if an email wasn't found. Throw an exception if an email was found, but it wasn't valid. Should the method comment be written as though it would always work, or should it indicate that it might ...
I am reading Martin Fowler's 'Refactoring: Improving the Design of Existing Code'. I have not understood a section of the second chapter where Kent Beck describes the pros of indirection. One of the pros listed is Encoding Conditional Logic and it is described as: Objects have a fabulous mechanism, polymorphic message...
Suppose that you describe programs, which have a lot of AssignmentStatement(target, /*value*/Expression). There are other statements, like if-statement and for-statement and all of them may have optional label. So, our assignment must be coded like AssignmentStatement(name, target, /*value*/Expression) on the blackboar...
I have been wondering this question recently. Why does PE images have to be executable in MS-DOS? I've read on the topic and most of the answers I've seen simply explain it with compatibility. But what this compatibility actually means and targets? If it was intended to allow a single executable both to run on DOS and ...
So Im building an app and I'm trying to implement the structure of the app so that its robust and scalable in future. My app is mostly divided into JavaScript Modules (revealing pattern): // filter.js file //My javascript module structure var filter = (function(){ var _privateMethod = function(){ } var publicMethod ...
The lastest version of Python is 3.5.1. However, the latest release is 3.4.4. Why is 3.4.x still developed? Are there breaking changes in 3.5 with respect to 3.4? https://www.python.org/downloads/
Let's say I have an API method with can be used to calculate the sum of all orders made by a specific customer: Amount CalculateOrderSum(int customerId) { // Perform authentication to make sure caller has access to customerId // Retrieve customer with id customerId // Retrieve all orders related to the cu...
We support IE9, IE10, IE11, Chrome and Firefox, and we support them on Win7, Win8, Win8, and Win10. If we tested every possible combination of browser and OS that would be 20 times through our script and we're wondering if that is necessary. I'm fairly confident that the results we get for Chrome or Firefox on one OS w...
in UML deployment diagrams, the node element is used to represent a "computational resource" (in other words, something that can run software). I know that nodes may have other nodes placed inside them (to imply nesting), and that they may have artifacts placed inside them (to imply the deployment relationship, i. e. t...
I've been working on a small Java project by myself for a department that does not do a lot of software development but mostly database stuff. I showed my boss the code I've been writing and he saw that in some classes there were some static variables. He then told me to put the static variables in XML instead to make ...
I am writing an application and I got to this point: private void SomeMethod() { if (Settings.GiveApples) { GiveApples(); } if (Settings.GiveBananas) { GiveBananas(); } } private void GiveApples() { ... } private void GiveBananas() { ... } This looks pretty straight-f...
I am not so experienced in client-server applications and I could not find exactly answer to my question anywhere in google. I am developing part of application on server side and my collegue who develops frontend suggest me that I should manipulate his payload rather then act as a service. I will explain it in example...