instruction
stringlengths
34
36.1k
I see a lot of programs that does write a pidfile, and check at boot its existence. And this is good. But many application does not start even if they check that the pidfile exists, yes, but no process with that pid is running. Why this behavior? Is it not more simple to remove the pidfile and warn the user, at most?
I recently came across a website that contained an anchor element without a href attribute. I immediately thought that was stupid, but, could there be an actual situation where having an anchor without a href makes sense?
I'm working on a project with web services, and I've been structuring things where: The web service contains the business logic layer A library which handles the data access layer I've recently been learning about micro services. In hindsight, I'd want to split the service in multiple services each covering a specifi...
Continuing from Author has inserted copyright into code with gnu public license notice - implications?, can I add my author name to a new file (with original code) that I added to a project that comes with a GPL license - as in: # GPL License and Copyright Notice ============================================ # This file...
Linq has a method Select, which takes a Func<TIn, TOut> and maps it over an iterable. I'm trying to come up with a good name for a method that takes an Action <TIn>, transforms it to return its argument, and maps that over an iterable. The method is public static IEnumerable<T> MyMap<T>(this IEnumerable<T> source, Act...
Recently, I've gone through techcrunch article where it says, Dropbox is working in Project Infinite technology which allows to load cloud content in local PC without actually storing in memory/drive Today at the Dropbox Open conference in London, the company announced Project Infinite with the goal of giving busine...
I've been studying the cyber security field with great interest. I understand how networking can help cyber security but I am not sure how advanced programming knowledge can help fight cyber crime or why certain cyber security experts need programming knowledge. In my experience so far with penetration testing tools a...
Should I write my code to be clear what I am doing and rely on the optimizer to clean up my code efficiency, or should I be obsessive about getting every last ounce of power out of my code? And how much speed/size am I losing on by choosing one option over the other?
I am working on a game framework that would allow users to use multiple mods/plugins to add additional features to the game. For the remainder of the post, I'll use the following definitions: mod: code that requires changes to both the client and the server. For example, adding a new packet to the protocol. plugin: cod...
Is it considered good practice to start a transaction in the "service/application" layer, and then have objects in the domain model make DAO calls which participate in that transaction?
In the excellent book Node.js the right way the author shows this example: const fs = require('fs'), zmq = require('zmq'), // socket to reply to client requests responder = zmq.socket('rep'); // handle incoming requests responder.on('message', function(data) { // parse incoming message let r...
Do I need an "application/service" layer to manage transactions if the domain layer only services the UI? In other words, can't I just manage transactions in the UI when I have only one consumer of the domain layer? In this case isn't the "application/service" layer just an un-needed extra layer of abstraction?
I'm working on an application to help create printed-page layouts (to be then fed into a custom script for InDesign). I'm facing a problem regarding placing images on a page. Either a single image could be placed on a page, or multiple images. If a single image is placed, the user should be able to define whether it's...
Should I write unit tests for complex regular expressions in my application? On the one hand: they are easy to test because input and output format is often simple and well-defined, and they can often become so complex so tests of them specifically are valuable. On the other hand: they themselves are seldom part of th...
We recently started learning about binary search trees. We created one of our own using integers as our Key/Data. It's easy to achieve the BST property using an int key, but what happens when we template our tree? How do we achieve our BST property with say a char, string or foo? - These don't seem fitting for keys. Do...
This question is about handling namespaces and unit testing in ZF2. Let's say I have a module called Application. I have constructed composer.json to be like so "autoload":{ "psr-4": { "Application\\" : ["module/Application/src", "module/Application"], } } where first path is for the main code in the src...
For a C project, I'm upgrading my build process from MingGW-GCC / make and Android Studio under Windows (2 separate processes) to Clang / CMake under Debian 8, using wclang and wine to compile and run the Windows build It seems to me as if we build for one platform at a time. I suppose there is a large part of the ...
I recently came across the ReactiveX pattern for asynchronous data-flows. I studied the information provided there and also watched this talk by a Netflix engineer on how they used Observables to redesign their web API architecture. ReactiveX certainly seems like a clean and powerful abstraction, but I don't see the di...
I have a car maintenance garage program that has an abstract Vehicle class that has several derived classes like Car MotorCycle, etc. Each of those derived vehicles in turn is either a fuel or an electric vehicle. So instead of having a FuelCar, ElectricCar, FuelMotorCycle, ElectricMotorCycle etc, I'm trying to impleme...
Let's say i have two class named Object (base class) and an actor class (derived class). The actor class uses physics so i need to implement it on the Actor class. But there are other derived class of the "Object" class that don't use physics so i don't want to have physics implemented on them because it would be usele...
For the fields that you have as encapsulated members of a class, does it make sense to declare their type to be of the interface that you are using? For example: public class PayrollInfo { private Map<String, Employee> employees; public PayrollInfo() { employees = new HashMap<>(); } } This gives you max...
I'm in RFP phase working with outsourcing vendors on the 100% rewrite of a fully operational prototype asp.net app that I wrote, to make it commercially viable. I have an idea for a project design and I'd like some feedback on whether it makes sense. In summary it is to write the JS and the server software in paralle...
I have a question about software modeling terminology, when modeling time. Say you have a repeating schedule MWF 4-5 p.m. What do you call Monday 4-5 p.m.? What's the term for that? using System; namespace myproject.biz { public class ScheduleComponent { public DayOfWeek DayOfWeek; public TimeSpan StartTim...
Why does c# compiler force an abstract class to define (as opposed to implement) all the methods of the inherited interface ? why does it not mark unimplemented methods of an inherited interface as abstract on its own ? I'm unable to appreciate this constraint, Is it because the language designers wanted the programme...
I'm in RFP phase on a 100% re-code of a fully functional asp.net prototype. The prototype was reverse-spec'd into a detailed requirements document and a full set of wireframes. I can understand the need for a database designer, however, who should be doing the application module architecture? And I'm meaning that at ...
I have a project which involves using C++ files along with an API on a local PC to communicate with a remote server app, and for sake of maintaining a semblance of non-disclosure with any hired developer(s), I'd like to 'mask' the context of the logic by renaming all variables to something less-obvious. However, the lo...
I'm working on wrapping a C++ API which provides access to a data store (Hazelcast) in C functions, so that the data store can also be accessed from C-only code. The Hazelcast C++ API for the Map datastructure looks like this: auto map = hazelcastClient->client->getMap<int, string>(mapName); map.put(key, value); It m...
My question is more about the transformation from programming code to control flow graph. Say, I have a piece of code: public class Contractor { // other member fields... private bool isVerified; private int noOfA; private int noOfB; // other member methods... public int GetNumberOfDependents...
I am trying to understand the advantages and disadvantages of a Foreign Function Interface (FFI) (in which the high-level languagd can call most C functions directly and can manipulate C data structures) vs. a C/C++/etc. API, in which the native function is passed runtime-specific data structures and must use runtime-p...
I have built a simple authentication system for my web application that makes use of the open-source time-based OTP algorithm (RFC 6238). The key for each user is generated when the user is registered in the system. When the user first signs into their account, they are asked to set up their authenticator apps with the...
By "real" I mean Exceptions that would work as the ones predefined by the system. I mean for a custom exception you have to use the reserved word throw CustomException once you have checked the condition that might cause the Exception, but if you have done that there's not that big o f a need to throw the Exception, yo...
I have a perfectly parallel function that would run great on a machine with 1024 cores and 4GB RAM. There's quite a lot of branching (doing set union and traversing structs). There is no communication between threads (except when the whole calculation is complete). Each thread needs less than 1MB of private memory, and...
Questions I am trying to understand whether Rust fundamentally and sufficiently improves upon the concurrency facilities of C++ so that to decide if I should spend the time to learn Rust. Specifically, how does idiomatic Rust improve upon, or at any rate diverge from, the concurrency facilities of idiomatic C++? Is the...
I have been looking at AWS Elastic Beanstalk service for the deploymeny of my rails application, and I came to think it was actually a bad idea given some specific requirements of my application. But then, it is still quite a pain to configure manually the other services that provide scaling/elasticity, so I would like...
I have been reading on the internet about the metric "number of bugs per 1000 lines of code" and what would be a good number. However, I wonder how someone would compute such a metric? The reason a bug is in there is that nobody has found it. And testing can't show you that there are no more bugs. You may assume that ...
Example case: You have a truck, that can hold 2.8m by 3.2m by 16m of storage capacity. You you get a bunch of physical objects you want to store in that truck. These objects are not always cubic, but sometimes rounded, or have concave shapes. The problem to solve I want to implement an algorithm, that finds the optimal...
I am working on a project that involves a "team builder" type application, if you will using C#. For the sake of simplicity, let us say it involves the user creating a "Team." There are three teams to choose from. Each team has "positions," for example, such as Captain, Shooter and Runner. Each Captain has 3 possible ...
I have two classes. The first, called Game_Events, controls the objects and manages the general tasks. The second, called Button, is for one of those object instances. The example below is wrong but shows how I want to do it: class Button { public: Button(void (*f)()) : f_m(f) ~Button(){} private: ...
The Vertical Bar Operator (|) is used in a variety of constants to mean OR in some way: C-style languages use a | b to mean bitwise OR of a and b, a || b to mean logical OR of a and b. Regular expressions use a|b to mean match with a or match with b. Context Free Grammars use x := a | b in much the same sense as regexe...
I want to use an existing project as a starting point for a new project by copying or cloning it. There are at least two ways of doing this. Method 1: Copy it. cp -R /path/to/source /path/to/dest and Method 2: Clone it. git clone /path/to/source What are the relative advantages and disadvantages of each approach ...
I want to know if there's a way or known way to implement this: Lets say I have: a C# WinForms program a Javascript Mobile Application (Android / iOS) What I want to do is: for my C# application to show a one-time use (disposable) code or token. The user enters the code or token in the mobile app The code is no lon...
simple question, I want to know if there's a word/term used to describe the collection/pair of a key and value in a C# Dictionary.
Regarding GPL software use in a commercial project, I have the following situation: I would like to commercially distribute an Excel-Macro application, which uses a GPL licensed software (G77 compiler) and some Fortran codes. The Macro and Fortran codes are all written by myself. No changes are made to any of the GPL s...
I'm writing a small application in TypeScript that has to do some asynchronous operation and I'm doing it with Promise and async/await sugar. But my problem do not rely on the particular language or asynchronicity strategy. The operation are both I/O and network operation, something like: every 2 minutes find a suitab...
Our API accepts PUT requests in order to change status of resources. Think of this as a state machine. Client can specify the target state of the resource via PUT request but it is possible that the resource is not in a state from where it can go into the target state specified by the client. What HTTP code should we r...
I would like to know if it is possible to include source code licensed under: Mozilla Public License (MPL) version 2.0 In a project licensed with: The MIT License (MIT) If yes I would like to ask: Can I modify the code from MPL, but keeping their credits?
Suppose that I have a Java code base and I want to be able to execute multiple tasks that are based on this same base: Run an embedded Jetty web server. Run a one-time initialization of database (creation, seed, etc.) Run a cron-scheduled maintenance operation (cleanup, backup, etc.) Maybe more ... I was thinking abo...
Let's say I have a MediaPlayer class which has play() and stop() methods. What is the best strategy to use when implementing the stop method in case when the play method has not been called before. I see two options: throw an exception because the player is not in appropriate state, or silently ignore calls to the stop...
I'm having a bit of hard time finding a solution to the following problem. I need to find tuples of (a-c, 0-2) such that if I make a choice with one letter and a key I can't select it again. Example: input: {'a': [0, 1], 'b': [1, 2], 'c': [0, 1]} output: [(a, 0), (b, 2), (c, 1)] Example valid choices which lead to inco...
I've recently poured a couple of hours into JavaScript because I wanted to benefit from the massive userbase. Doing that I have noticed a pattern that most people attribute to dynamic languages. You get things working really quickly, but once your code reaches a certain size you waste much time with type, spelling and ...
A colleague of mine came up with an idea that I found interesting. Wouldn't it be beneficial to write tests during code review, by the person doing the review assuming that we don't do TDD? For this question assume that this is a purely academic project so there is no life at stake. Moreover the team is 4 people. Ever...
I was reading some code here and saw that an enum is used to store names of html tags. Why do we ever need to do this? What benefit do I get using this strategy? I know that how useful enums are in compiled or statically typed languages but when I see enums in dynamically typed languages I get curious, like the example...
Background I have a project that depends on the usage of a certain type of hardware device, while it doesn't really matter who makes that hardware device as long as it does what I need it to do. With that being said, even two devices that are supposed to do the same thing will have differences when they are not made by...
Sometimes, we need to stuff an integer ID into a string, for example when generating HTML form <select> items. Calling int.ToString() can result in digits outside the range [0-9] in certain cultures. For that reason, you need to specify the invariant culture in culture-spanning apps (e.g. int.ToString(CultureInfo.Invar...
I'm trying to tackle the While Language problem on HackerRank using Scala. I've been given a set of grammar rules and have to implement the actual interpreter underlying it. I've decided to approach this by building a lexer and parser in two separate stages. My lexer works perfectly: it correctly tags tokens and wraps ...
I am writing a rather large class where the user can specify at runtime whether she wants to use algorithm A or B of an third party library e. Basically there is only one function call different in choosing A or B, but this function is called in many different places in the code. I would like to omit having to write ...
I'm doing a object Garbage class using c++: #include "Object.h" class ObjectGarbage { public: ObjectGarbage(); ~ObjectGarbage(); void Call_All_Objects() { //(some for loops) {Garbage[..][..][i].Main(); } } void GetObject(Object *obj) { //Data type get (...
I'm working on an API and I always seem to run into this thought debate. When designing the code structure that interacts with the database (repositories, data providers ect..) how do I structure the repositories based on hierarchical relations? For example I have an app with Items and those items have images. Do I ma...
I need to write a part of the program which will work with a string, find in it some substrings and copy they to dictionary. Example of the string: thestring ='\ #: somethings\nchars0 "substr0"\nchars1 "substr1"\n\n\ #: something\nchars0 "substr2"\nchars1 "substr3"' so it have current substrings 'chars0' and 'chars1' ...
I am attempting to refactor a component of a large project, which currently has a lot of dependencies to global state of the project environment. The goal (for my taste) is a "SOLID" architecture, where everything can be properly tested. Sometimes the dependency may simply be a string or value: A specific directory, a ...
I support an Internal ERP system and an external Reporting/Dashboard that our customers use that both use the same database. Internal normal application users can control what customers can access through the external dashboard - this can be sites, jobs, documents etc as who can see what on which accounts/sites gets ve...
Let's say I have a basic procedural program which is well structured into decomposed functions. For example, a main() function which calls functions a and b, which in turn each call functions c and d, and e and f. In pseudo-Python, this could be written bottom-up like this: def c(): # Do stuff def d(): # Do st...
Extracting functionality into methods or functions is a must for code modularity, readability and interoperability, especially in OOP. But this means more functions calls will be made. How does splitting our code into methods or functions actually impact performance in modern* languages? *The most popular ones: C, Java...
About the subject I hesitated for a while between using singletons objects or plain static ones. After having read a lot of different opinions, I made mine: If you don't need to prevent multiple creation of an object, don't use a singleton. Therefore I used mostly static objects. Context My program is a complex sci...
I'm currently developing my own (sort of) programming language. It currently looks something like this: asdf = 2; print(asdf); And print(2); And surprisingly, it works. (Both output 2) However, the problem is I can't do this: print(sqrt(25)); I also can't do this: asdf = sqrt(25); print(asdf); My big problem is I c...
I'm building a simulator which parses some events from STDIN and "runs" them. My background is mostly functional programming these days, so it seemed natural to do something like this: data Event = Thing1 String Int | Thing2 Int | Thing3 String String Int Parse :: String -> [Event] Simulate :: [Event] -> [Result] wher...
Is it bad to pass a reference to the behavior's owner object to the behavior? For example, if I have a Duck and DuckBehavior class. DuckBehavior is a part of the Duck Class. But what if I need to get some internal information of the Duck. Can I pass a reference of Duck to the DuckBehavior class when I'm constructin...
The company I work for follows a business model where a core product exists (originally written in C, now in C++) with some default implementation but details are tailor-made for each customer (there are cca. 10-20 of them). What's the best programming approach in such a scenario? Is there a good design pattern/methodo...
Looking through this article on Rust's concurrency safety: http://blog.rust-lang.org/2015/04/10/Fearless-Concurrency.html I was wondering how many of these ideas can be achieved in C++11 (or newer). In particular can I create an owner class that transfers ownership to any method to which it may be passed? It seems tha...
When a beginner starts off reading ifstreams, his/her instinct is to read the file using a loop that usually looks like this: while (!ifstream.eof() { ... } However, when I used this code I noticed that it didn't stop until it had read the last line of the file twice. C++ programmers note that this isn't actually how ...
I have an Asp.Net MVC application where I need to create a report. This report will show some data about an entity (activities), but only activities of ONE specific type that will be inserted in the database (until now). My data model is: Activity: Int ID DateTime Date Int TypeId Activity Type: Int ID String TypeName ...
I got inspired by a similar question on the Stackoverflow.com and after reading what Martin Fowler has written (and Jez Humble, of course at http://continuousdelivery.com/), I still struggle to understand the difference, or the border line, between continuous integration and continuous delivery. Let's assume there is a...
in my project I am finding that I mix and match the following two patterns, when it comes to organizing classes in folders/namespaces: Modularized MVC Blocks module/Album/Feature/Controller/AlbumFeatureController.php module/Album/Feature/Repository/AlbumFeatureRepository.php module/Album/Feature/Form/AlbumFeatureForm.p...
I'm attempting to migrate some of my already existing pages over to bootstrap 3, and I'm wondering the best design to do this. On the non-mobile devices, I display a list of items on the left. If you click an item, it will either render a detail section or pop up a dialog. On mobile, however, I need this to slide into...
This could be a simple yes/no answer, but I invite detailed explanations. Scenario I have been asked to extend a closed source system at my job, which is not formally released under any license. I thought I'd learned once that meant all rights are reserved by default, but I can't find a source for that now, so please c...
According to oracle docs: the class name in java should be nouns, in mixed case with the first letter of each internal word capitalized. Is this just a good practice rule or a mandatory rule? (I'm a beginner so please excuse me if this is too silly)
The following scenario happened to me several times. I programmed a algorithm that solves a certain problem. It works fine and finds the correct solutions. Now, I want to have an option to tell the algorithm "write a full explanation of how you got to the solution". My goal is to be able to use the algorithm in online ...
I recently just started looking at Func in C#, and as far as I can tell, they pretty much are the same as methods, which is fair enough. However, I was wondering if there is any point in using them, because as far as I can tell they seem to just be a slightly less version of methods. Consider the following: Func<int,in...
C has family of integer types i.e {short, int, long, long long}. Any new programmer is likely to use int to represent integer variable in the application and since int type has 32 bit space with range (-2,147,483,648 to 2,147,483,647), there will be bug as soon value of the variable goes out of the range. As you can se...
Let's say I have two files I am working on - "a.txt" and "b.txt". I need to commit my change to "b.txt" but want to keep working on "a.txt" for some more time. I do a "git add b.txt". Now, before I actually commit this change, is there a way to test that the commit will not break the master branch? If I run a test loca...
Even after thorough requirements engineering we end up with users wanting to attach 'notes' to their otherwise well-structured data records, in other words: arbitrary key-value pairs. Their primary interest is to find records later based on this meta data. Example: { fixedattr1: 10, fixedattr2: 11, fixedattr3: 12...
Is O(n^2 * 2^(log n)) == O(n^2) ? Why I think that this could be the case: In big O, you only take the parts of the term that are most relevant, right? O(n^2 + 3n + 9) == O(n^2). The n^2 has a lot more influence to the result of the term than the 2^(log n)-part. http://www.wolframalpha.com/input/?i=Plot%5B%7Bn%5E2,+2%5...
I am implementing a trigger system. There are objects that take the role of observers (this is not strictly an observer pattern because the observers are inter-dependent, see my question here). They register to be triggered during certain events (by being added to the list of that event) and provide the functionality w...
The following piece of Python code uses a superclass solely as the repository of functions that one of more subclasses may draw from: class Class(object): ''' A trivial repository for functions to be inherited ''' def function(self): print self class Subclass(Class): ''' A subclass where the actio...
Though I like recursions and understand it, I fail to master it! I am stuck with a problem which I know that recursion can solve, but I do not know how. I have an array of strings like: "hundred", "fifty", "thirtythree" etc. I have 'x' number of places to arrange them but the condition is, the string following in next ...
I recently realized that I have way too many dependencies in many of my classes. Now I am trying to solve that for the most important class. I think I have an idea how but I'm not sure if it is the best idea. The most important class is a Service class. What it does is make one "thing" in the app go through different s...
What would you call a test that is similar to a unit test, except it actually modifies a file, directory, or database data? It is similar to a unit test in that it does test a single method of a single class as opposed to testing an entire feature of a program or a scenario a user would run through. It does not use moc...
Definitions used by this question: 'functional' Try is what https://github.com/lambdista/try is. Success and Failure are subclasses of Try. Exceptions aren't thrown by the called function. 'rx' Try is what https://github.com/aol/cyclops/wiki/Try-:-functional-exception-handling-for-Java-8 is. Exceptions are thrown by t...
I have a dilemma. How to do better? I have a bunch of API interfaces and their implementations which use some specific frameworks/librarys which I would not like to expose. I cannot make a decision about whether to put both API interfaces and their implementation in the same package or split them up to different packag...
In functional programming, given a function f and a function g we can define a function . (compose): let (.) f g = fun x -> g (f x) Is there a term for the function which applies arguments in the opposite order? What would be an appropriate term for the # operator in the following definition? let (#) f g = fun x -> f (...
I read a lot of questions about this concern, and some of them are Presentation VS Application layer in DDD Application layer vs domain layer? So my question is if the top layer is REST API and there is no need for any UI, is REST api considered as a presentation layer or application layer? Update Since I received som...
I've seen some people overusing default arguments and I was wondering when it is reasonable to use them. The main issue that I have is that sometimes it makes me think it using overloading when it isn't.
I just changed branch settings on my GitHub repository, so that my [next] branch requires a passing CI build through a pull request. A discussion followed with a number of team members, about failing tests. For context's sake... The repository has a [master] branch that's only PR'd into when there's a release, so [mast...
It is usually well known how to deal with model classes that have a 1:N relationship: classical examples are order->items or client->orders. Every layer of the software has its appropriate and typical solution: a sort of prepared template. Again, the same classical example: a GUI of an order where the user can enter a ...
So, I recently noticed something on some code I was writing. I could get a variable for a different class/object using dot notation to get the variable: object.someVarable or I could do it the way I was taught and use an accessor method: object.getSomeVariable() to return the variable. So, my question is: which is ...
I am using a modified Linux kernel from a NAS company for my own project. It has been more then one month since the company released a new version of their software which includes the modified kernel so far the code has not been made available. Is it allowed to delay the release of the source code or does GNU GPL v2 re...
I have a client that wants me to build a SaaS application with a multi-tenant architecture, where different clients will go in a separate schema on the same db server. I have seen this architecture before, but never really used it, so I am quite new to the concept. I am strongly against this as I think it would add a l...
Say I have my project that looks like /src/main/java/... /src/main/resources/... /src/main/webapp pom.xml And I have this stored in my version control, Git/SVN etc. My artifact has a signature like <groupId>dwj.me</groupId> <artifactId>some-project<artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packagi...
I am on a micro controller (which means I can only have static memory allocation) and I am trying to work with inheritance..... Suppose I have a abstract class Image and an abstract class Font. An instance of Font can return an Image based off of the char given in a function like so: Font* mf; Image* image = mf->GetIm...
Suppose I have a custom object, Student: public class Student{ public int _id; public String name; public int age; public float score; } And a class, Window, that is used to show information of a Student: public class Window{ public void showInfo(Student student); } It looks quite normal, but I fo...