instruction
stringlengths
34
36.1k
I'm a beginner and I'm following a course on C programming. In my book,a variable is defined as a memory space that stores a single unit of data (datum). Is a data structure considered to be a single unit of data (datum)? Ex: struct Point single_point;
I am not sure what the correct terminology is as I have not seen this topic discussed in any articles. Often to call an API one must find the number of parameters from another API/service etc. My question is from the point of view ofthe Web Service/API user, what is the chain of API/Services to be called so that when w...
The Problem A problem I keep running into again and again in C# is how to treat a class of things as the same in some contexts, but as different in different contexts. I have found some ways of handling this that I'm satisfied with for now, but this particular case I'm facing is leaving me unsatisfied. I'm sure that de...
We want a new hire to work on some features of our current project, however, since he is a new hire, we would like to do code review before he can commit into master branch. Also, we don't want his changes which is rejected by our code review and get into the history. What would be the ideal git workflow for this? (I ...
Sorry for this question seems naive. I am new to MVC model (I know I am a bit late to join the club), and I have a question regarding MVC with PHP. I think the implementation language doesn't really matter but I intended to specify it in order to make it clear that I use web applications. I am planning to use Entity cl...
I will soon install wooden parquet floor in my home. And just for fun, I am thinking of writing an algorithm for making efficient use of the wooden planks I have. Here's the problem: I have planks of different lengths enough to cover the surface. The room is rectangular (Later I would like to expand algorithm to take ...
Looking at the w3 spec for FormData there seems to be very very little there. Certainly very little compared with the MDN documentation. Of most concern, there is nothing here that defines constructor behavior beyond that it must return an instance of FormData. Am I reading this incorrectly, or is the constructor behav...
I am writing a cross platform socket library and will use the pimpl idiom so that users include'ing headers for the library will not need to worry about operating system specific issues. So, for example a file portable.hpp would be like this: // forward declare pimpl struct socketimpl; class portable { public: priva...
I follow this example on decorator patterns to implement objects who's functionality can be dynamically be coupled together. Namely: class I: is the interface class, common to both "core" class and "decorator base" class class A: is the "core functionality class" class D: is the "decorator base" class classes X,Y,Z: in...
I am attempting to implement a shunting-yard algorithm for a calculator following the rules laid out in https://en.wikipedia.org/wiki/Shunting-yard_algorithm . When programming the unary minus, however, I do not know which precedence method to follow due to the ideas raised in following question https://math.stackexcha...
To some extent, I don't have a problem with JPA which inevitably needs an implementation such as Hibernate. However, it requires configuration and ORM. I don't specifically like using Hibernate directly, based on the fact that it is a vendor specific approach. Nonetheless, I've been preferring the usage of JDBC, and I ...
I have written some small HTTP services myself and the clients that consumed them. There's a question on CodeReview in the hot questions about a wrapper for some RESTful API which made me wonder, should one ever write such wrappers "by hand"? My workflow was usually: Write server side code Test it or, to be honest, tr...
When completing online forms, many online applications will instruct users how to format their input, detect whether the input is formatted correctly, and issue error messages if it's entered "wrong" forcing the user to make corrections or (worse) start over. Examples: credit cards, "don't enter spaces"; phone numbers ...
I am putting together an web app with relatively complex but standard database relationships. I notice that anytime I use an ORM, in python/ruby/php etc, in general, a lot of queries are generated. This is stating the obvious. ORM's typically create more queries than necessary to get the job done. They aren't perfect....
Is it a good practice to declare all the variables in my program as a const variable? eg:- private int myAge = 20; private const int Age = 20; Now, from the above example, which one is a good practice for declaring variables. Is declaring const proved to be more effective in coding than just declaring a variabl...
I'm currently reading "Working Effectively with Legacy Code" by Michael Feathers. So far, a lot of techniques the book mentions, start with a problem similar to: "it's really difficult / it would take too long to get the class into a test harness..." Then the book goes on to suggest a technique to work-around this prob...
I guess the question is about PC based (Windows, Non-Macintosh) processor Architecture Design and open use. Is there a "Standard Interface" (byte-code) for PC machines, aside from processor specific optimizations, available to the public and can be used for (General) Custom Kernel Designs and Operations and OS Develop...
From what I understand first you need to find the dominant colors in the images and store them inside a database. There's a script called "color thief" that does that beautifully. But chances are all the colors will be different! The color search form can't display all of them. Google search only allows you to pick fro...
I'm a web programmer with several years of experience in RoR and node.js. I have a project idea that is quite big and I need some input in how it can be achieved. I heard of the Diaspora project, and how it is de-centralised. In a way, which I don't really get, anyone can setup an instance of the app and connect it to ...
We have three levels of code in our big and complex Web site: plain SQL (in fact Perl DBI), a primitive ORM (we wrote our own primitive ORM, because DBIx::Class appeared too slow in our environment), business objects (high level interface to the database, grouped by topics (not by tables and fields)). (well fourth, sp...
In the C programming language (and many subsequent languages that either directly interfaced with or built a facsimile of the C's Standard IO functions), there exists a function called ungetc: int ungetc(int char, FILE *stream);. It 'puts back' a char to the front of the stream that is being read. This putting back is ...
I would like to build software to help folks with their personal finances. One area I would like to tackle is trying to predict future transactions based in past transactions. For instance you might see the electric bill being paid near a certain day of the month. The algorithm would then be able to create future predi...
This is more of an OOD problem and I have no specific code to post here. Can the same class violate the SRP in one context and be SRP compliant in other without changing a single line of code? In other words, can there be a situation that within the frameworks of the former requirements the class is SRP compliant and t...
A question has surfaced on the team: would it be a good or a bad idea to have a script auto merge from master to all this release's branches on a daily basis? I'm not entirely convinced by it -- it seems that merging may yield conflicts (and in that case the script would back-off), but even if it doesn't, I can imagine...
I am planning to remodel my current application and I am not sure if this is the right approach. Currently I have a Java Enterprise server application with 3 web-applications and an ejb-application which handles the database (JPA with EJB-Facades). Everything in one single project (deployed as an ear file). The web-app...
How should I track requests for very small changes in the user interface of my Agile project? These changes will take very little time to complete and require only a few words to specify. However, they have originated with the customer, and it is therefore very important that they are not overlooked. Creating a 'User S...
What is the complexity of the following loop? for(i=1;i<n;i=2^i) sum+=i;
I have a class which is refactored in 1 main class and 2 smaller classes. The main classes use the database (like a lot of my classes do) and sends an email. So the main class has an IPersonRepository and an IEmailRepository injected which in his turn sends to the 2 smaller classes. Now I want to unit test the main cla...
Define a BST as: all left descendants <= n < all right descendants. Then is it possible to build two binary search trees with different structures but the same exact values? Duplicate values are allowed.
I am having trouble with code design for current scenario of process workflow. For example, by default it is set in the app that for some request 'A' direct manager has the authority to 'approve' that but later on, this approval authority has been moved to 'department head'. How can I accommodate these changes without ...
Kind of as the title implies - I can understand why Apps Hungarian might crop up, but Systems Hungarian seems almost entirely pointless in a strongly-typed language. Why, then, is it so apparently prevalent in the VB world? Going back to my high school programming courses (late '00s), I had a teacher who knew nearly no...
When I start a new project based on a nice starter kit like this Angular 2 one. How do you keep up with changes to a base repo like this? I know that it is a 'starter', but it would be nice to merge smart new insights from the starter kit into my own code base. What's the most commonly used Git workflow to do this? I m...
Let's say that we have a class PersonName and we throw an exception when some one try to create a instance of PersonName passing an invalid name to the constructor. Should the exception InvalidPersonName be expressed on the domain model? And if it should, how should it be represented?
I'm writing an API for a bunch of different aspects of my project. I have some code that currently looks like interface LoginCredentialRepository { Callable<LoginCredential> fetchCredentials(String username); } I had the thought to add a new interface to the mix, a FetchLoginCredentialTask that looked something l...
I'm working on a project which revolves around a database of about 750.000 entities. Let's just say these entities are musical works. Each musical work is associated with an album, one or more composers and some other entities. The business who owns this database has bought services from other providers which requires...
Background: I couldn't find a standard definition for "rich domain model". I may call it non-anemic domain model. So, it could be defined as a software domain model where the domain objects contain little or no intensive business logic (validations, calculations, business rules etc.). Anemic domain models are widely de...
I want to make a builder pattern in a DDD application, but my builder is not stateless, is not a entity and is not service. If the stateless should be use for service, how to make the builder pattern like a service stateless with sub type specific parameter and initialisation ? And how to make factory class compositi...
In a java code the Printer class has a print method. This print method, rather than performing the print itself, delegates to class RealPrinter. To the outside world it appears that the Printer class is doing the print, but the RealPrinter class is the one actually doing the work. Draw the UML class diagram showing Del...
There are many typical questions like Return random `list` item by its `weight` Imagine more advanced problem. You have N sources of pair (item_id, weight) information. Let's call them Shards. Shards contain lists of pairs (item_id, weight). And you have central node, let's call it Central. The problem is: on Central c...
I m trying to learn how to make my code better. This way, I try to learn some books and understand them. I m having some troubles dealing with Domain Objects. From the first year of my IT school, I've learnt to create some UML diagrams, and more particularly class diagrams. When I need to represent the following user s...
In the program I'm making I have a pixtureBox (.NET) that is used to show related images. I found images after searching online, and some are CC BY-SA 2.0, 3.0, 4.0, and some belong to the public domain. I read the related FAQ of Creative Commons, but its kind of vague as in it does not give me a clear enough image of ...
I've been asked to takeover an existing Android project and the developer who was previously working on this project has left many things incomplete and un-solved with some really bad code documentation. I am finding it difficult to understand the code and his coding standard and the previous developer can't be reached...
I am trying to create a partial view (re-used many times) that will prompt the user for data and return that value to the parent view. My best solution so far is to pass to the partial view the name of a hidden object (a div, for instance) in the parent view, that the partial view will then set teh value of when the us...
Currently I'm working on a new open-source project for a packet inspection. I have almost none experience with designing an architecture. Thus I would like to ask your opinion on my current architecture and what issues could I face during scaling it. I have a set of large packet capture files with network traffic. Thes...
I am trying to figure our what is the appropriate granularity for code libraries. Specifically, I want to work out if all my general code libraries should be rolled into a single DLL, or if they are better separated into separate DLLs, one for each discrete area of functionality. Background I have a a set of code libr...
I hope this isn't too subjective, but this question definitely doesn't belong on SO... I'm currently writing a large ASP.NET MVC 5 application and most views have their own javascript files as to be expected. What I'm having an issue with is determining is how to include the various javascript dependencies. Obviously...
What is the difference of Principle of least privilege and Interface segregation principle? As much as I understand ISP is just the projection of PoLP on the OOD plain.
Some languages, including C++ and Python, have "standard libraries" associated with them. What are the advantages of separating functionality out into standard libraries rather than build it directly into the language, where it would take less effort to access? Clarification: by "built in" I mean "usable out of the bo...
Today I was watching a "JUnit basics" video and the author said that when testing a given method in your program, you shouldn't use other of your own methods in the process. To be more specific, he was talking about testing some record-creation method that took a name and last name for arguments, and it used them to cr...
The GitHub API supports HATEOAS quite elegantly, so navigating it from a graphical REST client like Postman is intuitive and fast. They don't list all possible permutations of the endpoints when requesting "/", my guess is they only list the top 'root' endpoints that get you started so that you can then use the respons...
I'm looking to implement a fast, well-distributed hash table in C#. I'm having trouble choosing my hash-constraining function that takes an arbitrary hash code and "constrains" it so it can be used to index the buckets. There are two options that I see so far: On one hand, you can make sure your buckets always have a ...
I am just reading Fielding's Dissertation and have a question about Chapter 5 where he introduces REST. In 5.1.5, he writes about trade-offs that come with the decision to enforce uniform interfaces. To quote: The central feature that distinguishes the REST architectural style from other network-based styles is its em...
In answers to this question, the general consensus was that static methods are not meant to be overridden (and thus static functions in C# cannot be virtual or abstract). This is not only the case in C#, though; Java also forbids this and C++ doesn't seem to like it either. However, I can think of many examples of stat...
In terms of good OOP design, what is the best way to structure code that is just containers of list of objects that contains other lists of objects that also are just other containers? Example: A Cookbook owns a list of Chapters that owns a list of Recipes that owns a list of Directions. Each object is a different lay...
For a new project we try to set up the development process and the intention is to have a simple, pragmatic process. We use Atlassian Stash with Git in our company. We came up with the following proposal: In the central repo exist two branches development and production. All development takes place in the development b...
I'm currently in the process of developing my first API. This is a private api that will send information back and forth between my two sites, not one that will be open to the public. I'm working on making it as robust as possible, but since this is my first time developing something like this I want to make sure I kno...
I'm building my first app and have reached a point where I'm considering switching to a MySQL database. However, I noticed the GPL on the Community version of MySQL. So I did some prowling and noticed that it was also the connector supplied to connect MySQL to Python. If this connector is going into my server's code, t...
I'm building a boutique website using Kirby (a flat-file CMS) and I'm looking for a way to structure the site for best performance and maintainability. The website will have multiple categories and under those categories, it will have subcategories. It will only go a max of two levels deep. Example of current structure...
In Angular 2 (currently 2.0.0-rc.6), routerLink is used as a directive to indicate a path we wish to follow in our routing, e.g. in response to clicking a link. However, in the documentation both of the following are used: routerLink [routerLink] I don't understand when I should use which. The Basics / Template Synta...
recently I came across this blog post from asp.net monsters which talks about issues with using HttpClientin following way: using(var client = new HttpClient()) { } As per the blog post, if we dispose the HttpClient after every request it can keep the TCP connections open. This can potentially lead to System.Net.Socke...
I have a repository that contains login credentials interface LoginCredentialRepository { LoginCredential fetchCredentials(String username); } For this framework, I'm designating one thread to handle all IO-based tasks. This is only by convention, and if someone really wants to submit an IO-based task to a differ...
The naive solution is to generate the set of subarrays/substrings and check each for the property, but that is very inefficient. Is there a general algorithm that offers better performance without knowing more about the data or the criteria themselves? The substrings would be defined as contiguous subsets. So for insta...
I m trying to learn DDD and I m having some troubles dealing with the Infrastructure services. In fact, I understand what they aim to, but I don't see where they fit inside of my application. Actually, I m having the following stuff An application Service (REST API) Some Domain Services (managed with Specification Pat...
I have a view controller which has 5 different subviews, these subviews are changed according to some conditions, then there are functions which apply background color and add some minor aesthetics to the views. I have segregated the functions in the viewcontroller only for views i.e Applying colors,adding views and b...
Our company uses another companys api. This api is written using IBM domino. This api is horrifically inconsistent and outdated. E.g. sometimes returning JSON, sometimes html. Inconsistent naming and types. What would be the best course of action? I don't think we can force them to update their api. Would it be best to...
Let's say I write a parser. It takes an argument that is a String and does something with that. This String can be very long so keeping it in a test class can dirty my code. I think that it would be better to keep this String in a file and read it during unit test. I have doubts if it is still unit test or maybe integr...
When implementing a state machine and it comes to the fact that a transition depends on an external boolean a, or an enum value b which can be one out of three (which are set somewhere else in the control flow), like // ... more states ... L : { // example for a ‘common’ state event27 → G event12 → J // events...
I have a system in PHP that works like a booking system. Once a booking is confirmed there are a total of 7 emails/sms that needs to be send. The times of when they need to be send are already known. For example, 24h before the bookingdate, a email goes out. Right now we have a cron checking if it is 24h< and the 24h e...
I need to develop the following Java solution and I would like to double-check here that my approach is correct. At the very basic level, I need the solution to (1) perform an automated activity at the same time every day. This requires no user input. (2) perform the same activity on an ad-hoc basis which is triggered ...
How are multiple exit conditions in a system sequence diagram loop frame indicated? And how would the alternative event flow based on how the system exited the loop be shown? For example a login loop could exit after a valid login or after a set number of failed login attempts.
I recently read the Three Big Lies blog post and I am having a hard time justifying the second lie, which is quoted here: (LIE #2) CODE SHOULD BE DESIGNED AROUND A MODEL OF THE WORLD There is no value in code being some kind of model or map of an imaginary world. I don't know why this one is so compelling for some pro...
I have an api with 3 layers 1.) The endpoint layer which exposes api endpoint handler functions. These generally call the business layer, aggregate the results to form an http response. 2.) The business logic layer, which provides interfaces to get or edit data while employing business rules behind the scenes, modifyin...
I m studying DDD these days, and I m having some questions concerning how to manage repositories with DDD. Actually, I have met two possibilies : First one The first way of manage services I've read is to inject a repository and a domain model in an application service. This way, in one of the application service metho...
In the ARM C/C++ Language Implementation Guide (p 99), NOINIT is listed as a pragma directive. In the previous code that I'm working with, __no_init was defined as an intrinsic function (IAR compiler for MSP430). I understand that intrinsic functions are sets of assembly code that are convenient to not have to attempt ...
I am currently taking AP Computer Science at my high school and while looking at some sample AP test problems I came across one that really confused me. Sample Problem The answer to the problem is letter A but I don't seem to understand why that is the answer or how to even begin to try and solve a problem like this.
Title say it all - I'm trying to remove every line from a file that contains the string "PresenceManager" I first loop through the file, removing any instance of the string. However, this leaves a TON of empty lines, so I have to go and remove those with another block of code. This seems like quite a lot of code to do ...
Why aren't lisp keywords protected? For example, (define a 3) (define define +) #makes define useless (define a 1) #outputs 4, instead of assigning 1 to a. Is this flexibility so important? Or even worse: (define + -) (+ 1 1) #Output 0. Where can this be useful, and, can this behavior be blocked? AFAIK, all programmi...
I have an API that generates a resource randomly when requested. What path could I use that would follow REST conventions? A - /generate/random.png B - /generators/random C - ? Should I place all my resources in a root like /api to differentiate them from web pages? (For example, I might want to display a HTML page at...
I am currently developing a java application, which will communicate with a SQL server. Therefore I created the class Database which is responsible for open() and close(). I want to be able to add data to the database. In this example, the table is called job. Therefore I created a class Job. Besides these jobs, there...
I'm studying Python and hung up on a simple problem. Let's say we have: string = "hello" When we invoke the find method on the string to find an empty string like this: string.find("") Why does that equal to 0? I thought it would equal to -1 since an empty space could not be found.
I have a design question in the "field" of CQRS / DDD. I will not explain in depth the domain, but only what's needed. It's a CONTACT domain, so it manages the contact informations of people and organisations. A relation can exist between people and addresses. This relation exists in time so it can be active or inacti...
Sometimes I see bits of code in functions that I suspect could be changed in a specific way later that would break its functionality. For example, function A could be changed to call function B, but it shouldn't. Should there be a unit test that asserts that function A does not call function B? The case I am thinking ...
I am starting to learn parallel programming in c++, and I have a program like this: for i = 1:N do something time and memory intensive end If I program this in parallel, and my processors have shared memory access, will the parallel programming help? I thought maybe I am going to overflow the memory, since I am l...
Albeit a general question my scope is rather C# as I am aware that languages like C++ have different semantics regarding constructor execution, memory management, undefined behaviour, etc. Somebody asked me an interesting question which was for me not easily answered. Why (or is it at all?) regarded as bad design to le...
I am working on client JavaScript SPA and a restful API on HTTPS. Client application needs to call a public endpoint (no token required) in order to valid (GET) a specific TOKEN previously remember within the SPA application. API returns: If token is valid a status code 200 is returned and a json value {"isValid": "t...
I am a 4+ years experienced C#, ASP.NET MVC5, Flex, Actionscript, Html, css, jquery, php developer. I have a passion for developing and I'm not scared about learning new things. In fact I read technical books about what I know to get a deeper knowledge and dive also into new things like learning how to work with a rasp...
I am tasked to design an OpenID provider for the public facing applications of my company. The idea is to authorize the user via an email/PW combination. The subject will be a GUID. Should an user be able to change his email address (that is used for login) or should there be a changeable contact email address.
System consists of several micro-services and each of them is in charge of it's own context, such as booking, payment, products and notifications. Let's imagine we have a traveler who is seeking accommodation on website. Accommodation is listed by retrieving information from products micro-service. Traveler found what ...
I have a form and I was wondering about best practices when validating names (specifically throwing out characters which do not typically make up a name e.g. 123%^*$£ though theoretically could) and if it's sensible to carry out anything more than checking for presence. I've often read that you shouldn't try validating...
Freeing unused memory is a major issue, causing unwanted GC delays in some languages, use-after-free vulnerabilities in others, and Rust has significant complexity to try to fix the issue. Many server-side applications are request (or transaction) based, with no state shared between requests. An idea I had was that mem...
I have a struct called State which holds all the variables for the program. Rather than being modified by functions directly, it is the value returned. Here is some code: #define USERNAME_LENGTH 20 #define MAX_NUMBEROFUSERS 64 #include <string.h> #include <stdio.h> struct User { char name[USERNAME_LENGTH +1]; ...
This program run successfully . What is use of blank return in constructor as we know it return this implicitly . Is it is a bug in java or have some use . class Demo { int salary; Demo() { salary =11500; //return this;(implicitly) return; } public static void main(String......
This is a question for those times you are creating the read model by event handlers. The question comes down to : How can a Event Handler draw from other sources of information than what is contained in the handled event itself to construct a read model? I have two aggregates, Person and Address. A person can be assoc...
Not too long ago I started using Scala instead of Java. Part of the "conversion" process between the languages for me was learning to use Eithers instead of (checked) Exceptions. I've been coding this way for a while, but recently I started wondering if that's really a better way to go. One major advantage Either has o...
Say you have an equation like x1 + c1 * x2 + c2 / (y1 + c3) = y2 - x3 My goal is to rearrange it so that all x's are on one side of the equation, and all y's are on the other, f(x1, x2, ..., xi) = g(y1, y2, ..., yj) (so, for my example, x1 + c1 * x2 + x3 = y2 - c2 / (y1 + c3) is a solution) First of all, is there a nam...
Unit testing is something I love now after forcing myself to do it in projects (and doing it at work) after seeing the massive rewards it offers down the road when refactoring and ensuring things work the way they should. Right now I'm writing a software renderer an I'm unsure if there's ways to go about setting it up ...
Given a set S of disjoint 2D line segments, is there a way to pre-process S into a data structure that can check if a single arbitrary segment L intersects any segment in S in log2(n) time, as well as modify the structure using the same time complexity bounds? The endpoints in S are closed, and lines may have slopes. S...
I have gone through lot of explanations about a compiler and interpreter. I think I understood the difference between compiler and interpreter clearly. I'll explain my learning through the following example. Let's say we have the three lines of code in a file. a=3; b=4; a=a+b; A compiler converts these three lines in...
I just picked up a React/Flux app and I'm new to the technology stack. One of the things that's throwing me off is that just about every tutorial I view on this stack very clearly defines Dispatchers as a necessary component. I'm wondering if the previous developer chose not to use them, or if the notation he used act...
I'm working on a suite of micro-services, with a web-based GUI. We are using a 3rd party state machine via REST calls. Sometimes we get/set state from one of our micro-services, while other times we go straight from the GUI directly to the state machine bypassing our micro-services entirely. I'm of the opinion that the...