instruction
stringlengths
34
36.1k
I have a python function x that returns some module x(): return y I would like to parse the file x is located in and learn that "x returns this thing called 'y'". I have no idea how. I'm not trying to get the type of the return type, just what the programmer calls exactly what is being returned.
For a long time our time is discussing about propagating global events between applications that could (but don't have to) be on different servers. We have few solutions but we can't find perfect one. Background: Suppose there are Application A, Application B and Application C where Application A can be an app access...
I'm using C in a minimal, efficient OOP style to build a game engine. A problem I've begun to face as the engine code settles is my (erstwhile) choice to use this. For example, I have: void Engine_initialise(Engine * this); void Window_terminate(Window * this); Window * this contains a reference to the singleton Engi...
I was thinking about pure functions especially in the context of C++, which of course is not a purely functional language, and was wondering if higher order functions in C++ can ever be considered pure? Take for example std::find_if: it would be very pure except it takes another function, which might not be pure. There...
I've designed the below code for one of the requirement. I have to write different tests for the code and I would need feedback on where I can improve the design. Requirement: Read the customer details from csv, calculate his average expenses on different items on yearly and write to csv again. Read the customer de...
Is returning sensitive data like a password from a function safe, and what attack vectors exist? (Personally, it is regarding PHP, but is a general question.) function returnDBPass(){ $pass="mydbpass"; return $pass; }
We have server that runs data processing tasks, using Python, Django and Celery, on Linux. Once a batch of data comes in, a number of Celery tasks are scheduled and they run, some of them in parallel, some depend on the results of earlier tasks, this all works. Now we have to implement a new task -- a proprietary Windo...
Is there a preferable way of when a service should persist data? Update Does this depend on if the services are public or internal? Some services take entity objects as parameters to do some action on that object, update it's status or add some data to it. Should that service also persist changes to that object to the ...
Background From a developer's viewpoint, the main selling point of Windows 10 is its new Universal* Windows Platform (UWP). * Where "Universal" really means "universal to all devices that run Windows 10", and not "universal to devices that run not only Windows 10, but also Windows 8.1 and maybe Windows 7". So if you're...
There's been a lot of news in the enterprise world lately, specially in the web, and I've decided to build a small web framework on top of Netty to learn more about asynchronous programming and event-driven architecture. In my daily job, we're using Spring for almost everything. I want to break those chains and create ...
I've been trying to refactor an old design in to an Onion Architecture in DDD style. To that point, the project went from a monolith to 4 sub-projects: /src /Project.Application /Services /Project.Core /Domain /RepositoryInterfaces /Project.Infrastructure /DataModels ...
In this answer about threading it is said: In preemptive scheduling, a thread can be interrupted at any time, either by a timer interrupt or any other interrupt or during a system call. The part of the system that performs the context switch must save all the registers and other settings, and restore the context of th...
So I am making a mario clone in pygame and I have a base class Character and two sub classes, Mario and Luigi. The methods that the Character class defines require a significant amount of attributes from a sub class (around 20) to be defined. For example, the initial y velocity of the Character instance must be defined...
I have a new project to deal with. I'm the only one to deal with it currently (a kind of a personal project). It's likely that in the future there will be more contributors to it. Taking in account the best practices when it comes to talk about project management, how much is there a need for the project specifications...
We're implementing a service for creating a subscription where the subscription may be linked to an order. Quick background: the purpose of this service is to allow the customer to receive the item she's subscribing to as early as possible. The solution we chose is to create a separate order for the first item before h...
I was wondering what people think about using a reduce function vs loop for returning true if a condition exists. Example: var a = [1, 5, 7, 4, 2, 5, 3]; var greaterThan5 = a.reduce(function(prev, val) { return (prev || val > 5); }, false); vs var greaterThan5 = false; for(var i = 0; i < a.length; i++) { if(...
I work on an application that services a large hospital. The application allows users to create/edit/delete a series of data points that all relate to a specific drug being researched. Once the data is entered and considered complete, a higher level parent table in the database is tagged with a "Production" status. W...
What type of SLOC do you take into account for estimating web application development projects with COCOMO II? For instance, suppose you have to estimate a web application project that will probably result in those SLOC counts, based on what you know about similar previous projects: Python (back-end REST API) - 10'000...
I'm using a library that is licensed under a BSD-2 like license and I am wanting to override one of the methods they use and modify it slightly. My question is, when I copy the code from the method what do I need to include in the comments for said method? Do I have to go all out and include the whole license there or ...
I'm revising a proposal to expand the C++ feature where "temporary" objects cease to be temporary when attached to a name by binding a reference. Here's a sample of the classic behavior (not the proposal): int && i = 3 + 3; // Calculate 3+3 and give a name to the result. int j = 3 + 3; // Create a named variable, calcu...
I am working in a project in which at many point I need to change the code and fix the bug of the system but how can I inform other team members about this change? Usually I add single line comment to that particular point or create task in eclipse and write bug fix as follows, //Fixed PRJ110-345 called checkAndClear t...
Imagine an RPG game were you can cary N items, and you want to maximise your damage, attack speed and armour, given a set of items. I implemented simulated annealing where a permutation simply replaces a random item, and I compute the energy with some damage calculations. This works well for attack speed and damage, an...
Okay, this question is not on which is better. It is more about when to use Dependency Injection vs Factory. I have done a bit of research and it goes like this. DIP: Provides loose coupling, through IoC. The class does not need to know how it got the dependencies. IoC Containers take the control of providing the dep...
I was taking a look at this question here: Open Source License that prevents re-selling And it makes some good points on how open source is defined by its ability for resale... However, I still have a bit of a concern of verbatim resale. I don't mind letting my code be changed, edited, modified, shared, etc... what wou...
In a shared library I have a function that is widely used. I'm implementing a requirement for the function to override its behavior when the entities are in a specific state. I have decided on implementing this requirement with the decorator pattern. All of my clinets program against an interface for this service and m...
What I am interested is the similarities and differences between the two. It is my understanding to present time that Luhn algorithm is a type of checksum function same as some cryptographic hash functions. From what I have read, the hash functions cannot be reversed as it is a "one-way" function, mathematically speaki...
This probably a rather naive question given my limited knowledge in the code I've been looking at, but I want to get my head around it before I start diving into writing actual code myself. I'm writing a common set of tools for PHP and most of my inspiration has come from the .NET framework. The ironic thing is that I...
I've been reading over and over that functional languages are ideal (or at least very often useful) for parallelism. Why is this? What core concepts and paradigms are typically employed and which specific problems do they solve? On an abstract level, for example, I can see how immutability might be useful in preventi...
I'm a newbie for PHP ecommerce applications. For my academic activities, I need to complete a shopping cart system with basic shopping cart functions. I have studied several apps which are already developed. I noticed that most of them are using encrypted product ids. I mean they are not just plain numbers. As I think ...
Given immutability (which is often encouraged and said to be one of building blocks of functional programming) and CQS (which says that commands should not return a value other than void/unit), how do these work together? For example: How would you perform a series of commands (eg multiple file copies, which can throw ...
I have three views in my program (iOS app). Only one of them is ever active at the same time so I set the visibility off for two of them and switch visibility as the user presses buttons. The views are initialized as visible so I set the visibility off in code before the main view shows. I can do [view1 setAlpha:0....
Say that you want to rotate something 360 steps 100 times. You now have a choise to pre-calculate 360 sin and cos values once and then use the stored values 100 times, or you can calculate sin and cos every time. As far as I understand on modern CPUs you're better off just calculating sin and cos each time because the ...
We use TFS at my workplace to manage our source code and track development. Whenever we have a bug or work to do, we always have to do the following two tasks as a minimum: Test the work, or decide whether testing is needed. Update the release notes for the current release, or decide whether it needs a specific entry....
Please note that I asked the same question on stackoverflow but they directed me to ask here. While I am trying to discerne the difference between the application logic and business logic I have found set of articles but unfortunately there is a contradiction between them. Here they say that they are the same but the ...
I am newly employed by a company. After a couple of weeks, I have heard lots of time that there is a huge project which most of the programmers are working on it. They call it something like Managing Everything Software. Then, somehow I got the document which they define what the MES will do. The document itself was 60...
I am in the process of designing and building a large-scale inventory management software-as-a-service that will, hopefully, live a long and fruitful life. Therefore I am exerting a lot of effort up-front to ensure the application will be maintainable and horizontally scabale. I really enjoyed this talk by Mathias Verr...
I was watching this talk about implementing Async IO in Rust and Carl mentions two potential models. Readiness and Completion. Readiness Model: you tell the kernel you want to read from a socket do other things for awhile… the kernel tells you when the socket is ready you read (fill a buffer) do whatever you need free...
I am trying to calculate the break-even price on an individual product given a percent of the price I sold it for and the price I bought it for. For example: I buy an item for $200 and the fees on the sale of the item are 13% of the final sale price. I want the answer to be $230. $230 (sale price) * .13 (percent fee) ...
A product version, such as v1.0.0.100, represents not only a unique production release of software, but helps identify feature sets and hotfix stages for said product. Right now I see two ways to maintain the final package/build/binary version of a product: Version Control. A file somewhere stores the version number. ...
I went through the Django tutorial with in mind to go through it again using it to set up my small app. So now I am making a simple app where users can search a large set of strings and get a subset as a result. The only relevant search criteria is the first and last character of the string. So the table is static, me...
Consider this: public function polynominal($a, $b, $c, $d) { return $a * pow($x, 3) + $b * pow($x, 2) + $c * $x + $d; } Suppose you write various tests for the above function and prove to yourself and others that "it works". Why not then remove those tests, and live happily ever after? My points is that some fun...
The documentation states: An array that represents the months of the year in the current locale. This follows normal convention of January being month number 1, so it has a length of 13 and month_name[0] is the empty string. Is this level of skeuomorphism warranted? Or is it confusing and potentially bug prone to...
So, one of the differences between "main memory" and disk storage is durability -- the data on hard disks will stay accessible and unaffected even if the host machine crashes or loses power. One can also use distributed systems which replicate the data across many servers, and from what I can tell, on sufficiently fas...
The title says it all, basically. Are there any deterministic compression algorithms - that is, an algorithm which, given identical input, will always produce identical output? As far as I know, all widely-used compression algoritms are "adaptive" and will vary their output based on whatever heuristic they happen to b...
My new company has never had unit testing, but have finally been persuaded to introduce it. They have chosen Google test and, for some reason, want to run the unit tests from within Eclipse (where I, personally, would run it from the command line, preferably as some sort of CI and/or check-in process). With hundreds, p...
I have an API that uses oAuth2 and my own mobile apps that use this API as their backend. Since users can be logged on via multiple devices (i.e iPhone, iPad, android tablet or android phone) at the same time, I need the API to distinguish between each connection. I would like to do this via separate access tokens: eac...
I am new to a team developing a very large web application. Prior to my start, the team had 0 automation in place and just did everything by hand. This was possible because they were only a team of 2. I am now gradually changing this but obviously I can't just make everyone start from scratch and "do it right". A probl...
I'm trying to switch my brain in to a NoSQL mode (document oriented database). I created a JSON datastructure that looks a little bit like this { "listInstances" : [ { "listClassId" : 1, "listInstanceName" : "Test", "instanceFields" : { "header" : [ ], "rows" : [ ...
I've inherited a pretty big and old project with a tiny bit of technical debt which is still under active development. A couple of months ago we made the jump from Eclipse+Ant to Android Studio+Gradle. I don't have much experience with gradle now and had a lot less back then, so a colleague (who is also working on the ...
Located here, RFC 7231 is all about the HTTP protocol (status codes) I'm developing an in-house web application for my university's department and I'm at a (probably unimportant) impasse. I'm reducing users' access to resources based on role (student, faculty, staff) and have it working just fine. However, when a user ...
My application has a configuration file and a "Settings" window. When the user confirms the changes in this window they are applied and written to the config file. These settings are often changed and referenced throughout my program. I'm trying to figure out how to model the accessing and manipulating of these setting...
I am starting a small ASP.NET MVC project, each task on the board must come with unit tests. The project is small, just a few pages with not that much processing, so I decided not to implement DI. My thoughts being DI is for larger projects with dependency graphs. However, now I am writing tests it has made me realise...
We are using the git flow workflow, and it sometimes happens that we have long-lived feature branches. Of course we can merge from the develop branch into our feature branch, when another feature branch gets finished and merged to the develop branch. However, is it a good idea to merge directly from other feature branc...
I am writing a toy compiler. During the semantic passes, I want to add information to the AST. Which of the following is the best approach? Define 1 mutable AST type whose fields are updated with each pass Define multiple immutable ASTs, each of which are an input and output of a semantic pass A mix of both?
I am using nhibernate in a quite big project. The system has a settings table which has 10 columns and one row, there is always a row and it should not be deleted only modified. Concurrency can be a problem as many clients can increment columns in the table like LastReceiptId. I'm thinking, it can't be a good idea to u...
Basic requirement I'm making a framework for learning purposes (and likely usage on personal sites). I'm using dependency injection in classes and I'm trying to design where would be a good place to instantiate dependency objects. Note: This is in the framework, not front end (so not templates etc). So when a class...
We are working on a simple login/registration form. Our login script checks to see if the username and password exist in the same row of the database. If it does exist, we bring the user to a welcome page. However, our problem lies when we check to see if the password exists in the database because we have applied the ...
I'm building a service on top of Google App Engine Datastore, which is an eventually consistent data store. For my application, this is fine. However, I'm developing tests that do things like PUT object and then GET object and checking properties on the returned object. Unfortunately, because the datastore is eventuall...
I can sell a software which uses an open source library as long as I provide the source of this software with the binaries. Can I make the source available only to those who bought the software? Can the customers give the source code to anybody? Will this happen? How is it considered by the open source community? Th...
I'm currently designing a REST-API with the following properties: Backend for a single page application (Later Apps) Integrated user database for each instance HTTPS/TLS only Authentication with a username / password combination My current approach for the authentication process is the following: (Client) POST Us...
The Austrian electronic ID card relies on the so-called sector identifiers. For example a hospital gets to identify a person by getting a sectorId for that person, which is computed roughly as follows: sha1(personalId + "+" + prefix + sectorId); // prefix is constant and irrelevant Is that a good idea? I think the pos...
I am testing some AngularJS code using Selenium. Angular updates the DOM in unpredictable order, sometimes completely async (via setTimeout), so it is difficult to know when the DOM has been completely updated after an AJAX request (or if the AJAX request has finished or not). (Because of this, all solutions that purel...
I'm creating a very small text editor in C++ with the ncurses library. So far, it works great. I have implemented the Gap Buffer data structure to make the editing more efficient than a line-based buffer. I have considered the Ropes data structure, but it seemed very complex for this. However, I'm now trying to impleme...
I'm building an embedded text editor consisting of a keyboard, an LCD display and a PIC32 microcontroller, to be programmed in C. The application should look, for example, like the GNU nano editor. The display is 40x16 characters big. I'm currently wondering what would be a good abstraction from the display. We could c...
I'm currently working on design of small web service, and I have a following feature (simplified): After some user actions, there is a wait period (ranging from 30sec to 40h) and after it's passed, the server should update database entry for the task, unless user cancelled it during the waiting period. Executed task i...
I am trying to understand how to design classes which take an input, do some processing, and return a result. More specifically, should the object store the intermediate results between function calls as state, or should all methods be static, and pass params around. Example: I am currently working on a class which det...
I'm working on a small project coded in Python that uses a single button for input and a RGB LED as feedback, which responds to button presses and asynchronous events from the network. As the feedback has become more complex (lot's of ifs, elses and timers), it's become evident that a UI design pattern, such as MVC or ...
So it's well known that C does not have any array bounds checking when accessing memory. Nowadays, if you call myArray[7] when you initialised it as int myArray[3], your program will get a segfault and crash thanks to protected memory. Now, if you have an argument in a function such as myFunc(int *yourArray), but you k...
I am running in the exact problem Robert Martin mentioned when having a class named Manager, mine has too much (redudant) code. I am writing a system doing computations on many buffers containing data form a timestamped source. The Buffers store different data types, they are template classes. When a new Observation...
Admittedly that's a bad title, but the full title would be far too long. To give some context. I volunteer at a charity where I maintain a MSSQL Database and an MS Access client application and I'm currently in the process of completely overhauling and rewriting the existing system to use .NET applications and PowerShe...
I have a class called MyClass and a method called Get that looks something like this: public class MyClass{ string ClassVariable1 {get; set;} string ClassVariable2 {get; set;} string ClassVariable3 {get; set;} public MyClass Get() { ..set variable1, variable2, and variable3.. ...
While I understand that the difference between integral and long values is blurred in Python, the difference between floats and integral values is not. Therefore, I'm having a difficult time understanding why math.ceil and math.floor return floating-point values when the only possible outcome is integral, whole numbers...
I am working on an application that requires manual approval of requests put in by customers. Now lets say there are 10 people involved in this operation and each of them has a webpage in front of them that serves one request after the other. The problem I am trying to solve is that the same customer request should not...
Imagine, I have class IAlgo which is an interface. I have derived from him and implemented his single method called matchCount in different implementations - AlgoA1, AlgoA2, AlgoA3, AlgoB1, AlgoB2. class IAlgo { virtual int matchCount(T1* p1, T2* p2) = 0; } class AlgoA1 : public IAlgo { virtual int matchCount(...
Say I define an interface IAnimal which has a pure virtual (abstract) method called eat like this: class IAnimal { virtual void eat(Food*) = 0; }; In the future I inherit form IAnimal and create different animals. and eventually I find out that some animals need not only food to eat but also other things. Say in my...
If a User is exchanging messages with a Server over HTTPS, could a man in the middle intercept messages and send them several time. For instance, George orders a laptop on a https e-commerce, could Dimitri, a man in the middle, intercept the message and send it 100 times to the e-commerce so George will have 100 laptop...
In MVVM (or Presentation Model), my (web) view listens to a CLICK event and calls a function of the Presentation Model to ask for the result. To clarify, the presentation model lives browser-side. The presentation model then calculates the result asynchronously. Is it then OK for the Presentation Model to return a (Jav...
My project has a single message stream (communicating with an external device) which is accessed via multiple client threads. The workflow is: There is a thread (the "messaging thread") which reads the message stream and is able to dispatch received messages to clients. This works by waiting on a thread-safe queue whi...
In company where I work we have lots of "utility" classes, each has lots of code inside (thousands of lines), and they are all static. And one static methods call anothers. The problem here is that when you want to test other classes you have lots of pain when tested function uses these static utility classes inside be...
Our company uses multiple log file formats. We would like to develop a series of tools to parse them, often the same core functionality for multiple log file formats. A classical example is generating Message Sequence Charts from the log files (other candidates are memory usage, stack size and time measurement between ...
My first attempt at this question was too theoretical, so I've rewritten it with actual code. See the edit history if you care. Supposing this logic, "suffering" from the arrow anti-pattern: /** * Function:effective * ... the DateTime the org should be considered expired (or null if never). * * If a non-group org h...
I have a Private Key that is regularly used to decode incoming files during off-business hours as part of an automated process. Currently, it is stored in the application code itself, and only ever used for this process - but this is probably not a good idea, even though our application is internal-facing only. Wher...
The short question: How do you follow Test-Driven Development on a project that spans multiple languages? Specifically, I'm writing a web application that uses JavaScript and PHP, and I want to follow the TDD principles, but I'm not sure how to integrate them. Do I run separate test suites for the JS and PHP sections, ...
I am writing an app that is supposed to talk to a web service. Let's say it's a chat app. It would need to receive a stream of new messages (so that they are pushed to the interface as quickly as possible), as well as send its own messages. Furthermore, I'd like the interface to be as responsive as possible, so immedia...
I'm not a Asp.net/C# developer myself but recently had to slightly refactor a Asp.net/C# project and I had to use Session at some point. When working with the session, regardless of the data type that I was specifying for the session variable, I had to cast the session variable any time I needed to access it. Session["...
I'm trying to make sense of IBM Jazz. I'm trying to figure out what it is, and what it isn't. "Streams" have been giving me trouble. From IBM's online library: The stream is similar in concept to a branch in most other version control systems. However, there are some significant differences that enable specifi...
Lately I came across a way of using mutables which I had not thought of before. Let's say you have a list comprehension which calls a method, and you put the result in a list like the following (normal stuff): my_list = [my_object.do_stuff() for my_object in all_objects] The do_stuff method does some loop computations...
An out of source build is a build which can be in any directory other than the source directory I have a project which contains relative paths to some resource files, needed at runtime, which are located close to the source directory. But when I build the project in an arbitrary folder, the resource files are (obviou...
I have designed and developed a C++ API. Its dependencies are: BLAS - custom license - http://www.netlib.org/blas/#_licensing LAPACK - modified BSD - http://www.netlib.org/lapack/LICENSE.txt GLPK - GPL Mytonly restriction, besides being properly quoted as the author, is that I DO NOT want those who download it from m...
Most of the static code analysis tools which analyse class dependencies generate dependency pairs of classes where each pair represents a direct dependency between two classes. Given those dependency pairs, it is straight forward to calculate number of direct dependencies of a particular class. However, if we have to c...
A colleague of mine told me that he is thinking in making our CI server to revert commits that failed the build, so the HEAD in master is always stable (as in passing the build at least). Is this a best practice or it may be more problematic than just leaving master broken until the developer fixes it? My thinking is t...
Let's say I have 14 days sprint iterations where I have several stories for new features, few improvements and some bugs to fix. I also deploy those changes when they are ready, I'm not waiting for end of sprint. My problem is - how to track semantic versioning of products developed and maintained like this? If there w...
So I have a rendering engine, and I have a resource manager that adds classes that derive from type 'Resource'. It's a very flexible and generic resource manager, of which only one can exist (it is a static class). Thus, a class ShaderProgram or Camera can easily be added like so: rm::add("textShader", new ...
I'm trying to make a meteor app which every user can extend. Meteor uses hot code swapping which I would like to use, so I'd probably need to save scripts on file system of the server. Have You got any ideas to store and execute user-made scripts in file-system in both easy for the user and secure way?
I'm building a web-app for a licensing service. My domain models are Licenses, and they can be of two types at the moment: server and client license. They are almost same, except server license has softwareId field, and client license has hardwareIdArray (client licenses can be registered to multiple clients). So, I ha...
My question maybe related to this question - Encapsulating Internal Data Structure I have a class LCTile.java which contains a Coordinate.java class. Coordinate.java that contains latitude and longitude(essentially a Point2D.java). Now I wish to sort the coordinates by latitude or longitude for which I have already de...
In practical terms it means using an custom (immutable) class over a string or some other primitive type. Examples: Publishing: International Standard Book Number. Finance: International Securities Identification Number. Advantages: Can ensure the format of an identifier. Becomes a first-class member of the model. ...
I have a web service which allows to retrieve users: http://example.com/users. It returns a list of users. That service accepts a number of parameters (age, gender) to select which users to retrieve. Examples: http://example.com/users?age=34 http://example.com/users?gender=male Should that service return an error mes...
I'm trying to calculate the min/max, or the lowest to highest value range of a 48 bit floating point type MIL-STD-1750A (PDF) (WIKI). Ex: How a double range is 1.7E +/- 308 I've looked around for equations, and am unsure if what I have found will work. The first equation I found was The second was I'm not quite sure...
I am working on a design to create a generic rest client for our application for current and future integration's with multiple services (different external systems). Following is a high level diagram I am thinking of creating a RestClient per external host, and Store them in a Map with Service name as Key and RestCli...