instruction stringlengths 34 36.1k |
|---|
I have a relatively large GUI based OOP software (in Python) were I rely heavily on keeping references throughout the program. For example I would define a Main class with some stored options as an attribute (code example below). In a second class, e.g. OptionFrame I would pass the reference to that stored options obje... |
How will I have to update "views_count" each time(!) a user loads my page? It will be costly. And I don't need such accuracy when I update "views_count" after a user loads a page.
Then is there any way to buffer "views_count" to somewhere so that I'll be able to update a field in database in one fell swoop, say, by +5 ... |
I am working on a concurrency system based on message queues with an underlying thread pool. A queue can target other queues. Also a queue can be targeted by multiple queues (i.e. children) to create a tree hierarchy and to prioritise some of the queues.
I want to avoid signalling threads each time a message is queued ... |
Is it possible for two variables to point to the same piece of memory?
My professor wrote a short snippet of code where he created a second instantiation of a class and assigned it a previously created object and referred to this as two variables pointing to the same location/info in the memory, which left me pretty co... |
I'm using JWTs for user auth in a web application. I have a user db where each user's unique ID is their email address. To identify the subject of the JWT, I currently have a claim which stores the user's email address in the token. Does that pose a security problem? If so, should I be using a GUID or a hash of the... |
I was wondering if there is a recommended approach to defining a property of a plain object that is used for data transfer, for example via a REST-API which is a list of other objects. Which C# type should one prefer for defining those?
List<T> maybe? It's short, everybody knows it, and we don't have to cast or transf... |
Update: C# 9 should fix this problem using records :D
I was wondering if there is a recommended approach to initializing the properties of a plain object that is used for data transfer, for example via a REST-API.
Here are two variants I can think of:
public class Dto
{
public string Name { get; set; }
public... |
I am currently dealing with an app that has several classes which are used to compare files in various formats (xls, csv, xml, html, pdf...). They are all implementing an interface that is defined like this:
public interface ReportComparator {
// compare files (1 - match, 0 - no match, -1 - both files empty)
... |
If an enum type is dedicate only to a specific class, does it make sense to declare it inside the class itself? I mean, would it help to understand that this enum type was designed to be used only with this class? Another option would be to put them inside the same namespace.
We also need to consider that another Dimen... |
I'm building a RESTful API using Node/Express4 and so far I've been successful. However, I'm not sure where to implement URL data validation - should the router script block invalid URI requests or should it send the controller the invalid data for it to send back an error?
The expected URI is as in the following examp... |
Which is better? I noticed the latter is used in a lot of C code. People will typically malloc an array, and then pass that as a parameter to a function, which will then populate it. Whereas in Java, the former seems more popular.
Is one better than the other? If not, do language features invoke a preference?
|
Is it possible to lock "txt" files using GIT LFS , if not is there any alternative to lock files in git to prevent other users from using it (similar to Checkout in ClearCase)
|
I am designing basic software for smart wireless lighting systems. The software is GUI based, and I have a slider for the brightness setting of a light in my GUI. The lighting system has a RESTful API so I can listen to changes on the slider value and make an HTTP request with the value to the system. The thing is, it ... |
Lets say there is a real time application where a list is shared among multiple people and updates done to the list must propagate to all the subscribers of the list. Like in trello.
The list is stored in a database on a remote server and list is updated with an API call from the app. The changes are conveyed to the su... |
I have a Publisher object that raises an event at regular intervals (think of it something like a clock tick). I then have 100s (or 1000s) of subscriber objects (all instances of a single type or two) which may have to update themselves in response to the event. But most of the time the event won't apply to them, so th... |
If a feature that was done in 2, 3 months and before it was merged into the main branch, and both branches were under constant changes every day, should integration tests be written at this stage?
Will it be too early, because both branches are changing, the UI were changing, and even the specs were changing. If the in... |
Recently, I have been reading the JWT' RFC and I'm struggling to understand the meaning of claim names collision.
The registered claim names are more or less clear. If I got it right, these are addressed to provide JWT specification with a set of claims out of the box. 1
However, when it comes to public and private cla... |
For example, if there's multiple lines to be drawn, I could do
function drawLines(lines) {
lines.forEach(function (line) {
drawLine(line);
});
}
function drawLine(line) {
//...
}
and then in the "main" section of the code I would merely have to call drawLines(lines) rather than writing a forEach th... |
I am looking to build and host a website for a client. Their existing site has a facility that allows customers to make donations and they want the new site to have it too.
My manager has told them that we can just lift their existing code and data and put it onto our servers and has asked me to go ahead and do this.
I... |
The Clean Architecture suggests to let a use case interactor call the actual implementation of the presenter (which is injected, following the DIP) to handle the response/display. However, I see people implementing this architecture, returning the output data from the interactor, and then let the controller (in the ada... |
I'm currently working on refacting an existing project. Basicaly, I need to perform requests to remote services. Current solution is to write tasks to a database and then poll them using cron jobs. This approach creates quite high load on the database. I'm thinking of using a task queue, like Celery for example, to que... |
I was reading "Beginning Spring" and this particular paragraph caught my attention:
The DI pattern resembles other patterns such as Factory or Strategy.
We can say that with the Factory pattern the instantiation of objects
is still within the responsibility of the Factory definition, which
is your code, but with... |
Need an advice on how to achieve decoupling of UI graphs from content.
Preamble:
I have an abstract Sensor interface and a bunch of implementations. Interface defines a couple of functions, such as parsing text to actual values, etc.
On the other hand, each Sensor implementation has it's own defined maximum range, whi... |
I'm a student and I'm learning about domain driven design. From my reading, an important part is removing the getters and setters from a class (thus keeping the implementation of that class private). My question is how can you do unit tests for this class.
Consider the following example:
public class Account {
priv... |
I know that often catching all exceptions (C#: catch(Exception exception){...}) is deemed bad practice.
However, I believe that there are situations where it is perfectly reasonable to do it. For example, if I have a number of operations to perform:
foreach(var operation in operationBatch)
operation.Do();
and a ba... |
I develop primarily using Visual Studio on Windows. The problem is that after a while Windows gets bogged down and I'm faced with needing to reinstall Windows. Similarly switching to new machines is a problem.
Reinstalling Windows is painful because my development environment has a lot of dependencies (such as extra M... |
I would like to show a web page from another website and show it on my website. I want to annotate some text on their website content.
Conceptually I know what needs to be done:
- I will capture their web page's html and probably the css and js files and put them in a folder on my web server. I will keep the images url... |
Rust is advertised as a "concurrent" language, what does this mean specifically and how is it different from other languages such as C++?
|
I am a religious person and make efforts not to commit sins. That is why I tend to write small (smaller than that, to reword Robert C. Martin) functions to comply with the several commandments ordered by the Clean Code bible. But while checking some stuff, I landed on this post, below which I read this comment:
Reme... |
Many web application require a seed file -- a file, written in the same language as a web application, where I have data to pre-populate a database. This makes sense.
Nonetheless, I sometimes see that some parts of that data is extracted into separate, text files to be read from the main seed.{rb, py, php} file and i... |
Description:
Given an aggregator portal the user must be able to create, read and update the requested entity. The entity here are all of different types and live in different systems. The portal shows the metric of the entities at a given unit of time and allows an user to filter the details by their type, name etc. T... |
Built a microservice which will update column value each time when it is called.
Application stack - Spring boot ,hibernate and mySQL database.
Currently we have listed following approaches in case of concurrency scenarios
Creating a column of datatype timestamp ,assuming the customer holds this timestamp value in re... |
I'm trying to practice TDD in my personal project and I wonder how to deal with the situation when after adding new test it pass from the start based on existing implementation?
On the one hand the new can test provide additional documentation of the design and a protection from accidental violation of assumptions.
On ... |
Problem description:
I am running performance test of calculation of PI number with primitives and with BigDecimal class.
Calculation of PI with primitives is around 5-6 times faster than the same algorithm, but with BigDecimal class.
I see a problem with creation of new BigDecimal object in the for loop, when adding ... |
I am building a CMS and need guidance on how to structure the application. I simply do not understand when I should use interfaces or an abstract class.
The system being built is using .Net Core and EF core I plan to allow MySQL and SQL Server as datasource. I also want a modular approach where I can add things on a pa... |
I have a simple task this is what I need the code to do:
Read data from a third party REST resource.
Parse the json object to match my internal structure.
Save the parsed data in my database.
I could just be lazy and have everything done in a single method, but I want to apply best practices, apply tests and have cle... |
I'm building an application with events in different countries and cities. An event is always presented in a local time of a place where it occurs.
Therefore I'm thinking that I won't need a time-zone information along with a date-time of an event in database.
Are there any arguments against this? Should I change my mi... |
Inheritance vs coding to an interface is something I have wondered with respect to proper architecture design but actually have not run into an problems when using abstract inheritance over coding to an interface in my own projects.
According to SOLID principles of OOP Design (and general OOP advice), you should code t... |
does anybody know how the code smells "rigidity", "fragility", "immobility" and "viscosity" can be explained in short code examples?
I've found a lot of text but never a source code example.
Thanks for your hints.
Are there at least very pratical examples, like the following
- rigidity: "if the access permission is che... |
By easy I mean easy to implement in code.
By reliable I mean that it doesn't depend sources who might fail under which there is no good control.
By secure I mean that it cannot be worked around or that if it could be worked around it would be pretty complicated.
The best solution I can think about for the moment is try... |
I'm looking for patterns or best practices for maintaining different versions of an API contract. There's lots of information on the internet about how to version API's (URL's vs. headers etc), but this question is related to the mapping from one object model to different versions of the contract types (DTO's), and for... |
I'm working on parsers that not only process delimited content, but also escape sequences within certain portions of that content. I'm contemplating the efficiency of several approaches to tokenization and would appreciate thoughts on the following.
To use JSON as but one example, there's a few ways to process the foll... |
I was coding some functions in C++ and wondered how different versions of those functions would affect generated assembly code. I put different versions into the Godbolt Compiler Explorer Tool and looked at the generated assembly. It was an interesting experience to see those differences and how some versions that seem... |
I'm working on a little pet program in C where I have a game board that consists of a bunch of squares:
typedef struct _square {
bool checked;
} Square;
typedef struct _board {
Square *squares;
uint8_t width;
uint8_t height;
} Board;
I don't want these structs to be visible to the public, so instead I... |
I have a restful api router , where it connects with database and returns some rows. So is it Unit test or Integration test ? From my knowledge, unit test doesn't connect with external services likes database, files, ... . and how to write an actual unit test for restful api ?
|
I am currently in the process of trying to master C#, so I am reading Adaptive Code via C# by Gary McLean Hall.
He writes about patterns and anti-patterns. In the implementations versus interfaces part he writes the following:
Developers who are new to the concept of programming to interfaces often have difficulty let... |
I am looking for a way for providing customers with hot-fixes and patches of my product.
The patch could contain one or more hot-fixes, and customer should be able to check/uncheck any of hot-fix(es) from a list during the update installation.
Every hot-fix may contain operations like:
Add/Remove/Replace file
Start/st... |
Summary
Our company runs two week sprints for our software development team. We have many projects our team shares with some being individual projects. We've noticed that when we end our sprint an hour or so before our sprint review meeting that we sometimes have problems demoing our software in the sprint review meeti... |
Recently came across MDDA, I think the term was first coined by Salesforce (pg3) and others have followed it like Metadata Driven Architecture
at benefitfocus.com (less dense and well written).
The design sounds useful for enterprise products where the platform is flexible enough to help customers tailor (by end user ... |
I have an ASP.NET web site on a shared server. The site is mainly used to house some WCF services that are used by a desktop application.
We had a problem in that the server stopped responding, and the hosting company said that the application pool logs showed that we had hit our memory limit (500Mb), which caused the ... |
We have a number of systems that are based on the competing consumers pattern. We currently monitor the delay between an item of work being queued and processing finishing, however, as throughput increases, this metric will only increase over the average when the system is already above its maximum capacity - the point... |
Currently we are using a tag for every build on master which passes CI. This leads to a lot of tags (3-10 per day). The good side is, that those commits are easily human readable, show the version (v.X.Y.ZZZ) which is also shown in the .exe built and deployed of that very commit making it very easy to find the exact co... |
Classical programs run a loop with prioritized ISRs. How do RTOS do this differently of better?
|
I am very new Java and have been messing around with a program that essentially prints a random line of characters based on random char values and array manipulation.
I am having a lot of trouble understanding the object-class relationship as my only other programming experience comes from MATLAB. Therefore, I have be... |
Problem
I have a graphical console widget that receives output from an interpreter. Unfortunately the console is not fast enough to paint the output in real-time. So I had to implement a buffer(FIFO Thread Safe Queue) that delayed the writes to the console by 5ms. So when normally a loop of 1000 prints would be done in... |
In many applications the 'UI thread' is special and framework UI updates must be dispatched from this thread.
However, in order to avoid locking the UI slow tasks are executed in background threads and the results propagated back to the UI thread to be displayed.
Different frameworks solve this in slightly different wa... |
Our team is building an Android app using Kotlin (if that matters at all) by following the guidelines described by Uncle Bob (Robert Martin).
The presentation pattern we use is MVI. We have presenters that communicate with Use Cases/Interactors and convert the resulting entity objects into ViewModels, suitable for rend... |
I noticed something strange after compiling this code on my machine:
#include <stdio.h>
int main()
{
printf("Hello, World!\n");
int a,b,c,d;
int e,f,g;
long int h;
printf("The addresses are:\n %0x \n %0x \n %0x \n %0x \n %0x \n %0x \n %0x \n %0x",
&a,&b,&c,&d,&e,&f,&g,&h);
return 0... |
Suppose I have the following devices:
Device A
Device B
Device C
(...)
Also, for each device, I have the following measurements:
Measurement 1
Measurement 2
(...)
Each measurement event includes a measurement id (int), a date (DateTime) and a value (double).
What I'm trying to achieve is, in an event driven scenario, h... |
I have an array that contains over 150,000+ object pointers of over 300+ different classes, but they all inherit from the same base class. Obviously that's very inefficient when we need to search for an object.
I've thought about splitting this array per-object-type, which got some better performance, but not as much a... |
I have to store many pdf/jpg/png file of max 10mb in a filesystem, and need to save their metadata on a database.
The SFTP and the DB may be on different nodes. On WS, I've a local db where I can check the login and ask the address to the database and the filesystem.
I was wondering: what happens if DB fails just befo... |
Overview
This question really becomes can I ask a software developer in Argentina or a software developer in Zimbabwe for a component in a standard way?
Background
Something that acts like I am thinking is how in the construction industry there are industry-specific classification codes, the Construction Specifications... |
I keep thinking I have my head wrapped around the Liskov Substitution Principle, and then I realize I don't. Here's where I've gathered from
StackExchange:
Subclassing Square from Rectangle violates LSP because if you change the width of a Square the height changes too.
Null Objects don't violate LSP.
Those seem to c... |
My company has one repository that contains five top-level projects, which are all different "services" (that being the flavor of the month). Even though they're all in a single repository, they're deployed separately and treated as different applications. We have some common code that we would like to share between al... |
I have a list of steadily growing values like 19:57(12.259), 19:58(13.101) stored in mongodb.
Now I want to find out if the value grew 50% within 30 minutes within the last 3 hours.
My first naive approach was to take the value from 3 hours ago (a) and then look for the point in time when the value is greater than or e... |
One of the most important rule in TDD is to write the simplest test to implement the simplest code in order to get closer to the end of a project.
I'd like to implement the game of Briscola.
It's a simple card game, with 40 cards, 2-5 players, and simple rules.
To start, I thought the best thing to implement was the c... |
I just debugged a problem which proved to be that "and" evaluated both arguments before checking whether either was false. That's fine, not all languages handle x = (will_return_true() || loop_forever()) ? "win" : "lose" in short circuit fashion.
Is there prior art on a symmetric equivalent?
Interpret x = (loop_forever... |
I've read in a lot of forums, a lot of users agree C++ is faster than Java (even if it leads for a microsecond, it is important), so why are the majority of data mining software or software tools developed in java? Shouldn't there be a greater advantage by using C++??
|
In Python it is common to have "doctests" - simple tests inside the documentation of classes and methods. Their main advantage is that they can easily be executed while editing the code - when I change some code, I can run all tests with a single click, I do not have to open another file.
In Java AFAIK there is no "do... |
I have this method, which has multiple private calls: GetConfigStatuses(), ApplyFilters(), GetConfigListInfo().
Since these do not expose anything public I cannot test them like I would a public. And I am not changing access level, that would be a smell.
So the only thing I can actually Verify and Assert in this meth... |
Is it ok when I do rebase and force push in branch which is used only by me? And will I have a problem after merge this branch in master later?
A few situations to illustrate this:
We have master, I need to add some feature, so:
git pull origin master
git checkout -b new_feature
make some changes inside my branch
g... |
I am interested in whether IDEs, compilers or linkers are considered SOUP in IEC62304. I found one website which claimed this is not the case. I think I agree based on my reading of the standard, however, I would like to double check.
|
I'm writing some pedagogic material and when I started explaining what an API is I realized I didn't know why we say "application programming interface" instead of just "programming interface". Does anyone know the history?
|
I am a self-taught programmer, and started my job as a PHP developer,in a small company.
I then got some work to write python script. I didn't have any senior with proper Python experience. So I started learning on my own, and started with work.
With time, it has happened that, I have written about 90-100 scripts, all ... |
I want to have functions that convert numeric values into strings in English words, to pluralize nouns, to inflect, break by words and so on. I will use these throughout a big project. Normally I would put them as pure static methods in a StringHelper class with nothing but static methods. But it there a better way to ... |
I'm very new at writing Cucumber tests. I'm writing Ruby helper functions to assist Cucumber step definitions. Should there be a separate set of tests to test my helper functions i.e. unit tests?
The step definitions are using the helper functions but there's nothing really testing that the helper functions are working... |
I am not sure why there are so many header file for the C standard library (stdio.h, stdlib.h, math.h).
How do these header files point to the same library?
I guess I am a little bit confused about what actually is a library. Where does it exist? Isn't a library linked to the program through a header file?
|
Early on in my career I was advised to add additional spacing between source code and an inline comment, like so:
de_cologne = (i == 4711 # 1
and j == 1799) # 2
Note the two spaces.
Supposedly, the reason for doing this is to distinguish operators that we use to delimit comments from other operators. P... |
Here's the representation of commonly seen Spiral Model:
From what it has been written in book and articles that I have read that in every iteration, the four steps are carried out in a loop:
Determine objectives/ Plan
Risk Analysis
Development / Code
Evaluation for next phase
But what are the sub-steps in each spir... |
According to this article, nginx has a master process and a number of worker processes. I'm trying to understand how a request is handled by the nginx worker processes. nginx uses an event driven architecture with multiple listen sockets and connection sockets.
Typically with an HTTP web server you'd have a single pro... |
I've read about NEAT/Evolutionary Artificial Neural Networks/Genetic Algorithms.
I understand the concept of choosing the fittest neural networks and breeding them to produce another one, but how exactly does this work?
Do you simply choose at random, weights from the parents, for the child network? Do you cross over t... |
I'm a software intern and I am assigned bugs to fix as well as features to add to the software. When I add features, everything works well. My problem is more with fixing bugs. I'm working on an extremely large codebase (span of millions of lines) with poor documentation (There are no comments, tons of magic numbers... |
I have written two small programs in which I declare a very small array.
Then I try to access values out of bounds.
The interesting thing I noticed that when I try to decrement the index I can decrement this very very further away. If I try to increment it the program crashes much faster.
This is my two codes and the r... |
Let's say I have an entity class ListOfItems with many related entities Item. These items are processed in a ItemsProcessor class that encapsulates the behavior. This class has several control lists and variable, for example, a processed_items list. Every time an item is done processing, it is added to that list:
class... |
TL/DR: When requiring another script in Node.js and defining it as a const should the variable name still be in camelCase like it was usual with var or should it instead be in SCREAMING_SNAKE_CASE as is more usual for a const?
const someVariable = require('...js');
vs
const SOME_VARIABLE = require('...js');
Longer v... |
Entscheidungsproblem placed a challenge in 1926,
Can we write an algorithm that checks to see if a proof can be solved without actually doing the proof?
Alan Turing reduced his Halting problem to this problem, by saying in his paper: "Corresponding to each computing machine 'it' we construct a formula 'Un(it)' and we... |
I have an API being used in an app which has URIs like these :
/API_Name_1/v1/param1/param2
/API_Name_2/v1/param1
/API_Name_3/v1/param1/param2/param3
/API_Name_4/v1/param1/param2
etc.
Now only one of my API [eg. API_Name_2] need to change while others need to remain the same. Should I just upgrade this particular one... |
Assume I have a class that represents a complex domain object with dozens of properties, such as a pension policy.
The GUI lists all pensions in a summary table that only contains a small subset of those properties.
The application uses an ORM such as .NET's entity framework.
When querying the db to populate the summar... |
I have a solution with an onion architecture using an asp.net MVC project. I also access Active Directory, and was wondering if one needs to loosely couple Active Directory access? Say I have :
Entity Framework POCOs
Repository
Service
MVC
The way I currently do it is by adding Active Directory operations classes dir... |
When debugging object oriented (Java) code, sometimes some field of some object is null while it should not be. I often spend what I feel is way too much time trying to figure out where it should have been set (at which point it's often quickly clear what went wrong).
If it had been a function argument, I'd be easy to ... |
Each time an iOS app is installed a new device token is generated.
When the app asks the user for permission to push notifications one can get the new device token value.
How can I know that this device token is from the same device (e.g., the user has deleted and reinstalled the app) and not from another device used b... |
I am running an ecommerce website built in Java using Spring and Hibernate. If I have to briefly describe current architecture then it is like this:
I am having two projects by name - store front and admin
Storefront project holds DAO, model, service, controller and views for showing the storefront view of website and... |
At my company we have multiple C# programs that use Dictionaries in a config class to keep track of the configuration and state of the program.
For example,
bool isFoo = config.GetBool("Foo");
This seems clunky to me for a number of reasons. For one, there is no easy way of knowing what is in the Dictionary at any gi... |
I'm working on a hardware product that contains an embedded Linux system. The majority of what we execute on that system is a set of Python code which currently has its own Git repository and is version controlled like a normal standalone software project.
I'm stuck on how to manage and version control the OS configura... |
I have an Enum in Python that looks something like this:
import enum
class Color(enum.Enum):
red = 'red'
blue = 'blue'
yellow = 'yellow'
puce = 'puce'
chartreuse = 'chartreuse'
And I want to have something like:
primary_colors = (Color.red, Color.blue, Color.yellow)
But naturally if I try and sti... |
The following explanation is rather detailed, but I think if I simplified the problem at hand no proper answer could be given.
I'm working on a scripting system for a game (for end users rather than internal developer usage). The game has both singleplayer and multiplayer modes. There is a base Script class, inherited ... |
For reasons lost in the mists of time, your project has a code coverage standard. Unfortunately, some new code has gone in which takes the coverage below this figure. John Doe is duly assigned to write more tests (since Jane Doe is off snowboarding). John is unfamiliar with the code and drags the coverage over the line... |
I got asked a question today that was so basic I was unsure how to answer it.
I had added some logging statements to our integration testing package, to find out what part of it was taking so long (many hours) to finish. These tests are huge, so I've been going through them adding logging to different parts as time pe... |
I always wanted to create software but was not really into websites.I see that popular programs(such as skype) don't make as much money as popular websites(such as facebook,twitter etc.).
Is this because monetizing websites is easier than programs? If so, why is that?
And what are some popular methods to monetize free ... |
I've developed an SDK (link) for a RESTful API in PHP, and my automated tests (example) are actually live calls against the API, which is bad for multiple reasons, mainly:
it takes a long time (about 3 hours) for the tests to complete
it's impossible to do concurrent tests because they'll interfere with each other
I ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.